Manuel Jacob avatar Manuel Jacob committed 1988eab Merge

hg merge default

Comments (0)

Files changed (2)

pypy/module/_io/interp_bytesio.py

         self.pos += size
         return space.wrapbytes(output)
 
+    def readline_w(self, space, w_limit=None):
+        self._check_closed(space)
+        limit = convert_size(space, w_limit)
+
+        cur_pos = self.pos
+        if limit < 0:
+            end_pos = self.string_size
+        else:
+            end_pos = min(cur_pos + limit, self.string_size)
+        while cur_pos != end_pos:
+            if self.buf[cur_pos] == '\n':
+                cur_pos += 1
+                break
+            cur_pos += 1
+
+        output = buffer2string(self.buf, self.pos, cur_pos)
+        self.pos = cur_pos
+        return space.wrap(output)
+
     def read1_w(self, space, w_size):
         return self.read_w(space, w_size)
 
 
     read = interp2app(W_BytesIO.read_w),
     read1 = interp2app(W_BytesIO.read1_w),
+    readline = interp2app(W_BytesIO.readline_w),
     readinto = interp2app(W_BytesIO.readinto_w),
     write = interp2app(W_BytesIO.write_w),
     truncate = interp2app(W_BytesIO.truncate_w),

pypy/module/_io/test/test_bytesio.py

         del buf
         memio.truncate()
 
+    def test_readline(self):
+        import _io
+        f = _io.BytesIO(b'abc\ndef\nxyzzy\nfoo\x00bar\nanother line')
+        assert f.readline() == b'abc\n'
+        assert f.readline(10) == b'def\n'
+        assert f.readline(2) == b'xy'
+        assert f.readline(4) == b'zzy\n'
+        assert f.readline() == b'foo\x00bar\n'
+        assert f.readline(None) == b'another line'
+        raises(TypeError, f.readline, 5.3)
+
+    def test_overread(self):
+        import _io
+        f = _io.BytesIO(b'abc')
+        assert f.readline(10) == b'abc'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.