this try catch is a poor man's patch for issue #630 see https://github.com/kennethrei...
authorTzury Bar Yochay <tzury.by@gmail.com>
Thu, 24 May 2012 03:17:21 +0000 (06:17 +0300)
committerTzury Bar Yochay <tzury.by@gmail.com>
Thu, 24 May 2012 03:17:21 +0000 (06:17 +0300)
requests/utils.py

index e60b9c48e2dd851901c935ad4cfb9d9627bd597a..966f19e611dfd46428224060f3b261b08aa9e2eb 100644 (file)
@@ -407,22 +407,29 @@ UNRESERVED_SET = frozenset(
 
 
 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.
-    """
-    parts = uri.split('%')
-    for i in range(1, len(parts)):
-        h = parts[i][0:2]
-        if len(h) == 2:
-            c = chr(int(h, 16))
-            if c in UNRESERVED_SET:
-                parts[i] = c + parts[i][2:]
+    '''
+    this try catch is a poor man's patch for issue #630
+    https://github.com/kennethreitz/requests/issues/630
+    '''
+    try:
+        """Un-escape any percent-escape sequences in a URI that are unreserved
+        characters.
+        This leaves all reserved, illegal and non-ASCII bytes encoded.
+        """
+        parts = uri.split('%')
+        for i in range(1, len(parts)):
+            h = parts[i][0:2]
+            if len(h) == 2:
+                c = chr(int(h, 16))
+                if c in UNRESERVED_SET:
+                    parts[i] = c + parts[i][2:]
+                else:
+                    parts[i] = '%' + parts[i]
             else:
                 parts[i] = '%' + parts[i]
-        else:
-            parts[i] = '%' + parts[i]
-    return ''.join(parts)
+        return ''.join(parts)
+    except:
+        return uri
 
 
 def requote_uri(uri):