code: def parse_url(url):
      
      if ":" not in url:
          raise ValueError("url is invalid")
  
      scheme, url = url.split(":", 1)
  
      parsed = urlparse(url, scheme="ws")
      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
docs: parse url and the result is tuple of
      (hostname, port, resource path and the flag of secure mode)
  
      url: url string.