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
68c6e92f
Commit
68c6e92f
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
7d4f8fda
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
12 deletions
+9
-12
Lib/httplib.py
Lib/httplib.py
+9
-12
No files found.
Lib/httplib.py
View file @
68c6e92f
...
...
@@ -554,10 +554,7 @@ class HTTPResponse:
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.
value
=
[]
while
True
:
if
chunk_left
is
None
:
line
=
self
.
fp
.
readline
()
...
...
@@ -570,22 +567,22 @@ class HTTPResponse:
# close the connection as protocol synchronisation is
# probably lost
self
.
close
()
raise
IncompleteRead
(
value
)
raise
IncompleteRead
(
''
.
join
(
value
)
)
if
chunk_left
==
0
:
break
if
amt
is
None
:
value
+=
self
.
_safe_read
(
chunk_left
)
value
.
append
(
self
.
_safe_read
(
chunk_left
)
)
elif
amt
<
chunk_left
:
value
+=
self
.
_safe_read
(
amt
)
value
.
append
(
self
.
_safe_read
(
amt
)
)
self
.
chunk_left
=
chunk_left
-
amt
return
value
return
''
.
join
(
value
)
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
.
chunk_left
=
None
return
value
return
''
.
join
(
value
)
else
:
value
+=
self
.
_safe_read
(
chunk_left
)
value
.
append
(
self
.
_safe_read
(
chunk_left
)
)
amt
-=
chunk_left
# we read the whole chunk, get another
...
...
@@ -606,7 +603,7 @@ class HTTPResponse:
# we read everything; close the "file"
self
.
close
()
return
value
return
''
.
join
(
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