Author: Brian Kearns <bdkea...@gmail.com> Branch: Changeset: r62606:535f3a9dd3b6 Date: 2013-03-21 03:27 -0400 http://bitbucket.org/pypy/pypy/changeset/535f3a9dd3b6/
Log: move readline to RStringIO diff --git a/pypy/module/cStringIO/interp_stringio.py b/pypy/module/cStringIO/interp_stringio.py --- a/pypy/module/cStringIO/interp_stringio.py +++ b/pypy/module/cStringIO/interp_stringio.py @@ -149,22 +149,6 @@ RStringIO.__init__(self) self.space = space - def readline(self, size=-1): - p = self.tell() - bigbuffer = self.copy_into_bigbuffer() - end = len(bigbuffer) - if size >= 0 and size < end - p: - end = p + size - assert p >= 0 - i = p - while i < end: - finished = bigbuffer[i] == '\n' - i += 1 - if finished: - break - self.seek(i) - return ''.join(bigbuffer[p:i]) - def descr_truncate(self, w_size=None): self.check_closed() space = self.space diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py --- a/rpython/rlib/rStringIO.py +++ b/rpython/rlib/rStringIO.py @@ -126,6 +126,22 @@ self.pos = p + count return ''.join(self.bigbuffer[p:p+count]) + def readline(self, size=-1): + p = self.tell() + self.copy_into_bigbuffer() + end = len(self.bigbuffer) + if size >= 0 and size < end - p: + end = p + size + assert p >= 0 + i = p + while i < end: + finished = self.bigbuffer[i] == '\n' + i += 1 + if finished: + break + self.seek(i) + return ''.join(self.bigbuffer[p:i]) + def truncate(self, size): # NB. 'size' is mandatory. This has the same un-Posix-y semantics # than CPython: it never grows the buffer, and it sets the current diff --git a/rpython/rlib/test/test_rStringIO.py b/rpython/rlib/test/test_rStringIO.py --- a/rpython/rlib/test/test_rStringIO.py +++ b/rpython/rlib/test/test_rStringIO.py @@ -77,6 +77,16 @@ assert f.read(2) == '' assert f.tell() == 15 +def test_readline(): + f = RStringIO() + f.write('foo\nbar\nbaz') + f.seek(0) + assert f.readline() == 'foo\n' + assert f.readline(2) == 'ba' + assert f.readline() == 'r\n' + assert f.readline() == 'baz' + assert f.readline() == '' + def test_truncate(): f = RStringIO() f.truncate(20) _______________________________________________ pypy-commit mailing list pypy-commit@python.org http://mail.python.org/mailman/listinfo/pypy-commit