summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_codecs.py
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2007-11-19 12:41:10 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2007-11-19 12:41:10 (GMT)
commit183744d6b9d45e77c3bd2dc30a6eb41c9f1c58f1 (patch)
tree9999590e5cb293ba30ebc9133ac0860f3999bcc9 /Lib/test/test_codecs.py
parentfc7e72d1c6f9977d027dcea827707f8cbd5fa4bc (diff)
downloadcpython-183744d6b9d45e77c3bd2dc30a6eb41c9f1c58f1.zip
cpython-183744d6b9d45e77c3bd2dc30a6eb41c9f1c58f1.tar.gz
cpython-183744d6b9d45e77c3bd2dc30a6eb41c9f1c58f1.tar.bz2
Fix for #1444: utf_8_sig.StreamReader was (indirectly through decode())
calling codecs.utf_8_decode() with final==True, which falled with incomplete byte sequences. Fix and test by James G. Sack.
Diffstat (limited to 'Lib/test/test_codecs.py')
-rw-r--r--Lib/test/test_codecs.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
index 95dd432..bfb417c 100644
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -565,6 +565,50 @@ class UTF8SigTest(ReadTest):
s = u"spam"
self.assertEqual(d.decode(s.encode("utf-8-sig")), s)
+ def test_stream_bom(self):
+ unistring = u"ABC\u00A1\u2200XYZ"
+ bytestring = codecs.BOM_UTF8 + "ABC\xC2\xA1\xE2\x88\x80XYZ"
+
+ reader = codecs.getreader("utf-8-sig")
+ for sizehint in [None] + range(1, 11) + \
+ [64, 128, 256, 512, 1024]:
+ istream = reader(StringIO.StringIO(bytestring))
+ ostream = StringIO.StringIO()
+ while 1:
+ if sizehint is not None:
+ data = istream.read(sizehint)
+ else:
+ data = istream.read()
+
+ if not data:
+ break
+ ostream.write(data)
+
+ got = ostream.getvalue()
+ self.assertEqual(got, unistring)
+
+ def test_stream_bare(self):
+ unistring = u"ABC\u00A1\u2200XYZ"
+ bytestring = "ABC\xC2\xA1\xE2\x88\x80XYZ"
+
+ reader = codecs.getreader("utf-8-sig")
+ for sizehint in [None] + range(1, 11) + \
+ [64, 128, 256, 512, 1024]:
+ istream = reader(StringIO.StringIO(bytestring))
+ ostream = StringIO.StringIO()
+ while 1:
+ if sizehint is not None:
+ data = istream.read(sizehint)
+ else:
+ data = istream.read()
+
+ if not data:
+ break
+ ostream.write(data)
+
+ got = ostream.getvalue()
+ self.assertEqual(got, unistring)
+
class EscapeDecodeTest(unittest.TestCase):
def test_empty(self):
self.assertEquals(codecs.escape_decode(""), ("", 0))