Skip to content

Update base64 3.13.5 #5872

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.

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
merged 1 commit into from
Jun 30, 2025
Merged

Update base64 3.13.5 #5872

merged 1 commit into from
Jun 30, 2025

Conversation

ShaharNaveh
Copy link
Contributor

@ShaharNaveh ShaharNaveh commented Jun 30, 2025

Summary by CodeRabbit

  • New Features

    • Added support for Z85 encoding and decoding alongside existing base64 features.
  • Tests

    • Introduced comprehensive tests for Z85 encoding and decoding, including validation of correct outputs and error handling for invalid inputs.

Copy link

coderabbitai bot commented Jun 30, 2025

Walkthrough

Support for Z85 encoding and decoding is added to the base64 module, including new z85encode and z85decode functions and their exports. Translation tables between Base85 and Z85 alphabets are introduced. Comprehensive unit tests for these new functions are implemented, covering normal operation and error conditions.

Changes

File(s) Change Summary
Lib/base64.py Added Z85 encoding/decoding via z85encode and z85decode, translation tables, and exports.
Lib/test/test_base64.py Added unit tests for Z85 encode/decode, error handling, and input type coverage.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant base64
    Caller->>base64: z85encode(bytes)
    base64->>base64: base85encode(input)
    base64->>base64: translate to Z85 alphabet
    base64-->>Caller: Z85-encoded bytes

    Caller->>base64: z85decode(z85_bytes)
    base64->>base64: translate to Base85 alphabet
    base64->>base64: base85decode(translated)
    base64-->>Caller: decoded bytes
Loading

Poem

In the warren of code, a new path appears,
Z85 hops in, allaying old fears.
Encoders and decoders, now side by side,
With tests to ensure they never collide.
A rabbit’s delight—more bytes to explore,
Encoding adventures forever in store!
🐇✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b59a666 and a357401.

