def _url_to_origin(url):
 if (url.lower() == 'null'):
  return 'null'
 res = urllib.parse.urlsplit(url)
 scheme = res.scheme.lower()
 if (scheme == 'file'):
  return 'null'
 host = res.hostname
 port = res.port
 if (port is None):
  try:
   port = {'https': 443, 'http': 80}[scheme]
  except KeyError:
   port = None
 if (not host):
  raise ValueError("No host part in Origin '{}'".format(url))
 return (scheme, host, port)

def _url_to_origin ( url ) : if ( url . lower ( ) == 'null' ) : return 'null' res = urllib . parse . urlsplit ( url ) scheme = res . scheme . lower ( ) if ( scheme == 'file' ) : return 'null' host = res . hostname port = res . port if ( port is None ) : try : port = { 'https' : 443 , 'http' : 80 } [ scheme ] except KeyError : port = None if ( not host ) : raise ValueError ( "No host part in Origin '{}'" . format ( url ) ) return ( scheme , host , port )
given an rfc6455 origin url .