summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-01-21 07:20:56 (GMT)
committerGeorg Brandl <georg@python.org>2006-01-21 07:20:56 (GMT)
commit531cebad4c815f8fcf7abaf680ceb88c014d7d3f (patch)
tree975d780fe39ce413e0606c595d9c7df1430d7b6d /Lib
parent3d5635091069c2fce4896429bca1e063ea223c48 (diff)
downloadcpython-531cebad4c815f8fcf7abaf680ceb88c014d7d3f.zip
cpython-531cebad4c815f8fcf7abaf680ceb88c014d7d3f.tar.gz
cpython-531cebad4c815f8fcf7abaf680ceb88c014d7d3f.tar.bz2
Bug #902075: urllib2 now handles "host:port" proxy specifications
Can/should this be backported?
Diffstat (limited to 'Lib')
-rw-r--r--Lib/urllib2.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/Lib/urllib2.py b/Lib/urllib2.py
index 015fdb5..ba0d5b5 100644
--- a/Lib/urllib2.py
+++ b/Lib/urllib2.py
@@ -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: