gb18030.py 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #
  2. # gb18030.py: Python Unicode Codec for GB18030
  3. #
  4. # Written by Hye-Shik Chang <perky@FreeBSD.org>
  5. #
  6. import _codecs_cn, codecs
  7. import _multibytecodec as mbc
  8. codec = _codecs_cn.getcodec('gb18030')
  9. class Codec(codecs.Codec):
  10. encode = codec.encode
  11. decode = codec.decode
  12. class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
  13. codecs.IncrementalEncoder):
  14. codec = codec
  15. class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
  16. codecs.IncrementalDecoder):
  17. codec = codec
  18. class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
  19. codec = codec
  20. class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
  21. codec = codec
  22. def getregentry():
  23. return codecs.CodecInfo(
  24. name='gb18030',
  25. encode=Codec().encode,
  26. decode=Codec().decode,
  27. incrementalencoder=IncrementalEncoder,
  28. incrementaldecoder=IncrementalDecoder,
  29. streamreader=StreamReader,
  30. streamwriter=StreamWriter,
  31. )