[Python-ideas] Pre-PEP Adding A Secrets Module To The Standard Library

Steven D'Aprano steve at pearwood.info
Mon Sep 21 18:16:45 CEST 2015

On Sun, Sep 20, 2015 at 01:45:36PM +0900, Stephen J. Turnbull wrote:
> Chris Angelico writes:
>  > My personal preference for shed colour: token_bytes returns a
>  > bytestring, its length being the number provided. All the others
>  > return Unicode strings, their lengths again being the number provided.
>  > So they're all text bar the one that explicitly says it's in bytes.
> I think that token_url may need a bytes mode, for the same reasons
> that bytes needs __mod__: such tokens will often be created and parsed
> by programs that never leave the "ASCII-compatible bytes" world.

I expect that token_url would return a string (Unicode), but since
it's pure ASCII (being base64 encoded), if you want bytes, you can just
call token_url().encode('ascii').

Or maybe it should return bytes, and if you want a string, you just say 

Out of the two, I'm very slightly leaning towards the first (Unicode by 
default, encode to ASCII if you want bytes) than the second.

I'm very much not in favour of a "return_bytes=True" argument.


More information about the Python-ideas mailing list