Skip to content

Commit 99e0bde

Browse files
Rename parameters to match the base64 module.
1 parent 4ba3e50 commit 99e0bde

File tree

9 files changed

+127
-134
lines changed

9 files changed

+127
-134
lines changed

Doc/library/binascii.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ The :mod:`binascii` module defines the following functions:
9898
Added the *wrapcol* parameter.
9999

100100

101-
.. function:: a2b_ascii85(string, /, *, fold_spaces=False, wrap=False, ignore=b"")
101+
.. function:: a2b_ascii85(string, /, *, foldspaces=False, adobe=False, ignorechars=b"")
102102

103103
Convert Ascii85 data back to binary and return the binary data.
104104

@@ -109,34 +109,34 @@ The :mod:`binascii` module defines the following functions:
109109
accepted as a short form of the group ``!!!!!``, which encodes four
110110
consecutive null bytes.
111111

112-
If *fold_spaces* is true, the special character ``y`` is also accepted as a
112+
If *foldspaces* is true, the special character ``y`` is also accepted as a
113113
short form of the group ``+<VdL``, which encodes four consecutive spaces.
114114
Note that neither short form is permitted if it occurs in the middle of
115115
another group.
116116

117-
If *wrap* is true, the input begins with ``<~`` and ends with ``~>``, as in
117+
If *ignorechars* is true, the input begins with ``<~`` and ends with ``~>``, as in
118118
the Adobe Ascii85 format.
119119

120-
*ignore* is an optional bytes-like object that specifies characters to
120+
*ignorechars* is an optional bytes-like object that specifies characters to
121121
ignore in the input.
122122

123123
Invalid Ascii85 data will raise :exc:`binascii.Error`.
124124

125125
.. versionadded:: next
126126

127127

128-
.. function:: b2a_ascii85(data, /, *, fold_spaces=False, wrap=False, width=0, pad=False)
128+
.. function:: b2a_ascii85(data, /, *, foldspaces=False, adobe=False, wrapcol=0, pad=False)
129129

130130
Convert binary data to a formatted sequence of ASCII characters in Ascii85
131131
coding. The return value is the converted data.
132132

133-
If *fold_spaces* is true, four consecutive spaces are encoded as the
133+
If *foldspaces* is true, four consecutive spaces are encoded as the
134134
special character ``y`` instead of the sequence ``+<VdL``.
135135

136-
If *wrap* is true, the output begins with ``<~`` and ends with ``~>``, as
136+
If *adobe* is true, the output begins with ``<~`` and ends with ``~>``, as
137137
in the Adobe Ascii85 format.
138138

