MCPcopy Index your code
hub / github.com/python/cpython / urlsafe_b64decode

Function urlsafe_b64decode

Lib/base64.py:165–191  ·  view source on GitHub ↗

Decode bytes using the URL- and filesystem-safe Base64 alphabet. Argument s is a bytes-like object or ASCII string to decode. The result is returned as a bytes object. A binascii.Error is raised if the input is incorrectly padded. Characters that are not in the URL-safe base-64 a

(s, *, padded=False)

Source from the content-addressed store, hash-verified

163 alphabet=binascii.URLSAFE_BASE64_ALPHABET)
164
165def urlsafe_b64decode(s, *, padded=False):
166 """Decode bytes using the URL- and filesystem-safe Base64 alphabet.
167
168 Argument s is a bytes-like object or ASCII string to decode. The result
169 is returned as a bytes object. A binascii.Error is raised if the input
170 is incorrectly padded. Characters that are not in the URL-safe base-64
171 alphabet, and are not a plus '+' or slash '/', are discarded prior to the
172 padding check.
173
174 If padded is false, padding in input is not required.
175
176 The alphabet uses '-' instead of '+' and '_' instead of '/'.
177 """
178 s = _bytes_from_decode_data(s)
179 badchar = None
180 for b in b'+/':
181 if b in s:
182 badchar = b
183 break
184 s = s.translate(_urlsafe_decode_translation)
185 result = binascii.a2b_base64(s, strict_mode=False, padded=padded)
186 if badchar is not None:
187 import warnings
188 warnings.warn(f'invalid character {chr(badchar)!a} in URL-safe Base64 data '
189 f'will be discarded in future Python versions',
190 FutureWarning, stacklevel=2)
191 return result
192
193
194

Callers 2

checkMethod · 0.85
test_b64decode_paddedMethod · 0.85

Calls 3

_bytes_from_decode_dataFunction · 0.85
translateMethod · 0.45
warnMethod · 0.45

Tested by 2

checkMethod · 0.68
test_b64decode_paddedMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…