mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-12-24 03:33:11 +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
|
||||
try:
|
||||
if not isinstance(url, urllib2.Request):
|
||||
if '#' in url:
|
||||
url = url[:url.index('#')]
|
||||
(scheme, loc, path, query, frag) = urlparse.urlsplit(url)
|
||||
(user, host) = urllib.splituser(loc)
|
||||
url = urlparse.urlunsplit((scheme, host, path, query, ''))
|
||||
request = urllib2.Request(url, headers=headers, data=data)
|
||||
if '@' in url:
|
||||
scheme, url = url.split('://', 2)
|
||||
auth, url = url.split('@')
|
||||
url = scheme + '://' + url
|
||||
if user:
|
||||
request.add_header('Authorization',
|
||||
'Basic ' + base64.b64encode(auth))
|
||||
'Basic %s' % base64.b64encode(user))
|
||||
else:
|
||||
request = url
|
||||
request.add_data(data)
|
||||
|
Loading…
Reference in New Issue
Block a user