def splithost(url):
 global _hostprog
 if (_hostprog is None):
  import re
  _hostprog = re.compile('^//([^/?]*)(.*)$')
 match = _hostprog.match(url)
 if match:
  host_port = match.group(1)
  path = match.group(2)
  if (path and (not path.startswith('/'))):
   path = ('/' + path)
  return (host_port, path)
 return (None, url)

def splithost ( url ) : global _hostprog if ( _hostprog is None ) : import re _hostprog = re . compile ( '^//([^/?]*)(.*)$' ) match = _hostprog . match ( url ) if match : host_port = match . group ( 1 ) path = match . group ( 2 ) if ( path and ( not path . startswith ( '/' ) ) ) : path = ( '/' + path ) return ( host_port , path ) return ( None , url )
splithost --> host[:port] .