📒 Files selected for processing (2)
  • Lib/base64.py (3 hunks)
  • Lib/test/test_base64.py (5 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
Lib/test/test_base64.py (2)
Lib/base64.py (5)
  • z85encode (511-513)
  • a85decode (367-435)
  • z85decode (515-525)
  • decode (543-547)
  • b85decode (459-498)
Lib/unittest/case.py (1)
  • assertRaises (738-769)
🪛 Flake8 (7.2.0)
Lib/test/test_base64.py

[error] 555-555: continuation line unaligned for hanging indent

(E131)


[error] 670-670: continuation line unaligned for hanging indent

(E131)

Lib/base64.py

[error] 500-500: expected 2 blank lines after class or function definition, found 1

(E305)


[error] 511-511: expected 2 blank lines, found 1

(E302)


[error] 515-515: expected 2 blank lines, found 1

(E302)

⏰ Context from checks skipped due to timeout of 90000ms (11)
  • GitHub Check: Run snippets and cpython tests on wasm-wasi
  • GitHub Check: Run tests under miri
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Check Rust code with rustfmt and clippy
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Ensure compilation on various targets
  • GitHub Check: Run rust tests (windows-latest)
🔇 Additional comments (7)
Lib/base64.py (1)

21-21: LGTM! Z85 functions properly exported.

The new Z85 encoding and decoding functions are correctly added to the module's __all__ exports, maintaining consistency with other encoding functions.

Lib/test/test_base64.py (6)

548-581: Excellent comprehensive test coverage for z85encode.

The test cases cover all the important scenarios including empty bytes, various data types, and edge cases. The test data appears to be correctly generated and validates the Z85 encoding implementation thoroughly.

However, there's a minor formatting issue to fix:

             b"""009c61o!#m2NH?C3>iWS5d]J*6CRx17-skh9337x"""
-                b"""ar.{NbQB=+c[cR@eg&FcfFLssg=mfIi5%2YjuU>)kTv.7l}6Nnnj=AD"""
+            b"""ar.{NbQB=+c[cR@eg&FcfFLssg=mfIi5%2YjuU>)kTv.7l}6Nnnj=AD"""

663-697: Excellent comprehensive test coverage for z85decode.

The test cases thoroughly validate the Z85 decoding implementation with various input types and data scenarios.

However, there's a minor formatting issue to fix:

             b"""009c61o!#m2NH?C3>iWS5d]J*6CRx17-skh9337x"""
-                b"""ar.{NbQB=+c[cR@eg&FcfFLssg=mfIi5%2YjuU>)kTv.7l}6Nnnj=AD"""
+            b"""ar.{NbQB=+c[cR@eg&FcfFLssg=mfIi5%2YjuU>)kTv.7l}6Nnnj=AD"""

779-793: Comprehensive error testing for z85decode.

The error tests properly validate that z85decode rejects invalid characters and handles overflow conditions correctly. The test coverage includes both character validation and truncated input scenarios.


801-802: Good consistency - z85decode properly included in non-ASCII string test.

Adding base64.z85decode to the list of decode functions tested for non-ASCII string rejection ensures consistency with other decode functions.


623-623: Good addition to a85decode test coverage.

The additional test case for a85decode with foldspaces improves test coverage.


762-763: Appropriate test modification for a85decode error cases.

The modification to the existing a85decode error test maintains proper test coverage while accommodating changes in the test structure.

Comment on lines +515 to +525
def z85decode(s):
"""Decode the z85-encoded bytes-like object or ASCII string b

The result is returned as a bytes object.
"""
s = _bytes_from_decode_data(s)
s = s.translate(_z85_decode_translation)
try:
return b85decode(s)
except ValueError as e:
raise ValueError(e.args[0].replace('base85', 'z85')) from None
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix PEP 8 formatting and improve docstring consistency.

The z85decode function implementation is correct but needs formatting fixes and a minor docstring improvement.

Apply this diff to fix the formatting and improve consistency:

+
 def z85decode(s):
-    """Decode the z85-encoded bytes-like object or ASCII string b
+    """Decode the z85-encoded bytes-like object or ASCII string s
 
     The result is returned as a bytes object.
     """
     s = _bytes_from_decode_data(s)
     s = s.translate(_z85_decode_translation)
     try:
         return b85decode(s)
     except ValueError as e:
         raise ValueError(e.args[0].replace('base85', 'z85')) from None

The error message translation approach is clever - it reuses the existing b85decode error handling while customizing the error messages for Z85 context.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def z85decode(s):
"""Decode the z85-encoded bytes-like object or ASCII string b
The result is returned as a bytes object.
"""
s = _bytes_from_decode_data(s)
s = s.translate(_z85_decode_translation)
try:
return b85decode(s)
except ValueError as e:
raise ValueError(e.args[0].replace('base85', 'z85')) from None
def z85decode(s):
"""Decode the z85-encoded bytes-like object or ASCII string s
The result is returned as a bytes object.
"""
s = _bytes_from_decode_data(s)
s = s.translate(_z85_decode_translation)
try:
return b85decode(s)
except ValueError as e:
raise ValueError(e.args[0].replace('base85', 'z85')) from None
🧰 Tools
🪛 Flake8 (7.2.0)

[error] 515-515: expected 2 blank lines, found 1

(E302)

🤖 Prompt for AI Agents
In Lib/base64.py around lines 515 to 525, fix the PEP 8 formatting issues by
ensuring proper indentation and spacing throughout the z85decode function. Also,
improve the docstring by correcting the description to be more consistent and
clear, for example, clarify the input type and output in the docstring format.
Make sure the function signature and body follow PEP 8 style guidelines,
including blank lines and line length.

Comment on lines +511 to +513
def z85encode(s):
"""Encode bytes-like object b in z85 format and return a bytes object."""
return b85encode(s).translate(_z85_encode_translation)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix PEP 8 formatting for function definition.

The z85encode function implementation is correct but needs proper spacing.

Apply this diff to fix the formatting:

+
 def z85encode(s):
     """Encode bytes-like object b in z85 format and return a bytes object."""
     return b85encode(s).translate(_z85_encode_translation)
+
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def z85encode(s):
"""Encode bytes-like object b in z85 format and return a bytes object."""
return b85encode(s).translate(_z85_encode_translation)
def z85encode(s):
"""Encode bytes-like object b in z85 format and return a bytes object."""
return b85encode(s).translate(_z85_encode_translation)
🧰 Tools
🪛 Flake8 (7.2.0)

[error] 511-511: expected 2 blank lines, found 1

(E302)

🤖 Prompt for AI Agents
In Lib/base64.py around lines 511 to 513, the function definition for z85encode
lacks proper spacing according to PEP 8 standards. Add a blank line before the
function definition to separate it from preceding code or comments, ensuring
consistent vertical spacing and improving readability.

Comment on lines +500 to +509
_z85alphabet = (b'0123456789abcdefghijklmnopqrstuvwxyz'
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#')
# Translating b85 valid but z85 invalid chars to b'\x00' is required
# to prevent them from being decoded as b85 valid chars.
_z85_b85_decode_diff = b';_`|~'
_z85_decode_translation = bytes.maketrans(
_z85alphabet + _z85_b85_decode_diff,
_b85alphabet + b'\x00' * len(_z85_b85_decode_diff)
)
_z85_encode_translation = bytes.maketrans(_b85alphabet, _z85alphabet)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

⚠️ Potential issue

Fix PEP 8 formatting and verify translation table logic.

The Z85 alphabet definition and translation tables look correct, but there are formatting issues that need to be addressed.

Apply this diff to fix the formatting issues:

+
 _z85alphabet = (b'0123456789abcdefghijklmnopqrstuvwxyz'
                 b'ABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#')
 # Translating b85 valid but z85 invalid chars to b'\x00' is required
 # to prevent them from being decoded as b85 valid chars.
 _z85_b85_decode_diff = b';_`|~'
 _z85_decode_translation = bytes.maketrans(
     _z85alphabet + _z85_b85_decode_diff,
     _b85alphabet + b'\x00' * len(_z85_b85_decode_diff)
 )
 _z85_encode_translation = bytes.maketrans(_b85alphabet, _z85alphabet)
+

The translation logic correctly handles the differences between Base85 and Z85 alphabets by mapping invalid Z85 characters to null bytes during decoding.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
_z85alphabet = (b'0123456789abcdefghijklmnopqrstuvwxyz'
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#')
# Translating b85 valid but z85 invalid chars to b'\x00' is required
# to prevent them from being decoded as b85 valid chars.
_z85_b85_decode_diff = b';_`|~'
_z85_decode_translation = bytes.maketrans(
_z85alphabet + _z85_b85_decode_diff,
_b85alphabet + b'\x00' * len(_z85_b85_decode_diff)
)
_z85_encode_translation = bytes.maketrans(_b85alphabet, _z85alphabet)
_z85alphabet = (b'0123456789abcdefghijklmnopqrstuvwxyz'
b'ABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#')
# Translating b85 valid but z85 invalid chars to b'\x00' is required
# to prevent them from being decoded as b85 valid chars.
_z85_b85_decode_diff = b';_`|~'
_z85_decode_translation = bytes.maketrans(
_z85alphabet + _z85_b85_decode_diff,
_b85alphabet + b'\x00' * len(_z85_b85_decode_diff)
)
_z85_encode_translation = bytes.maketrans(_b85alphabet, _z85alphabet)
🧰 Tools
🪛 Flake8 (7.2.0)

[error] 500-500: expected 2 blank lines after class or function definition, found 1

(E305)

🤖 Prompt for AI Agents
In Lib/base64.py around lines 500 to 509, fix the PEP 8 formatting issues by
ensuring proper line breaks and indentation for the _z85alphabet definition and
the translation table assignments. Verify that the translation tables correctly
map the Z85 alphabet and the differing Base85 characters, maintaining the logic
that translates invalid Z85 characters to null bytes during decoding. Adjust the
code formatting without altering the existing translation logic.

Copy link
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

Thank you!

@youknowone youknowone merged commit 3bde2dd into RustPython:main Jun 30, 2025
12 checks passed
@ShaharNaveh ShaharNaveh deleted the update-base64 branch June 30, 2025 22:01
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.

2 participants