The top-level compress function in bzip2 module also now
only accepts a byte string not a text string.

Python 3.0b2+ (py3k:65401, Aug  2 2008, 18:57:08)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bz2
>>> s='This is a line of text'
>>> bz2.compress(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument 1 must be bytes or read-only buffer, not str
>>> bz2.compress(s.encode('ascii'))
b'BZh91AY&[EMAIL PROTECTED]@
\x001\x00\xd0\x01\x13\xd2=F\x9eB\x8d\xf0\xb2\xa5\xd3(0"\xe5`\xbb\x92)\xc2\x84\x87\xe5\xdc\'\xe8'
>>>

In Python 2.x, text strings work, but in Python 2.x, we did not have
the distinction between binary strings and text strings anyway.

Since this is the way bz2 behaves, I have submitted my patch
for adding compress/uncompress functions in gzip module
also to follow the same behavior.

--Anand

On Sat, Aug 2, 2008 at 4:54 AM, Georg Brandl <[EMAIL PROTECTED]> wrote:
> Anand Balachandran Pillai schrieb:
>>
>> Try this in Python 3.0 trunk.
>>
>>>>> import zlib
>>>>> s='This is a string'
>>>>> sc=zlib.compress(s)
>>>>> sc
>>
>>
>> bytearray(b'x\x9c\x0b\xc9\xc8,V\x00\xa2D\x85\xe2\x92\xa2\xcc\xbct\x00/\xc2\x05\xcd')
>>>>>
>>>>> zlib.decompress(sc)
>>
>> bytearray(b'This is a string')
>>>>>
>>
>> This is wrong behavior as compress functions should return byte
>> ,not a bytearray. Same for decompress.
>>
>> Saw this while trying to write a patch for #3382.
>> Shall I file an issue ?
>
> I also wonder why compress() takes a Unicode string.
>
> Georg
>
> _______________________________________________
> Python-3000 mailing list
> Python-3000@python.org
> http://mail.python.org/mailman/listinfo/python-3000
> Unsubscribe:
> http://mail.python.org/mailman/options/python-3000/abpillai%40gmail.com
>



-- 
-Anand
_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to