1""" Python 'mbcs' Codec for Windows 2 3 4Cloned by Mark Hammond (mhammond@skippinet.com.au) from ascii.py, 5which was written by Marc-Andre Lemburg (mal@lemburg.com). 6 7(c) Copyright CNRI, All Rights Reserved. NO WARRANTY. 8 9""" 10# Import them explicitly to cause an ImportError 11# on non-Windows systems 12from codecs import mbcs_encode, mbcs_decode 13# for IncrementalDecoder, IncrementalEncoder, ... 14import codecs 15 16### Codec APIs 17 18encode = mbcs_encode 19 20def decode(input, errors='strict'): 21 return mbcs_decode(input, errors, True) 22 23class IncrementalEncoder(codecs.IncrementalEncoder): 24 def encode(self, input, final=False): 25 return mbcs_encode(input, self.errors)[0] 26 27class IncrementalDecoder(codecs.BufferedIncrementalDecoder): 28 _buffer_decode = mbcs_decode 29 30class StreamWriter(codecs.StreamWriter): 31 encode = mbcs_encode 32 33class StreamReader(codecs.StreamReader): 34 decode = mbcs_decode 35 36### encodings module API 37 38def getregentry(): 39 return codecs.CodecInfo( 40 name='mbcs', 41 encode=encode, 42 decode=decode, 43 incrementalencoder=IncrementalEncoder, 44 incrementaldecoder=IncrementalDecoder, 45 streamreader=StreamReader, 46 streamwriter=StreamWriter, 47 ) 48