diff options
author | Hye-Shik Chang <hyeshik@gmail.com> | 2004-07-18 03:06:29 (GMT) |
---|---|---|
committer | Hye-Shik Chang <hyeshik@gmail.com> | 2004-07-18 03:06:29 (GMT) |
commit | 2bb146f2f4fd52b03cfa7ae739adb35d2b9f5421 (patch) | |
tree | ebd4c873cfc841dc978053941b2859d4efbd9082 /Lib | |
parent | 264c659197bcd2fc3e22776fc711f31b953daae5 (diff) | |
download | cpython-2bb146f2f4fd52b03cfa7ae739adb35d2b9f5421.zip cpython-2bb146f2f4fd52b03cfa7ae739adb35d2b9f5421.tar.gz cpython-2bb146f2f4fd52b03cfa7ae739adb35d2b9f5421.tar.bz2 |
Bring CJKCodecs 1.1 into trunk. This completely reorganizes source
and installed layouts to make maintenance simple and easy. And it
also adds four new codecs; big5hkscs, euc-jis-2004, shift-jis-2004
and iso2022-jp-2004.
Diffstat (limited to 'Lib')
38 files changed, 339 insertions, 138 deletions
diff --git a/Lib/encodings/aliases.py b/Lib/encodings/aliases.py index 579cf17..79f3cc6 100644 --- a/Lib/encodings/aliases.py +++ b/Lib/encodings/aliases.py @@ -39,6 +39,10 @@ aliases = { 'big5_tw' : 'big5', 'csbig5' : 'big5', + # big5hkscs codec + 'big5_hkscs' : 'big5hkscs', + 'hkscs' : 'big5hkscs', + # bz2_codec codec 'bz2' : 'bz2_codec', @@ -197,8 +201,12 @@ aliases = { '950' : 'cp950', 'ms950' : 'cp950', + # euc_jis_2004 codec + 'jisx0213' : 'euc_jis_2004', + 'eucjis2004' : 'euc_jis_2004', + 'euc_jis2004' : 'euc_jis_2004', + # euc_jisx0213 codec - 'jisx0213' : 'euc_jisx0213', 'eucjisx0213' : 'euc_jisx0213', # euc_jp codec @@ -254,6 +262,10 @@ aliases = { 'iso2022jp_2' : 'iso2022_jp_2', 'iso_2022_jp_2' : 'iso2022_jp_2', + # iso2022_jp_2004 codec + 'iso_2022_jp_2004' : 'iso2022_jp_2004', + 'iso2022jp_2004' : 'iso2022_jp_2004', + # iso2022_jp_3 codec 'iso2022jp_3' : 'iso2022_jp_3', 'iso_2022_jp_3' : 'iso2022_jp_3', @@ -416,6 +428,11 @@ aliases = { 'sjis' : 'shift_jis', 's_jis' : 'shift_jis', + # shift_jis_2004 codec + 'shiftjis2004' : 'shift_jis_2004', + 'sjis_2004' : 'shift_jis_2004', + 's_jis_2004' : 'shift_jis_2004', + # shift_jisx0213 codec 'shiftjisx0213' : 'shift_jisx0213', 'sjisx0213' : 'shift_jisx0213', diff --git a/Lib/encodings/big5.py b/Lib/encodings/big5.py index 0f855f8..d56aa1b 100644 --- a/Lib/encodings/big5.py +++ b/Lib/encodings/big5.py @@ -2,11 +2,12 @@ # big5.py: Python Unicode Codec for BIG5 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: big5.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: big5.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_big5 import codec -import codecs +import _codecs_tw, codecs + +codec = _codecs_tw.getcodec('big5') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/big5hkscs.py b/Lib/encodings/big5hkscs.py new file mode 100644 index 0000000..443997f --- /dev/null +++ b/Lib/encodings/big5hkscs.py @@ -0,0 +1,34 @@ +# +# big5hkscs.py: Python Unicode Codec for BIG5HKSCS +# +# Written by Hye-Shik Chang <perky@FreeBSD.org> +# $CJKCodecs: big5hkscs.py,v 1.1 2004/06/29 05:14:27 perky Exp $ +# + +import _codecs_hk, codecs + +codec = _codecs_hk.getcodec('big5hkscs') + +class Codec(codecs.Codec): + encode = codec.encode + decode = codec.decode + +class StreamReader(Codec, codecs.StreamReader): + def __init__(self, stream, errors='strict'): + codecs.StreamReader.__init__(self, stream, errors) + __codec = codec.StreamReader(stream, errors) + self.read = __codec.read + self.readline = __codec.readline + self.readlines = __codec.readlines + self.reset = __codec.reset + +class StreamWriter(Codec, codecs.StreamWriter): + def __init__(self, stream, errors='strict'): + codecs.StreamWriter.__init__(self, stream, errors) + __codec = codec.StreamWriter(stream, errors) + self.write = __codec.write + self.writelines = __codec.writelines + self.reset = __codec.reset + +def getregentry(): + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/cp932.py b/Lib/encodings/cp932.py index 028832d..38937f5 100644 --- a/Lib/encodings/cp932.py +++ b/Lib/encodings/cp932.py @@ -2,11 +2,12 @@ # cp932.py: Python Unicode Codec for CP932 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: cp932.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: cp932.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_cp932 import codec -import codecs +import _codecs_jp, codecs + +codec = _codecs_jp.getcodec('cp932') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/cp949.py b/Lib/encodings/cp949.py index c499d20..0f3c847 100644 --- a/Lib/encodings/cp949.py +++ b/Lib/encodings/cp949.py @@ -2,11 +2,12 @@ # cp949.py: Python Unicode Codec for CP949 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: cp949.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: cp949.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_cp949 import codec -import codecs +import _codecs_kr, codecs + +codec = _codecs_kr.getcodec('cp949') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/cp950.py b/Lib/encodings/cp950.py index 104651d..dab3e28 100644 --- a/Lib/encodings/cp950.py +++ b/Lib/encodings/cp950.py @@ -2,11 +2,12 @@ # cp950.py: Python Unicode Codec for CP950 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: cp950.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: cp950.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_cp950 import codec -import codecs +import _codecs_tw, codecs + +codec = _codecs_tw.getcodec('cp950') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/euc_jis_2004.py b/Lib/encodings/euc_jis_2004.py new file mode 100644 index 0000000..02d55ca --- /dev/null +++ b/Lib/encodings/euc_jis_2004.py @@ -0,0 +1,34 @@ +# +# euc_jis_2004.py: Python Unicode Codec for EUC_JIS_2004 +# +# Written by Hye-Shik Chang <perky@FreeBSD.org> +# $CJKCodecs: euc_jis_2004.py,v 1.1 2004/07/07 16:18:25 perky Exp $ +# + +import _codecs_jp, codecs + +codec = _codecs_jp.getcodec('euc_jis_2004') + +class Codec(codecs.Codec): + encode = codec.encode + decode = codec.decode + +class StreamReader(Codec, codecs.StreamReader): + def __init__(self, stream, errors='strict'): + codecs.StreamReader.__init__(self, stream, errors) + __codec = codec.StreamReader(stream, errors) + self.read = __codec.read + self.readline = __codec.readline + self.readlines = __codec.readlines + self.reset = __codec.reset + +class StreamWriter(Codec, codecs.StreamWriter): + def __init__(self, stream, errors='strict'): + codecs.StreamWriter.__init__(self, stream, errors) + __codec = codec.StreamWriter(stream, errors) + self.write = __codec.write + self.writelines = __codec.writelines + self.reset = __codec.reset + +def getregentry(): + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/euc_jisx0213.py b/Lib/encodings/euc_jisx0213.py index 9da6b99..30f173e 100644 --- a/Lib/encodings/euc_jisx0213.py +++ b/Lib/encodings/euc_jisx0213.py @@ -2,11 +2,12 @@ # euc_jisx0213.py: Python Unicode Codec for EUC_JISX0213 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: euc_jisx0213.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: euc_jisx0213.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_euc_jisx0213 import codec -import codecs +import _codecs_jp, codecs + +codec = _codecs_jp.getcodec('euc_jisx0213') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/euc_jp.py b/Lib/encodings/euc_jp.py index 77fe2b6..a3947a3 100644 --- a/Lib/encodings/euc_jp.py +++ b/Lib/encodings/euc_jp.py @@ -2,11 +2,12 @@ # euc_jp.py: Python Unicode Codec for EUC_JP # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: euc_jp.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: euc_jp.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_euc_jp import codec -import codecs +import _codecs_jp, codecs + +codec = _codecs_jp.getcodec('euc_jp') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/euc_kr.py b/Lib/encodings/euc_kr.py index 9ef155e..bbebee8 100644 --- a/Lib/encodings/euc_kr.py +++ b/Lib/encodings/euc_kr.py @@ -2,11 +2,12 @@ # euc_kr.py: Python Unicode Codec for EUC_KR # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: euc_kr.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: euc_kr.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_euc_kr import codec -import codecs +import _codecs_kr, codecs + +codec = _codecs_kr.getcodec('euc_kr') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/gb18030.py b/Lib/encodings/gb18030.py index f628af3..7eca319 100644 --- a/Lib/encodings/gb18030.py +++ b/Lib/encodings/gb18030.py @@ -2,11 +2,12 @@ # gb18030.py: Python Unicode Codec for GB18030 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: gb18030.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: gb18030.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_gb18030 import codec -import codecs +import _codecs_cn, codecs + +codec = _codecs_cn.getcodec('gb18030') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/gb2312.py b/Lib/encodings/gb2312.py index 7ced701..5130efa 100644 --- a/Lib/encodings/gb2312.py +++ b/Lib/encodings/gb2312.py @@ -2,11 +2,12 @@ # gb2312.py: Python Unicode Codec for GB2312 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: gb2312.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: gb2312.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_gb2312 import codec -import codecs +import _codecs_cn, codecs + +codec = _codecs_cn.getcodec('gb2312') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/gbk.py b/Lib/encodings/gbk.py index f5e32e5..67854bc 100644 --- a/Lib/encodings/gbk.py +++ b/Lib/encodings/gbk.py @@ -2,11 +2,12 @@ # gbk.py: Python Unicode Codec for GBK # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: gbk.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: gbk.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_gbk import codec -import codecs +import _codecs_cn, codecs + +codec = _codecs_cn.getcodec('gbk') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/hz.py b/Lib/encodings/hz.py index 0278ce5..3940894 100644 --- a/Lib/encodings/hz.py +++ b/Lib/encodings/hz.py @@ -2,11 +2,12 @@ # hz.py: Python Unicode Codec for HZ # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: hz.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: hz.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_hz import codec -import codecs +import _codecs_cn, codecs + +codec = _codecs_cn.getcodec('hz') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/iso2022_jp.py b/Lib/encodings/iso2022_jp.py index a23a13a..109658b 100644 --- a/Lib/encodings/iso2022_jp.py +++ b/Lib/encodings/iso2022_jp.py @@ -1,12 +1,13 @@ # -# iso2022_jp.py: Python Unicode Codec for ISO_2022_JP +# iso2022_jp.py: Python Unicode Codec for ISO2022_JP # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: iso2022_jp.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: iso2022_jp.py,v 1.2 2004/06/28 18:16:03 perky Exp $ # -from _codecs_iso2022_jp import codec -import codecs +import _codecs_iso2022, codecs + +codec = _codecs_iso2022.getcodec('iso2022_jp') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/iso2022_jp_1.py b/Lib/encodings/iso2022_jp_1.py index 6050e5f..201bd28 100644 --- a/Lib/encodings/iso2022_jp_1.py +++ b/Lib/encodings/iso2022_jp_1.py @@ -1,12 +1,13 @@ # -# iso2022_jp_1.py: Python Unicode Codec for ISO_2022_JP_1 +# iso2022_jp_1.py: Python Unicode Codec for ISO2022_JP_1 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: iso2022_jp_1.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: iso2022_jp_1.py,v 1.2 2004/06/28 18:16:03 perky Exp $ # -from _codecs_iso2022_jp_1 import codec -import codecs +import _codecs_iso2022, codecs + +codec = _codecs_iso2022.getcodec('iso2022_jp_1') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/iso2022_jp_2.py b/Lib/encodings/iso2022_jp_2.py index 6171710..7a61018 100644 --- a/Lib/encodings/iso2022_jp_2.py +++ b/Lib/encodings/iso2022_jp_2.py @@ -1,12 +1,13 @@ # -# iso2022_jp_2.py: Python Unicode Codec for ISO_2022_JP_2 +# iso2022_jp_2.py: Python Unicode Codec for ISO2022_JP_2 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: iso2022_jp_2.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: iso2022_jp_2.py,v 1.2 2004/06/28 18:16:03 perky Exp $ # -from _codecs_iso2022_jp_2 import codec -import codecs +import _codecs_iso2022, codecs + +codec = _codecs_iso2022.getcodec('iso2022_jp_2') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/iso2022_jp_2004.py b/Lib/encodings/iso2022_jp_2004.py new file mode 100644 index 0000000..2497124 --- /dev/null +++ b/Lib/encodings/iso2022_jp_2004.py @@ -0,0 +1,34 @@ +# +# iso2022_jp_2004.py: Python Unicode Codec for ISO2022_JP_2004 +# +# Written by Hye-Shik Chang <perky@FreeBSD.org> +# $CJKCodecs: iso2022_jp_2004.py,v 1.1 2004/07/07 16:18:25 perky Exp $ +# + +import _codecs_iso2022, codecs + +codec = _codecs_iso2022.getcodec('iso2022_jp_2004') + +class Codec(codecs.Codec): + encode = codec.encode + decode = codec.decode + +class StreamReader(Codec, codecs.StreamReader): + def __init__(self, stream, errors='strict'): + codecs.StreamReader.__init__(self, stream, errors) + __codec = codec.StreamReader(stream, errors) + self.read = __codec.read + self.readline = __codec.readline + self.readlines = __codec.readlines + self.reset = __codec.reset + +class StreamWriter(Codec, codecs.StreamWriter): + def __init__(self, stream, errors='strict'): + codecs.StreamWriter.__init__(self, stream, errors) + __codec = codec.StreamWriter(stream, errors) + self.write = __codec.write + self.writelines = __codec.writelines + self.reset = __codec.reset + +def getregentry(): + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/iso2022_jp_3.py b/Lib/encodings/iso2022_jp_3.py index 144f83e..8b2ed00 100644 --- a/Lib/encodings/iso2022_jp_3.py +++ b/Lib/encodings/iso2022_jp_3.py @@ -1,12 +1,13 @@ # -# iso2022_jp_3.py: Python Unicode Codec for ISO_2022_JP_3 +# iso2022_jp_3.py: Python Unicode Codec for ISO2022_JP_3 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: iso2022_jp_3.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: iso2022_jp_3.py,v 1.2 2004/06/28 18:16:03 perky Exp $ # -from _codecs_iso2022_jp_3 import codec -import codecs +import _codecs_iso2022, codecs + +codec = _codecs_iso2022.getcodec('iso2022_jp_3') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/iso2022_jp_ext.py b/Lib/encodings/iso2022_jp_ext.py index 7adf758..97cb4e7 100644 --- a/Lib/encodings/iso2022_jp_ext.py +++ b/Lib/encodings/iso2022_jp_ext.py @@ -1,12 +1,13 @@ # -# iso2022_jp_ext.py: Python Unicode Codec for ISO_2022_JP_EXT +# iso2022_jp_ext.py: Python Unicode Codec for ISO2022_JP_EXT # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: iso2022_jp_ext.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: iso2022_jp_ext.py,v 1.2 2004/06/28 18:16:03 perky Exp $ # -from _codecs_iso2022_jp_ext import codec -import codecs +import _codecs_iso2022, codecs + +codec = _codecs_iso2022.getcodec('iso2022_jp_ext') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/iso2022_kr.py b/Lib/encodings/iso2022_kr.py index ead7ff5..f5549ca 100644 --- a/Lib/encodings/iso2022_kr.py +++ b/Lib/encodings/iso2022_kr.py @@ -1,12 +1,13 @@ # -# iso2022_kr.py: Python Unicode Codec for ISO_2022_KR +# iso2022_kr.py: Python Unicode Codec for ISO2022_KR # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: iso2022_kr.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: iso2022_kr.py,v 1.2 2004/06/28 18:16:03 perky Exp $ # -from _codecs_iso2022_kr import codec -import codecs +import _codecs_iso2022, codecs + +codec = _codecs_iso2022.getcodec('iso2022_kr') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/johab.py b/Lib/encodings/johab.py index 720195e..b6a87d7 100644 --- a/Lib/encodings/johab.py +++ b/Lib/encodings/johab.py @@ -2,11 +2,12 @@ # johab.py: Python Unicode Codec for JOHAB # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: johab.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: johab.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_johab import codec -import codecs +import _codecs_kr, codecs + +codec = _codecs_kr.getcodec('johab') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/shift_jis.py b/Lib/encodings/shift_jis.py index d235c1e..ec5e517 100644 --- a/Lib/encodings/shift_jis.py +++ b/Lib/encodings/shift_jis.py @@ -2,11 +2,12 @@ # shift_jis.py: Python Unicode Codec for SHIFT_JIS # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: shift_jis.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: shift_jis.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_shift_jis import codec -import codecs +import _codecs_jp, codecs + +codec = _codecs_jp.getcodec('shift_jis') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/shift_jis_2004.py b/Lib/encodings/shift_jis_2004.py new file mode 100644 index 0000000..446cd7c --- /dev/null +++ b/Lib/encodings/shift_jis_2004.py @@ -0,0 +1,34 @@ +# +# shift_jis_2004.py: Python Unicode Codec for SHIFT_JIS_2004 +# +# Written by Hye-Shik Chang <perky@FreeBSD.org> +# $CJKCodecs: shift_jis_2004.py,v 1.1 2004/07/07 16:18:25 perky Exp $ +# + +import _codecs_jp, codecs + +codec = _codecs_jp.getcodec('shift_jis_2004') + +class Codec(codecs.Codec): + encode = codec.encode + decode = codec.decode + +class StreamReader(Codec, codecs.StreamReader): + def __init__(self, stream, errors='strict'): + codecs.StreamReader.__init__(self, stream, errors) + __codec = codec.StreamReader(stream, errors) + self.read = __codec.read + self.readline = __codec.readline + self.readlines = __codec.readlines + self.reset = __codec.reset + +class StreamWriter(Codec, codecs.StreamWriter): + def __init__(self, stream, errors='strict'): + codecs.StreamWriter.__init__(self, stream, errors) + __codec = codec.StreamWriter(stream, errors) + self.write = __codec.write + self.writelines = __codec.writelines + self.reset = __codec.reset + +def getregentry(): + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/encodings/shift_jisx0213.py b/Lib/encodings/shift_jisx0213.py index 8759c8c..495468b 100644 --- a/Lib/encodings/shift_jisx0213.py +++ b/Lib/encodings/shift_jisx0213.py @@ -2,11 +2,12 @@ # shift_jisx0213.py: Python Unicode Codec for SHIFT_JISX0213 # # Written by Hye-Shik Chang <perky@FreeBSD.org> -# $CJKCodecs: shift_jisx0213.py,v 1.3 2004/01/17 11:26:10 perky Exp $ +# $CJKCodecs: shift_jisx0213.py,v 1.8 2004/06/28 18:16:03 perky Exp $ # -from _codecs_shift_jisx0213 import codec -import codecs +import _codecs_jp, codecs + +codec = _codecs_jp.getcodec('shift_jisx0213') class Codec(codecs.Codec): encode = codec.encode @@ -30,4 +31,4 @@ class StreamWriter(Codec, codecs.StreamWriter): self.reset = __codec.reset def getregentry(): - return (Codec().encode,Codec().decode,StreamReader,StreamWriter) + return (codec.encode, codec.decode, StreamReader, StreamWriter) diff --git a/Lib/test/cjkencodings_test.py b/Lib/test/cjkencodings_test.py index 8bd0ee7..f5f9a377 100644 --- a/Lib/test/cjkencodings_test.py +++ b/Lib/test/cjkencodings_test.py @@ -63,6 +63,9 @@ teststring = { "\x88\x91\xe5\x80\x91\xe6\x89\x80\x0a\xe8\xa6\x81\xe8\xa8\x8e\xe8" "\xab\x96\xe7\x9a\x84\xe5\x95\x8f\xe9\xa1\x8c\xe5\xb0\xb1\xe6\x98" "\xaf\x3a\x0a\x0a"), +'big5hkscs': ( +"\x88\x45\x88\x5c\x8a\x73\x8b\xda\x8d\xd8\x0a", +"\xf0\xa0\x84\x8c\xc4\x9a\xe9\xb5\xae\xe7\xbd\x93\xe6\xb4\x86\x0a"), 'cp949': ( "\x8c\x63\xb9\xe6\xb0\xa2\xc7\xcf\x20\xbc\x84\xbd\xc3\xc4\xdd\xb6" "\xf3\x0a\x0a\xa8\xc0\xa8\xc0\xb3\xb3\x21\x21\x20\xec\xd7\xce\xfa" diff --git a/Lib/test/test_codecencodings_cn.py b/Lib/test/test_codecencodings_cn.py index 269e00a..6d71218 100644 --- a/Lib/test/test_codecencodings_cn.py +++ b/Lib/test/test_codecencodings_cn.py @@ -3,7 +3,7 @@ # test_codecencodings_cn.py # Codec encoding tests for PRC encodings. # -# $CJKCodecs: test_codecencodings_cn.py,v 1.1 2003/12/19 03:00:05 perky Exp $ +# $CJKCodecs: test_codecencodings_cn.py,v 1.2 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support @@ -27,8 +27,8 @@ class Test_GBK(test_multibytecodec_support.TestBase, unittest.TestCase): tstring = test_multibytecodec_support.load_teststring('gbk') codectests = ( # invalid bytes - ("abc\x80\x80\xc1\xc4", "strict", None), - ("abc\xc8", "strict", None), + ("abc\x80\x80\xc1\xc4", "strict", None), + ("abc\xc8", "strict", None), ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u804a"), ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u804a\ufffd"), ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u804a"), diff --git a/Lib/test/test_codecencodings_hk.py b/Lib/test/test_codecencodings_hk.py new file mode 100644 index 0000000..e7fad90 --- /dev/null +++ b/Lib/test/test_codecencodings_hk.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python +# +# test_codecencodings_hk.py +# Codec encoding tests for HongKong encodings. +# +# $CJKCodecs: test_codecencodings_hk.py,v 1.1 2004/07/10 17:35:20 perky Exp $ + +from test import test_support +from test import test_multibytecodec_support +import unittest + +class Test_Big5HKSCS(test_multibytecodec_support.TestBase, unittest.TestCase): + encoding = 'big5hkscs' + tstring = test_multibytecodec_support.load_teststring('big5hkscs') + codectests = ( + # invalid bytes + ("abc\x80\x80\xc1\xc4", "strict", None), + ("abc\xc8", "strict", None), + ("abc\x80\x80\xc1\xc4", "replace", u"abc\ufffd\u8b10"), + ("abc\x80\x80\xc1\xc4\xc8", "replace", u"abc\ufffd\u8b10\ufffd"), + ("abc\x80\x80\xc1\xc4", "ignore", u"abc\u8b10"), + ) + +def test_main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(Test_Big5HKSCS)) + test_support.run_suite(suite) + +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_codecencodings_jp.py b/Lib/test/test_codecencodings_jp.py index f574511..483b7db 100644 --- a/Lib/test/test_codecencodings_jp.py +++ b/Lib/test/test_codecencodings_jp.py @@ -3,7 +3,7 @@ # test_codecencodings_jp.py # Codec encoding tests for Japanese encodings. # -# $CJKCodecs: test_codecencodings_jp.py,v 1.2 2004/01/06 09:25:37 perky Exp $ +# $CJKCodecs: test_codecencodings_jp.py,v 1.3 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support @@ -64,16 +64,6 @@ class Test_EUC_JP_COMPAT(test_multibytecodec_support.TestBase, (u"\u203e", "strict", "\x7e"), ) -class Test_EUC_JP_STRICT(test_multibytecodec_support.TestBase, - unittest.TestCase): - encoding = 'euc_jp_strict' - tstring = test_multibytecodec_support.load_teststring('euc_jp') - codectests = eucjp_commontests + ( - ("\xa1\xc0\\", "strict", u"\\\\"), - (u"\xa5", "strict", None), - (u"\u203e", "strict", None), - ) - shiftjis_commonenctests = ( ("abc\x80\x80\x82\x84", "strict", None), ("abc\xf8", "strict", None), @@ -90,14 +80,6 @@ class Test_SJIS_COMPAT(test_multibytecodec_support.TestBase, unittest.TestCase): ("\x81\x5f\x81\x61\x81\x7c", "strict", u"\uff3c\u2016\u2212"), ) -class Test_SJIS_STRICT(test_multibytecodec_support.TestBase, unittest.TestCase): - encoding = 'shift_jis_strict' - tstring = test_multibytecodec_support.load_teststring('shift_jis') - codectests = shiftjis_commonenctests + ( - ("\\\x7e", "replace", u"\xa5\u203e"), - ("\x81\x5f\x81\x61\x81\x7c", "replace", u"\x5c\u2016\u2212"), - ) - class Test_SJISX0213(test_multibytecodec_support.TestBase, unittest.TestCase): encoding = 'shift_jisx0213' tstring = test_multibytecodec_support.load_teststring('shift_jisx0213') @@ -123,9 +105,6 @@ def test_main(): suite.addTest(unittest.makeSuite(Test_EUC_JISX0213)) suite.addTest(unittest.makeSuite(Test_EUC_JP_COMPAT)) suite.addTest(unittest.makeSuite(Test_SJIS_COMPAT)) - if test_multibytecodec_support.__cjkcodecs__: - suite.addTest(unittest.makeSuite(Test_EUC_JP_STRICT)) - suite.addTest(unittest.makeSuite(Test_SJIS_STRICT)) suite.addTest(unittest.makeSuite(Test_SJISX0213)) test_support.run_suite(suite) diff --git a/Lib/test/test_codecencodings_kr.py b/Lib/test/test_codecencodings_kr.py index 449237d..489c9f1 100644 --- a/Lib/test/test_codecencodings_kr.py +++ b/Lib/test/test_codecencodings_kr.py @@ -3,7 +3,7 @@ # test_codecencodings_kr.py # Codec encoding tests for ROK encodings. # -# $CJKCodecs: test_codecencodings_kr.py,v 1.1 2003/12/19 03:00:06 perky Exp $ +# $CJKCodecs: test_codecencodings_kr.py,v 1.2 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support diff --git a/Lib/test/test_codecencodings_tw.py b/Lib/test/test_codecencodings_tw.py index 897f060..fb8a4d0 100644 --- a/Lib/test/test_codecencodings_tw.py +++ b/Lib/test/test_codecencodings_tw.py @@ -3,7 +3,7 @@ # test_codecencodings_tw.py # Codec encoding tests for ROC encodings. # -# $CJKCodecs: test_codecencodings_tw.py,v 1.1 2003/12/19 03:00:06 perky Exp $ +# $CJKCodecs: test_codecencodings_tw.py,v 1.2 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support diff --git a/Lib/test/test_codecmaps_cn.py b/Lib/test/test_codecmaps_cn.py index 337ac91..31871e2 100644 --- a/Lib/test/test_codecmaps_cn.py +++ b/Lib/test/test_codecmaps_cn.py @@ -3,7 +3,7 @@ # test_codecmaps_cn.py # Codec mapping tests for PRC encodings # -# $CJKCodecs: test_codecmaps_cn.py,v 1.2 2004/01/17 12:47:19 perky Exp $ +# $CJKCodecs: test_codecmaps_cn.py,v 1.3 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support diff --git a/Lib/test/test_codecmaps_hk.py b/Lib/test/test_codecmaps_hk.py new file mode 100644 index 0000000..43137b6 --- /dev/null +++ b/Lib/test/test_codecmaps_hk.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# +# test_codecmaps_hk.py +# Codec mapping tests for HongKong encodings +# +# $CJKCodecs: test_codecmaps_hk.py,v 1.1 2004/07/10 17:35:20 perky Exp $ + +from test import test_support +from test import test_multibytecodec_support +import unittest + +class TestBig5HKSCSMap(test_multibytecodec_support.TestBase_Mapping, + unittest.TestCase): + encoding = 'big5hkscs' + mapfilename = 'BIG5HKSCS.TXT' + mapfileurl = 'http://people.freebsd.org/~perky/i18n/BIG5HKSCS.TXT' + +def test_main(): + suite = unittest.TestSuite() + suite.addTest(unittest.makeSuite(TestBig5HKSCSMap)) + test_support.run_suite(suite) + +test_multibytecodec_support.register_skip_expected(TestBig5HKSCSMap) +if __name__ == "__main__": + test_main() diff --git a/Lib/test/test_codecmaps_jp.py b/Lib/test/test_codecmaps_jp.py index 9519da2..014a952 100644 --- a/Lib/test/test_codecmaps_jp.py +++ b/Lib/test/test_codecmaps_jp.py @@ -3,7 +3,7 @@ # test_codecmaps_jp.py # Codec mapping tests for Japanese encodings # -# $CJKCodecs: test_codecmaps_jp.py,v 1.2 2004/01/17 12:47:19 perky Exp $ +# $CJKCodecs: test_codecmaps_jp.py,v 1.3 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support @@ -48,15 +48,6 @@ class TestSJISCOMPATMap(test_multibytecodec_support.TestBase_Mapping, ('\x81_', u'\\'), ] - -class TestSJISSTRICTMap(test_multibytecodec_support.TestBase_Mapping, - unittest.TestCase): - encoding = 'shift_jis_strict' - mapfilename = 'SHIFTJIS.TXT' - mapfileurl = 'http://www.unicode.org/Public/MAPPINGS/OBSOLETE' \ - '/EASTASIA/JIS/SHIFTJIS.TXT' - - class TestEUCJISX0213Map(test_multibytecodec_support.TestBase_Mapping, unittest.TestCase): encoding = 'euc_jisx0213' @@ -76,8 +67,6 @@ def test_main(): suite.addTest(unittest.makeSuite(TestCP932Map)) suite.addTest(unittest.makeSuite(TestEUCJPCOMPATMap)) suite.addTest(unittest.makeSuite(TestSJISCOMPATMap)) - if test_multibytecodec_support.__cjkcodecs__: - suite.addTest(unittest.makeSuite(TestSJISSTRICTMap)) suite.addTest(unittest.makeSuite(TestEUCJISX0213Map)) suite.addTest(unittest.makeSuite(TestSJISX0213Map)) test_support.run_suite(suite) @@ -85,5 +74,6 @@ def test_main(): test_multibytecodec_support.register_skip_expected(TestCP932Map, TestEUCJPCOMPATMap, TestSJISCOMPATMap, TestEUCJISX0213Map, TestSJISX0213Map) + if __name__ == "__main__": test_main() diff --git a/Lib/test/test_codecmaps_kr.py b/Lib/test/test_codecmaps_kr.py index 9a71939..be19811 100644 --- a/Lib/test/test_codecmaps_kr.py +++ b/Lib/test/test_codecmaps_kr.py @@ -3,7 +3,7 @@ # test_codecmaps_kr.py # Codec mapping tests for ROK encodings # -# $CJKCodecs: test_codecmaps_kr.py,v 1.2 2004/01/17 12:47:19 perky Exp $ +# $CJKCodecs: test_codecmaps_kr.py,v 1.3 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support diff --git a/Lib/test/test_codecmaps_tw.py b/Lib/test/test_codecmaps_tw.py index 2f41660..61d83cd 100644 --- a/Lib/test/test_codecmaps_tw.py +++ b/Lib/test/test_codecmaps_tw.py @@ -3,7 +3,7 @@ # test_codecmaps_tw.py # Codec mapping tests for ROC encodings # -# $CJKCodecs: test_codecmaps_tw.py,v 1.2 2004/01/17 12:47:19 perky Exp $ +# $CJKCodecs: test_codecmaps_tw.py,v 1.3 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py index e96afba..acf333e 100644 --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -3,7 +3,7 @@ # test_multibytecodec.py # Unit test for multibytecodec itself # -# $CJKCodecs: test_multibytecodec.py,v 1.5 2004/01/06 02:26:28 perky Exp $ +# $CJKCodecs: test_multibytecodec.py,v 1.8 2004/06/19 06:09:55 perky Exp $ from test import test_support from test import test_multibytecodec_support @@ -69,6 +69,12 @@ class Test_StreamWriter(unittest.TestCase): def test_str_decode(self): self.assertEqual('abcd'.encode('gb18030'), 'abcd') + def test_streamwriter_strwrite(self): + s = StringIO.StringIO() + wr = codecs.getwriter('gb18030')(s) + wr.write('abcd') + self.assertEqual(s.getvalue(), 'abcd') + def test_main(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(Test_StreamWriter)) diff --git a/Lib/test/test_multibytecodec_support.py b/Lib/test/test_multibytecodec_support.py index f471adf..22b52f7 100644 --- a/Lib/test/test_multibytecodec_support.py +++ b/Lib/test/test_multibytecodec_support.py @@ -3,7 +3,7 @@ # test_multibytecodec_support.py # Common Unittest Routines for CJK codecs # -# $CJKCodecs: test_multibytecodec_support.py,v 1.5 2004/01/17 12:47:19 perky Exp $ +# $CJKCodecs: test_multibytecodec_support.py,v 1.6 2004/06/19 06:09:55 perky Exp $ import sys, codecs, os.path import unittest @@ -164,13 +164,8 @@ class TestBase_Mapping(unittest.TestCase): def __init__(self, *args, **kw): unittest.TestCase.__init__(self, *args, **kw) if not os.path.exists(self.mapfilename): - parent = os.path.join(os.pardir, self.mapfilename) - if not os.path.exists(parent): - format = '%s not found, download from %s' - raise test_support.TestSkipped(format % - (self.mapfilename, self.mapfileurl)) - else: - self.mapfilename = parent + raise test_support.TestSkipped('%s not found, download from %s' % + (self.mapfilename, self.mapfileurl)) def test_mapping_file(self): unichrs = lambda s: u''.join(map(unichr, map(eval, s.split('+')))) |