MCPcopy Index your code
hub / github.com/RustPython/RustPython / a85decode

Function a85decode

Lib/base64.py:364–432  ·  view source on GitHub ↗

Decode the Ascii85 encoded bytes-like object or ASCII string b. foldspaces is a flag that specifies whether the 'y' short sequence should be accepted as shorthand for 4 consecutive spaces (ASCII 0x20). This feature is not supported by the "standard" Adobe encoding. adobe controls w

(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v')

Source from the content-addressed store, hash-verified

362 return result
363
364def a85decode(b, *, foldspaces=False, adobe=False, ignorechars=b' \t\n\r\v'):
365 """Decode the Ascii85 encoded bytes-like object or ASCII string b.
366
367 foldspaces is a flag that specifies whether the 'y' short sequence should be
368 accepted as shorthand for 4 consecutive spaces (ASCII 0x20). This feature is
369 not supported by the "standard" Adobe encoding.
370
371 adobe controls whether the input sequence is in Adobe Ascii85 format (i.e.
372 is framed with <~ and ~>).
373
374 ignorechars should be a byte string containing characters to ignore from the
375 input. This should only contain whitespace characters, and by default
376 contains all whitespace characters in ASCII.
377
378 The result is returned as a bytes object.
379 """
380 b = _bytes_from_decode_data(b)
381 if adobe:
382 if not b.endswith(_A85END):
383 raise ValueError(
384 "Ascii85 encoded byte sequences must end "
385 "with {!r}".format(_A85END)
386 )
387 if b.startswith(_A85START):
388 b = b[2:-2] # Strip off start/end markers
389 else:
390 b = b[:-2]
391 #
392 # We have to go through this stepwise, so as to ignore spaces and handle
393 # special short sequences
394 #
395 packI = struct.Struct('!I').pack
396 decoded = []
397 decoded_append = decoded.append
398 curr = []
399 curr_append = curr.append
400 curr_clear = curr.clear
401 for x in b + b'u' * 4:
402 if b'!'[0] <= x <= b'u'[0]:
403 curr_append(x)
404 if len(curr) == 5:
405 acc = 0
406 for x in curr:
407 acc = 85 * acc + (x - 33)
408 try:
409 decoded_append(packI(acc))
410 except struct.error:
411 raise ValueError('Ascii85 overflow') from None
412 curr_clear()
413 elif x == b'z'[0]:
414 if curr:
415 raise ValueError('z inside Ascii85 5-tuple')
416 decoded_append(b'\0\0\0\0')
417 elif foldspaces and x == b'y'[0]:
418 if curr:
419 raise ValueError('y inside Ascii85 5-tuple')
420 decoded_append(b'\x20\x20\x20\x20')
421 elif x in ignorechars:

Callers

nothing calls this directly

Calls 6

_bytes_from_decode_dataFunction · 0.85
lenFunction · 0.85
endswithMethod · 0.45
formatMethod · 0.45
startswithMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected