[Python-Dev] Dropping bytes "support" in json

Barry Warsaw barry at python.org
Thu Apr 9 13:01:19 CEST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Apr 9, 2009, at 1:15 AM, Antoine Pitrou wrote:

> Guido van Rossum <guido <at> python.org> writes:
>>
>> I'm kind of surprised that a serialization protocol like JSON  
>> wouldn't
>> support reading/writing bytes (as the serialized format -- I don't
>> care about having bytes as values, since JavaScript doesn't have
>> something equivalent AFAIK, and hence JSON doesn't allow it IIRC).
>> Marshal and Pickle, for example, *always* treat the serialized format
>> as bytes. And since in most cases it will be sent over a socket, at
>> some point the serialized representation *will* be bytes, I presume.
>> What makes supporting this hard?
>
> It's not hard, it just means a lot of duplicated code if the library  
> wants to
> support both str and bytes in an optimized way as Martin alluded to.  
> This
> duplicated code already exists in the C parts to support the 2.x  
> semantics of
> accepting unicode objects as well as str, but not in the Python  
> parts, which
> explains why the bytes support is broken in py3k - in 2.x, the same  
> Python code
> can be used for str and unicode.

This is an interesting question, and something I'm struggling with for  
the email package for 3.x.  It turns out to be pretty convenient to  
have both a bytes and a string API, both for input and output, but I  
think email really wants to be represented internally as bytes.   
Maybe.  Or maybe just for content bodies and not headers, or maybe  
both.  Anyway, aside from that decision, I haven't come up with an  
elegant way to allow /output/ in both bytes and strings (input is I  
think theoretically easier by sniffing the arguments).

Barry

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)

iQCVAwUBSd3Vf3EjvBPtnXfVAQKyNgQApNmI5hh9heTYynyADYaDkP8wzZFXUpgg
cKYL741MbLpOFn3IFGAGaRWBQe4Dt8i4CiIEIbg3X7QZqwQJjoTtFwxsJKmXFd1M
JR0oCB8Du2kE5YzD+avrEp+d8zwl2goxvzD9dJwziBav5V98w7PMiZc3sApklQFD
gNYzbHEOfv4=
=tjGr
-----END PGP SIGNATURE-----


More information about the Python-Dev mailing list