
     ke                         d dl Z d dlZd dlZd dlmZ d dlmZmZ 	 ddgZde	de
fdZd	d
gZde	defdZde	defdZde	de	defdZde	dee   defdZ	 	 	 	 	 dde	dedee	   dedee
   dee   de	de
fdZy)    N)Optional)unquoteurlparse	parse_urlget_proxy_infourlreturnc                    d| vrt        d      | j                  dd      \  }} t        | d      }|j                  r|j                  }nt        d      d}|j                  r|j                  }d}|d	k(  r|sd
}n|dk(  rd}|sd}nt        d|z        |j
                  r|j
                  }nd}|j                  r|d|j                   z  }||||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)r   r   parsedr   r   	is_secureresources          0/usr/lib/python3/dist-packages/websocket/_url.pyr   r      s     #~)**))C#KFCc&)F??.//D{{{{I~D	5	D/&899{{;;||a~&&T8Y..    	localhostz	127.0.0.1addrc                 b    	 t        j                  |        y# t         j                  $ r Y yw xY w)NTF)socket	inet_atonerror)r    s    r   _is_ip_addressr%   N   s2      << s    ..r   c                     	 | j                  d      \  }}t        |      xr dt        |      cxk  xr dk  S c S # t        $ r Y yw xY w)Nr   r       F)r   r%   intr   )r   r    netmasks      r   _is_subnet_addressr*   W   sO     s+gd#>S\(>B(>>(>> s   6< < 	AAipnetc                    t        j                  dt        j                  |             d   }|j	                  d      \  }}t        j                  dt        j                  |            d   }ddt        |      z
  z  dz  }||z  |k(  S )Nz!Ir   r   l    r'   )structunpackr"   r#   r   r(   )r+   r,   ipaddrnetaddrr)   s        r   _is_address_in_networkr2   _   s|    --f&6&6r&:;A>Fyy~GW==v'7'7'@A!DGb3w</0J>GGw&&r   no_proxyc           	         |sat         j                  j                  dt         j                  j                  dd            j                  dd      x}r|j	                  d      }|st
        }d|v ry| |v ryt        |       r.t        |D cg c]  }t        |      rt        | |       c}      S |D cg c]  }|j                  d      s| c}D ]  }| j                  |      s y y	c c}w c c}w )
Nr3   NO_PROXY  ,*T.F)osenvirongetreplacer   DEFAULT_NO_PROXY_HOSTr%   anyr*   r2   
startswithendswith)r   r3   vsubnetdomains        r   _is_no_proxy_hostrF   h   s    

z2::>>*b+IJRR
 
1 
 wws|H(
h8h '%f- 'x8
 	
 )1KfF4E4Ec4J6K V$  Ls   
C*3C/
C/r   
proxy_host
proxy_port
proxy_auth
proxy_typec                    t        | |      ry|r	|}|}|||fS |rdnd}	t        j                  j                  |	t        j                  j                  |	j	                         d            j                  dd      }
|
r\t        |
      }|j                  r*t        |j                        t        |j                        fnd}|j                  |j                  |fS y)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   Nhttps_proxy
http_proxyr6   r7   N)rF   r;   r<   r=   upperr>   r   usernamer   passwordr   r   )r   r   rG   rH   rI   r3   rJ   r   authenv_keyvalueproxys               r   r   r      s    F 8,4%%(mlGJJNN7BJJNN7==?B$GHPPRE  ~~ U^^$genn&=> 	
 ~~uzz4//r   )Nr   NNr   )r;   r"   r.   typingr   urllib.parser   r   __all__strtupler   r?   boolr%   r*   r2   listrF   r(   r    r   r   <module>r]      s   	    *& (
)+/3 +/5 +/\ %k2     's ' ' ' x~ $ < !%"&#888 8 	8
 8 tn8 8 8r   