o
    M,h"                     @   s   d dl Z d dlZd dlmZ d dlmZmZ ddlmZ 	 ddgZ	de
d	efd
dZde
d	efddZde
d	efddZde
de
d	efddZde
deee
  d	efddZ		 			dde
dedee
 dedee deee
  de
d	efddZdS )     N)Optional)unquoteurlparse   )WebSocketProxyException	parse_urlget_proxy_infourlreturnc                 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rY|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 invalidr   http)schemezhostname is invalidr   FwsP   wssTi  zscheme %s is invalid/?)
ValueErrorsplitr   hostnameportpathquery)r	   r   parsedr   r   	is_secureresource r   Z/var/www/www-root/data/www/bot.pdev.uz/venv/lib/python3.10/site-packages/websocket/_url.pyr      s6   
addrc                 C   s8   t | ts	tdzt|  W dS  ty   Y dS w )Nz'_is_ip_address() argument 1 must be strFT)
isinstancestr	TypeError	ipaddress
ip_addressr   )r   r   r   r   _is_ip_addressK   s   
r$   r   c                 C   s&   zt |  W dS  ty   Y dS w )NFT)r"   
ip_networkr   r   r   r   r   _is_subnet_addressV   s   r'   ipnetc                 C   s.   zt | t |W S  ty   Y dS w )NF)r"   r%   	subnet_ofr!   )r(   r)   r   r   r   _is_address_in_network_   s
   r+   no_proxyc                    s   |st jdt jdddd }r|d}|sg }d|v r#dS  |v r)dS t r8t fdd	|D S d
d	 |D D ]}|d} |rN dS q?dS )Nr,   NO_PROXY  ,*Tc                    s   g | ]}t |rt |qS r   )r'   r+   ).0subnetr&   r   r   
<listcomp>v   s    z%_is_no_proxy_host.<locals>.<listcomp>c                 S   s   g | ]	}| d r|qS ).)
startswith)r2   domainr   r   r   r4   |   s    r5   F)	osenvirongetreplacer   r$   anylstripendswith)r   r,   vr7   	endDomainr   r&   r   _is_no_proxy_hostf   s.   



rA   r   r   
proxy_host
proxy_port
proxy_auth
proxy_typec                 C   s   t | |rdS |r|std|}|}|||fS |rdnd}	tj|	tj|	 ddd}
|
rPt|
}|jrGt	|jp>dt	|j
pDdfnd}|j|j|fS 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
        instead of "http_proxy"
    proxy_host: str
        http proxy host name.
    proxy_port: str or int
        http proxy port.
    no_proxy: list
        Whitelisted host names that don't use the proxy.
    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   Nz+Cannot use port 0 when proxy_host specifiedhttps_proxy
http_proxyr.   r/   N)rA   r   r8   r9   r:   upperr;   r   usernamer   passwordr   r   )r   r   rB   rC   rD   r,   rE   r   authenv_keyvalueproxyr   r   r   r      s(   
#
)Nr   NNr   )r"   r8   typingr   urllib.parser   r   _exceptionsr   __all__r    tupler   boolr$   r'   r+   listrA   intr   r   r   r   r   <module>   sD    .	 
