Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f8abb38

Browse files
committed
Slightly faster (un)quoting.
1 parent f480c67 commit f8abb38

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

Lib/urllib.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,26 +642,26 @@ def splitgophertype(selector):
642642
def unquote(s):
643643
i = 0
644644
n = len(s)
645-
res = ''
645+
res = []
646646
while 0 <= i < n:
647647
j = _quoteprog.search(s, i)
648648
if j < 0:
649-
res = res + s[i:]
649+
res.append(s[i:])
650650
break
651-
res = res + (s[i:j] + chr(string.atoi(s[j+1:j+3], 16)))
651+
res.append(s[i:j] + chr(string.atoi(s[j+1:j+3], 16)))
652652
i = j+3
653-
return res
653+
return string.joinfields(res, '')
654654

655655
always_safe = string.letters + string.digits + '_,.-'
656656
def quote(s, safe = '/'):
657657
safe = always_safe + safe
658-
res = ''
658+
res = []
659659
for c in s:
660660
if c in safe:
661-
res = res + c
661+
res.append(c)
662662
else:
663-
res = res + '%%%02x' % ord(c)
664-
return res
663+
res.append('%%%02x' % ord(c))
664+
return string.joinfields(res, '')
665665

666666

667667
# Proxy handling

0 commit comments

Comments
 (0)