14adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao""" Python 'mbcs' Codec for Windows 24adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 34adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 44adfde8bc82dd39f59e0445588c3e599ada477dJosh GaoCloned by Mark Hammond (mhammond@skippinet.com.au) from ascii.py, 54adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaowhich was written by Marc-Andre Lemburg (mal@lemburg.com). 64adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 74adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao(c) Copyright CNRI, All Rights Reserved. NO WARRANTY. 84adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 94adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao""" 104adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao# Import them explicitly to cause an ImportError 114adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao# on non-Windows systems 124adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaofrom codecs import mbcs_encode, mbcs_decode 134adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao# for IncrementalDecoder, IncrementalEncoder, ... 144adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaoimport codecs 154adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 164adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao### Codec APIs 174adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 184adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaoencode = mbcs_encode 194adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 204adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaodef decode(input, errors='strict'): 214adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao return mbcs_decode(input, errors, True) 224adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 234adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaoclass IncrementalEncoder(codecs.IncrementalEncoder): 244adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao def encode(self, input, final=False): 254adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao return mbcs_encode(input, self.errors)[0] 264adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 274adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaoclass IncrementalDecoder(codecs.BufferedIncrementalDecoder): 284adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao _buffer_decode = mbcs_decode 294adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 304adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaoclass StreamWriter(codecs.StreamWriter): 314adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao encode = mbcs_encode 324adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 334adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaoclass StreamReader(codecs.StreamReader): 344adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao decode = mbcs_decode 354adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 364adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao### encodings module API 374adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao 384adfde8bc82dd39f59e0445588c3e599ada477dJosh Gaodef getregentry(): 394adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao return codecs.CodecInfo( 404adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao name='mbcs', 414adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao encode=encode, 424adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao decode=decode, 434adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao incrementalencoder=IncrementalEncoder, 444adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao incrementaldecoder=IncrementalDecoder, 454adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao streamreader=StreamReader, 464adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao streamwriter=StreamWriter, 474adfde8bc82dd39f59e0445588c3e599ada477dJosh Gao ) 48