]> granicus.if.org Git - python/commitdiff
Bug #902075: urllib2 now handles "host:port" proxy specifications
authorGeorg Brandl <georg@python.org>
Sat, 21 Jan 2006 07:20:56 +0000 (07:20 +0000)
committerGeorg Brandl <georg@python.org>
Sat, 21 Jan 2006 07:20:56 +0000 (07:20 +0000)
Can/should this be backported?

Lib/urllib2.py
Misc/NEWS

index 015fdb51e84c5bd3d905d0d28c35e6cfa49de906..ba0d5b57ad77be02c0cead4f3cd3952cbf5ee831 100644 (file)
@@ -579,14 +579,19 @@ class ProxyHandler(BaseHandler):
     def proxy_open(self, req, proxy, type):
         orig_type = req.get_type()
         type, r_type = splittype(proxy)
-        host, XXX = splithost(r_type)
-        if '@' in host:
-            user_pass, host = host.split('@', 1)
-            if ':' in user_pass:
-                user, password = user_pass.split(':', 1)
-                user_pass = base64.encodestring('%s:%s' % (unquote(user),
-                                                unquote(password))).strip()
-                req.add_header('Proxy-authorization', 'Basic ' + user_pass)
+        if not type or r_type.isdigit():
+            # proxy is specified without protocol
+            type = orig_type
+            host = proxy
+        else:
+            host, r_host = splithost(r_type)
+        user_pass, host = splituser(host)
+        user, password = splitpasswd(user_pass)
+        if user and password:
+            user, password = user_pass.split(':', 1)
+            user_pass = base64.encodestring('%s:%s' % (unquote(user),
+                                            unquote(password))).strip()
+            req.add_header('Proxy-authorization', 'Basic ' + user_pass)
         host = unquote(host)
         req.set_proxy(host, type)
         if orig_type == type:
index ca5c5d9d0b7390c10022eae64059f046e307bcf1..af41f33ceaa5c702654cfb21164b21739d785486 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -337,7 +337,9 @@ Extension Modules
 Library
 -------
 
-- Bug #1407902: Added support for sftp:// URIs to urlparse.
+- Bug #902075: urllib2 now supports 'host:port' style proxy specifications.
+
+- Bug #1407902: Add support for sftp:// URIs to urlparse.
 
 - Bug #1371247: Update Windows locale identifiers in locale.py.