[pypy-svn] pypy default: Expose newlines property on stringio.
alex_gaynor
commits-noreply at bitbucket.org
Thu Feb 3 23:17:11 CET 2011
Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch:
Changeset: r41589:8708a496628e
Date: 2011-02-03 17:16 -0500
http://bitbucket.org/pypy/pypy/changeset/8708a496628e/
Log: Expose newlines property on stringio.
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
@@ -227,3 +227,15 @@
sio.seek(0)
res = list(sio)
assert res == [u"a\r\n", u"b\r\r\n", u"c\rd"]
+
+ def test_newline_property(self):
+ import io
+
+ sio = io.StringIO(newline=None)
+ assert sio.newlines is None
+ sio.write(u"a\n")
+ assert sio.newlines == "\n"
+ sio.write(u"b\r\n")
+ assert sio.newlines == ("\n", "\r\n")
+ sio.write(u"c\rd")
+ assert sio.newlines == ("\r", "\n", "\r\n")
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
@@ -210,6 +210,11 @@
def line_buffering_get_w(space, self):
return space.w_False
+ def newlines_get_w(space, self):
+ if self.w_decoder is None:
+ return space.w_None
+ return space.getattr(self.w_decoder, space.wrap("newlines"))
+
W_StringIO.typedef = TypeDef(
'StringIO', W_TextIOBase.typedef,
@@ -228,4 +233,5 @@
close = interp2app(W_StringIO.close_w),
closed = GetSetProperty(W_StringIO.closed_get_w),
line_buffering = GetSetProperty(W_StringIO.line_buffering_get_w),
+ newlines = GetSetProperty(W_StringIO.newlines_get_w),
)
More information about the Pypy-commit
mailing list