Merge branch 'develop_cleanhost' of git://github.com/mano3m/CouchPotatoServer into mano3m-develop_cleanhost

This commit is contained in:
Ruud
2014-01-15 19:31:45 +01:00
13 changed files with 90 additions and 34 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