jpayne@68: """ Python 'utf-8' Codec jpayne@68: jpayne@68: jpayne@68: Written by Marc-Andre Lemburg (mal@lemburg.com). jpayne@68: jpayne@68: (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. jpayne@68: jpayne@68: """ jpayne@68: import codecs jpayne@68: jpayne@68: ### Codec APIs jpayne@68: jpayne@68: encode = codecs.utf_8_encode jpayne@68: jpayne@68: def decode(input, errors='strict'): jpayne@68: return codecs.utf_8_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_8_encode(input, self.errors)[0] jpayne@68: jpayne@68: class IncrementalDecoder(codecs.BufferedIncrementalDecoder): jpayne@68: _buffer_decode = codecs.utf_8_decode jpayne@68: jpayne@68: class StreamWriter(codecs.StreamWriter): jpayne@68: encode = codecs.utf_8_encode jpayne@68: jpayne@68: class StreamReader(codecs.StreamReader): jpayne@68: decode = codecs.utf_8_decode jpayne@68: jpayne@68: ### encodings module API jpayne@68: jpayne@68: def getregentry(): jpayne@68: return codecs.CodecInfo( jpayne@68: name='utf-8', 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: )