annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/encodings/quopri_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 """Codec for quoted-printable encoding.
jpayne@69 2
jpayne@69 3 This codec de/encodes from bytes to bytes.
jpayne@69 4 """
jpayne@69 5
jpayne@69 6 import codecs
jpayne@69 7 import quopri
jpayne@69 8 from io import BytesIO
jpayne@69 9
jpayne@69 10 def quopri_encode(input, errors='strict'):
jpayne@69 11 assert errors == 'strict'
jpayne@69 12 f = BytesIO(input)
jpayne@69 13 g = BytesIO()
jpayne@69 14 quopri.encode(f, g, quotetabs=True)
jpayne@69 15 return (g.getvalue(), len(input))
jpayne@69 16
jpayne@69 17 def quopri_decode(input, errors='strict'):
jpayne@69 18 assert errors == 'strict'
jpayne@69 19 f = BytesIO(input)
jpayne@69 20 g = BytesIO()
jpayne@69 21 quopri.decode(f, g)
jpayne@69 22 return (g.getvalue(), len(input))
jpayne@69 23
jpayne@69 24 class Codec(codecs.Codec):
jpayne@69 25 def encode(self, input, errors='strict'):
jpayne@69 26 return quopri_encode(input, errors)
jpayne@69 27 def decode(self, input, errors='strict'):
jpayne@69 28 return quopri_decode(input, errors)
jpayne@69 29
jpayne@69 30 class IncrementalEncoder(codecs.IncrementalEncoder):
jpayne@69 31 def encode(self, input, final=False):
jpayne@69 32 return quopri_encode(input, self.errors)[0]
jpayne@69 33
jpayne@69 34 class IncrementalDecoder(codecs.IncrementalDecoder):
jpayne@69 35 def decode(self, input, final=False):
jpayne@69 36 return quopri_decode(input, self.errors)[0]
jpayne@69 37
jpayne@69 38 class StreamWriter(Codec, codecs.StreamWriter):
jpayne@69 39 charbuffertype = bytes
jpayne@69 40
jpayne@69 41 class StreamReader(Codec, codecs.StreamReader):
jpayne@69 42 charbuffertype = bytes
jpayne@69 43
jpayne@69 44 # encodings module API
jpayne@69 45
jpayne@69 46 def getregentry():
jpayne@69 47 return codecs.CodecInfo(
jpayne@69 48 name='quopri',
jpayne@69 49 encode=quopri_encode,
jpayne@69 50 decode=quopri_decode,
jpayne@69 51 incrementalencoder=IncrementalEncoder,
jpayne@69 52 incrementaldecoder=IncrementalDecoder,
jpayne@69 53 streamwriter=StreamWriter,
jpayne@69 54 streamreader=StreamReader,
jpayne@69 55 _is_text_encoding=False,
jpayne@69 56 )