gh-145980: Add support for alternative alphabets in the binascii module#145981
gh-145980: Add support for alternative alphabets in the binascii module#145981serhiy-storchaka wants to merge 10 commits intopython:mainfrom
Conversation
…i module * Add the alphabet parameter in functions b2a_base64(), a2b_base64(), b2a_base85() and a2b_base85(). * And a number of "*_ALPHABET" constants. * Remove b2a_z85() and a2b_z85().
Doc/library/binascii.rst
Outdated
|
|
||
| .. data:: UU_ALPHABET | ||
|
|
||
| The Uuencoding alphabet. |
There was a problem hiding this comment.
I think it's uuencoding for Unix-to-Unix instead of Uuencoding. I would suggest that you also link the Wikipedia page maybe?
There was a problem hiding this comment.
I wrote "Uuencoding" because this is how it is written in https://en.wikipedia.org/wiki/Base64.
There are no any links for a2b_uu() and b2a_uu(). There were no links in the old uu module.
There was a problem hiding this comment.
The page seems to use a capital letter (https://en.wikipedia.org/wiki/Uuencoding) but not the sentence in the introduction:
uuencoding is a form of binary-to-text encoding that originated in the Unix
So up to you!
There was a problem hiding this comment.
I changed it to lower case. It is in lower case in other parts of the documentation and on other Wikipedia pages.
Doc/library/binascii.rst
Outdated
|
|
||
| .. data:: XX_ALPHABET | ||
|
|
||
| The Xxencoding alphabet. |
There was a problem hiding this comment.
I am not sure that it is worth to add this alphabet. Uuencoding, binhex and crypt were supported in Python earlier.
| return binascii.b2a_base64(s, newline=False, | ||
| alphabet=binascii.URLSAFE_BASE64_ALPHABET) |
There was a problem hiding this comment.
For clarity in the code, maybe have an _URLSAFE_BASE64_ALPHABET global variable?
There was a problem hiding this comment.
Do you mean importing binascii.URLSAFE_BASE64_ALPHABET as _URLSAFE_BASE64_ALPHABET? But we do not add this for binascii.b2a_base64 and other functions.
| static PyObject * | ||
| get_reverse_table(binascii_state *state, PyObject *alphabet, int size, int padchar) | ||
| { | ||
| PyObject *reverse_table; |
There was a problem hiding this comment.
I'd suggest having a goto error for cleanup in case this function grows.
There was a problem hiding this comment.
I think this is preliminary.
📚 Documentation preview 📚: https://cpython-previews--145981.org.readthedocs.build/