Better support of utf-8 paths.
authorJérémy Bethmont <jeremy.bethmont@gmail.com>
Tue, 9 Aug 2011 13:14:08 +0000 (15:14 +0200)
committerJérémy Bethmont <jeremy.bethmont@gmail.com>
Tue, 9 Aug 2011 13:14:08 +0000 (15:14 +0200)
requests/models.py

index 619d099fdf6d3ebec10e0491fbff8418b4a1fa11..511002905370ac3619c32ebb54d00d8429f93278 100644 (file)
@@ -247,10 +247,12 @@ class Request(object):
         """Build the actual URL to use"""
 
         # Support for unicode domain names and paths.
-        parsed_url = list(urlparse(self.url))
-        parsed_url[1] = parsed_url[1].encode('idna')
-        parsed_url[2] = urllib.quote(urllib.unquote(parsed_url[2]))
-        self.url = urlunparse(parsed_url)
+        scheme, netloc, path, params, query, fragment = urlparse(self.url)
+        netloc = netloc.encode('idna')
+        if isinstance(path, unicode):
+            path = path.encode('utf-8')
+        path = urllib.quote(urllib.unquote(path))
+        self.url = str(urlunparse([ scheme, netloc, path, params, query, fragment ]))
 
         if self._enc_params:
             if urlparse(self.url).query: