From: Antoine Pitrou Date: Thu, 22 Jan 2009 11:59:55 +0000 (+0000) Subject: Followup of #4874: also fix multibytecodec.c X-Git-Tag: v3.1a1~432 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=44bf631ad9996004cbd3e0cb03dd94febcba950f;p=thirdparty%2FPython%2Fcpython.git Followup of #4874: also fix multibytecodec.c --- diff --git a/Lib/test/test_multibytecodec.py b/Lib/test/test_multibytecodec.py index 7962d5e9e3b6..2f648675c270 100644 --- a/Lib/test/test_multibytecodec.py +++ b/Lib/test/test_multibytecodec.py @@ -44,7 +44,7 @@ class Test_MultibyteCodec(unittest.TestCase): myreplace = lambda exc: ('', sys.maxsize+1) codecs.register_error('test.cjktest', myreplace) self.assertRaises(IndexError, dec, - 'apple\x92ham\x93spam', 'test.cjktest') + b'apple\x92ham\x93spam', 'test.cjktest') def test_codingspec(self): try: @@ -61,6 +61,10 @@ class Test_MultibyteCodec(unittest.TestCase): self.assertRaises(AttributeError, _multibytecodec.MultibyteStreamWriter, None) + def test_decode_unicode(self): + # Trying to decode an unicode string should raise a TypeError + for enc in ALL_CJKENCODINGS: + self.assertRaises(TypeError, codecs.getdecoder(enc), "") class Test_IncrementalEncoder(unittest.TestCase): @@ -146,6 +150,12 @@ class Test_IncrementalDecoder(unittest.TestCase): self.assertRaises(UnicodeDecodeError, decoder.decode, b'', True) self.assertEqual(decoder.decode(b'B@$'), '\u4e16') + def test_decode_unicode(self): + # Trying to decode an unicode string should raise a TypeError + for enc in ALL_CJKENCODINGS: + decoder = codecs.getincrementaldecoder(enc)() + self.assertRaises(TypeError, decoder.decode, "") + class Test_StreamReader(unittest.TestCase): def test_bug1728403(self): try: diff --git a/Modules/cjkcodecs/multibytecodec.c b/Modules/cjkcodecs/multibytecodec.c index 2732270903ac..82dfd49c74f5 100644 --- a/Modules/cjkcodecs/multibytecodec.c +++ b/Modules/cjkcodecs/multibytecodec.c @@ -612,7 +612,7 @@ MultibyteCodec_Decode(MultibyteCodecObject *self, const char *data, *errors = NULL; Py_ssize_t datalen, finalsize; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|z:decode", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|z:decode", codeckwarglist, &pdata, &errors)) return NULL; data = pdata.buf; @@ -1038,7 +1038,7 @@ mbidecoder_decode(MultibyteIncrementalDecoderObject *self, Py_ssize_t wsize, finalsize = 0, size, origpending; int final = 0; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s*|i:decode", + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "y*|i:decode", incrementalkwarglist, &pdata, &final)) return NULL; data = pdata.buf;