mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
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.
This commit is contained in:
parent
5573541b6f
commit
4922768d02
1 changed files with 28 additions and 18 deletions
|
@ -864,32 +864,42 @@ class SSLFile(SharedSocketClient):
|
||||||
|
|
||||||
def read(self, size=None):
|
def read(self, size=None):
|
||||||
L = [self._buf]
|
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:
|
if size is None:
|
||||||
self._buf = ''
|
self._buf = ''
|
||||||
for s in iter(self._read, ""):
|
return all
|
||||||
L.append(s)
|
|
||||||
return "".join(L)
|
|
||||||
else:
|
else:
|
||||||
avail = len(self._buf)
|
self._buf = all[size:]
|
||||||
for s in iter(self._read, ""):
|
return all[:size]
|
||||||
L.append(s)
|
|
||||||
avail += len(s)
|
|
||||||
if avail >= size:
|
|
||||||
all = "".join(L)
|
|
||||||
self._buf = all[size:]
|
|
||||||
return all[:size]
|
|
||||||
|
|
||||||
def readline(self):
|
def readline(self):
|
||||||
L = [self._buf]
|
L = [self._buf]
|
||||||
self._buf = ''
|
self._buf = ''
|
||||||
for s in iter(self._read, ""):
|
while 1:
|
||||||
L.append(s)
|
i = L[-1].find("\n")
|
||||||
if "\n" in s:
|
if i >= 0:
|
||||||
i = s.find("\n") + 1
|
|
||||||
self._buf = s[i:]
|
|
||||||
L[-1] = s[:i]
|
|
||||||
break
|
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):
|
class FakeSocket(SharedSocketClient):
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue