blob: 1bf6336571547bcec3f5aa7978ff1c7f247490ce [file] [log] [blame]
Guido van Rossum0229bf62000-03-10 23:17:24 +00001""" Python 'utf-8' Codec
2
3
4Written by Marc-Andre Lemburg (mal@lemburg.com).
5
6(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
7
8"""
9import codecs
10
11### Codec APIs
12
Walter Dörwald69652032004-09-07 20:24:22 +000013encode = codecs.utf_8_encode
Guido van Rossum0229bf62000-03-10 23:17:24 +000014
Walter Dörwald69652032004-09-07 20:24:22 +000015def decode(input, errors='strict'):
16 return codecs.utf_8_decode(input, errors, True)
17
Walter Dörwaldabb02e52006-03-15 11:35:15 +000018class IncrementalEncoder(codecs.IncrementalEncoder):
19 def encode(self, input, final=False):
20 return codecs.utf_8_encode(input, self.errors)[0]
21
22class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
23 _buffer_decode = codecs.utf_8_decode
24
Walter Dörwald69652032004-09-07 20:24:22 +000025class StreamWriter(codecs.StreamWriter):
Guido van Rossum0229bf62000-03-10 23:17:24 +000026 encode = codecs.utf_8_encode
Walter Dörwald69652032004-09-07 20:24:22 +000027
28class StreamReader(codecs.StreamReader):
Guido van Rossum0229bf62000-03-10 23:17:24 +000029 decode = codecs.utf_8_decode
30
Guido van Rossum0229bf62000-03-10 23:17:24 +000031### encodings module API
32
33def getregentry():
Walter Dörwaldabb02e52006-03-15 11:35:15 +000034 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 )