Problem with wsgiref.headers.Headers

P

Phil

I am having an issue with wsgiref.headers.Headers.

For example, if I do this...

from wsgiref.headers import Headers
list = []
wrapper = Headers(list)
wrapper['content-type'] = "text/html"
print(list)
print(wrapper)

I get an empty list printed, and then the correct result for wrapper
printed.

Am I misunderstanding the documentation?

class wsgiref.headers.Headers(headers)
Create a mapping-like object wrapping headers, which must be a list of
header name/value tuples as described in PEP 333. Any changes made to
the new Headers object will directly update the headers list it was
created with.

Thanks for any help,

Phil
 
P

Phil

I left one crucial detail out. My concern was the fact that the
original headers list being wrapped ('list' in my example) is not
being updated.
 
G

Gabriel Genellina

I am having an issue with wsgiref.headers.Headers.

For example, if I do this...

from wsgiref.headers import Headers
list = []
wrapper = Headers(list)
wrapper['content-type'] = "text/html"
print(list)
print(wrapper)

I get an empty list printed, and then the correct result for wrapper
printed.

You forgot to mention the Python version; the code works fine with 2.x,
but fails in 3.1
r68205 [1] is the culprit, in response to issue #4718 [2]
The commit message says the changes were made to comply with
http://www.wsgi.org/wsgi/Amendments_1.0 (basically, clarify
str/unicode/bytes handling in Python 3.x). Either the documentation should
be updated or the original behavior be maintained (meaning the original
list contents could be altered); you probably should raise the question in
the Web-SIG [3].

[1] http://svn.python.org/view?view=rev&revision=68205
[2] http://bugs.python.org/issue4718
[3] http://www.python.org/community/sigs/current/web-sig/
 
G

Gabriel Genellina

I am having an issue with wsgiref.headers.Headers.

For example, if I do this...

from wsgiref.headers import Headers
list = []
wrapper = Headers(list)
wrapper['content-type'] = "text/html"
print(list)
print(wrapper)

I get an empty list printed, and then the correct result for wrapper
printed.

You forgot to mention the Python version; the code works fine with 2.x,
but fails in 3.1
r68205 [1] is the culprit, in response to issue #4718 [2]
The commit message says the changes were made to comply with
http://www.wsgi.org/wsgi/Amendments_1.0 (basically, clarify
str/unicode/bytes handling in Python 3.x). Either the documentation should
be updated or the original behavior be maintained (meaning the original
list contents could be altered); you probably should raise the question in
the Web-SIG [3].

[1] http://svn.python.org/view?view=rev&revision=68205
[2] http://bugs.python.org/issue4718
[3] http://www.python.org/community/sigs/current/web-sig/
 
G

Gabriel Genellina

I am having an issue with wsgiref.headers.Headers.

For example, if I do this...

from wsgiref.headers import Headers
list = []
wrapper = Headers(list)
wrapper['content-type'] = "text/html"
print(list)
print(wrapper)

I get an empty list printed, and then the correct result for wrapper
printed.

You forgot to mention the Python version; the code works fine with 2.x,
but fails in 3.1
r68205 [1] is the culprit, in response to issue #4718 [2]
The commit message says the changes were made to comply with
http://www.wsgi.org/wsgi/Amendments_1.0 (basically, clarify
str/unicode/bytes handling in Python 3.x). Either the documentation should
be updated or the original behavior be maintained (meaning the original
list contents could be altered); you probably should raise the question in
the Web-SIG [3].

[1] http://svn.python.org/view?view=rev&revision=68205
[2] http://bugs.python.org/issue4718
[3] http://www.python.org/community/sigs/current/web-sig/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top