Home | History | Annotate | Download | only in encodings
      1 """ Python 'mbcs' Codec for Windows
      2 
      3 
      4 Cloned by Mark Hammond (mhammond (at] skippinet.com.au) from ascii.py,
      5 which was written by Marc-Andre Lemburg (mal (at] 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
     12 from codecs import mbcs_encode, mbcs_decode
     13 # for IncrementalDecoder, IncrementalEncoder, ...
     14 import codecs
     15 
     16 ### Codec APIs
     17 
     18 encode = mbcs_encode
     19 
     20 def decode(input, errors='strict'):
     21     return mbcs_decode(input, errors, True)
     22 
     23 class IncrementalEncoder(codecs.IncrementalEncoder):
     24     def encode(self, input, final=False):
     25         return mbcs_encode(input, self.errors)[0]
     26 
     27 class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
     28     _buffer_decode = mbcs_decode
     29 
     30 class StreamWriter(codecs.StreamWriter):
     31     encode = mbcs_encode
     32 
     33 class StreamReader(codecs.StreamReader):
     34     decode = mbcs_decode
     35 
     36 ### encodings module API
     37 
     38 def 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