A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-April/088581.html below:

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

[Python-Dev] Dropping bytes "support" in jsonglyph at divmod.com glyph at divmod.com
Fri Apr 10 07:19:02 CEST 2009
On 02:38 am, barry at python.org wrote:
>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:
>
> >>> message['Subject']
>
>The raw bytes or the decoded unicode?

My personal preference would be to just get deprecate this API, and get 
rid of it, replacing it with a slightly more explicit one.

    message.headers['Subject']
    message.bytes_headers['Subject']
>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.headers['Subject'] = 'Some text'

should be equivalent to

    message.headers['Subject'] = Header('Some text')

My preference would be that

    message.headers['Subject'] = b'Some Bytes'

would simply raise an exception.  If you've got some bytes, you should 
instead do

    message.bytes_headers['Subject'] = b'Some Bytes'

or

    message.headers['Subject'] = Header(bytes=b'Some Bytes', 
encoding='utf-8')

Explicit is better than implicit, right?
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4