undefined.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. """ Python 'undefined' Codec
  2. This codec will always raise a ValueError exception when being
  3. used. It is intended for use by the site.py file to switch off
  4. automatic string to Unicode coercion.
  5. Written by Marc-Andre Lemburg (mal@lemburg.com).
  6. (c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
  7. """
  8. import codecs
  9. ### Codec APIs
  10. class Codec(codecs.Codec):
  11. def encode(self,input,errors='strict'):
  12. raise UnicodeError("undefined encoding")
  13. def decode(self,input,errors='strict'):
  14. raise UnicodeError("undefined encoding")
  15. class IncrementalEncoder(codecs.IncrementalEncoder):
  16. def encode(self, input, final=False):
  17. raise UnicodeError("undefined encoding")
  18. class IncrementalDecoder(codecs.IncrementalDecoder):
  19. def decode(self, input, final=False):
  20. raise UnicodeError("undefined encoding")
  21. class StreamWriter(Codec,codecs.StreamWriter):
  22. pass
  23. class StreamReader(Codec,codecs.StreamReader):
  24. pass
  25. ### encodings module API
  26. def getregentry():
  27. return codecs.CodecInfo(
  28. name='undefined',
  29. encode=Codec().encode,
  30. decode=Codec().decode,
  31. incrementalencoder=IncrementalEncoder,
  32. incrementaldecoder=IncrementalDecoder,
  33. streamwriter=StreamWriter,
  34. streamreader=StreamReader,
  35. )