-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Update base64 3.13.5 #5872
Conversation
WalkthroughSupport for Z85 encoding and decoding is added to the base64 module, including new Changes
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
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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.
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 |
There was a problem hiding this comment.
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.
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.
def z85encode(s): | ||
"""Encode bytes-like object b in z85 format and return a bytes object.""" | ||
return b85encode(s).translate(_z85_encode_translation) |
There was a problem hiding this comment.
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.
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.
_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) |
There was a problem hiding this comment.
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 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.
_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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Summary by CodeRabbit
New Features
Tests