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

Function _85encode

Lib/base64.py:299–321  ·  view source on GitHub ↗
(b, chars, chars2, pad=False, foldnuls=False, foldspaces=False)

Source from the content-addressed store, hash-verified

297_A85END = b"~>"
298
299def _85encode(b, chars, chars2, pad=False, foldnuls=False, foldspaces=False):
300 # Helper function for a85encode and b85encode
301 if not isinstance(b, bytes_types):
302 b = memoryview(b).tobytes()
303
304 padding = (-len(b)) % 4
305 if padding:
306 b = b + b'\0' * padding
307 words = struct.Struct('!%dI' % (len(b) // 4)).unpack(b)
308
309 chunks = [b'z' if foldnuls and not word else
310 b'y' if foldspaces and word == 0x20202020 else
311 (chars2[word // 614125] +
312 chars2[word // 85 % 7225] +
313 chars[word % 85])
314 for word in words]
315
316 if padding and not pad:
317 if chunks[-1] == b'z':
318 chunks[-1] = chars[0] * 5
319 chunks[-1] = chunks[-1][:-padding]
320
321 return b''.join(chunks)
322
323def a85encode(b, *, foldspaces=False, wrapcol=0, pad=False, adobe=False):
324 """Encode bytes-like object b using Ascii85 and return a bytes object.

Callers 2

a85encodeFunction · 0.85
b85encodeFunction · 0.85

Calls 5

isinstanceFunction · 0.85
lenFunction · 0.85
tobytesMethod · 0.45
unpackMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected