diff options
author | Guido van Rossum <guido@python.org> | 1996-12-13 14:47:36 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1996-12-13 14:47:36 (GMT) |
commit | 0564e12367dc10349cd5596bdbe9bbcb44e112c2 (patch) | |
tree | 5ab6839cdb8731799613fbca22dad0a31f9da8af | |
parent | fbcfd52a9ab413fdf4e2ffadde727cd378982de6 (diff) | |
download | cpython-0564e12367dc10349cd5596bdbe9bbcb44e112c2.zip cpython-0564e12367dc10349cd5596bdbe9bbcb44e112c2.tar.gz cpython-0564e12367dc10349cd5596bdbe9bbcb44e112c2.tar.bz2 |
Added quote_plus() and unquote_plus(), to do space/plus substitutions
for form field values.
-rw-r--r-- | Lib/urllib.py | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py index 0644ecd..e44f6b1 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -693,6 +693,12 @@ def unquote(s): i = j+3 return string.joinfields(res, '') +def unquote_plus(s): + if '+' in s: + import regsub + s = regsub.gsub('+', ' ', s) + return unquote(s) + always_safe = string.letters + string.digits + '_,.-' def quote(s, safe = '/'): safe = always_safe + safe @@ -704,6 +710,14 @@ def quote(s, safe = '/'): res.append('%%%02x' % ord(c)) return string.joinfields(res, '') +def quote_plus(s, safe = '/'): + if ' ' in s: + import regsub + s = regsub.gsub(' ', '+', s) + return quote(s, safe + '+') + else: + return quote(s, safe) + # Proxy handling def getproxies(): |