--- /dev/null
+""" Generic Python Character Mapping Codec.\r
+\r
+ Use this codec directly rather than through the automatic\r
+ conversion mechanisms supplied by unicode() and .encode().\r
+\r
+\r
+Written by Marc-Andre Lemburg (mal@lemburg.com).\r
+\r
+(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.\r
+\r
+"""#"\r
+\r
+import codecs\r
+\r
+### Codec APIs\r
+\r
+class Codec(codecs.Codec):\r
+\r
+ # Note: Binding these as C functions will result in the class not\r
+ # converting them to methods. This is intended.\r
+ encode = codecs.charmap_encode\r
+ decode = codecs.charmap_decode\r
+\r
+class IncrementalEncoder(codecs.IncrementalEncoder):\r
+ def __init__(self, errors='strict', mapping=None):\r
+ codecs.IncrementalEncoder.__init__(self, errors)\r
+ self.mapping = mapping\r
+\r
+ def encode(self, input, final=False):\r
+ return codecs.charmap_encode(input, self.errors, self.mapping)[0]\r
+\r
+class IncrementalDecoder(codecs.IncrementalDecoder):\r
+ def __init__(self, errors='strict', mapping=None):\r
+ codecs.IncrementalDecoder.__init__(self, errors)\r
+ self.mapping = mapping\r
+\r
+ def decode(self, input, final=False):\r
+ return codecs.charmap_decode(input, self.errors, self.mapping)[0]\r
+\r
+class StreamWriter(Codec,codecs.StreamWriter):\r
+\r
+ def __init__(self,stream,errors='strict',mapping=None):\r
+ codecs.StreamWriter.__init__(self,stream,errors)\r
+ self.mapping = mapping\r
+\r
+ def encode(self,input,errors='strict'):\r
+ return Codec.encode(input,errors,self.mapping)\r
+\r
+class StreamReader(Codec,codecs.StreamReader):\r
+\r
+ def __init__(self,stream,errors='strict',mapping=None):\r
+ codecs.StreamReader.__init__(self,stream,errors)\r
+ self.mapping = mapping\r
+\r
+ def decode(self,input,errors='strict'):\r
+ return Codec.decode(input,errors,self.mapping)\r
+\r
+### encodings module API\r
+\r
+def getregentry():\r
+ return codecs.CodecInfo(\r
+ name='charmap',\r
+ encode=Codec.encode,\r
+ decode=Codec.decode,\r
+ incrementalencoder=IncrementalEncoder,\r
+ incrementaldecoder=IncrementalDecoder,\r
+ streamwriter=StreamWriter,\r
+ streamreader=StreamReader,\r
+ )\r