latin_1.py 1.2 KB

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