a
   s]Y                   @   sn   d Z ddlZddlZddlZddl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 )aL  
websocket - WebSocket client library for Python

Copyright (C) 2010 Hiroki Ohtani(liris)

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor,
    Boston, MA  02110-1335  USA

    N)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rR|j}d}|dkrh|sd	}n"|d
kr~d}|sd}nt d| |jr|j}nd}|jr|d|j 7 }||||fS )z
    parse url and the result is tuple of
    (hostname, port, resource path and the flag of secure mode)

    url: 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resource r   2/usr/lib/python3.9/site-packages/websocket/_url.pyr   !   s2    Z	localhostz	127.0.0.1c                 C   s.   zt |  W n t jy$   Y dS 0 dS d S )NFT)socket	inet_atonerror)addrr   r   r   _is_ip_addressO   s
    r   c                 C   sN   z4|  d\}}t|o2dt|  ko.dk n  W S  tyH   Y dS 0 d S )Nr   r       F)r   r   intr   )r   r   netmaskr   r   r   _is_subnet_addressX   s
    &r!   c                 C   sZ   t dt| d }|d\}}t dt|d dt|d > d @ }||@ |kS )NIr   r      r   )structunpackr   r   r   r   )ZipZnetZipaddrZnetaddrbitsr    r   r   r   _is_address_in_network`   s    *r'   c                    s^   |s(t jdddd}|r(|d}|s0t} |v r<dS t rZt fdd|D S dS )	Nno_proxy  ,Tc                    s   g | ]}t |rt |qS r   )r!   r'   ).0Zsubnetr   r   r   
<listcomp>r       z%_is_no_proxy_host.<locals>.<listcomp>F)osenvirongetreplacer   DEFAULT_NO_PROXY_HOSTr   any)r   r(   vr   r-   r   _is_no_proxy_hostg   s    
r7   httpc                 C   s   t | |rdS |r$|}|}|||fS dg}	|r:|	dd |	D ]F}
tj|
d}|r>t|}|jrn|j|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.

    hostname: websocket server name.

    is_secure:  is the connection secure? (wss)
                looks for "https_proxy" in env
                before falling back to "http_proxy"

    options:    "http_proxy_host" - http proxy host name.
                "http_proxy_port" - http proxy port.
                "http_no_proxy"   - host names, which doesn't use proxy.
                "http_proxy_auth" - http proxy auth information.
                                    tuple of username and password.
                                    default is None
                "proxy_type"      - if set to "socks5" PySocks wrapper
                                    will be used in place of a http proxy.
                                    default is "http"
    )Nr   NZ
http_proxyr   Zhttps_proxyN)
r7   insertr0   r1   r2   r   usernamepasswordr   r   )r   r   Z
proxy_hostZ
proxy_portZ
proxy_authr(   Z
proxy_typer   ZauthZenv_keyskeyvalueproxyr   r   r   r   w   s     

)Nr   NNr8   )__doc__r0   r   r$   Zsix.moves.urllib.parser   __all__r   r4   r   r!   r'   r7   r   r   r   r   r   <module>   s   +	  