annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/encodings/quopri_codec.py @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 """Codec for quoted-printable encoding.
jpayne@68 2
jpayne@68 3 This codec de/encodes from bytes to bytes.
jpayne@68 4 """
jpayne@68 5
jpayne@68 6 import codecs
jpayne@68 7 import quopri
jpayne@68 8 from io import BytesIO
jpayne@68 9
jpayne@68 10 def quopri_encode(input, errors='strict'):
jpayne@68 11 assert errors == 'strict'
jpayne@68 12 f = BytesIO(input)
jpayne@68 13 g = BytesIO()
jpayne@68 14 quopri.encode(f, g, quotetabs=True)
jpayne@68 15 return (g.getvalue(), len(input))
jpayne@68 16
jpayne@68 17 def quopri_decode(input, errors='strict'):
jpayne@68 18 assert errors == 'strict'
jpayne@68 19 f = BytesIO(input)
jpayne@68 20 g = BytesIO()
jpayne@68 21 quopri.decode(f, g)
jpayne@68 22 return (g.getvalue(), len(input))
jpayne@68 23
jpayne@68 24 class Codec(codecs.Codec):
jpayne@68 25 def encode(self, input, errors='strict'):
jpayne@68 26 return quopri_encode(input, errors)
jpayne@68 27 def decode(self, input, errors='strict'):
jpayne@68 28 return quopri_decode(input, errors)
jpayne@68 29
jpayne@68 30 class IncrementalEncoder(codecs.IncrementalEncoder):
jpayne@68 31 def encode(self, input, final=False):
jpayne@68 32 return quopri_encode(input, self.errors)[0]
jpayne@68 33
jpayne@68 34 class IncrementalDecoder(codecs.IncrementalDecoder):
jpayne@68 35 def decode(self, input, final=False):
jpayne@68 36 return quopri_decode(input, self.errors)[0]
jpayne@68 37
jpayne@68 38 class StreamWriter(Codec, codecs.StreamWriter):
jpayne@68 39 charbuffertype = bytes
jpayne@68 40
jpayne@68 41 class StreamReader(Codec, codecs.StreamReader):
jpayne@68 42 charbuffertype = bytes
jpayne@68 43
jpayne@68 44 # encodings module API
jpayne@68 45
jpayne@68 46 def getregentry():
jpayne@68 47 return codecs.CodecInfo(
jpayne@68 48 name='quopri',
jpayne@68 49 encode=quopri_encode,
jpayne@68 50 decode=quopri_decode,
jpayne@68 51 incrementalencoder=IncrementalEncoder,
jpayne@68 52 incrementaldecoder=IncrementalDecoder,
jpayne@68 53 streamwriter=StreamWriter,
jpayne@68 54 streamreader=StreamReader,
jpayne@68 55 _is_text_encoding=False,
jpayne@68 56 )