Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-101178: Add Ascii85, base85, and Z85 support to binascii#102753

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
kangtastic wants to merge12 commits intopython:main
base:main
Choose a base branch
Loading
fromkangtastic:gh-101178-rework-base85
Open
Changes from1 commit
Commits
Show all changes
12 commits
Select commitHold shift + click to select a range
05ae5ad
Add Ascii85, base85, and Z85 support to binascii
kangtasticMar 8, 2023
aa06c5d
Restore base64.py
kangtasticApr 26, 2025
6377440
Create _base64 module with wrappers for accelerated functions
kangtasticApr 26, 2025
6c0e4a3
Test both Python and C codepaths in base64
kangtasticApr 26, 2025
ce4773c
Match behavior between Python and C base 85 functions
kangtasticApr 26, 2025
4072e3b
Add Z85 tests to binascii
kangtasticApr 27, 2025
bc9217f
Update generated files
kangtasticApr 27, 2025
2c40ba0
Avoid importing functools
kangtasticApr 28, 2025
fd9eaf7
Avoid circular import in _base64
kangtasticApr 28, 2025
4746d18
Do not use a decorator for changing exception type
kangtasticApr 28, 2025
d075593
Test Python and C codepaths in base64 using mixins
kangtasticApr 28, 2025
6d65fec
Remove leading underscore from functions in private module
kangtasticApr 29, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
Test both Python and C codepaths in base64
This is done differently toPEP-0399 to minimize the number ofchanged lines.
  • Loading branch information
@kangtastic
kangtastic committedApr 26, 2025
commit6c0e4a3089a90a21e35e48731ca5a976acf4095a
40 changes: 39 additions & 1 deletionLib/test/test_base64.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
import unittest
import base64
import binascii
import os
from array import array
from functools import update_wrapper
from test.support import os_helper
from test.support import script_helper
from test.support.import_helper import import_fresh_module

base64 = import_fresh_module("base64", blocked=["_base64"])
c_base64 = import_fresh_module("base64", fresh=["_base64"])


def with_c_implementation(test_func):
Copy link
Member

Choose a reason for hiding this comment

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

Instead of a decorator, perhaps use the mixin approach from other modules.

if c_base64 is None:
return test_func

def _test_func(self):
global base64

# Test Python implementation
test_func(self)

# Test C implementation
base64_ = base64
try:
base64 = c_base64
test_func(self)
finally:
base64 = base64_

update_wrapper(_test_func, test_func)

return _test_func


class LegacyBase64TestCase(unittest.TestCase):
Expand DownExpand Up@@ -461,6 +488,7 @@ def test_b16decode(self):
# Incorrect "padding"
self.assertRaises(binascii.Error, base64.b16decode, '010')

@with_c_implementation
def test_a85encode(self):
eq = self.assertEqual

Expand DownExpand Up@@ -511,6 +539,7 @@ def test_a85encode(self):
eq(base64.a85encode(b' '*6, foldspaces=True, adobe=False), b'y+<U')
eq(base64.a85encode(b' '*5, foldspaces=True, adobe=False), b'y+9')

@with_c_implementation
def test_b85encode(self):
eq = self.assertEqual

Expand DownExpand Up@@ -545,6 +574,7 @@ def test_b85encode(self):
self.check_other_types(base64.b85encode, b"www.python.org",
b'cXxL#aCvlSZ*DGca%T')

@with_c_implementation
def test_z85encode(self):
eq = self.assertEqual

Expand DownExpand Up@@ -579,6 +609,7 @@ def test_z85encode(self):
self.check_other_types(base64.z85encode, b"www.python.org",
b'CxXl-AcVLsz/dgCA+t')

@with_c_implementation
def test_a85decode(self):
eq = self.assertEqual

Expand DownExpand Up@@ -625,6 +656,7 @@ def test_a85decode(self):
self.check_other_types(base64.a85decode, b'GB\\6`E-ZP=Df.1GEb>',
b"www.python.org")

@with_c_implementation
def test_b85decode(self):
eq = self.assertEqual

Expand DownExpand Up@@ -660,6 +692,7 @@ def test_b85decode(self):
self.check_other_types(base64.b85decode, b'cXxL#aCvlSZ*DGca%T',
b"www.python.org")

@with_c_implementation
def test_z85decode(self):
eq = self.assertEqual

Expand DownExpand Up@@ -695,6 +728,7 @@ def test_z85decode(self):
self.check_other_types(base64.z85decode, b'CxXl-AcVLsz/dgCA+t',
b'www.python.org')

@with_c_implementation
def test_a85_padding(self):
eq = self.assertEqual

Expand All@@ -710,6 +744,7 @@ def test_a85_padding(self):
eq(base64.a85decode(b'G^+IX'), b"xxxx")
eq(base64.a85decode(b'G^+IXGQ7^D'), b"xxxxx\x00\x00\x00")

@with_c_implementation
def test_b85_padding(self):
eq = self.assertEqual

Expand All@@ -725,6 +760,7 @@ def test_b85_padding(self):
eq(base64.b85decode(b'czAet'), b"xxxx")
eq(base64.b85decode(b'czAetcmMzZ'), b"xxxxx\x00\x00\x00")

@with_c_implementation
def test_a85decode_errors(self):
illegal = (set(range(32)) | set(range(118, 256))) - set(b' \t\n\r\v')
for c in illegal:
Expand DownExpand Up@@ -762,6 +798,7 @@ def test_a85decode_errors(self):
self.assertRaises(ValueError, base64.a85decode, b'aaaay',
foldspaces=True)

@with_c_implementation
def test_b85decode_errors(self):
illegal = list(range(33)) + \
list(b'"\',./:[\\]') + \
Expand All@@ -776,6 +813,7 @@ def test_b85decode_errors(self):
self.assertRaises(ValueError, base64.b85decode, b'|NsC')
self.assertRaises(ValueError, base64.b85decode, b'|NsC1')

@with_c_implementation
def test_z85decode_errors(self):
illegal = list(range(33)) + \
list(b'"\',;_`|\\~') + \
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp