o
    i                     @   st   d dl Z d dlZd dlZd dlmZmZ 	 ddgZdd ZddgZdd	 Z	d
d Z
dd Zdd Z		dddZdS )    N)unquoteurlparse	parse_urlget_proxy_infoc                 C   s   d| vrt d| dd\}} t| dd}|jr|j}nt dd}|jr)|j}d}|d	kr4|s3d
}n|dkr?d}|s>d}nt d| |jrL|j}nd}|jrX|d|j 7 }||||fS )z
    parse url and the result is tuple of
    (hostname, port, resource path and the flag of secure mode)

    Parameters
    ----------
    url: str
        url string.
    :zurl is invalid   http)schemezhostname is invalidr   FwsP   wssTi  zscheme %s is invalid/?)
ValueErrorsplitr   hostnameportpathquery)urlr	   parsedr   r   	is_secureresource r   I/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/websocket/_url.pyr      s6   
	localhostz	127.0.0.1c                 C   s(   zt |  W dS  t jy   Y dS w )NFT)socket	inet_atonerror)addrr   r   r   _is_ip_addressN   s   r    c                 C   sL   z|  d\}}t|odt|  kodk W S   W S  ty%   Y dS w )Nr   r       F)r   r    intr   )r   r   netmaskr   r   r   _is_subnet_addressW   s   (r$   c                 C   sZ   t dt| d }|d\}}t dt|d }ddt| > d@ }||@ |kS )Nz!Ir   r   l    r!   )structunpackr   r   r   r"   )ipnetipaddrnetaddrr#   r   r   r   _is_address_in_network_   s
   r+   c                    s   |st jdt jdddd}|r|d}|st}d|v r#dS  |v r)dS t r8t fdd	|D S d
d	 |D D ]
} |rI dS q?dS )Nno_proxyNO_PROXY  ,*Tc                    s   g | ]}t |rt |qS r   )r$   r+   ).0subnetr   r   r   
<listcomp>u   s    z%_is_no_proxy_host.<locals>.<listcomp>c                 S   s   g | ]	}| d r|qS ).)
startswith)r2   domainr   r   r   r5   v   s    F)	osenvirongetreplacer   DEFAULT_NO_PROXY_HOSTr    anyendswith)r   r,   vr8   r   r4   r   _is_no_proxy_hosth   s"    

rA   r   c                 C   s   t | |rdS |r|}|}|||fS dg}	|r|	dd |	D ]2}
tj|
tj|
 ddd}|rQt|}|jrFt	|jt	|j
fnd}|j|j|f  S qdS )a  
    Try to retrieve proxy host and port from environment
    if not provided in options.
    Result is (proxy_host, proxy_port, proxy_auth).
    proxy_auth is tuple of username and password
    of proxy authentication information.

    Parameters
    ----------
    hostname: str
        Websocket server name.
    is_secure: bool
        Is the connection secure? (wss) looks for "https_proxy" in env
        before falling back to "http_proxy"
    proxy_host: str
        http proxy host name.
    http_proxy_port: str or int
        http proxy port.
    http_no_proxy: list
        Whitelisted host names that don't use the proxy.
    http_proxy_auth: tuple
        HTTP proxy auth information. Tuple of username and password. Default is None.
    proxy_type: str
        Specify the proxy protocol (http, socks4, socks4a, socks5, socks5h). Default is "http".
        Use socks4a or socks5h if you want to send DNS requests through the proxy.
    )Nr   N
http_proxyr   https_proxyr.   r/   N)rA   insertr9   r:   r;   upperr<   r   usernamer   passwordr   r   )r   r   
proxy_host
proxy_port
proxy_authr,   
proxy_typer   authenv_keyskeyvalueproxyr   r   r   r   |   s"   

$)Nr   NNr   )r9   r   r%   urllib.parser   r   __all__r   r=   r    r$   r+   rA   r   r   r   r   r   <module>   s    .		