Guido van Rossum | 0229bf6 | 2000-03-10 23:17:24 +0000 | [diff] [blame] | 1 | """ Python 'utf-8' Codec |
| 2 | |
| 3 | |
| 4 | Written by Marc-Andre Lemburg (mal@lemburg.com). |
| 5 | |
| 6 | (c) Copyright CNRI, All Rights Reserved. NO WARRANTY. |
| 7 | |
| 8 | """ |
| 9 | import codecs |
| 10 | |
| 11 | ### Codec APIs |
| 12 | |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 13 | encode = codecs.utf_8_encode |
Guido van Rossum | 0229bf6 | 2000-03-10 23:17:24 +0000 | [diff] [blame] | 14 | |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 15 | def decode(input, errors='strict'): |
| 16 | return codecs.utf_8_decode(input, errors, True) |
| 17 | |
Walter Dörwald | abb02e5 | 2006-03-15 11:35:15 +0000 | [diff] [blame] | 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 | |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 25 | class StreamWriter(codecs.StreamWriter): |
Guido van Rossum | 0229bf6 | 2000-03-10 23:17:24 +0000 | [diff] [blame] | 26 | encode = codecs.utf_8_encode |
Walter Dörwald | 6965203 | 2004-09-07 20:24:22 +0000 | [diff] [blame] | 27 | |
| 28 | class StreamReader(codecs.StreamReader): |
Guido van Rossum | 0229bf6 | 2000-03-10 23:17:24 +0000 | [diff] [blame] | 29 | decode = codecs.utf_8_decode |
| 30 | |
Guido van Rossum | 0229bf6 | 2000-03-10 23:17:24 +0000 | [diff] [blame] | 31 | ### encodings module API |
| 32 | |
| 33 | def getregentry(): |
Walter Dörwald | abb02e5 | 2006-03-15 11:35:15 +0000 | [diff] [blame] | 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 | ) |