summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-08-26 15:56:12 (GMT)
committerGuido van Rossum <guido@python.org>1996-08-26 15:56:12 (GMT)
commitf8abb38737e0490ef3fe59bc908285fa85bb9470 (patch)
tree279027699aa16f85810a0accec918679f918a4ee /Lib
parentf480c674b1462db277f997dcdc120006a79cdcb2 (diff)
downloadcpython-f8abb38737e0490ef3fe59bc908285fa85bb9470.zip
cpython-f8abb38737e0490ef3fe59bc908285fa85bb9470.tar.gz
cpython-f8abb38737e0490ef3fe59bc908285fa85bb9470.tar.bz2
Slightly faster (un)quoting.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index 63e4182..f1756e2 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -642,26 +642,26 @@ _quoteprog = regex.compile('%[0-9a-fA-F][0-9a-fA-F]')
def unquote(s):
i = 0
n = len(s)
- res = ''
+ res = []
while 0 <= i < n:
j = _quoteprog.search(s, i)
if j < 0:
- res = res + s[i:]
+ res.append(s[i:])
break
- res = res + (s[i:j] + chr(string.atoi(s[j+1:j+3], 16)))
+ res.append(s[i:j] + chr(string.atoi(s[j+1:j+3], 16)))
i = j+3
- return res
+ return string.joinfields(res, '')
always_safe = string.letters + string.digits + '_,.-'
def quote(s, safe = '/'):
safe = always_safe + safe
- res = ''
+ res = []
for c in s:
if c in safe:
- res = res + c
+ res.append(c)
else:
- res = res + '%%%02x' % ord(c)
- return res
+ res.append('%%%02x' % ord(c))
+ return string.joinfields(res, '')
# Proxy handling