0001 """Codec for quoted-printable encoding. 0002 0003 Like base64 and rot13, this returns Python strings, not Unicode. 0004 """ 0005 0006 import codecs, quopri 0007 try: 0008 from cStringIO import StringIO 0009 except ImportError: 0010 from StringIO import StringIO 0011 0012 def quopri_encode(input, errors='strict'): 0013 """Encode the input, returning a tuple (output object, length consumed). 0014 0015 errors defines the error handling to apply. It defaults to 0016 'strict' handling which is the only currently supported 0017 error handling for this codec. 0018 0019 """ 0020 assert errors == 'strict' 0021 f = StringIO(input) 0022 g = StringIO() 0023 quopri.encode(f, g, 1) 0024 output = g.getvalue() 0025 return (output, len(input)) 0026 0027 def quopri_decode(input, errors='strict'): 0028 """Decode the input, returning a tuple (output object, length consumed). 0029 0030 errors defines the error handling to apply. It defaults to 0031 'strict' handling which is the only currently supported 0032 error handling for this codec. 0033 0034 """ 0035 assert errors == 'strict' 0036 f = StringIO(input) 0037 g = StringIO() 0038 quopri.decode(f, g) 0039 output = g.getvalue() 0040 return (output, len(input)) 0041 0042 class Codec(codecs.Codec): 0043 0044 def encode(self, input,errors='strict'): 0045 return quopri_encode(input,errors) 0046 def decode(self, input,errors='strict'): 0047 return quopri_decode(input,errors) 0048 0049 class StreamWriter(Codec, codecs.StreamWriter): 0050 pass 0051 0052 class StreamReader(Codec,codecs.StreamReader): 0053 pass 0054 0055 # encodings module API 0056 0057 def getregentry(): 0058 return (quopri_encode, quopri_decode, StreamReader, StreamWriter) 0059
Generated by PyXR 0.9.4