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

Tim Peters tim.peters at gmail.com
Sun Sep 20 02:19:27 CEST 2015


[Tim Peters]
>>  Token functions
>>     .token_bytes(nbytes)
>>         another name for os.urandom()
>>     .token_hex(nbytes)
>>         same, but return string of ASCII hex digits
>>     .token_url(nbytes)
>>         same, but return URL-safe base64-encoded ASCII
>>     .token_alpha(alphabet, nchars)
>>         string of `nchars` characters drawn uniformly
>>         from `alphabet`

[Chris Angelico <rosuav at gmail.com>]
> token_bytes "obviously" should return a bytes,

Which os.urandom() does in Python 3.  I'm not writing docs, just
suggesting the functions.

> and token_alpha equally obviously should be returning a str.

Which part of "string" doesn't suggest "str"?

> (Or maybe it should return the same type as alphabet, which
> could be either?)
>
>: What about the other two?

Which part of "ASCII" is ambiguous?

> Also, if you ask for 4 bytes from token_hex, do you get 4 hex
> digits or 8 (four bytes of entropy)?

And which part of "same"?  ;-)

Bikeshed away.;  I'm outta this now ;-)


More information about the Python-ideas mailing list