Author: Matti Picus <[email protected]>
Branch: unicode-utf8
Changeset: r95705:9853efedd970
Date: 2019-01-23 19:29 +0200
http://bitbucket.org/pypy/pypy/changeset/9853efedd970/

Log:    backport relevant parts of 8e00f53ea94c

diff --git a/pypy/module/_io/interp_stringio.py 
b/pypy/module/_io/interp_stringio.py
--- a/pypy/module/_io/interp_stringio.py
+++ b/pypy/module/_io/interp_stringio.py
@@ -196,7 +196,8 @@
         if pos < 0:
             raise oefmt(space.w_ValueError,
                         "position value cannot be negative")
-        self.buf = UnicodeIO(initval, pos)
+        self.buf = UnicodeIO(initval)
+        self.buf.seek(pos)
         if not space.is_w(w_dict, space.w_None):
             if not space.isinstance_w(w_dict, space.w_dict):
                 raise oefmt(
diff --git a/pypy/module/_io/test/test_stringio.py 
b/pypy/module/_io/test/test_stringio.py
--- a/pypy/module/_io/test/test_stringio.py
+++ b/pypy/module/_io/test/test_stringio.py
@@ -307,3 +307,17 @@
         raises(TypeError, sio.__setstate__, 0)
         sio.close()
         raises(ValueError, sio.__setstate__, (u"closed", u"", 0, None))
+
+    def test_roundtrip_state(self):
+        import io
+        s = u'12345678'
+        sio1 = io.StringIO(s)
+        sio1.foo = 42
+        sio1.seek(2)
+        assert sio1.getvalue() == s
+        state = sio1.__getstate__()
+        sio2 = io.StringIO()
+        sio2.__setstate__(state)
+        assert sio2.getvalue() == s
+        assert sio2.foo == 42
+        assert sio2.tell() == 2
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to