[Checkins] SVN: zope.app.container/branches/3.5/ (merge from the trunk)

Christophe Combelles ccomb at free.fr
Mon Jun 16 05:02:35 EDT 2008


Log message for revision 87423:
  (merge from the trunk)
  - 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/branches/3.5/CHANGES.txt
  U   zope.app.container/branches/3.5/src/zope/app/container/btree.py
  U   zope.app.container/branches/3.5/src/zope/app/container/contained.py
  U   zope.app.container/branches/3.5/src/zope/app/container/interfaces.py

-=-
Modified: zope.app.container/branches/3.5/CHANGES.txt
===================================================================
--- zope.app.container/branches/3.5/CHANGES.txt	2008-06-16 08:59:45 UTC (rev 87422)
+++ zope.app.container/branches/3.5/CHANGES.txt	2008-06-16 09:02:34 UTC (rev 87423)
@@ -8,6 +8,10 @@
 - fixed #238579 / #163149: error with unicode traversing
 - fixed #221025 : adding menu is sorted with translated item
                   by using a collator (better localized sorting)
+- fixed #227617 :
+    - prevent the namechooser from failing on '+', '@' and '/'
+    - added tests in the namechooser
+    - be sure the name chooser returns unicode
 
 3.5.3 (2007-11-09)
 ------------------

Modified: zope.app.container/branches/3.5/src/zope/app/container/btree.py
===================================================================
--- zope.app.container/branches/3.5/src/zope/app/container/btree.py	2008-06-16 08:59:45 UTC (rev 87422)
+++ zope.app.container/branches/3.5/src/zope/app/container/btree.py	2008-06-16 09:02:34 UTC (rev 87423)
@@ -83,7 +83,6 @@
         return l
 
     def __len__(self):
-        #import pdb;pdb.set_trace()
         return self.__len()
 
     def __setitem__(self, key, value):

Modified: zope.app.container/branches/3.5/src/zope/app/container/contained.py
===================================================================
--- zope.app.container/branches/3.5/src/zope/app/container/contained.py	2008-06-16 08:59:45 UTC (rev 87422)
+++ zope.app.container/branches/3.5/src/zope/app/container/contained.py	2008-06-16 09:02:34 UTC (rev 87423)
@@ -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/branches/3.5/src/zope/app/container/interfaces.py
===================================================================
--- zope.app.container/branches/3.5/src/zope/app/container/interfaces.py	2008-06-16 08:59:45 UTC (rev 87422)
+++ zope.app.container/branches/3.5/src/zope/app/container/interfaces.py	2008-06-16 09:02:34 UTC (rev 87423)
@@ -247,7 +247,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