Skip to content

Commit 081d550

Browse files
simplification from review
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent d484023 commit 081d550

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

Lib/base64.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,17 +100,8 @@ def b64decode(s, altchars=None, validate=_NOT_SPECIFIED, *, ignorechars=_NOT_SPE
100100
break
101101
s = s.translate(bytes.maketrans(altchars, b'+/'))
102102
else:
103-
altchars_out = (
104-
altchars[0] if altchars[0] not in b'+/' else altchars[1],
105-
altchars[1] if altchars[1] not in b'+/' else altchars[0],
106-
)
107-
trans_in = bytearray(altchars)
108-
trans_out = bytearray(b'+/')
109-
for b, b_out in zip(b'+/', altchars_out):
110-
if b not in altchars:
111-
trans_in.append(b)
112-
trans_out.append(b_out)
113-
trans = bytes.maketrans(trans_in, trans_out)
103+
trans = bytes.maketrans(altchars + bytes(set(b'+/') - set(altchars)),
104+
b'+/' + bytes(set(altchars) - set(b'+/')))
114105
s = s.translate(trans)
115106
ignorechars = ignorechars.translate(trans)
116107
if ignorechars is _NOT_SPECIFIED:

0 commit comments

Comments
 (0)