Home | History | Annotate | Download | only in encodings
      1 """ Python 'utf-8' Codec
      2 
      3 
      4 Written by Marc-Andre Lemburg (mal (at] lemburg.com).
      5 
      6 (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
      7 
      8 """
      9 import codecs
     10 
     11 ### Codec APIs
     12 
     13 encode = codecs.utf_8_encode
     14 
     15 def decode(input, errors='strict'):
     16     return codecs.utf_8_decode(input, errors, True)
     17 
     18 class IncrementalEncoder(codecs.IncrementalEncoder):
     19     def encode(self, input, final=False):
     20         return codecs.utf_8_encode(input, self.errors)[0]
     21 
     22 class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
     23     _buffer_decode = codecs.utf_8_decode
     24 
     25 class StreamWriter(codecs.StreamWriter):
     26     encode = codecs.utf_8_encode
     27 
     28 class StreamReader(codecs.StreamReader):
     29     decode = codecs.utf_8_decode
     30 
     31 ### encodings module API
     32 
     33 def getregentry():
     34     return codecs.CodecInfo(
     35         name='utf-8',
     36         encode=encode,
     37         decode=decode,
     38         incrementalencoder=IncrementalEncoder,
     39         incrementaldecoder=IncrementalDecoder,
     40         streamreader=StreamReader,
     41         streamwriter=StreamWriter,
     42     )
     43