annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/encodings/charmap.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 """ Generic Python Character Mapping Codec.
jpayne@68 2
jpayne@68 3 Use this codec directly rather than through the automatic
jpayne@68 4 conversion mechanisms supplied by unicode() and .encode().
jpayne@68 5
jpayne@68 6
jpayne@68 7 Written by Marc-Andre Lemburg (mal@lemburg.com).
jpayne@68 8
jpayne@68 9 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
jpayne@68 10
jpayne@68 11 """#"
jpayne@68 12
jpayne@68 13 import codecs
jpayne@68 14
jpayne@68 15 ### Codec APIs
jpayne@68 16
jpayne@68 17 class Codec(codecs.Codec):
jpayne@68 18
jpayne@68 19 # Note: Binding these as C functions will result in the class not
jpayne@68 20 # converting them to methods. This is intended.
jpayne@68 21 encode = codecs.charmap_encode
jpayne@68 22 decode = codecs.charmap_decode
jpayne@68 23
jpayne@68 24 class IncrementalEncoder(codecs.IncrementalEncoder):
jpayne@68 25 def __init__(self, errors='strict', mapping=None):
jpayne@68 26 codecs.IncrementalEncoder.__init__(self, errors)
jpayne@68 27 self.mapping = mapping
jpayne@68 28
jpayne@68 29 def encode(self, input, final=False):
jpayne@68 30 return codecs.charmap_encode(input, self.errors, self.mapping)[0]
jpayne@68 31
jpayne@68 32 class IncrementalDecoder(codecs.IncrementalDecoder):
jpayne@68 33 def __init__(self, errors='strict', mapping=None):
jpayne@68 34 codecs.IncrementalDecoder.__init__(self, errors)
jpayne@68 35 self.mapping = mapping
jpayne@68 36
jpayne@68 37 def decode(self, input, final=False):
jpayne@68 38 return codecs.charmap_decode(input, self.errors, self.mapping)[0]
jpayne@68 39
jpayne@68 40 class StreamWriter(Codec,codecs.StreamWriter):
jpayne@68 41
jpayne@68 42 def __init__(self,stream,errors='strict',mapping=None):
jpayne@68 43 codecs.StreamWriter.__init__(self,stream,errors)
jpayne@68 44 self.mapping = mapping
jpayne@68 45
jpayne@68 46 def encode(self,input,errors='strict'):
jpayne@68 47 return Codec.encode(input,errors,self.mapping)
jpayne@68 48
jpayne@68 49 class StreamReader(Codec,codecs.StreamReader):
jpayne@68 50
jpayne@68 51 def __init__(self,stream,errors='strict',mapping=None):
jpayne@68 52 codecs.StreamReader.__init__(self,stream,errors)
jpayne@68 53 self.mapping = mapping
jpayne@68 54
jpayne@68 55 def decode(self,input,errors='strict'):
jpayne@68 56 return Codec.decode(input,errors,self.mapping)
jpayne@68 57
jpayne@68 58 ### encodings module API
jpayne@68 59
jpayne@68 60 def getregentry():
jpayne@68 61 return codecs.CodecInfo(
jpayne@68 62 name='charmap',
jpayne@68 63 encode=Codec.encode,
jpayne@68 64 decode=Codec.decode,
jpayne@68 65 incrementalencoder=IncrementalEncoder,
jpayne@68 66 incrementaldecoder=IncrementalDecoder,
jpayne@68 67 streamwriter=StreamWriter,
jpayne@68 68 streamreader=StreamReader,
jpayne@68 69 )