def parse_url(url):
 scheme = None
 auth = None
 host = None
 port = None
 path = None
 fragment = None
 query = None
 if ('://' in url):
  (scheme, url) = url.split('://', 1)
 (url, path_, delim) = split_first(url, ['/', '?', '#'])
 if delim:
  path = (delim + path_)
 if ('@' in url):
  (auth, url) = url.split('@', 1)
 if (url and (url[0] == '[')):
  (host, url) = url.split(']', 1)
  host += ']'
 if (':' in url):
  (_host, port) = url.split(':', 1)
  if (not host):
   host = _host
  if (not port.isdigit()):
   raise LocationParseError(('Failed to parse: %s' % url))
  port = int(port)
 elif ((not host) and url):
  host = url
 if (not path):
  return Url(scheme, auth, host, port, path, query, fragment)
 if ('#' in path):
  (path, fragment) = path.split('#', 1)
 if ('?' in path):
  (path, query) = path.split('?', 1)
 return Url(scheme, auth, host, port, path, query, fragment)

def parse_url ( url ) : scheme = None auth = None host = None port = None path = None fragment = None query = None if ( '://' in url ) : ( scheme , url ) = url . split ( '://' , 1 ) ( url , path_ , delim ) = split_first ( url , [ '/' , '?' , '#' ] ) if delim : path = ( delim + path_ ) if ( '@' in url ) : ( auth , url ) = url . split ( '@' , 1 ) if ( url and ( url [ 0 ] == '[' ) ) : ( host , url ) = url . split ( ']' , 1 ) host += ']' if ( ':' in url ) : ( _host , port ) = url . split ( ':' , 1 ) if ( not host ) : host = _host if ( not port . isdigit ( ) ) : raise LocationParseError ( ( 'Failed to parse: %s' % url ) ) port = int ( port ) elif ( ( not host ) and url ) : host = url if ( not path ) : return Url ( scheme , auth , host , port , path , query , fragment ) if ( '#' in path ) : ( path , fragment ) = path . split ( '#' , 1 ) if ( '?' in path ) : ( path , query ) = path . split ( '?' , 1 ) return Url ( scheme , auth , host , port , path , query , fragment )
parse url into mapping of components .