Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
d77fe94b
Commit
d77fe94b
authored
Dec 14, 2015
by
Martin Panter
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #22088: Port base64 character ignoring doc and test from 857d9fe60169
parent
edd6a817
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
7 deletions
+21
-7
Doc/library/base64.rst
Doc/library/base64.rst
+3
-3
Lib/base64.py
Lib/base64.py
+3
-3
Lib/test/test_base64.py
Lib/test/test_base64.py
+15
-1
No files found.
Doc/library/base64.rst
View file @
d77fe94b
...
...
@@ -45,9 +45,9 @@ The modern interface, which was introduced in Python 2.4, provides:
length 2 (additional characters are ignored) which specifies the alternative
alphabet used instead of the ``+`` and ``/`` characters.
The decoded string is returned. A :exc:`TypeError` is raised if *s*
were
incorrectly padded
or if there are non-alphabet characters present in th
e
string
.
The decoded string is returned. A :exc:`TypeError` is raised if *s*
is
incorrectly padded
. Non-base64-alphabet characters ar
e
discarded prior to the padding check
.
.. function:: standard_b64encode(s)
...
...
Lib/base64.py
View file @
d77fe94b
...
...
@@ -64,9 +64,9 @@ def b64decode(s, altchars=None):
length 2 (additional characters are ignored) which specifies the
alternative alphabet used instead of the '+' and '/' characters.
The decoded string is returned. A TypeError is raised if s
were
incorrectly padded
or if there are non-alphabet characters present in the
string
.
The decoded string is returned. A TypeError is raised if s
is
incorrectly padded
. Non-base64-alphabet characters are discarded prior
to the padding check
.
"""
if
altchars
is
not
None
:
s
=
s
.
translate
(
string
.
maketrans
(
altchars
[:
2
],
'+/'
))
...
...
Lib/test/test_base64.py
View file @
d77fe94b
...
...
@@ -137,9 +137,23 @@ class BaseXYTestCase(unittest.TestCase):
# Non-bytes
eq
(
base64
.
urlsafe_b64decode
(
bytearray
(
'01a-b_cd'
)),
'
\
xd3
V
\
xbe
o
\
xf7
\
x1d
'
)
def
test_b64decode_error
(
self
):
def
test_b64decode_
padding_
error
(
self
):
self
.
assertRaises
(
TypeError
,
base64
.
b64decode
,
'abc'
)
def
test_b64decode_invalid_chars
(
self
):
# issue 1466065: Test some invalid characters.
tests
=
((
b'%3d=='
,
b'
\
xdd
'
),
(
b'$3d=='
,
b'
\
xdd
'
),
(
b'[=='
,
b''
),
(
b'YW]3='
,
b'am'
),
(
b'3{d=='
,
b'
\
xdd
'
),
(
b'3d}=='
,
b'
\
xdd
'
),
(
b'@@'
,
b''
),
(
b'!'
,
b''
),
(
b'YWJj
\
n
YWI='
,
b'abcab'
))
for
bstr
,
res
in
tests
:
self
.
assertEqual
(
base64
.
b64decode
(
bstr
),
res
)
def
test_b32encode
(
self
):
eq
=
self
.
assertEqual
eq
(
base64
.
b32encode
(
''
),
''
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment