Author: Armin Rigo <[email protected]>
Branch:
Changeset: r84284:591a29bc54fc
Date: 2016-05-08 08:58 +0200
http://bitbucket.org/pypy/pypy/changeset/591a29bc54fc/
Log: Issue #2293: codecs.py will sometimes issue a reset() on a
StreamWriter attached to a file that is not opened for writing at
all. We must not emit a "write('')"!
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
@@ -44,8 +44,10 @@
self, data))
def reset(self):
- self.stream.write(MultibyteIncrementalEncoder.encode(
- self, '', final=True))
+ data = MultibyteIncrementalEncoder.encode(
+ self, '', final=True)
+ if len(data) > 0:
+ self.stream.write(data)
MultibyteIncrementalEncoder.reset(self)
def writelines(self, 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
@@ -90,3 +90,15 @@
w.write(u'\u304b')
w.write(u'\u309a')
assert w.stream.output == ['\x83m', '', '\x82\xf5']
+
+ def test_writer_seek_no_empty_write(self):
+ # issue #2293: codecs.py will sometimes issue a reset()
+ # on a StreamWriter attached to a file that is not opened
+ # for writing at all. We must not emit a "write('')"!
+ class FakeFile:
+ def write(self, data):
+ raise IOError("can't write!")
+ #
+ w = self.ShiftJisx0213StreamWriter(FakeFile())
+ w.reset()
+ # assert did not crash
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit