
    DQcs                     j    d Z 	 ddlZddlZddlZddlmZ ddgZd ZddgZd	 Z	d
 Z
d Zd Z	 	 ddZdS )z

    N)urlparse	parse_urlget_proxy_infoc                    d| vrt          d          |                     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   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   ws)schemezhostname is invalidr   FP   wssTi  zscheme %s is invalid/?)
ValueErrorsplitr   hostnameportpathquery)urlr
   parsedr   r   	is_secureresources          .lib/python3.11/site-packages/websocket/_url.pyr   r   #   s    #~ +)***))C##KFCc$'''F 0?.///D{ {I~ : 	D	5 :	 	D/&8999{ ;| 'C&,&&T8Y..    	localhostz	127.0.0.1c                 \    	 t          j        |            dS # t           j        $ r Y dS w xY w)NTF)socket	inet_atonerror)addrs    r   _is_ip_addressr!   T   sE     t <   uus    ++c                     	 |                      d          \  }}t          |          odt          |          cxk    odk     nc S # t          $ r Y dS w xY w)Nr   r       F)r   r!   intr   )r   r    netmasks      r   _is_subnet_addressr&   ]   ss     s++gd##>S\\(>(>(>(>B(>(>(>(>>   uus   AA 
AAc                 *   t          j        dt          j        |                     d         }|                    d          \  }}t          j        dt          j        |                    d         dt          |          dz
  z  dz
  z  }||z  |k    S )NIr   r      r   )structunpackr   r   r   r$   )ipnetipaddrnetaddrbitsr%   s         r   _is_address_in_networkr1   e   s    ]3 0 4 455a8FIIcNNMGTmC!1'!:!:;;A>1D		TUCUYZBZ[GGw&&r   c                     |sKt           j                            dd                              dd          }|r|                    d          }|st
          } |v rdS t                     rt           fd|D                       S dS )Nno_proxy  ,Tc                 N    g | ]!}t          |          t          |          "S  )r&   r1   ).0subnetr   s     r   
<listcomp>z%_is_no_proxy_host.<locals>.<listcomp>w   s3    rrrWijpWqWqr*8V<<rrrr   F)osenvirongetreplacer   DEFAULT_NO_PROXY_HOSTr!   any)r   r3   vs   `  r   _is_no_proxy_hostrC   l   s     $JNN:r**223;; 	$wws||H )(8 tt		!	! trrrr8rrrsss5r   httpc                 2   t          | |          rdS |r	|}|}|||fS dg}	|r|	                    dd           |	D ][}
t          j                            |
d          }|r7t          |          }|j        r|j        |j        fnd}|j        |j	        |fc 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: <type>
        websocket server name.
    is_secure: <type>
        is the connection secure? (wss) looks for "https_proxy" in env
        before falling back to "http_proxy"
    options: <type>
        - http_proxy_host: <type>
            http proxy host name.
        - http_proxy_port: <type>
            http proxy port.
        - http_no_proxy: <type>
            host names, which doesn't use proxy.
        - http_proxy_auth: <type>
            http proxy auth information. tuple of username and password. default is None
        - proxy_type: <type>
            if set to "socks5" PySocks wrapper will be used in place of a http proxy. default is "http"
    )Nr   N
http_proxyr   https_proxyN)
rC   insertr<   r=   r>   r   usernamepasswordr   r   )r   r   
proxy_host
proxy_port
proxy_authr3   
proxy_typer   authenv_keyskeyvalueproxys                r   r   r   |   s    : 8,, } &4%%~H *=))) 4 4
sD)) 	4UOOE7<~OENEN334D>5:t3333	4
 =r   )Nr   NNrD   )__doc__r<   r   r*   six.moves.urllib.parser   __all__r   r@   r!   r&   r1   rC   r   r8   r   r   <module>rW      s    * 
			   + + + + + + (
)+/ +/ +/\ %k2     ' ' '  " HL"(0 0 0 0 0 0r   