summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorachapp <adamdchappell@gmail.com>2014-11-25 12:30:32 -0600
committerJeff Forcier <jeff@bitprophet.org>2014-12-17 15:51:19 -0800
commit0a5485390d43f408b130011ae3452855e766786d (patch)
tree89691efa30620d7da6d28e42fba2348e2b132207
parent34c4d0c4a29c8b3c26925c2a05a9b0e50a83f617 (diff)
downloadparamiko-0a5485390d43f408b130011ae3452855e766786d.tar.gz
new readline test passes
Changed file.py readline() to always check for a newline. Had to make a few changes for what went into self._rbuffer in the case where buffer size was met or exceeded and we found a newline.
-rw-r--r--paramiko/file.py12
-rwxr-xr-xtests/test_file.py1
2 files changed, 7 insertions, 6 deletions
diff --git a/paramiko/file.py b/paramiko/file.py
index 139c453b..f549cb99 100644
--- a/paramiko/file.py
+++ b/paramiko/file.py
@@ -204,6 +204,7 @@ class BufferedFile (object):
if not (self._flags & self.FLAG_READ):
raise IOError('File not open for reading')
line = self._rbuffer
+ truncated = False;
while True:
if self._at_trailing_cr and (self._flags & self.FLAG_UNIVERSAL_NEWLINE) and (len(line) > 0):
# edge case: the newline may be '\r\n' and we may have read
@@ -218,11 +219,11 @@ class BufferedFile (object):
# enough.
if (size is not None) and (size >= 0):
if len(line) >= size:
- # truncate line and return
+ # truncate line
self._rbuffer = line[size:]
line = line[:size]
- #self._pos += len(line)
- break#return line if self._flags & self.FLAG_BINARY else u(line)
+ truncated = True
+ break
n = size - len(line)
else:
n = self._bufsize
@@ -245,14 +246,13 @@ class BufferedFile (object):
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
- self._rbuffer = line[xpos:]
+
+ self._rbuffer = line[xpos:] + self._rbuffer if truncated else line[xpos:]
lf = line[pos:xpos]
line = line[:pos] + linefeed_byte
if (len(self._rbuffer) == 0) and (lf == cr_byte):
diff --git a/tests/test_file.py b/tests/test_file.py
index 24a7fa9b..044dc591 100755
--- a/tests/test_file.py
+++ b/tests/test_file.py
@@ -77,6 +77,7 @@ class BufferedFileTest (unittest.TestCase):
# truncated line:
self.assertEqual(f.readline(7), 'Third l')
self.assertEqual(f.readline(), 'ine.\n')
+ # readline should not read past the fourth line
self.assertEqual(f.readline(25), 'Fourth line.\n')
self.assertEqual(f.readline(), 'Fifth line.\n')
self.assertEqual(f.readline(), 'Final line non-terminated.')