a
    ñ»j+  ã                   @  sœ   d dl mZ d dlZd dlZd dlZddlmZmZ ddgZ	dZ
ejG dd„ dƒƒZd	dd
œdd„ZejG dd„ dƒƒZd	ddœdd„Zddd
œdd„ZdS )é    )ÚannotationsNé   )ÚInvalidProxyÚ
InvalidURIÚ	parse_uriÚWebSocketURIz:/?#[]@!$&'()*+,;=c                   @  sv   e Zd ZU dZded< ded< ded< ded< ded	< d
Zded< d
Zded< eddœdd„ƒZeddœdd„ƒZ	d
S )r   a  
    WebSocket URI.

    Attributes:
        secure: :obj:`True` for a ``wss`` URI, :obj:`False` for a ``ws`` URI.
        host: Normalized to lower case.
        port: Always set even if it's the default.
        path: May be empty.
        query: May be empty if the URI doesn't include a query component.
        username: Available when the URI contains `User Information`_.
        password: Available when the URI contains `User Information`_.

    .. _User Information: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1

    ÚboolÚsecureÚstrÚhostÚintÚportÚpathÚqueryNú
str | NoneÚusernameÚpassword©Úreturnc                 C  s*   | j r| j }nd}| jr&|d| j 7 }|S )Nú/ú?)r   r   )ÚselfÚresource_name© r   ú4E:\soccer\ml_env\Lib\site-packages\websockets/uri.pyr   +   s    zWebSocketURI.resource_nameútuple[str, str] | Nonec                 C  s(   | j d u rd S | jd usJ ‚| j | jfS ©N©r   r   ©r   r   r   r   Ú	user_info5   s    
zWebSocketURI.user_info)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r   r   Úpropertyr   r   r   r   r   r   r      s   
	r
   )Úurir   c           	      C  s8  t j | ¡}|jdvr t| dƒ‚|jdu r4t| dƒ‚|jdkrHt| dƒ‚|jdk}|j}|jph|rfdnd	}|j}|j	}|j
}|j}|durœ|du rœt| d
ƒ‚z|  d¡ W nx t�y"   | d¡ ¡ }t jj|td�}t jj|td�}|du�r|dusþJ ‚t jj|td�}t jj|td�}Y n0 t|||||||ƒS )zÊ
    Parse and validate a WebSocket URI.

    Args:
        uri: WebSocket URI.

    Returns:
        Parsed WebSocket URI.

    Raises:
        InvalidURI: If ``uri`` isn't a valid WebSocket URI.

    )ÚwsÚwsszscheme isn't ws or wssNúhostname isn't providedÚ z"fragment identifier is meaninglessr(   é»  éP   ú"username provided without passwordÚasciiÚidna©Úsafe)ÚurllibÚparseÚurlparseÚschemer   ÚhostnameÚfragmentr   r   r   r   r   ÚencodeÚUnicodeEncodeErrorÚdecodeÚquoteÚDELIMSr   )	r&   Úparsedr	   r   r   r   r   r   r   r   r   r   r   =   s6    








c                   @  sT   e Zd ZU dZded< ded< ded< dZded	< dZded
< eddœdd„ƒZdS )ÚProxyaè  
    Proxy.

    Attributes:
        scheme: ``"socks5h"``, ``"socks5"``, ``"socks4a"``, ``"socks4"``,
            ``"https"``, or ``"http"``.
        host: Normalized to lower case.
        port: Always set even if it's the default.
        username: Available when the proxy address contains `User Information`_.
        password: Available when the proxy address contains `User Information`_.

    .. _User Information: https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.1

    r
   r5   r   r   r   Nr   r   r   r   r   c                 C  s(   | j d u rd S | jd usJ ‚| j | jfS r   r   r   r   r   r   r   †   s    
zProxy.user_info)	r    r!   r"   r#   r$   r   r   r%   r   r   r   r   r   r>   o   s   
r>   )Úproxyr   c                 C  s>  t j | ¡}|jdvr*t| d|j› d�ƒ‚|jdu r>t| dƒ‚|jdvrRt| dƒ‚|jdkrft| d	ƒ‚|jdkrzt| d
ƒ‚|j}|j}|j	pœ|jdkršdnd}|j
}|j}|durÄ|du rÄt| dƒ‚z|  d¡ W nZ t�y,   | d¡ ¡ }|du�r(|du�sJ ‚t jj|td�}t jj|td�}Y n0 t|||||ƒS )z°
    Parse and validate a proxy.

    Args:
        proxy: proxy.

    Returns:
        Parsed proxy.

    Raises:
        InvalidProxy: If ``proxy`` isn't a valid proxy.

    )Zsocks5hZsocks5Zsocks4aZsocks4ÚhttpsÚhttpzscheme z isn't supportedNr)   )r*   r   zpath is meaninglessr*   zquery is meaninglesszfragment is meaninglessr@   r+   r,   r-   r.   r/   r0   )r2   r3   r4   r5   r   r6   r   r   r7   r   r   r   r8   r9   r:   r;   r<   r>   )r?   r=   r5   r   r   r   r   r   r   r   Úparse_proxyŽ   s6    










rB   r   c                 C  sŠ   t j | j› d| j› �¡rdS t j ¡ }| jr8g d¢}ng d¢}|D ]@}| |¡}|durD|dkr|| d¡r|d|dd…  }|  S qDdS )	zU
    Return the proxy to use for connecting to the given WebSocket URI, if any.

    ú:N)r(   Úsocksr@   )r'   rD   r@   rA   rD   zhttp://z
socks5h://é   )	r2   ÚrequestÚproxy_bypassr   r   Ú
getproxiesr	   ÚgetÚ
startswith)r&   ÚproxiesÚschemesr5   r?   r   r   r   Ú	get_proxyÀ   s    



rM   )Ú
__future__r   ÚdataclassesÚurllib.parser2   Úurllib.requestÚ
exceptionsr   r   Ú__all__r<   Ú	dataclassr   r   r>   rB   rM   r   r   r   r   Ú<module>   s   +22