[Zope-Coders] Re: BTrees, Unicode, and Python 2.2

Guido van Rossum guido@python.org
Thu, 18 Oct 2001 12:16:04 -0400


> lib/python/BTrees/tests/testBTreesUnicode.py in the trunk.
> 
> When accessing the unicode key is prints <unprintable object>

I don't find the string "<unprintable object>" anywhere in the Python
or Zope source.  There are near misses though: the Python module
traceback.py and the Zope module lib/python/ZPublisher/HTTPResponse.py
both contain the string "<unprintable %s object>" where the %s is
replaced with a type name.

I can't reproduce your problem.  Regardless of which variant of the
test file I run, I always get this result:



$ python utilities/testrunner.py -f lib/python/BTrees/tests/testBTreesUnicode.py
Adding /home/guido/Zope/lib/python to sys.path.
Running: lib/python/BTrees/tests/testBTreesUnicode.py
check every item of the tree ... ERROR
try to access unicode keys in tree ... ERROR

======================================================================
ERROR: check every item of the tree
----------------------------------------------------------------------
Traceback (most recent call last):
  File "testBTreesUnicode.py", line 23, in setUp
    for k,v in self.data:   self.tree[k]=v
UnicodeError: ASCII decoding error: ordinal not in range(128)

======================================================================
ERROR: try to access unicode keys in tree
----------------------------------------------------------------------
Traceback (most recent call last):
  File "testBTreesUnicode.py", line 23, in setUp
    for k,v in self.data:   self.tree[k]=v
UnicodeError: ASCII decoding error: ordinal not in range(128)

----------------------------------------------------------------------
Ran 2 tests in 0.014s

FAILED (errors=2)

======================================================================
OVERALL FAILED (total errors=2)



Is this what you get?  If not, please be specific about what you *do*
get -- and how you run the test.

Are you using a recent enough Python 2.2 from CVS?  I fixed a bug
yesterday that *might* affect this (it fixed problems that Jeremy
experienced when running the Zope test suite with Python 2.2).

Note that the error reported here are to be expected -- you cannot
compare 8-bit strings and Unicode strings when some of the characters
of the 8-bit string have the high bit set (i.e. are not pure ASCII).
If you need to compare such a pair, you must convert the 8-bit string
to Unicode using an explicitly given encoding before attempting to
compare.

--Guido van Rossum (home page: http://www.python.org/~guido/)