[Python-Dev] Dropping bytes "support" in json
barry at python.org
Fri Apr 10 04:38:11 CEST 2009
On Apr 9, 2009, at 11:55 AM, Daniel Stutzbach wrote:
> On Thu, Apr 9, 2009 at 6:01 AM, Barry Warsaw <barry at python.org> wrote:
> 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).
> Won't this work? (assuming dumps() always returns a string)
> def dumpb(obj, encoding='utf-8', *args, **kw):
> s = dumps(obj, *args, **kw)
> return s.encode(encoding)
So, what I'm really asking is this. Let's say you agree that there
are use cases for accessing a header value as either the raw encoded
bytes or the decoded unicode. What should this return:
The raw bytes or the decoded unicode?
Okay, so you've picked one. Now how do you spell the other way?
The Message class probably has these explicit methods:
(or better names... it's late and I'm tired ;). One of those maps to
message['Subject'] but which is the more obvious choice?
Now, setting headers. Sometimes you have some unicode thing and
sometimes you have some bytes. You need to end up with bytes in the
ASCII range and you'd like to leave the header value unencoded if so.
But in both cases, you might have bytes or characters outside that
range, so you need an explicit encoding, defaulting to utf-8 probably.
>>> Message.set_header('Subject', 'Some text', encoding='utf-8')
>>> Message.set_header('Subject', b'Some bytes')
One of those maps to
>>> message['Subject'] = ???
I'm open to any suggestions here!
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 304 bytes
Desc: This is a digitally signed message part
More information about the Python-Dev