Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd6bf6f2

Browse files
authored
bpo-36050: optimize HTTPResponse.read() (pythonGH-12698)
* No need to chunking for now.* No need to partial read caused by EINTR for now.
1 parenta0da131 commitd6bf6f2

File tree

2 files changed

+12
-32
lines changed

2 files changed

+12
-32
lines changed

‎Lib/http/client.py‎

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@
105105
# Mapping status codes to official W3C names
106106
responses= {v:v.phraseforvinhttp.HTTPStatus.__members__.values()}
107107

108-
# maximal amount of data to read at one time in _safe_read
109-
MAXAMOUNT=1048576
110-
111108
# maximal line length when calling readline().
112109
_MAXLINE=65536
113110
_MAXHEADERS=100
@@ -592,43 +589,24 @@ def _readinto_chunked(self, b):
592589
raiseIncompleteRead(bytes(b[0:total_bytes]))
593590

594591
def_safe_read(self,amt):
595-
"""Read the number of bytes requested, compensating for partial reads.
596-
597-
Normally, we have a blocking socket, but a read() can be interrupted
598-
by a signal (resulting in a partial read).
599-
600-
Note that we cannot distinguish between EOF and an interrupt when zero
601-
bytes have been read. IncompleteRead() will be raised in this
602-
situation.
592+
"""Read the number of bytes requested.
603593
604594
This function should be used when <amt> bytes "should" be present for
605595
reading. If the bytes are truly not available (due to EOF), then the
606596
IncompleteRead exception can be used to detect the problem.
607597
"""
608-
s= []
609-
whileamt>0:
610-
chunk=self.fp.read(min(amt,MAXAMOUNT))
611-
ifnotchunk:
612-
raiseIncompleteRead(b''.join(s),amt)
613-
s.append(chunk)
614-
amt-=len(chunk)
615-
returnb"".join(s)
598+
data=self.fp.read(amt)
599+
iflen(data)<amt:
600+
raiseIncompleteRead(data,amt-len(data))
601+
returndata
616602

617603
def_safe_readinto(self,b):
618604
"""Same as _safe_read, but for reading into a buffer."""
619-
total_bytes=0
620-
mvb=memoryview(b)
621-
whiletotal_bytes<len(b):
622-
ifMAXAMOUNT<len(mvb):
623-
temp_mvb=mvb[0:MAXAMOUNT]
624-
n=self.fp.readinto(temp_mvb)
625-
else:
626-
n=self.fp.readinto(mvb)
627-
ifnotn:
628-
raiseIncompleteRead(bytes(mvb[0:total_bytes]),len(b))
629-
mvb=mvb[n:]
630-
total_bytes+=n
631-
returntotal_bytes
605+
amt=len(b)
606+
n=self.fp.readinto(b)
607+
ifn<amt:
608+
raiseIncompleteRead(bytes(b[:n]),amt-n)
609+
returnn
632610

633611
defread1(self,n=-1):
634612
"""Read with at most one underlying system call. If at least one
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Optimized ``http.client.HTTPResponse.read()`` for large response. Patch by
2+
Inada Naoki.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2026 Movatter.jp