1 """ Python 'utf-7' Codec 2 3 Written by Brian Quinlan (brian (at] sweetapp.com). 4 """ 5 import codecs 6 7 ### Codec APIs 8 9 encode = codecs.utf_7_encode 10 11 def decode(input, errors='strict'): 12 return codecs.utf_7_decode(input, errors, True) 13 14 class IncrementalEncoder(codecs.IncrementalEncoder): 15 def encode(self, input, final=False): 16 return codecs.utf_7_encode(input, self.errors)[0] 17 18 class IncrementalDecoder(codecs.BufferedIncrementalDecoder): 19 _buffer_decode = codecs.utf_7_decode 20 21 class StreamWriter(codecs.StreamWriter): 22 encode = codecs.utf_7_encode 23 24 class StreamReader(codecs.StreamReader): 25 decode = codecs.utf_7_decode 26 27 ### encodings module API 28 29 def getregentry(): 30 return codecs.CodecInfo( 31 name='utf-7', 32 encode=encode, 33 decode=decode, 34 incrementalencoder=IncrementalEncoder, 35 incrementaldecoder=IncrementalDecoder, 36 streamreader=StreamReader, 37 streamwriter=StreamWriter, 38 ) 39