utf_7.py 946 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. """ Python 'utf-7' Codec
  2. Written by Brian Quinlan (brian@sweetapp.com).
  3. """
  4. import codecs
  5. ### Codec APIs
  6. encode = codecs.utf_7_encode
  7. def decode(input, errors='strict'):
  8. return codecs.utf_7_decode(input, errors, True)
  9. class IncrementalEncoder(codecs.IncrementalEncoder):
  10. def encode(self, input, final=False):
  11. return codecs.utf_7_encode(input, self.errors)[0]
  12. class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
  13. _buffer_decode = codecs.utf_7_decode
  14. class StreamWriter(codecs.StreamWriter):
  15. encode = codecs.utf_7_encode
  16. class StreamReader(codecs.StreamReader):
  17. decode = codecs.utf_7_decode
  18. ### encodings module API
  19. def getregentry():
  20. return codecs.CodecInfo(
  21. name='utf-7',
  22. encode=encode,
  23. decode=decode,
  24. incrementalencoder=IncrementalEncoder,
  25. incrementaldecoder=IncrementalDecoder,
  26. streamreader=StreamReader,
  27. streamwriter=StreamWriter,
  28. )