2004-01-17 10:29:29 -04:00
|
|
|
#
|
|
|
|
# gb2312.py: Python Unicode Codec for GB2312
|
|
|
|
#
|
|
|
|
# Written by Hye-Shik Chang <perky@FreeBSD.org>
|
|
|
|
#
|
|
|
|
|
2004-07-18 00:06:29 -03:00
|
|
|
import _codecs_cn, codecs
|
2006-03-25 22:34:59 -04:00
|
|
|
import _multibytecodec as mbc
|
2004-07-18 00:06:29 -03:00
|
|
|
|
|
|
|
codec = _codecs_cn.getcodec('gb2312')
|
2004-01-17 10:29:29 -04:00
|
|
|
|
|
|
|
class Codec(codecs.Codec):
|
|
|
|
encode = codec.encode
|
|
|
|
decode = codec.decode
|
|
|
|
|
2006-03-25 22:34:59 -04:00
|
|
|
class IncrementalEncoder(mbc.MultibyteIncrementalEncoder,
|
|
|
|
codecs.IncrementalEncoder):
|
|
|
|
codec = codec
|
2006-03-27 05:02:04 -04:00
|
|
|
|
2006-03-25 22:34:59 -04:00
|
|
|
class IncrementalDecoder(mbc.MultibyteIncrementalDecoder,
|
|
|
|
codecs.IncrementalDecoder):
|
|
|
|
codec = codec
|
2006-03-27 05:02:04 -04:00
|
|
|
|
2006-03-25 22:34:59 -04:00
|
|
|
class StreamReader(Codec, mbc.MultibyteStreamReader, codecs.StreamReader):
|
|
|
|
codec = codec
|
2006-03-27 05:02:04 -04:00
|
|
|
|
2006-03-25 22:34:59 -04:00
|
|
|
class StreamWriter(Codec, mbc.MultibyteStreamWriter, codecs.StreamWriter):
|
|
|
|
codec = codec
|
2004-01-17 10:29:29 -04:00
|
|
|
|
|
|
|
def getregentry():
|
2006-03-25 22:34:59 -04:00
|
|
|
return codecs.CodecInfo(
|
|
|
|
name='gb2312',
|
|
|
|
encode=Codec().encode,
|
|
|
|
decode=Codec().decode,
|
|
|
|
incrementalencoder=IncrementalEncoder,
|
|
|
|
incrementaldecoder=IncrementalDecoder,
|
|
|
|
streamreader=StreamReader,
|
|
|
|
streamwriter=StreamWriter,
|
|
|
|
)
|