File tree Expand file tree Collapse file tree
python-ecosys/requests/requests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,49 +5,40 @@ class BodyStream:
55 def __init__ (self , sock , remaining = 0 ):
66 self ._sock = sock
77 self ._chunked = remaining < 0
8- self ._remaining = - 1 if remaining < 0 else remaining
8+ self ._remaining = remaining
99
1010 def read (self , n = - 1 ):
11- if not self ._chunked :
12- if self ._remaining == 0 :
13- return b""
14- if n < 0 or n > self ._remaining :
15- n = self ._remaining
16- data = self ._sock .read (n )
17- self ._remaining -= len (data )
18- if not data :
19- raise ValueError ("Connection closed before body complete" )
20- return data
2111 buf = bytearray (n if n >= 0 else 256 )
12+ if n >= 0 :
13+ got = self .readinto (buf )
14+ return buf [:got ] if got else b""
2215 result = b""
23- while True :
16+ while 1 :
2417 got = self .readinto (buf )
2518 if not got :
26- break
27- if n >= 0 :
28- return buf [:got ]
19+ return result
2920 result += buf [:got ]
30- return result
3121
3222 def readinto (self , buf ):
23+ s = self ._sock
3324 if self ._remaining <= 0 :
3425 if self ._remaining == 0 :
3526 return 0
36- self ._remaining = int (self . _sock . readline ().split (b";" , 1 )[0 ], 16 )
27+ self ._remaining = int (s . readline ().split (b";" )[0 ], 16 )
3728 if self ._remaining == 0 :
38- while True :
39- l = self . _sock .readline ()
29+ while 1 :
30+ l = s .readline ()
4031 if not l or l == b"\r \n " :
4132 break
4233 return 0
4334 if len (buf ) > self ._remaining :
4435 buf = memoryview (buf )[: self ._remaining ]
45- got = self . _sock .readinto (buf )
36+ got = s .readinto (buf )
4637 if not got :
4738 raise ValueError ("Connection closed before body complete" )
4839 self ._remaining -= got
4940 if self ._remaining == 0 and self ._chunked :
50- self . _sock .readline ()
41+ s .readline ()
5142 self ._remaining = - 1
5243 return got
5344
You can’t perform that action at this time.
0 commit comments