o
    _c                     @  sf   d dl mZ d dlZd dlZd dlmZmZ ddlm	Z	 ddgZ
ejG dd dZd	ZdddZdS )    )annotationsN)OptionalTuple   )
exceptions	parse_uriWebSocketURIc                   @  sn   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Ze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://www.rfc-editor.org/rfc/rfc3986.html#section-3.2.1

    boolsecurestrhostintportpathqueryNzOptional[str]usernamepasswordreturnc                 C  s*   | j r| j }nd}| jr|d| j 7 }|S )N/?)r   r   )selfresource_name r   9/usr/local/lib/python3.10/dist-packages/websockets/uri.pyr   '   s   zWebSocketURI.resource_nameOptional[Tuple[str, str]]c                 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_info1   s   
zWebSocketURI.user_info)r   r   )r   r   )
__name__
__module____qualname____doc____annotations__r   r   propertyr   r   r   r   r   r   r      s   
 	z:/?#[]@!$&'()*+,;=urir   r   c           	      C  s<  t j| }|jdvrt| d|jdu rt| d|jdkr't| d|jdk}|j}|jp7|r6dnd	}|j	}|j
}|j}|j}|durR|du rRt| d
z| d W n: ty   |d }t jj|td}t jj|td}|dur|dusJ t jj|td}t jj|td}Y nw t|||||||S )z
    Parse and validate a WebSocket URI.

    Args:
        uri: WebSocket URI.

    Returns:
        WebSocketURI: Parsed WebSocket URI.

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

    )wswsszscheme isn't ws or wssNzhostname isn't provided z"fragment identifier is meaninglessr$   i  P   z"username provided without passwordasciiidna)safe)urllibparseurlparseschemer   Z
InvalidURIhostnamefragmentr   r   r   r   r   encodeUnicodeEncodeErrordecodequoteDELIMSr   )	r"   parsedr
   r   r   r   r   r   r   r   r   r   r   =   s:   



)r"   r   r   r   )
__future__r   dataclassesurllib.parser*   typingr   r   r%   r   __all__	dataclassr   r4   r   r   r   r   r   <module>   s    ,