Skip to content

Commit

Permalink
Merge pull request #500 from r3m0t/patch-1
Browse files Browse the repository at this point in the history
Fix IterO.readline
  • Loading branch information
Daniel Neuhäuser committed Mar 21, 2014
2 parents 13218de + 17efc32 commit 0e8ba22
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion werkzeug/contrib/iterio.py
Expand Up @@ -305,7 +305,10 @@ def readline(self, length=None):
nl_pos = self._buf.find(_newline(self._buf), self.pos)
buf = []
try:
pos = self.pos
if self._buf is None:
pos = self.pos
else:
pos = len(self._buf)
while nl_pos < 0:
item = next(self._gen)
local_pos = item.find(_newline(item))
Expand Down
7 changes: 7 additions & 0 deletions werkzeug/testsuite/contrib/iterio.py
Expand Up @@ -42,6 +42,13 @@ def test_basic_native(self):
io.seek(0)
self.assert_equal(io.readlines(), ['Hello\n', 'World!'])

io = IterIO(['Line one\nLine ', 'two\nLine three'])
self.assert_equal(list(io), ['Line one\n', 'Line two\n', 'Line three'])
io = IterIO(iter('Line one\nLine two\nLine three'))
self.assert_equal(list(io), ['Line one\n', 'Line two\n', 'Line three'])
io = IterIO(['Line one\nL', 'ine', ' two', '\nLine three'])
self.assert_equal(list(io), ['Line one\n', 'Line two\n', 'Line three'])

io = IterIO(["foo\n", "bar"])
io.seek(-4, 2)
self.assert_equal(io.read(4), '\nbar')
Expand Down

0 comments on commit 0e8ba22

Please sign in to comment.