[Zope-Checkins] SVN: Zope/branches/2.12/ - fixed ObjectManagerNameChooser: BTreeFolder2 raises KeyError, not AttributeError
Yvo Schubbe
y.2009 at wcm-solutions.de
Thu Jun 25 10:35:19 EDT 2009
Log message for revision 101274:
- fixed ObjectManagerNameChooser: BTreeFolder2 raises KeyError, not AttributeError
Changed:
U Zope/branches/2.12/doc/CHANGES.rst
U Zope/branches/2.12/src/Products/Five/browser/adding.py
U Zope/branches/2.12/src/Products/Five/browser/tests/adding.txt
-=-
Modified: Zope/branches/2.12/doc/CHANGES.rst
===================================================================
--- Zope/branches/2.12/doc/CHANGES.rst 2009-06-25 14:12:36 UTC (rev 101273)
+++ Zope/branches/2.12/doc/CHANGES.rst 2009-06-25 14:35:19 UTC (rev 101274)
@@ -19,6 +19,8 @@
Bugs Fixed
++++++++++
+- ObjectManagerNameChooser now also works with BTreeFolder2.
+
- Correctly handle unauthorized exceptions in the ZPublisherExceptionHook.
Zope 2.12.0 b2 (2009/05/27)
Modified: Zope/branches/2.12/src/Products/Five/browser/adding.py
===================================================================
--- Zope/branches/2.12/src/Products/Five/browser/adding.py 2009-06-25 14:12:36 UTC (rev 101273)
+++ Zope/branches/2.12/src/Products/Five/browser/adding.py 2009-06-25 14:35:19 UTC (rev 101274)
@@ -206,9 +206,9 @@
class ObjectManagerNameChooser:
"""A name chooser for a Zope object manager.
"""
-
+
implements(INameChooser)
-
+
def __init__(self, context):
self.context = context
@@ -248,10 +248,10 @@
i += 1
try:
self.context._getOb(n)
- except AttributeError:
+ except (AttributeError, KeyError):
break
n = name + '-' + str(i) + suffix
-
+
# Make sure the name is valid. We may have started with
# something bad.
self.checkName(n, object)
Modified: Zope/branches/2.12/src/Products/Five/browser/tests/adding.txt
===================================================================
--- Zope/branches/2.12/src/Products/Five/browser/tests/adding.txt 2009-06-25 14:12:36 UTC (rev 101273)
+++ Zope/branches/2.12/src/Products/Five/browser/tests/adding.txt 2009-06-25 14:35:19 UTC (rev 101274)
@@ -7,12 +7,18 @@
First we need to import and setup some prerequisites:
+ >>> from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
>>> from Products.Five.tests.testing import manage_addFiveTraversableFolder
>>> from Products.Five.browser.adding import ObjectManagerNameChooser
>>> manage_addFiveTraversableFolder(self.folder, 'testoid', 'Testoid')
>>> chooser = ObjectManagerNameChooser(self.folder)
+ >>> id = self.folder._setObject('btreefolder', BTreeFolder2('btreefolder'))
+ >>> btreefolder = self.folder[id]
+ >>> manage_addFiveTraversableFolder(btreefolder, 'testoid', 'Testoid')
+ >>> chooser2 = ObjectManagerNameChooser(btreefolder)
+
Now we can start. ``INameChooser`` defines a ``checkName()`` method
that checks whether a given name is valid in the container or not.
Under the hood, ``ObjectManagerNameChooser`` calls ``_checkId()`` of
@@ -20,16 +26,25 @@
and don't contain invalid characters.
>>> chooser.checkName('abc', object())
+ >>> chooser2.checkName('abc', object())
>>> chooser.checkName('testoid', object())
Traceback (most recent call last):
...
UserError: The id "testoid" is invalid - it is already in use.
+ >>> chooser2.checkName('testoid', object())
+ Traceback (most recent call last):
+ ...
+ UserError: The id "testoid" is invalid - it is already in use.
>>> chooser.checkName('slash/slash', object())
Traceback (most recent call last):
...
UserError: The id "slash/slash" contains characters illegal in URLs.
+ >>> chooser2.checkName('slash/slash', object())
+ Traceback (most recent call last):
+ ...
+ UserError: The id "slash/slash" contains characters illegal in URLs.
``INameChooser`` also promises us a ``chooseName()`` method that
chooses a name for us in case we don't have one or that chooses a
@@ -37,12 +52,18 @@
>>> chooser.chooseName('', self.folder.testoid)
'FiveTraversableFolder'
+ >>> chooser2.chooseName('', self.folder.testoid)
+ 'FiveTraversableFolder'
>>> chooser.chooseName('abc', self.folder.testoid)
'abc'
+ >>> chooser2.chooseName('abc', self.folder.testoid)
+ 'abc'
>>> chooser.chooseName('testoid', self.folder.testoid)
'testoid-1'
+ >>> chooser2.chooseName('testoid', self.folder.testoid)
+ 'testoid-1'
Of course, if we start out with something bad, it isn't going to
become good automagically:
@@ -51,3 +72,7 @@
Traceback (most recent call last):
...
UserError: The id "slash/slash" contains characters illegal in URLs.
+ >>> chooser2.chooseName('slash/slash', object())
+ Traceback (most recent call last):
+ ...
+ UserError: The id "slash/slash" contains characters illegal in URLs.
More information about the Zope-Checkins
mailing list