summaryrefslogtreecommitdiff
path: root/Lib/httplib.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2003-03-06 16:31:48 +0000
committerRaymond Hettinger <python@rcn.com>2003-03-06 16:31:48 +0000
commit5169eabfb54ee8e122309ed75b4cf65341c86268 (patch)
treed976aadb49055fd50d41d19d9c0db12e84b7c9f5 /Lib/httplib.py
parentc12e268c5b4d79c6d826bf8f316481bf1c8f3fbf (diff)
downloadcpython-5169eabfb54ee8e122309ed75b4cf65341c86268.tar.gz
Reverted the previous change to read() and readline().
Kevin Jacobs found that the code simplification did not exactly match the semantics of the original. Regression test cases were requested.
Diffstat (limited to 'Lib/httplib.py')
-rw-r--r--Lib/httplib.py46
1 files changed, 28 insertions, 18 deletions
diff --git a/Lib/httplib.py b/Lib/httplib.py
index 789d80c4e1..ca215a4f7a 100644
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -864,32 +864,42 @@ class SSLFile(SharedSocketClient):
def read(self, size=None):
L = [self._buf]
+ avail = len(self._buf)
+ while size is None or avail < size:
+ s = self._read()
+ if s == '':
+ break
+ L.append(s)
+ avail += len(s)
+ all = "".join(L)
if size is None:
self._buf = ''
- for s in iter(self._read, ""):
- L.append(s)
- return "".join(L)
+ return all
else:
- avail = len(self._buf)
- for s in iter(self._read, ""):
- L.append(s)
- avail += len(s)
- if avail >= size:
- all = "".join(L)
- self._buf = all[size:]
- return all[:size]
+ self._buf = all[size:]
+ return all[:size]
def readline(self):
L = [self._buf]
self._buf = ''
- for s in iter(self._read, ""):
- L.append(s)
- if "\n" in s:
- i = s.find("\n") + 1
- self._buf = s[i:]
- L[-1] = s[:i]
+ while 1:
+ i = L[-1].find("\n")
+ if i >= 0:
break
- return "".join(L)
+ s = self._read()
+ if s == '':
+ break
+ L.append(s)
+ if i == -1:
+ # loop exited because there is no more data
+ return "".join(L)
+ else:
+ all = "".join(L)
+ # XXX could do enough bookkeeping not to do a 2nd search
+ i = all.find("\n") + 1
+ line = all[:i]
+ self._buf = all[i:]
+ return line
class FakeSocket(SharedSocketClient):