parameters: (url)
return_statement: return (hostname, port, resource, is_secure)
docstring: parse url and the result is tuple of
      (hostname, port, resource path and the flag of secure mode)
  
      url: url string.
docstring_summary: parse url and the result is tuple of
      (hostname, port, resource path and the flag of secure mode)
docstring_tokens: parse url and the result is tuple of ( hostname port resource path and the flag of secure mode )
function: def _parse_url(url):
      """
      parse url and the result is tuple of
      (hostname, port, resource path and the flag of secure mode)
  
      url: url string.
      """
      if ":" not in url:
          raise ValueError("url is invalid")
  
      scheme, url = url.split(":", 1)
  
      parsed = urlparse(url, scheme="http")
      if parsed.hostname:
          hostname = parsed.hostname
      else:
          raise ValueError("hostname is invalid")
      port = 0
      if parsed.port:
          port = parsed.port
  
      is_secure = False
      if scheme == "ws":
          if not port:
              port = 80
      elif scheme == "wss":
          is_secure = True
          if not port:
              port = 443
      else:
          raise ValueError("scheme %s is invalid" % scheme)
  
      if parsed.path:
          resource = parsed.path
      else:
          resource = "/"
  
      if parsed.query:
          resource += "?" + parsed.query
  
      return (hostname, port, resource, is_secure)
function_tokens: def _parse_url ( url ) : if ":" not in url : raise ValueError ( "url is invalid" ) scheme , url = url . split ( ":" , 1 ) parsed = urlparse ( url , scheme = "http" ) if parsed . hostname : hostname = parsed . hostname else : raise ValueError ( "hostname is invalid" ) port = 0 if parsed . port : port = parsed . port is_secure = False if scheme == "ws" : if not port : port = 80 elif scheme == "wss" : is_secure = True if not port : port = 443 else : raise ValueError ( "scheme %s is invalid" % scheme ) if parsed . path : resource = parsed . path else : resource = "/" if parsed . query : resource += "?" + parsed . query return ( hostname , port , resource , is_secure )