utf_16_be.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. """ Python 'utf-16-be' Codec
  2. Written by Marc-Andre Lemburg (mal@lemburg.com).
  3. (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
  4. """
  5. import codecs
  6. ### Codec APIs
  7. encode = codecs.utf_16_be_encode
  8. def decode(input, errors='strict'):
  9. return codecs.utf_16_be_decode(input, errors, True)
  10. class IncrementalEncoder(codecs.IncrementalEncoder):
  11. def encode(self, input, final=False):
  12. return codecs.utf_16_be_encode(input, self.errors)[0]
  13. class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
  14. _buffer_decode = codecs.utf_16_be_decode
  15. class StreamWriter(codecs.StreamWriter):
  16. encode = codecs.utf_16_be_encode
  17. class StreamReader(codecs.StreamReader):
  18. decode = codecs.utf_16_be_decode
  19. ### encodings module API
  20. def getregentry():
  21. return codecs.CodecInfo(
  22. name='utf-16-be',
  23. encode=encode,
  24. decode=decode,
  25. incrementalencoder=IncrementalEncoder,
  26. incrementaldecoder=IncrementalDecoder,
  27. streamreader=StreamReader,
  28. streamwriter=StreamWriter,
  29. )