/Lib/encodings/unicode_escape.py

http://unladen-swallow.googlecode.com/ · Python · 45 lines · 45 code · 0 blank · 0 comment · 0 complexity · 41da3afec28596903e384515f6b9a9a5 MD5 · raw file

  1. """ Python 'unicode-escape' 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. class Codec(codecs.Codec):
  8. # Note: Binding these as C functions will result in the class not
  9. # converting them to methods. This is intended.
  10. encode = codecs.unicode_escape_encode
  11. decode = codecs.unicode_escape_decode
  12. class IncrementalEncoder(codecs.IncrementalEncoder):
  13. def encode(self, input, final=False):
  14. return codecs.unicode_escape_encode(input, self.errors)[0]
  15. class IncrementalDecoder(codecs.IncrementalDecoder):
  16. def decode(self, input, final=False):
  17. return codecs.unicode_escape_decode(input, self.errors)[0]
  18. class StreamWriter(Codec,codecs.StreamWriter):
  19. pass
  20. class StreamReader(Codec,codecs.StreamReader):
  21. pass
  22. ### encodings module API
  23. def getregentry():
  24. return codecs.CodecInfo(
  25. name='unicode-escape',
  26. encode=Codec.encode,
  27. decode=Codec.decode,
  28. incrementalencoder=IncrementalEncoder,
  29. incrementaldecoder=IncrementalDecoder,
  30. streamwriter=StreamWriter,
  31. streamreader=StreamReader,
  32. )