[pypy-commit] pypy default: Test and fix.

arigo noreply at buildbot.pypy.org
Mon Aug 1 16:18:44 CEST 2011


Author: Armin Rigo <arigo at tunes.org>
Branch: 
Changeset: r46152:9aa3003707ff
Date: 2011-08-01 15:45 +0200
http://bitbucket.org/pypy/pypy/changeset/9aa3003707ff/

Log:	Test and fix.

diff --git a/pypy/module/_multibytecodec/app_multibytecodec.py b/pypy/module/_multibytecodec/app_multibytecodec.py
--- a/pypy/module/_multibytecodec/app_multibytecodec.py
+++ b/pypy/module/_multibytecodec/app_multibytecodec.py
@@ -16,9 +16,10 @@
         while True:
             if size is None:
                 data = read()
+                final = True
             else:
                 data = read(size)
-            final = not data
+                final = not data
             output = MultibyteIncrementalDecoder.decode(self, data, final)
             if output or final:
                 return output
@@ -41,7 +42,7 @@
         return self
 
     def write(self, data):
-        self.stream.write(MultibyteIncrementalEncoder.encode(self, data))
+        self.stream.write(MultibyteIncrementalEncoder.encode(self, data, True))
 
     def writelines(self, lines):
         for data in lines:
diff --git a/pypy/module/_multibytecodec/test/test_app_stream.py b/pypy/module/_multibytecodec/test/test_app_stream.py
--- a/pypy/module/_multibytecodec/test/test_app_stream.py
+++ b/pypy/module/_multibytecodec/test/test_app_stream.py
@@ -40,6 +40,23 @@
         c = r.read(1)
         assert c == ''
 
+    def test_reader_replace(self):
+        class FakeFile:
+            def __init__(self, data):
+                self.data = data
+            def read(self):
+                return self.data
+        #
+        r = self.HzStreamReader(FakeFile("!~{a"), "replace")
+        c = r.read()
+        assert c == u'!\ufffd'
+        #
+        r = self.HzStreamReader(FakeFile("!~{a"))
+        r.errors = "replace"
+        assert r.errors == "replace"
+        c = r.read()
+        assert c == u'!\ufffd'
+
     def test_writer(self):
         class FakeFile:
             def __init__(self):


More information about the pypy-commit mailing list