Opened 12 years ago
Closed 10 years ago
#18523 closed New feature (fixed)
Add getvalue to HttpResponse
Reported by: | Claude Paroz | Owned by: | Michael Kelly |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The HttpResponse object can almost be used as another stream object. Unfortunately, it doesn't offer the getvalue() method to be able to read its content, hence requiring conditional code in some circonstances (see #15197). What about adding it (HttpResponse.getvalue() === HttpResponse.content)?
Change History (11)
comment:1 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 12 years ago
I think http://docs.python.org/library/io.html#io.IOBase lists basic API for streams.
comment:3 by , 11 years ago
I would add the following attributes and methods:
HttpResponseBase.closed
: set toFalse
in__init__
, set toTrue
inclose()
HttpResponseBase.writable()
: returnsFalse
becausewrite(content)
raises an exception (should be changed toIOError
BTW)HttpResponseBase.writelines(lines)
: raisesIOError
HttpResponseBase.tell()
: change it to raiseIOError
HttpResponse.getvalue()
: returnsself.content
HttpResponse.writelines(lines)
: writes each line withself.write(line)
comment:4 by , 11 years ago
Has patch: | set |
---|---|
Owner: | changed from | to
Status: | new → assigned |
I submitted a PR with the changes mentioned in comment:3 here: https://github.com/django/django/pull/2545 . If we think that all of the stuff from io.IOBase should be included, I can update my PR with the rest.
comment:5 by , 10 years ago
Patch needs improvement: | set |
---|
There are some comments for improvement on the PR. Please uncheck "Patch needs improvement" when you update it, thanks.
comment:6 by , 10 years ago
Will do, just having trouble finding a good time to work on this lately. :D
comment:7 by , 10 years ago
Patch needs improvement: | unset |
---|
Updated branch with changes in response to feedback.
comment:8 by , 10 years ago
Patch needs improvement: | set |
---|
There are some problems with the tests on Python 3.
comment:9 by , 10 years ago
Patch needs improvement: | unset |
---|
comment:10 by , 10 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:11 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Good idea.
Do Python's docs provide a list of the methods that a "stream object" must support? While we're there, we should also check that HttpRequest objects support all the methods that make sense.