jpayne@69: """ Python 'utf-8' Codec jpayne@69: jpayne@69: jpayne@69: Written by Marc-Andre Lemburg (mal@lemburg.com). jpayne@69: jpayne@69: (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. jpayne@69: jpayne@69: """ jpayne@69: import codecs jpayne@69: jpayne@69: ### Codec APIs jpayne@69: jpayne@69: encode = codecs.utf_8_encode jpayne@69: jpayne@69: def decode(input, errors='strict'): jpayne@69: return codecs.utf_8_decode(input, errors, True) jpayne@69: jpayne@69: class IncrementalEncoder(codecs.IncrementalEncoder): jpayne@69: def encode(self, input, final=False): jpayne@69: return codecs.utf_8_encode(input, self.errors)[0] jpayne@69: jpayne@69: class IncrementalDecoder(codecs.BufferedIncrementalDecoder): jpayne@69: _buffer_decode = codecs.utf_8_decode jpayne@69: jpayne@69: class StreamWriter(codecs.StreamWriter): jpayne@69: encode = codecs.utf_8_encode jpayne@69: jpayne@69: class StreamReader(codecs.StreamReader): jpayne@69: decode = codecs.utf_8_decode jpayne@69: jpayne@69: ### encodings module API jpayne@69: jpayne@69: def getregentry(): jpayne@69: return codecs.CodecInfo( jpayne@69: name='utf-8', jpayne@69: encode=encode, jpayne@69: decode=decode, jpayne@69: incrementalencoder=IncrementalEncoder, jpayne@69: incrementaldecoder=IncrementalDecoder, jpayne@69: streamreader=StreamReader, jpayne@69: streamwriter=StreamWriter, jpayne@69: )