diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2018-08-13 16:08:22 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2018-08-13 16:08:22 -0400 |
commit | b02ad86dee81c34e9e6fab0f6138590f667855cc (patch) | |
tree | 08158b601a34d1e420abaeb6a7aed63a6a39952e /cherrypy/_cpcompat.py | |
parent | 4dc9cf7e5ea872ae3ede43505ea14ae77b91a3bc (diff) | |
download | cherrypy-git-b02ad86dee81c34e9e6fab0f6138590f667855cc.tar.gz |
Extract unquote_plus and unquote methods, augmented with future-compatible behavior, from the unquote_qs function, which now reveals its main purpose is to change the default for errors and require an encoding.
Diffstat (limited to 'cherrypy/_cpcompat.py')
-rw-r--r-- | cherrypy/_cpcompat.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/cherrypy/_cpcompat.py b/cherrypy/_cpcompat.py index f0035362..e819335f 100644 --- a/cherrypy/_cpcompat.py +++ b/cherrypy/_cpcompat.py @@ -97,13 +97,20 @@ def assert_native(n): HTTPSConnection = getattr(six.moves.http_client, 'HTTPSConnection', None) +def _unquote_plus_compat(string, encoding='utf-8', errors='replace'): + return urllib.parse.unquote_plus(string).decode(encoding, errors) + + +def _unquote_compat(string, encoding='utf-8', errors='replace'): + return urllib.parse.unquote(string).decode(encoding, errors) + + +unquote_plus = urllib.parse.unquote_plus if six.PY3 else _unquote_plus_compat +unquote = urllib.parse.unquote if six.PY3 else _unquote_compat + + def unquote_qs(atom, encoding, errors='strict'): - atom_spc = atom.replace('+', ' ') - return ( - urllib.parse.unquote(atom_spc, encoding=encoding, errors=errors) - if six.PY3 else - urllib.parse.unquote(atom_spc).decode(encoding, errors) - ) + return unquote_plus(atom, encoding, errors) try: |