Skip to content

Commit

Permalink
Test update/Fix progress temp save
Browse files Browse the repository at this point in the history
Edited test to catch readline error. file.py code change in progress
(DOES NOT WORK PROPERLY) so saving it temporarily.
  • Loading branch information
achapp authored and bitprophet committed Dec 17, 2014
1 parent b3ed2d5 commit 34c4d0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 7 additions & 2 deletions paramiko/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,8 @@ def readline(self, size=None):
# truncate line and return
self._rbuffer = line[size:]
line = line[:size]
self._pos += len(line)
return line if self._flags & self.FLAG_BINARY else u(line)
#self._pos += len(line)
break#return line if self._flags & self.FLAG_BINARY else u(line)
n = size - len(line)
else:
n = self._bufsize
Expand All @@ -244,6 +244,11 @@ def readline(self, size=None):
rpos = line.find(cr_byte)
if (rpos >= 0) and (rpos < pos or pos < 0):
pos = rpos
if pos == -1:
#self._rbuffer = line[size:]
#line = line[:size]
self._pos += len(line)
return line if self._flags & self.FLAG_BINARY else u(line)
xpos = pos + 1
if (line[pos] == cr_byte_value) and (xpos < len(line)) and (line[xpos] == linefeed_byte_value):
xpos += 1
Expand Down
4 changes: 3 additions & 1 deletion tests/test_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ def test_1_simple(self):

def test_2_readline(self):
f = LoopbackFile('r+U')
f.write(b'First line.\nSecond line.\r\nThird line.\nFinal line non-terminated.')
f.write(b'First line.\nSecond line.\r\nThird line.\nFourth line.\nFifth line.\nFinal line non-terminated.')
self.assertEqual(f.readline(), 'First line.\n')
# universal newline mode should convert this linefeed:
self.assertEqual(f.readline(), 'Second line.\n')
# truncated line:
self.assertEqual(f.readline(7), 'Third l')
self.assertEqual(f.readline(), 'ine.\n')
self.assertEqual(f.readline(25), 'Fourth line.\n')
self.assertEqual(f.readline(), 'Fifth line.\n')
self.assertEqual(f.readline(), 'Final line non-terminated.')
self.assertEqual(f.readline(), '')
f.close()
Expand Down

0 comments on commit 34c4d0c

Please sign in to comment.