[Python-Dev] bytes.from_hex()

Ron Adam rrr at ronadam.com
Sun Feb 26 02:50:24 CET 2006


Greg Ewing wrote:
> Stephen J. Turnbull wrote:
>> It's "what is the Python compiler/interpreter going
>  > to think?"  AFAICS, it's going to think that base64 is
>  > a unicode codec.
> 
> Only if it's designed that way, and I specifically
> think it shouldn't -- i.e. it should be an error
> to attempt the likes of a_unicode_string.encode("base64")
> or unicode(something, "base64"). The interface for
> doing base64 encoding should be something else.

I agree

> I think we need some concrete use cases to talk
> about if we're to get any further with this. Do
> you have any such use cases in mind?
> 
> Greg

Or at least some where more concrete than trying to debate abstract 
meanings. ;-)

Running a short test over all the codecs and converting u"Python" to 
string and back to unicode resulted in the following output.  These are 
the only ones of the 92 that couldn't do the round trip successfully.

It seems to me these will need to be moved and/or made to work with 
unicode at some point.


Test 1: UNICODE -> STRING -> UNICODE
1: 'bz2_codec'
Traceback (most recent call last):
   File "codectest.py", line 29, in test1
     u2 = unicode(s, c)       # to unicode
TypeError: decoder did not return an unicode object (type=str)

2: 'hex_codec'
Traceback (most recent call last):
   File "codectest.py", line 29, in test1
     u2 = unicode(s, c)       # to unicode
TypeError: decoder did not return an unicode object (type=str)

3: 'uu_codec'
Traceback (most recent call last):
   File "codectest.py", line 29, in test1
     u2 = unicode(s, c)       # to unicode
TypeError: decoder did not return an unicode object (type=str)

4: 'quopri_codec'
Traceback (most recent call last):
   File "codectest.py", line 29, in test1
     u2 = unicode(s, c)       # to unicode
TypeError: decoder did not return an unicode object (type=str)

5: 'base64_codec'
Traceback (most recent call last):
   File "codectest.py", line 29, in test1
     u2 = unicode(s, c)       # to unicode
TypeError: decoder did not return an unicode object (type=str)

6: 'zlib_codec'
Traceback (most recent call last):
   File "codectest.py", line 29, in test1
     u2 = unicode(s, c)       # to unicode
TypeError: decoder did not return an unicode object (type=str)

7: 'tactis'
Traceback (most recent call last):
   File "codectest.py", line 28, in test1
     s = u1.encode(c)         # to string
LookupError: unknown encoding: tactis







More information about the Python-Dev mailing list