Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 2 compatibility with unicode response header keys and wsgiref #1420

Closed
mircea3 opened this issue May 10, 2023 · 1 comment
Closed

Comments

@mircea3
Copy link

mircea3 commented May 10, 2023

Example:

from __future__ import unicode_literals

...
response.headers['Cache-Control'] = 'max-age=0'
...

Results in:

Traceback (most recent call last):
  File "bottle.py", line 1134, in wsgi
    start_response(response._wsgi_status_line(), response.headerlist, exc_info)
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 179, in start_response
    assert type(name) is StringType,"Header names must be strings"
AssertionError: Header names must be strings

This is similar to issue #923, including the fix, but applies to the header key, as opposed to the value.

The simple fix previously used for header value:

def _hval(value):
+    value = tonat(value)
     ...

could also be used for the header key:

def _hkey(key):
+   key = tonat(key)
    ...
@defnull
Copy link
Member

defnull commented Sep 10, 2024

It's hard enough to have Python 2 and 3 compatibility from a single source file. Not sure if we really want to support a third option (Python 2 with __future__ imports). Most public Bottle APIs expect and return 'native' strings (bytes in Python2 and unicode in Python 3). All those APIs would have to be checked and fixed.

@defnull defnull closed this as completed Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants