Add support for authentication scheme.

This commit closes http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=690879
This commit is contained in:
Valentin Lorentz 2012-10-20 20:23:32 +02:00
parent 86d590c8c8
commit 3a78300971

View File

@ -30,6 +30,7 @@
import re import re
import sys import sys
import base64
import socket import socket
import urllib import urllib
import urllib2 import urllib2
@ -61,9 +62,9 @@ _ipAddr = r'%s(?:\.%s){3}' % (_octet, _octet)
# Base domain regex off RFC 1034 and 1738 # Base domain regex off RFC 1034 and 1738
_label = r'[0-9a-z][-0-9a-z]*[0-9a-z]?' _label = r'[0-9a-z][-0-9a-z]*[0-9a-z]?'
_domain = r'%s(?:\.%s)*\.[0-9a-z][-0-9a-z]+' % (_label, _label) _domain = r'%s(?:\.%s)*\.[0-9a-z][-0-9a-z]+' % (_label, _label)
_urlRe = r'(\w+://(?:%s|%s)(?::\d+)?(?:/[^\])>\s]*)?)' % (_domain, _ipAddr) _urlRe = r'(\w+://(?:\S+@)?(?:%s|%s)(?::\d+)?(?:/[^\])>\s]*)?)' % (_domain, _ipAddr)
urlRe = re.compile(_urlRe, re.I) urlRe = re.compile(_urlRe, re.I)
_httpUrlRe = r'(https?://(?:%s|%s)(?::\d+)?(?:/[^\])>\s]*)?)' % (_domain, _httpUrlRe = r'(https?://(?:\S+@)?(?:%s|%s)(?::\d+)?(?:/[^\])>\s]*)?)' % (_domain,
_ipAddr) _ipAddr)
httpUrlRe = re.compile(_httpUrlRe, re.I) httpUrlRe = re.compile(_httpUrlRe, re.I)
@ -110,7 +111,13 @@ def getUrlFd(url, headers=None, data=None):
if not isinstance(url, urllib2.Request): if not isinstance(url, urllib2.Request):
if '#' in url: if '#' in url:
url = url[:url.index('#')] url = url[:url.index('#')]
if '@' in url:
scheme, url = url.split('://', 2)
auth, url = url.split('@')
url = scheme + '://' + url
request = urllib2.Request(url, headers=headers, data=data) request = urllib2.Request(url, headers=headers, data=data)
request.add_header('Authorization',
'Basic ' + base64.b64encode(auth))
else: else:
request = url request = url
request.add_data(data) request.add_data(data)