+++ /dev/null
-"""Codec for quoted-printable encoding.\r
-\r
-Like base64 and rot13, this returns Python strings, not Unicode.\r
-"""\r
-\r
-import codecs, quopri\r
-try:\r
- from cStringIO import StringIO\r
-except ImportError:\r
- from StringIO import StringIO\r
-\r
-def quopri_encode(input, errors='strict'):\r
- """Encode the input, returning a tuple (output object, length consumed).\r
-\r
- errors defines the error handling to apply. It defaults to\r
- 'strict' handling which is the only currently supported\r
- error handling for this codec.\r
-\r
- """\r
- assert errors == 'strict'\r
- # using str() because of cStringIO's Unicode undesired Unicode behavior.\r
- f = StringIO(str(input))\r
- g = StringIO()\r
- quopri.encode(f, g, 1)\r
- output = g.getvalue()\r
- return (output, len(input))\r
-\r
-def quopri_decode(input, errors='strict'):\r
- """Decode the input, returning a tuple (output object, length consumed).\r
-\r
- errors defines the error handling to apply. It defaults to\r
- 'strict' handling which is the only currently supported\r
- error handling for this codec.\r
-\r
- """\r
- assert errors == 'strict'\r
- f = StringIO(str(input))\r
- g = StringIO()\r
- quopri.decode(f, g)\r
- output = g.getvalue()\r
- return (output, len(input))\r
-\r
-class Codec(codecs.Codec):\r
-\r
- def encode(self, input,errors='strict'):\r
- return quopri_encode(input,errors)\r
- def decode(self, input,errors='strict'):\r
- return quopri_decode(input,errors)\r
-\r
-class IncrementalEncoder(codecs.IncrementalEncoder):\r
- def encode(self, input, final=False):\r
- return quopri_encode(input, self.errors)[0]\r
-\r
-class IncrementalDecoder(codecs.IncrementalDecoder):\r
- def decode(self, input, final=False):\r
- return quopri_decode(input, self.errors)[0]\r
-\r
-class StreamWriter(Codec, codecs.StreamWriter):\r
- pass\r
-\r
-class StreamReader(Codec,codecs.StreamReader):\r
- pass\r
-\r
-# encodings module API\r
-\r
-def getregentry():\r
- return codecs.CodecInfo(\r
- name='quopri',\r
- encode=quopri_encode,\r
- decode=quopri_decode,\r
- incrementalencoder=IncrementalEncoder,\r
- incrementaldecoder=IncrementalDecoder,\r
- streamwriter=StreamWriter,\r
- streamreader=StreamReader,\r
- )\r