def cleanHost(host, protocol=True, ssl=False, username=None, password=None):
 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):
  try:
   auth = re.findall('^(?:.+?//)(.+?):(.+?)@(?:.+)$', host)
   if auth:
    log.error('Cleanhost error: auth already defined in url: %s, please remove BasicAuth from url.', host)
   else:
    host = host.replace('://', ('://%s:%s@' % (username, password)), 1)
  except:
   pass
 host = host.rstrip('/ ')
 if protocol:
  host += '/'
 return host

def cleanHost ( host , protocol = True , ssl = False , username = None , password = None ) : 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 ) : try : auth = re . findall ( '^(?:.+?//)(.+?):(.+?)@(?:.+)$' , host ) if auth : log . error ( 'Cleanhost error: auth already defined in url: %s, please remove BasicAuth from url.' , host ) else : host = host . replace ( '://' , ( '://%s:%s@' % ( username , password ) ) , 1 ) except : pass host = host . rstrip ( '/ ' ) if protocol : host += '/' return host
return a cleaned up host with given url options set changes protocol to https if ssl is set to true and http if ssl is set to false .