Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.2k
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
base:main
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
05ae5ad
aa06c5d
6377440
6c0e4a3
ce4773c
4072e3b
bc9217f
2c40ba0
fd9eaf7
4746d18
d075593
6d65fec
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
This is done differently toPEP-0399 to minimize the number ofchanged lines.
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
import unittest | ||
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): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
@@ -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 | ||
@@ -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 | ||
@@ -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 | ||
@@ -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 | ||
@@ -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 | ||
@@ -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 | ||
@@ -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 | ||
@@ -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 | ||
@@ -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: | ||
@@ -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'"\',./:[\\]') + \ | ||
@@ -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'"\',;_`|\\~') + \ | ||