Downloader cleanHost

Extend the use of clean host (add more checks and features) and make the settings more dummy proof.
This commit is contained in:
mano3m
2014-01-12 00:52:32 +01:00
parent c948f38469
commit 05c41460c2
12 changed files with 79 additions and 33 deletions
+15 -5
View File
@@ -118,12 +118,22 @@ def isLocalIP(ip):
def getExt(filename):
return os.path.splitext(filename)[1][1:]
def cleanHost(host):
if not host.startswith(('http://', 'https://')):
host = 'http://' + host
def cleanHost(host, protocol = True, ssl = False, username = None, password = None):
host = host.rstrip('/')
host += '/'
if not '://' in host and protocol:
host = 'https://' if ssl else 'http://' + host
if not protocol:
host = host.split('://', 1)[-1]
if protocol and username and password:
login = '%s:%s@' % (username, password)
if not login in host:
host.replace('://', '://' + login, 1)
host = host.rstrip('/ ')
if protocol:
host += '/'
return host