GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-143103: Added `pad` parameter to `base64.z85encode` by haukex · Pull Request #143106 · python/cpython

gh-143103: Added pad parameter to base64.z85encode #143106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
serhiy-storchaka merged 1 commit into python:main from haukex:z85pad
Dec 25, 2025

Uh oh!

There was an error while loading. Please reload this page.

Merged

gh-143103: Added pad parameter to base64.z85encode #143106

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
db73daa
Added `pad` parameter to `base64.z85encode`
haukex Dec 23, 2025
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

8 changes: 7 additions & 1 deletion 8 Doc/library/base64.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,20 @@ Refer to the documentation of the individual functions for more information.
.. versionadded:: 3.4


.. function:: z85encode(s)
.. function:: z85encode(s, pad=False)

Encode the :term:`bytes-like object` *s* using Z85 (as used in ZeroMQ)
and return the encoded :class:`bytes`. See `Z85 specification
<https://rfc.zeromq.org/spec/32/>`_ for more information.

If *pad* is true, the input is padded with ``b'\0'`` so its length is a
multiple of 4 bytes before encoding.

.. versionadded:: 3.13

.. versionchanged:: next
The *pad* parameter was added.


.. function:: z85decode(s)

Expand Down
4 changes: 2 additions & 2 deletions 4 Lib/base64.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ def b85decode(b):
)
_z85_encode_translation = bytes.maketrans(_b85alphabet, _z85alphabet)

def z85encode(s):
def z85encode(s, pad=False):
"""Encode bytes-like object b in z85 format and return a bytes object."""
return b85encode(s).translate(_z85_encode_translation)
return b85encode(s, pad).translate(_z85_encode_translation)

def z85decode(s):
"""Decode the z85-encoded bytes-like object or ASCII string b
Expand Down
16 changes: 16 additions & 0 deletions 16 Lib/test/test_base64.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ def test_z85encode(self):

tests = {
b'': b'',
b'\x86\x4F\xD2\x6F\xB5\x59\xF7\x5B': b'HelloWorld',
b'www.python.org': b'CxXl-AcVLsz/dgCA+t',
bytes(range(255)): b"""009c61o!#m2NH?C3>iWS5d]J*6CRx17-skh9337x"""
b"""ar.{NbQB=+c[cR@eg&FcfFLssg=mfIi5%2YjuU>)kTv.7l}6Nnnj=AD"""
Expand Down Expand Up @@ -840,6 +841,21 @@ def test_b85_padding(self):
eq(base64.b85decode(b'czAet'), b"xxxx")
eq(base64.b85decode(b'czAetcmMzZ'), b"xxxxx\x00\x00\x00")

def test_z85_padding(self):
eq = self.assertEqual

eq(base64.z85encode(b"x", pad=True), b'CMmZz')
eq(base64.z85encode(b"xx", pad=True), b'CZ6h*')
eq(base64.z85encode(b"xxx", pad=True), b'CZaDk')
eq(base64.z85encode(b"xxxx", pad=True), b'CZaET')
eq(base64.z85encode(b"xxxxx", pad=True), b'CZaETCMmZz')

eq(base64.z85decode(b'CMmZz'), b"x\x00\x00\x00")
eq(base64.z85decode(b'CZ6h*'), b"xx\x00\x00")
eq(base64.z85decode(b'CZaDk'), b"xxx\x00")
eq(base64.z85decode(b'CZaET'), b"xxxx")
eq(base64.z85decode(b'CZaETCMmZz'), b"xxxxx\x00\x00\x00")

Comment thread
haukex marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

def test_a85decode_errors(self):
illegal = (set(range(32)) | set(range(118, 256))) - set(b' \t\n\r\v')
for c in illegal:
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/ACKS
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ Lisandro Dalcin
Darren Dale
Andrew Dalke
Lars Damerow
Hauke Dämpfling
Evan Dandrea
Eric Daniel
Scott David Daniels
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2025-12-23-17-07-22.gh-issue-143103.LRjXEW.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add padding support to :func:`base64.z85encode` via the ``pad`` parameter.
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.