[Checkins] SVN: zope.app.container/trunk/ - fixed #227617 :
Christopher Combelles
cvs-admin at zope.org
Fri Jun 13 10:21:52 EDT 2008
Log message for revision 87367:
- fixed #227617 :
- prevent the namechooser from failing on '+', '@' and '/'
- added tests in the namechooser
- be sure the name chooser returns unicode
Changed:
U zope.app.container/trunk/CHANGES.txt
U zope.app.container/trunk/src/zope/app/container/btree.py
U zope.app.container/trunk/src/zope/app/container/contained.py
U zope.app.container/trunk/src/zope/app/container/interfaces.py
-=-
Modified: zope.app.container/trunk/CHANGES.txt
===================================================================
--- zope.app.container/trunk/CHANGES.txt 2008-06-13 13:54:45 UTC (rev 87366)
+++ zope.app.container/trunk/CHANGES.txt 2008-06-13 14:21:51 UTC (rev 87367)
@@ -7,7 +7,12 @@
- fixed #238579 / #163149: error with unicode traversing
- fixed #221025 : adding menu is sorted with translated item
+- fixed #227617 :
+ - prevent the namechooser from failing on '+', '@' and '/'
+ - added tests in the namechooser
+ - be sure the name chooser returns unicode
+
3.6.0 (2008-05-06)
------------------
Modified: zope.app.container/trunk/src/zope/app/container/btree.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/btree.py 2008-06-13 13:54:45 UTC (rev 87366)
+++ zope.app.container/trunk/src/zope/app/container/btree.py 2008-06-13 14:21:51 UTC (rev 87367)
@@ -86,7 +86,6 @@
return l
def __len__(self):
- #import pdb;pdb.set_trace()
return self.__len()
def __setitem__(self, key, value):
Modified: zope.app.container/trunk/src/zope/app/container/contained.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/contained.py 2008-06-13 13:54:45 UTC (rev 87366)
+++ zope.app.container/trunk/src/zope/app/container/contained.py 2008-06-13 14:21:51 UTC (rev 87367)
@@ -705,8 +705,46 @@
self.context = context
def checkName(self, name, object):
- "See zope.app.container.interfaces.INameChooser"
+ """See zope.app.container.interfaces.INameChooser
+ We create and populate a dummy container
+
+ >>> from zope.app.container.sample import SampleContainer
+ >>> container = SampleContainer()
+ >>> container['foo'] = 'bar'
+ >>> from zope.app.container.contained import NameChooser
+
+ All these names are invalid:
+
+ >>> NameChooser(container).checkName('+foo', object())
+ Traceback (most recent call last):
+ ...
+ UserError: Names cannot begin with '+' or '@' or contain '/'
+ >>> NameChooser(container).checkName('@foo', object())
+ Traceback (most recent call last):
+ ...
+ UserError: Names cannot begin with '+' or '@' or contain '/'
+ >>> NameChooser(container).checkName('f/oo', object())
+ Traceback (most recent call last):
+ ...
+ UserError: Names cannot begin with '+' or '@' or contain '/'
+ >>> NameChooser(container).checkName('foo', object())
+ Traceback (most recent call last):
+ ...
+ UserError: The given name is already being used
+ >>> NameChooser(container).checkName(2, object())
+ Traceback (most recent call last):
+ ...
+ TypeError: ('Invalid name type', <type 'int'>)
+
+ This one is ok:
+
+ >>> NameChooser(container).checkName('2', object())
+ True
+
+
+ """
+
if not name:
raise UserError(
_("An empty name was provided. Names cannot be empty.")
@@ -731,13 +769,36 @@
def chooseName(self, name, object):
- "See zope.app.container.interfaces.INameChooser"
+ """See zope.app.container.interfaces.INameChooser
+ The name chooser is expected to choose a name without error
+
+ We create and populate a dummy container
+
+ >>> from zope.app.container.sample import SampleContainer
+ >>> container = SampleContainer()
+ >>> container['foo.old.rst'] = 'rst doc'
+
+ >>> from zope.app.container.contained import NameChooser
+ >>> NameChooser(container).chooseName('+ at +@foo.old.rst', object())
+ u'foo.old-2.rst'
+ >>> NameChooser(container).chooseName('+ at +@foo/foo', object())
+ u'foo-foo'
+ >>> NameChooser(container).chooseName('', object())
+ u'object'
+ >>> NameChooser(container).chooseName('@+@', object())
+ u'object'
+
+ """
+
container = self.context
+ # remove characters that checkName does not allow
+ name = unicode(name.replace('/', '-').lstrip('+@'))
+
if not name:
- name = object.__class__.__name__
-
+ name = unicode(object.__class__.__name__)
+
dot = name.rfind('.')
if dot >= 0:
suffix = name[dot:]
Modified: zope.app.container/trunk/src/zope/app/container/interfaces.py
===================================================================
--- zope.app.container/trunk/src/zope/app/container/interfaces.py 2008-06-13 13:54:45 UTC (rev 87366)
+++ zope.app.container/trunk/src/zope/app/container/interfaces.py 2008-06-13 14:21:51 UTC (rev 87367)
@@ -287,7 +287,8 @@
"""
def chooseName(name, object):
- """Choose a unique valid name for the object
+ """Choose a unique valid name for the object.
+ This method is expected to always choose a valid name without error.
The given name and object may be taken into account when
choosing the name.
More information about the Checkins
mailing list