Back to issue #630, .isalnum() was sufficient in addressing the issue.
authorMarcin Wielgoszewski <marcin.wielgoszewski@gmail.com>
Thu, 22 Nov 2012 16:10:22 +0000 (11:10 -0500)
committerMarcin Wielgoszewski <marcin.wielgoszewski@gmail.com>
Thu, 22 Nov 2012 16:10:22 +0000 (11:10 -0500)
Adding a try/except block just masks any issues that are raised here, issues that the developer should definitely be made aware of.

requests/utils.py

index b3d33f4fbc2dbe9c7591db0fc8fd82a424fda57f..df25126bd2a0fec92ed6dc1cf97cd614bd6e337e 100644 (file)
@@ -473,21 +473,18 @@ def unquote_unreserved(uri):
     """Un-escape any percent-escape sequences in a URI that are unreserved
     characters. This leaves all reserved, illegal and non-ASCII bytes encoded.
     """
-    try:
-        parts = uri.split('%')
-        for i in range(1, len(parts)):
-            h = parts[i][0:2]
-            if len(h) == 2 and h.isalnum():
-                c = chr(int(h, 16))
-                if c in UNRESERVED_SET:
-                    parts[i] = c + parts[i][2:]
-                else:
-                    parts[i] = '%' + parts[i]
+    parts = uri.split('%')
+    for i in range(1, len(parts)):
+        h = parts[i][0:2]
+        if len(h) == 2 and h.isalnum():
+            c = chr(int(h, 16))
+            if c in UNRESERVED_SET:
+                parts[i] = c + parts[i][2:]
             else:
                 parts[i] = '%' + parts[i]
-        return ''.join(parts)
-    except ValueError:
-        return uri
+        else:
+            parts[i] = '%' + parts[i]
+    return ''.join(parts)
 
 
 def requote_uri(uri):