def parse_uri(uri):
    """Parse absolute URI then return host, port and resource."""

    parsed = urlparse.urlsplit(uri)
    if parsed.scheme != 'wss' and parsed.scheme != 'ws':
        # |uri| must be a relative URI.
        # TODO(toyoshim): Should validate |uri|.
        return None, None, uri

    if parsed.hostname is None:
        return None, None, None

    port = None
    try:
        port = parsed.port
    except __HOLE__, e:
        # port property cause ValueError on invalid null port description like
        # 'ws://host:/path'.
        return None, None, None

    if port is None:
        if parsed.scheme == 'ws':
            port = 80
        else:
            port = 443

    path = parsed.path
    if not path:
        path += '/'
    if parsed.query:
        path += '?' + parsed.query
    if parsed.fragment:
        path += '#' + parsed.fragment

    return parsed.hostname, port, path
dataset/ETHPy150Open google/pywebsocket/mod_pywebsocket/http_header_util.py/parse_uri