Accept objects with string representations as URLs.
authorCory Benfield <lukasaoz@gmail.com>
Wed, 8 Aug 2012 11:05:52 +0000 (12:05 +0100)
committerCory Benfield <lukasaoz@gmail.com>
Wed, 8 Aug 2012 12:33:25 +0000 (13:33 +0100)
requests/models.py

index d8c0f3e..20a2880 100644 (file)
@@ -71,7 +71,14 @@ class Request(object):
         self.timeout = timeout
 
         #: Request URL.
-        self.url = url
+        #: Accept objects that have string representations.
+        try:
+            self.url = unicode(url)
+        except NameError:
+            # We're on Python 3.
+            self.url = str(url)
+        except UnicodeDecodeError:
+            self.url = url
 
         #: Dictionary of HTTP Headers to attach to the :class:`Request <Request>`.
         self.headers = dict(headers or [])