[Zope3-checkins] CVS: Zope3/src/zope/app/container - sample.py:1.3

R. David Murray bitz@bitdance.com
Fri, 27 Dec 2002 13:39:03 -0500


Update of /cvs-repository/Zope3/src/zope/app/container
In directory cvs.zope.org:/tmp/cvs-serv7845

Modified Files:
	sample.py 
Log Message:
Fix bug revealed by improved IContainer unit test: check that name
contains no non-ascii values if it passes the string test.


=== Zope3/src/zope/app/container/sample.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/container/sample.py:1.2	Wed Dec 25 09:12:46 2002
+++ Zope3/src/zope/app/container/sample.py	Fri Dec 27 13:39:02 2002
@@ -86,8 +86,14 @@
 
     def setObject(self, key, object):
         '''See interface IWriteContainer'''
-        if not isinstance(key, StringTypes):
-            raise TypeError("The key must be an ascii or unicode string")
+        bad = False
+        if isinstance(key, StringTypes):
+            try: unicode(key)
+            except UnicodeDecodeError: bad = True
+        else: bad = True
+        if bad: 
+            raise TypeError(("'%s' is invalid, the key must be an " +
+                "ascii or unicode string") % key)
         if len(key) == 0:
             raise ValueError("The key cannot be an empty string")
         self.__data[key] = object