
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 token_url().decode('ascii'). 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. -- Steve