Skip to content

gh-145980: Add support for alternative alphabets in the binascii module#145981

Merged
serhiy-storchaka merged 12 commits intopython:mainfrom
serhiy-storchaka:binascii-alphabet
Mar 20, 2026
Merged

gh-145980: Add support for alternative alphabets in the binascii module#145981
serhiy-storchaka merged 12 commits intopython:mainfrom
serhiy-storchaka:binascii-alphabet

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchaka serhiy-storchaka commented Mar 15, 2026

  • 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().

📚 Documentation preview 📚: https://cpython-previews--145981.org.readthedocs.build/

…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().
static PyObject *
get_reverse_table(binascii_state *state, PyObject *alphabet, int size, int padchar)
{
PyObject *reverse_table;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest having a goto error for cleanup in case this function grows.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is preliminary.

@serhiy-storchaka
Copy link
Member Author

Damn, what is now? I spent more time fighting the CI than fixing genuine bugs.

@serhiy-storchaka
Copy link
Member Author

Are there other suggestions or notes? I am going to merge this PR, because it is a dependence for #146192 and other changes.

@picnixz
Copy link
Member

picnixz commented Mar 20, 2026

Not from side!

@serhiy-storchaka serhiy-storchaka merged commit 4507d49 into python:main Mar 20, 2026
50 checks passed
@serhiy-storchaka serhiy-storchaka deleted the binascii-alphabet branch March 20, 2026 11:07
@serhiy-storchaka
Copy link
Member Author

Thank you for your review @picnixz.

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 MacOS M1 Refleaks NoGIL 3.x (tier-2) has failed when building commit 4507d49.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1368/builds/4852) and take a look at the build logs.
  4. Check if the failure is related to this commit (4507d49) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1368/builds/4852

Failed tests:

  • test_capi
  • test.test_concurrent_futures.test_interpreter_pool
  • test_import

Test leaking resources:

  • test_interpreter_pool: references
  • test_capi: references
  • test_interpreter_pool: memory blocks
  • test_import: references
  • test_capi: memory blocks
  • test_import: memory blocks

Summary of the results of the build (if available):

==

Click to see traceback logs
TracebackTests.test_nonexistent_module_nested) ... ok


TracebackTests.test_broken_parent) ... ok


TracebackTests.test_unencodable_filename) ... skipped 'need TESTFN_UNENCODABLE'


TracebackTests.test_exec_failure_nested) ... ok


Traceback (most recent call last):
  File "<string>", line 10, in <module>
  File "<frozen importlib._bootstrap>", line 786, in module_from_spec
  File "<frozen importlib._bootstrap_external>", line 1025, in create_module
  File "<frozen importlib._bootstrap>", line 491, in _call_with_frames_removed
ImportError: module _test_module_state_shared does not support loading in subinterpreters
xpected failure


TracebackTests.test_import_bug) ... ok


TracebackTests.test_syntax_error) ... ok


TracebackTests.test_nonexistent_module) ... ok


TracebackTests.test_broken_from) ... ok


TracebackTests.test_broken_submodule) ... ok


TracebackTests.test_exec_failure) ... ok


TracebackTests.test_broken_parent_from) ... ok

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot s390x Fedora Stable Refleaks 3.x (tier-3) has failed when building commit 4507d49.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1641/builds/1849) and take a look at the build logs.
  4. Check if the failure is related to this commit (4507d49) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1641/builds/1849

Failed tests:

  • test_capi
  • test.test_concurrent_futures.test_interpreter_pool
  • test_import

Test leaking resources:

  • test_interpreter_pool: references
  • test_capi: references
  • test_interpreter_pool: memory blocks
  • test_import: references
  • test_capi: memory blocks
  • test_import: memory blocks

Summary of the results of the build (if available):

==

Click to see traceback logs
TracebackTests.test_nonexistent_module_nested) ... ok


TracebackTests.test_broken_parent) ... ok


TracebackTests.test_exec_failure_nested) ... ok


TracebackTests.test_import_bug) ... ok


TracebackTests.test_syntax_error) ... ok


TracebackTests.test_nonexistent_module) ... ok


TracebackTests.test_unencodable_filename) ... ok


TracebackTests.test_broken_from) ... ok


TracebackTests.test_broken_submodule) ... ok


TracebackTests.test_exec_failure) ... ok


TracebackTests.test_broken_parent_from) ... ok

@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot PPC64LE Fedora Stable Refleaks 3.x (tier-2) has failed when building commit 4507d49.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/280/builds/2905) and take a look at the build logs.
  4. Check if the failure is related to this commit (4507d49) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/280/builds/2905

Failed tests:

  • test_capi
  • test.test_concurrent_futures.test_interpreter_pool
  • test_import

Test leaking resources:

  • test_interpreter_pool: references
  • test_capi: references
  • test_interpreter_pool: memory blocks
  • test_import: references
  • test_capi: memory blocks
  • test_import: memory blocks

Summary of the results of the build (if available):

==

Click to see traceback logs
TracebackTests.test_nonexistent_module_nested) ... ok


TracebackTests.test_broken_parent) ... ok


TracebackTests.test_exec_failure_nested) ... ok


TracebackTests.test_import_bug) ... ok


TracebackTests.test_syntax_error) ... ok


TracebackTests.test_nonexistent_module) ... ok


TracebackTests.test_unencodable_filename) ... ok


TracebackTests.test_broken_from) ... ok


TracebackTests.test_broken_submodule) ... ok


TracebackTests.test_exec_failure) ... ok


TracebackTests.test_broken_parent_from) ... ok

ashm-dev pushed a commit to ashm-dev/cpython that referenced this pull request Mar 20, 2026
…i module (pythonGH-145981)

* 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().
kangtastic added a commit to kangtastic/cpython that referenced this pull request Mar 20, 2026
- Use the new `alphabet` parameter in `binascii`
- Remove `binascii.a2b_base32hex()` and `binascii.b2a_base32hex()`
- Change value for `.. versionadded::` ReST directive in docs for
  new `binascii` functions to "next" instead of "3.15"
@vstinner
Copy link
Member

This change introduced reference leaks in 3 tests:

  • test_capi: test.test_capi.test_misc.SubinterpreterTest.test_mutate_exception test
  • test_concurrent_futures.test_interpreter_pool
  • test_import

I wrote #146230 to fix the leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants