mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
utils.web: Simplify getUrlFd by using standard parse methods
Signed-off-by: James McCoy <jamessan@users.sourceforge.net>
This commit is contained in:
parent
180508496f
commit
90b7f3cd4e
@ -107,15 +107,13 @@ def getUrlFd(url, headers=None, data=None, timeout=None):
|
|||||||
headers = defaultHeaders
|
headers = defaultHeaders
|
||||||
try:
|
try:
|
||||||
if not isinstance(url, urllib2.Request):
|
if not isinstance(url, urllib2.Request):
|
||||||
if '#' in url:
|
(scheme, loc, path, query, frag) = urlparse.urlsplit(url)
|
||||||
url = url[:url.index('#')]
|
(user, host) = urllib.splituser(loc)
|
||||||
|
url = urlparse.urlunsplit((scheme, host, path, query, ''))
|
||||||
request = urllib2.Request(url, headers=headers, data=data)
|
request = urllib2.Request(url, headers=headers, data=data)
|
||||||
if '@' in url:
|
if user:
|
||||||
scheme, url = url.split('://', 2)
|
|
||||||
auth, url = url.split('@')
|
|
||||||
url = scheme + '://' + url
|
|
||||||
request.add_header('Authorization',
|
request.add_header('Authorization',
|
||||||
'Basic ' + base64.b64encode(auth))
|
'Basic %s' % base64.b64encode(user))
|
||||||
else:
|
else:
|
||||||
request = url
|
request = url
|
||||||
request.add_data(data)
|
request.add_data(data)
|
||||||
|
Loading…
Reference in New Issue
Block a user