139-
If *width* is provided and greater than 0, the output is split into lines
139+
If *wrapcol* is provided and greater than 0, the output is split into lines
140140
of no more than the specified width separated by the ASCII newline
141141
character.
142142

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ struct _Py_global_strings {
297297
STRUCT_FOR_ID(aclose)
298298
STRUCT_FOR_ID(add)
299299
STRUCT_FOR_ID(add_done_callback)
300+
STRUCT_FOR_ID(adobe)
300301
STRUCT_FOR_ID(after_in_child)
301302
STRUCT_FOR_ID(after_in_parent)
302303
STRUCT_FOR_ID(alias)
@@ -492,7 +493,7 @@ struct _Py_global_strings {
492493
STRUCT_FOR_ID(flags)
493494
STRUCT_FOR_ID(flush)
494495
STRUCT_FOR_ID(fold)
495-
STRUCT_FOR_ID(fold_spaces)
496+
STRUCT_FOR_ID(foldspaces)
496497
STRUCT_FOR_ID(follow_symlinks)
497498
STRUCT_FOR_ID(format)
498499
STRUCT_FOR_ID(format_spec)
@@ -879,9 +880,7 @@ struct _Py_global_strings {
879880
STRUCT_FOR_ID(weeks)
880881
STRUCT_FOR_ID(which)
881882
STRUCT_FOR_ID(who)
882-
STRUCT_FOR_ID(width)
883883
STRUCT_FOR_ID(withdata)
884-
STRUCT_FOR_ID(wrap)
885884
STRUCT_FOR_ID(wrapcol)
886885
STRUCT_FOR_ID(writable)
887886
STRUCT_FOR_ID(write)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 5 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/base64.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
354354
adobe controls whether the encoded byte sequence is framed with <~ and ~>,
355355
which is used by the Adobe implementation.
356356
"""
357-
return binascii.b2a_ascii85(b, fold_spaces=foldspaces,
358-
wrap=adobe, width=wrapcol, pad=pad)
357+
return binascii.b2a_ascii85(b, foldspaces=foldspaces,
358+
adobe=adobe, wrapcol=wrapcol, pad=pad)
359359

360360
def a85decode(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v'):
361361
"""Decode the Ascii85 encoded bytes-like object or ASCII string b.
@@ -373,8 +373,8 @@ def a85decode(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v'):
373373
374374
The result is returned as a bytes object.
375375
"""
376-
return binascii.a2b_ascii85(b, fold_spaces=foldspaces,
377-
wrap=adobe, ignore=ignorechars)
376+
return binascii.a2b_ascii85(b, foldspaces=foldspaces,
377+
adobe=adobe, ignorechars=ignorechars)
378378

379379
def b85encode(b, pad=False):
380380
"""Encode bytes-like object b in base85 format and return a bytes object.

Lib/test/test_binascii.py

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -320,16 +320,16 @@ def test_ascii85_valid(self):
320320

321321
# Test core parameter combinations
322322
params = (False, False), (False, True), (True, False), (True, True)
323-
for fold_spaces, wrap in params:
323+
for foldspaces, adobe in params:
324324
lines = []
325325
for rawline in rawlines:
326326
b = self.type2test(rawline)
327-
a = binascii.b2a_ascii85(b, fold_spaces=fold_spaces, wrap=wrap)
327+
a = binascii.b2a_ascii85(b, foldspaces=foldspaces, adobe=adobe)
328328
lines.append(a)
329329
res = bytearray()
330330
for line in lines:
331331
a = self.type2test(line)
332-
b = binascii.a2b_ascii85(a, fold_spaces=fold_spaces, wrap=wrap)
332+
b = binascii.a2b_ascii85(a, foldspaces=foldspaces, adobe=adobe)
333333
res += b
334334
self.assertEqual(res, rawdata)
335335

@@ -344,8 +344,8 @@ def test_ascii85_valid(self):
344344
(b"<~FCfN8yg~>", True, True, b"", b"test "),
345345
(b"FE;\x03#8zFCf\x02N8yh~>", True, True, b"\x02\x03", b"tset\x00\x00\x00\x00test "),
346346
]
347-
for a, fold_spaces, wrap, ignore, b in params:
348-
kwargs = {"fold_spaces": fold_spaces, "wrap": wrap, "ignore": ignore}
347+
for a, foldspaces, adobe, ignorechars, b in params:
348+
kwargs = {"foldspaces": foldspaces, "adobe": adobe, "ignorechars": ignorechars}
349349
self.assertEqual(binascii.a2b_ascii85(self.type2test(a), **kwargs), b)
350350

351351
def test_ascii85_invalid(self):
@@ -375,13 +375,13 @@ def addnoise(line):
375375
res = bytearray()
376376
for line in map(addnoise, lines):
377377
a = self.type2test(line)
378-
b = binascii.a2b_ascii85(a, ignore=fillers)
378+
b = binascii.a2b_ascii85(a, ignorechars=fillers)
379379
res += b
380380
self.assertEqual(res, self.rawdata)
381381

382382
# Test Ascii85 with only invalid characters
383383
fillers = self.type2test(fillers)
384-
b = binascii.a2b_ascii85(fillers, ignore=fillers)
384+
b = binascii.a2b_ascii85(fillers, ignorechars=fillers)
385385
self.assertEqual(b, b"")
386386

387387
def test_ascii85_errors(self):
@@ -390,13 +390,13 @@ def _assertRegexTemplate(assert_regex, data, **kwargs):
390390
binascii.a2b_ascii85(self.type2test(data), **kwargs)
391391

392392
def assertMissingDelimiter(data):
393-
_assertRegexTemplate(r"(?i)end with b'~>'", data, wrap=True)
393+
_assertRegexTemplate(r"(?i)end with b'~>'", data, adobe=True)
394394

395395
def assertOverflow(data):
396396
_assertRegexTemplate(r"(?i)Ascii85 overflow", data)
397397

398398
def assertInvalidSpecial(data):
399-
_assertRegexTemplate(r"(?i)'[yz]'.+5-tuple", data, fold_spaces=True)
399+
_assertRegexTemplate(r"(?i)'[yz]'.+5-tuple", data, foldspaces=True)
400400

401401
def assertInvalidChar(data, **kwargs):
402402
_assertRegexTemplate(r"(?i)Non-Ascii85 digit", data, **kwargs)
@@ -429,21 +429,21 @@ def assertInvalidChar(data, **kwargs):
429429

430430
# Test Ascii85 with non-ignored invalid characters
431431
assertInvalidChar(b"j\n")
432-
assertInvalidChar(b" ", ignore=b"")
433-
assertInvalidChar(b" valid\x02until\x03", ignore=b"\x00\x01\x02\x04")
434-
assertInvalidChar(b"\tFCb", ignore=b"\n")
435-
assertInvalidChar(b"xxxB\nP\thU'D v/F+", ignore=b" \n\tv")
436-
437-
def test_ascii85_width(self):
438-
# Test Ascii85 splitting lines by width
439-
def assertEncode(a_expected, data, n, wrap=False):
432+
assertInvalidChar(b" ", ignorechars=b"")
433+
assertInvalidChar(b" valid\x02until\x03", ignorechars=b"\x00\x01\x02\x04")
434+
assertInvalidChar(b"\tFCb", ignorechars=b"\n")
435+
assertInvalidChar(b"xxxB\nP\thU'D v/F+", ignorechars=b" \n\tv")
436+
437+
def test_ascii85_wrapcol(self):
438+
# Test Ascii85 splitting lines
439+
def assertEncode(a_expected, data, n, adobe=False):
440440
b = self.type2test(data)
441-
a = binascii.b2a_ascii85(b, wrap=wrap, width=n)
441+
a = binascii.b2a_ascii85(b, adobe=adobe, wrapcol=n)
442442
self.assertEqual(a, a_expected)
443443

444-
def assertDecode(data, b_expected, wrap=False):
444+
def assertDecode(data, b_expected, adobe=False):
445445
a = self.type2test(data)
446-
b = binascii.a2b_ascii85(a, wrap=wrap, ignore=b"\n")
446+
b = binascii.a2b_ascii85(a, adobe=adobe, ignorechars=b"\n")
447447
self.assertEqual(b, b_expected)
448448

449449
tests = [
@@ -466,9 +466,9 @@ def assertDecode(data, b_expected, wrap=False):
466466
]
467467
for b, n, a, a_wrap in tests:
468468
assertEncode(a, b, n)
469-
assertEncode(a_wrap, b, n, wrap=True)
469+
assertEncode(a_wrap, b, n, adobe=True)
470470
assertDecode(a, b)
471-
assertDecode(a_wrap, b, wrap=True)
471+
assertDecode(a_wrap, b, adobe=True)
472472

473473
def test_ascii85_pad(self):
474474
# Test Ascii85 with encode padding
@@ -494,29 +494,29 @@ def assertShortPad(data, expected, **kwargs):
494494
assertShortPad(b"\0" * 4, b"z", pad=True)
495495
assertShortPad(b"\0" * 5, b"zz", pad=True)
496496
assertShortPad(b"\0" * 6, b"z!!!")
497-
assertShortPad(b" " * 7, b"y+<Vd,", fold_spaces=True, pad=True)
497+
assertShortPad(b" " * 7, b"y+<Vd,", foldspaces=True, pad=True)
498498
assertShortPad(b"\0" * 8, b"<~zz~>",
499-
fold_spaces=True, wrap=True, pad=True)
499+
foldspaces=True, adobe=True, pad=True)
500500
assertShortPad(b"\0\0\0\0abcd \0\0", b"<~z@:E_Wy\nz~>",
501-
fold_spaces=True, wrap=True, width=9, pad=True)
501+
foldspaces=True, adobe=True, wrapcol=9, pad=True)
502502

503-
def test_ascii85_ignore(self):
503+
def test_ascii85_ignorechars(self):
504504
# Test Ascii85 with ignored characters
505-
def assertIgnore(data, expected, ignore=b"", **kwargs):
505+
def assertIgnore(data, expected, ignorechars=b"", **kwargs):
506506
data = self.type2test(data)
507-
ignore = self.type2test(ignore)
507+
ignore = self.type2test(ignorechars)
508508
with self.assertRaisesRegex(binascii.Error, r"(?i)Non-Ascii85 digit"):
509509
binascii.a2b_ascii85(data, **kwargs)
510-
res = binascii.a2b_ascii85(data, ignore=ignore, **kwargs)
510+
res = binascii.a2b_ascii85(data, ignorechars=ignorechars, **kwargs)
511511
self.assertEqual(res, expected)
512512

513-
assertIgnore(b"\n", b"", ignore=b"\n")
514-
assertIgnore(b"<~ ~>", b"", ignore=b" ", wrap=True)
515-
assertIgnore(b"z|z", b"\0" * 8, ignore=b"|||") # repeats don't matter
516-
assertIgnore(b"zz!!|", b"\0" * 9, ignore=b"|!z") # ignore only if invalid
517-
assertIgnore(b"<~B P~@~>", b"hi", ignore=b" <~>", wrap=True)
518-
assertIgnore(b"zy}", b"\0\0\0\0", ignore=b"zy}")
519-
assertIgnore(b"zy}", b"\0\0\0\0 ", ignore=b"zy}", fold_spaces=True)
513+
assertIgnore(b"\n", b"", ignorechars=b"\n")
514+
assertIgnore(b"<~ ~>", b"", ignorechars=b" ", adobe=True)
515+
assertIgnore(b"z|z", b"\0" * 8, ignorechars=b"|||") # repeats don't matter
516+
assertIgnore(b"zz!!|", b"\0" * 9, ignorechars=b"|!z") # ignore only if invalid
517+
assertIgnore(b"<~B P~@~>", b"hi", ignorechars=b" <~>", adobe=True)
518+
assertIgnore(b"zy}", b"\0\0\0\0", ignorechars=b"zy}")
519+
assertIgnore(b"zy}", b"\0\0\0\0 ", ignorechars=b"zy}", foldspaces=True)
520520

521521
def test_base85_valid(self):
522522
# Test base85 with valid data

0 commit comments

Comments
 (0)