jpayne@68: """ Python 'utf-7' Codec jpayne@68: jpayne@68: Written by Brian Quinlan (brian@sweetapp.com). jpayne@68: """ jpayne@68: import codecs jpayne@68: jpayne@68: ### Codec APIs jpayne@68: jpayne@68: encode = codecs.utf_7_encode jpayne@68: jpayne@68: def decode(input, errors='strict'): jpayne@68: return codecs.utf_7_decode(input, errors, True) jpayne@68: jpayne@68: class IncrementalEncoder(codecs.IncrementalEncoder): jpayne@68: def encode(self, input, final=False): jpayne@68: return codecs.utf_7_encode(input, self.errors)[0] jpayne@68: jpayne@68: class IncrementalDecoder(codecs.BufferedIncrementalDecoder): jpayne@68: _buffer_decode = codecs.utf_7_decode jpayne@68: jpayne@68: class StreamWriter(codecs.StreamWriter): jpayne@68: encode = codecs.utf_7_encode jpayne@68: jpayne@68: class StreamReader(codecs.StreamReader): jpayne@68: decode = codecs.utf_7_decode jpayne@68: jpayne@68: ### encodings module API jpayne@68: jpayne@68: def getregentry(): jpayne@68: return codecs.CodecInfo( jpayne@68: name='utf-7', jpayne@68: encode=encode, jpayne@68: decode=decode, jpayne@68: incrementalencoder=IncrementalEncoder, jpayne@68: incrementaldecoder=IncrementalDecoder, jpayne@68: streamreader=StreamReader, jpayne@68: streamwriter=StreamWriter, jpayne@68: )