ascii.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. """ Python 'ascii' 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.ascii_encode
  11. decode = codecs.ascii_decode
  12. class IncrementalEncoder(codecs.IncrementalEncoder):
  13. def encode(self, input, final=False):
  14. return codecs.ascii_encode(input, self.errors)[0]
  15. class IncrementalDecoder(codecs.IncrementalDecoder):
  16. def decode(self, input, final=False):
  17. return codecs.ascii_decode(input, self.errors)[0]
  18. class StreamWriter(Codec,codecs.StreamWriter):
  19. pass
  20. class StreamReader(Codec,codecs.StreamReader):
  21. pass
  22. class StreamConverter(StreamWriter,StreamReader):
  23. encode = codecs.ascii_decode
  24. decode = codecs.ascii_encode
  25. ### encodings module API
  26. def getregentry():
  27. return codecs.CodecInfo(
  28. name='ascii',
  29. encode=Codec.encode,
  30. decode=Codec.decode,
  31. incrementalencoder=IncrementalEncoder,
  32. incrementaldecoder=IncrementalDecoder,
  33. streamwriter=StreamWriter,
  34. streamreader=StreamReader,
  35. )