diff options
author | Cyril Roelandt <cyril.roelandt@enovance.com> | 2014-03-18 12:49:12 +0100 |
---|---|---|
committer | Cyril Roelandt <cyril.roelandt@enovance.com> | 2014-03-18 12:49:12 +0100 |
commit | 674ae7718bc06a8b8c8b658075bf82c8198fb632 (patch) | |
tree | 0075bace24ead7f03ae7cb18935e4c707f71a860 /paste/request.py | |
parent | 3cdb7e4227cbaad690b1c1557c03fa6da0decc36 (diff) | |
download | paste-674ae7718bc06a8b8c8b658075bf82c8198fb632.tar.gz |
Python 3: use new names of standard library modules
Use "try/except ImportError" to try Python 2 and Python 3 names.
Diffstat (limited to 'paste/request.py')
-rw-r--r-- | paste/request.py | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/paste/request.py b/paste/request.py index 9af494d..5649b7b 100644 --- a/paste/request.py +++ b/paste/request.py @@ -18,14 +18,21 @@ environment to solve common requirements. """ import cgi -from Cookie import SimpleCookie, CookieError -from StringIO import StringIO -import urlparse -import urllib +from six.moves import StringIO +from six.moves.urllib import parse as urlparse +from six.moves.urllib.parse import quote +try: + # Python 3 + from http.cookies import SimpleCookie, CookieError +except ImportError: + # Python 2 + from Cookie import SimpleCookie, CookieError + try: from UserDict import DictMixin except ImportError: - from paste.util.UserDict24 import DictMixin + from collections import MutableMapping as DictMixin + from paste.util.multidict import MultiDict __all__ = ['get_cookies', 'get_cookie_dict', 'parse_querystring', @@ -231,14 +238,14 @@ def construct_url(environ, with_query_string=True, with_path_info=True, url += ':' + environ['SERVER_PORT'] if script_name is None: - url += urllib.quote(environ.get('SCRIPT_NAME','')) + url += quote(environ.get('SCRIPT_NAME','')) else: - url += urllib.quote(script_name) + url += quote(script_name) if with_path_info: if path_info is None: - url += urllib.quote(environ.get('PATH_INFO','')) + url += quote(environ.get('PATH_INFO','')) else: - url += urllib.quote(path_info) + url += quote(path_info) if with_query_string: if querystring is None: if environ.get('QUERY_STRING'): |