annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/encodings/base64_codec.py @ 69:33d812a61356

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 17:55:14 -0400
parents
children
rev   line source
jpayne@69 1 """Python 'base64_codec' Codec - base64 content transfer encoding.
jpayne@69 2
jpayne@69 3 This codec de/encodes from bytes to bytes.
jpayne@69 4
jpayne@69 5 Written by Marc-Andre Lemburg (mal@lemburg.com).
jpayne@69 6 """
jpayne@69 7
jpayne@69 8 import codecs
jpayne@69 9 import base64
jpayne@69 10
jpayne@69 11 ### Codec APIs
jpayne@69 12
jpayne@69 13 def base64_encode(input, errors='strict'):
jpayne@69 14 assert errors == 'strict'
jpayne@69 15 return (base64.encodebytes(input), len(input))
jpayne@69 16
jpayne@69 17 def base64_decode(input, errors='strict'):
jpayne@69 18 assert errors == 'strict'
jpayne@69 19 return (base64.decodebytes(input), len(input))
jpayne@69 20
jpayne@69 21 class Codec(codecs.Codec):
jpayne@69 22 def encode(self, input, errors='strict'):
jpayne@69 23 return base64_encode(input, errors)
jpayne@69 24 def decode(self, input, errors='strict'):
jpayne@69 25 return base64_decode(input, errors)
jpayne@69 26
jpayne@69 27 class IncrementalEncoder(codecs.IncrementalEncoder):
jpayne@69 28 def encode(self, input, final=False):
jpayne@69 29 assert self.errors == 'strict'
jpayne@69 30 return base64.encodebytes(input)
jpayne@69 31
jpayne@69 32 class IncrementalDecoder(codecs.IncrementalDecoder):
jpayne@69 33 def decode(self, input, final=False):
jpayne@69 34 assert self.errors == 'strict'
jpayne@69 35 return base64.decodebytes(input)
jpayne@69 36
jpayne@69 37 class StreamWriter(Codec, codecs.StreamWriter):
jpayne@69 38 charbuffertype = bytes
jpayne@69 39
jpayne@69 40 class StreamReader(Codec, codecs.StreamReader):
jpayne@69 41 charbuffertype = bytes
jpayne@69 42
jpayne@69 43 ### encodings module API
jpayne@69 44
jpayne@69 45 def getregentry():
jpayne@69 46 return codecs.CodecInfo(
jpayne@69 47 name='base64',
jpayne@69 48 encode=base64_encode,
jpayne@69 49 decode=base64_decode,
jpayne@69 50 incrementalencoder=IncrementalEncoder,
jpayne@69 51 incrementaldecoder=IncrementalDecoder,
jpayne@69 52 streamwriter=StreamWriter,
jpayne@69 53 streamreader=StreamReader,
jpayne@69 54 _is_text_encoding=False,
jpayne@69 55 )