oem.py 1019 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. """ Python 'oem' Codec for Windows
  2. """
  3. # Import them explicitly to cause an ImportError
  4. # on non-Windows systems
  5. from codecs import oem_encode, oem_decode
  6. # for IncrementalDecoder, IncrementalEncoder, ...
  7. import codecs
  8. ### Codec APIs
  9. encode = oem_encode
  10. def decode(input, errors='strict'):
  11. return oem_decode(input, errors, True)
  12. class IncrementalEncoder(codecs.IncrementalEncoder):
  13. def encode(self, input, final=False):
  14. return oem_encode(input, self.errors)[0]
  15. class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
  16. _buffer_decode = oem_decode
  17. class StreamWriter(codecs.StreamWriter):
  18. encode = oem_encode
  19. class StreamReader(codecs.StreamReader):
  20. decode = oem_decode
  21. ### encodings module API
  22. def getregentry():
  23. return codecs.CodecInfo(
  24. name='oem',
  25. encode=encode,
  26. decode=decode,
  27. incrementalencoder=IncrementalEncoder,
  28. incrementaldecoder=IncrementalDecoder,
  29. streamreader=StreamReader,
  30. streamwriter=StreamWriter,
  31. )