[Python-Dev] PEP 461 Final? (original) (raw)
Ethan Furman ethan at stoneleaf.us
Sun Jan 19 03:34:49 CET 2014
- Previous message: [Python-Dev] PEP 461 Final?
- Next message: [Python-Dev] PEP 461 Final?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 01/18/2014 05:21 PM, Neil Schemenauer wrote:
Ethan Furman <ethan at stoneleaf.us> wrote:
So, if %a is added it would act like:
--------- "%a" % someobj --------- tmp = str(someobj) res = b'' for ch in tmp: if ord(ch) < 256: res += bytes([ord(ch)] else: res += unicodeescape(ch) --------- where 'unicodeescape' would yield something like "\u0440" ? My patch on the tracker already implements %a, it's simple.
Before one implements a patch it is good to know the specifications.
Just call PyObjectASCII() (same as ascii()) then call PyUnicodeAsLatin1String(s) to convert it to bytes and stick it in. PyObjectASCII does not return non-ASCII characters, no decode error is possible. We could call PyUnicodeAsASCIIString(s, "strict") instead if we are afraid for non-ASCII bytes coming out of PyObjectASCII.
I appreciate that this is the behavior you want, but I'm not sure it's the behavior Nick was describing.
--
Ethan
- Previous message: [Python-Dev] PEP 461 Final?
- Next message: [Python-Dev] PEP 461 Final?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]