Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
49148cf5
Commit
49148cf5
authored
Sep 04, 2009
by
Chris Withers
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes issue #6838: use a list to accumulate the value instead of repeatedly concatenating strings.
parent
cf4a7027
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
12 deletions
+14
-12
Lib/httplib.py
Lib/httplib.py
+9
-12
Misc/NEWS
Misc/NEWS
+5
-0
No files found.
Lib/httplib.py
View file @
49148cf5
...
@@ -544,10 +544,7 @@ class HTTPResponse:
...
@@ -544,10 +544,7 @@ class HTTPResponse:
def
_read_chunked
(
self
,
amt
):
def
_read_chunked
(
self
,
amt
):
assert
self
.
chunked
!=
_UNKNOWN
assert
self
.
chunked
!=
_UNKNOWN
chunk_left
=
self
.
chunk_left
chunk_left
=
self
.
chunk_left
value
=
''
value
=
[]
# XXX This accumulates chunks by repeated string concatenation,
# which is not efficient as the number or size of chunks gets big.
while
True
:
while
True
:
if
chunk_left
is
None
:
if
chunk_left
is
None
:
line
=
self
.
fp
.
readline
()
line
=
self
.
fp
.
readline
()
...
@@ -560,22 +557,22 @@ class HTTPResponse:
...
@@ -560,22 +557,22 @@ class HTTPResponse:
# close the connection as protocol synchronisation is
# close the connection as protocol synchronisation is
# probably lost
# probably lost
self
.
close
()
self
.
close
()
raise
IncompleteRead
(
value
)
raise
IncompleteRead
(
''
.
join
(
value
)
)
if
chunk_left
==
0
:
if
chunk_left
==
0
:
break
break
if
amt
is
None
:
if
amt
is
None
:
value
+=
self
.
_safe_read
(
chunk_left
)
value
.
append
(
self
.
_safe_read
(
chunk_left
)
)
elif
amt
<
chunk_left
:
elif
amt
<
chunk_left
:
value
+=
self
.
_safe_read
(
amt
)
value
.
append
(
self
.
_safe_read
(
amt
)
)
self
.
chunk_left
=
chunk_left
-
amt
self
.
chunk_left
=
chunk_left
-
amt
return
value
return
''
.
join
(
value
)
elif
amt
==
chunk_left
:
elif
amt
==
chunk_left
:
value
+=
self
.
_safe_read
(
amt
)
value
.
append
(
self
.
_safe_read
(
amt
)
)
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
self
.
_safe_read
(
2
)
# toss the CRLF at the end of the chunk
self
.
chunk_left
=
None
self
.
chunk_left
=
None
return
value
return
''
.
join
(
value
)
else
:
else
:
value
+=
self
.
_safe_read
(
chunk_left
)
value
.
append
(
self
.
_safe_read
(
chunk_left
)
)
amt
-=
chunk_left
amt
-=
chunk_left
# we read the whole chunk, get another
# we read the whole chunk, get another
...
@@ -596,7 +593,7 @@ class HTTPResponse:
...
@@ -596,7 +593,7 @@ class HTTPResponse:
# we read everything; close the "file"
# we read everything; close the "file"
self
.
close
()
self
.
close
()
return
value
return
''
.
join
(
value
)
def
_safe_read
(
self
,
amt
):
def
_safe_read
(
self
,
amt
):
"""Read the number of bytes requested, compensating for partial reads.
"""Read the number of bytes requested, compensating for partial reads.
...
...
Misc/NEWS
View file @
49148cf5
...
@@ -72,6 +72,11 @@ Core and Builtins
...
@@ -72,6 +72,11 @@ Core and Builtins
Library
Library
-------
-------
- Issue #6838: Use a list to accumulate the value instead of
repeatedly concatenating strings in httplib's
HTTPResponse._read_chunked providing a significant speed increase
when downloading large files servend with a Transfer-Encoding of 'chunked'.
- Issue #6794: Fix Decimal.compare_total and Decimal.compare_total_mag: NaN
- Issue #6794: Fix Decimal.compare_total and Decimal.compare_total_mag: NaN
payloads are now ordered by integer value rather than lexicographically.
payloads are now ordered by integer value rather than lexicographically.
...
...
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