]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Simplify and speed-up quote_plus().
authorRaymond Hettinger <python@rcn.com>
Sat, 10 Sep 2005 02:27:41 +0000 (02:27 +0000)
committerRaymond Hettinger <python@rcn.com>
Sat, 10 Sep 2005 02:27:41 +0000 (02:27 +0000)
Lib/urllib.py

index b8ba4540226c2517142ad1ac52ae6cbf7d1092fc..2889b3dbfb0d9fe9703f9bd7cc29219d436b45c5 100644 (file)
@@ -1115,12 +1115,9 @@ def quote(s, safe = '/'):
 def quote_plus(s, safe = ''):
     """Quote the query fragment of a URL; replacing ' ' with '+'"""
     if ' ' in s:
-        l = s.split(' ')
-        for i in range(len(l)):
-            l[i] = quote(l[i], safe)
-        return '+'.join(l)
-    else:
-        return quote(s, safe)
+        s = s.replace(' ', '+')
+        safe += '+'
+    return quote(s, safe)
 
 def urlencode(query,doseq=0):
     """Encode a sequence of two-element tuples or dictionary into a URL query string.