Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
d4c472c3
Kaydet (Commit)
d4c472c3
authored
Eyl 03, 2002
tarafından
Jeremy Hylton
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Move code for reading chunked responses in helper function,
along with some small changes (e.g. use of +=).
üst
066a8df3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
45 deletions
+52
-45
httplib.py
Lib/httplib.py
+52
-45
No files found.
Lib/httplib.py
Dosyayı görüntüle @
d4c472c3
...
...
@@ -370,50 +370,9 @@ class HTTPResponse:
return
''
if
self
.
chunked
:
assert
self
.
chunked
!=
_UNKNOWN
chunk_left
=
self
.
chunk_left
value
=
''
while
1
:
if
chunk_left
is
None
:
line
=
self
.
fp
.
readline
()
i
=
line
.
find
(
';'
)
if
i
>=
0
:
line
=
line
[:
i
]
# strip chunk-extensions
chunk_left
=
int
(
line
,
16
)
if
chunk_left
==
0
:
break
if
amt
is
None
:
value
=
value
+
self
.
_safe_read
(
chunk_left
)
elif
amt
<
chunk_left
:
value
=
value
+
self
.
_safe_read
(
amt
)
self
.
chunk_left
=
chunk_left
-
amt
return
value
elif
amt
==
chunk_left
:
value
=
value
+
self
.
_safe_read
(
amt
)
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
self
.
chunk_left
=
None
return
value
else
:
value
=
value
+
self
.
_safe_read
(
chunk_left
)
amt
=
amt
-
chunk_left
# we read the whole chunk, get another
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
chunk_left
=
None
# read and discard trailer up to the CRLF terminator
### note: we shouldn't have any trailers!
while
1
:
line
=
self
.
fp
.
readline
()
if
line
==
'
\r\n
'
:
break
# we read everything; close the "file"
self
.
close
()
return
value
elif
amt
is
None
:
return
self
.
_read_chunked
(
amt
)
if
amt
is
None
:
# unbounded read
if
self
.
will_close
:
s
=
self
.
fp
.
read
()
...
...
@@ -426,7 +385,7 @@ class HTTPResponse:
if
amt
>
self
.
length
:
# clip the read to the "end of response"
amt
=
self
.
length
self
.
length
=
self
.
length
-
amt
self
.
length
-=
amt
# we do not use _safe_read() here because this may be a .will_close
# connection, and the user is reading more bytes than will be provided
...
...
@@ -435,6 +394,54 @@ class HTTPResponse:
return
s
def
_read_chunked
(
self
,
amt
):
assert
self
.
chunked
!=
_UNKNOWN
chunk_left
=
self
.
chunk_left
value
=
''
# XXX This accumulates chunks by repeated string concatenation,
# which is not efficient as the number or size of chunks gets big.
while
1
:
if
chunk_left
is
None
:
line
=
self
.
fp
.
readline
()
i
=
line
.
find
(
';'
)
if
i
>=
0
:
line
=
line
[:
i
]
# strip chunk-extensions
chunk_left
=
int
(
line
,
16
)
if
chunk_left
==
0
:
break
if
amt
is
None
:
value
+=
self
.
_safe_read
(
chunk_left
)
elif
amt
<
chunk_left
:
value
+=
self
.
_safe_read
(
amt
)
self
.
chunk_left
=
chunk_left
-
amt
return
value
elif
amt
==
chunk_left
:
value
+=
self
.
_safe_read
(
amt
)
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
self
.
chunk_left
=
None
return
value
else
:
value
+=
self
.
_safe_read
(
chunk_left
)
amt
-=
chunk_left
# we read the whole chunk, get another
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
chunk_left
=
None
# read and discard trailer up to the CRLF terminator
### note: we shouldn't have any trailers!
while
1
:
line
=
self
.
fp
.
readline
()
if
line
==
'
\r\n
'
:
break
# we read everything; close the "file"
# XXX Shouldn't the client close the file?
self
.
close
()
return
value
def
_safe_read
(
self
,
amt
):
"""Read the number of bytes requested, compensating for partial reads.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment