mbcs.py 1.2 KB

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