[Web-SIG] PEP3333 and PATH_INFO

7 views
Skip to first unread message

Chris McDonough

unread,
Jan 3, 2012, 5:52:36 AM1/3/12
to web...@python.org
Perrenial topic, it seems, from the archives.

As far as I can tell from PEP 3333, every WSGI application that wants to
run on both Python 2 and Python 3 and which uses PATH_INFO will need to
define a helper function something like this:

"""
import sys

def decode_path_info(environ, encoding='utf-8'):
PY3 = sys.version_info[0] == 3
path_info = environ['PATH_INFO']
if PY3:
return path_info.encode('latin-1').decode(encoding)
else:
return path_info.decode(encoding)
"""

Is there a more elegant way to handle this?

- C


_______________________________________________
Web-SIG mailing list
Web...@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/python-web-sig-garchive-9074%40googlegroups.com

Reply all
Reply to author
Forward
0 new messages