U
    •uÄc  ã                   @   s~   d dl mZ d dlmZ ddgZej e¡ ej e¡ ej	 e¡ ej
 e¡ ej e¡ dZeddd	„ƒZed
d„ ƒZdS )é    )Úpublic)ÚparseÚrsÚrss)Ú
create_urlÚ	parse_urlNFc                 C   s’   t |ƒtkst‚| dkr"d| }nV|dksHt |ƒtkrD|tddƒksHt‚|dk	r^d| |f }n|rnd | ¡}n
d | ¡}|r‚d	}nd
}d ||¡S )aŠ  
    Create a RawSocket URL from components.

    :param hostname: RawSocket server hostname (for TCP/IP sockets) or
        filesystem path (for Unix domain sockets).
    :type hostname: str

    :param port: For TCP/IP sockets, RawSocket service port or ``None`` (to select default
        ports ``80`` or ``443`` depending on ``isSecure``. When ``hostname=="unix"``,
        this defines the path to the Unix domain socket instead of a TCP/IP network socket.
    :type port: int or str

    :param isSecure: Set ``True`` for secure RawSocket (``rss`` scheme).
    :type isSecure: bool

    :returns: Constructed RawSocket URL.
    :rtype: str
    Úunixzunix:%sNr   éÿÿ  z%s:%dz{}:443z{}:80r   r   z{}://{})ÚtypeÚboolÚAssertionErrorÚintÚrangeÚformat)ÚhostnameÚportZisSecureÚnetlocÚscheme© r   úY/var/www/html/NKSPORTS/school/venv/lib/python3.8/site-packages/autobahn/rawsocket/util.pyr   3   s    
&
r   c                 C   sN  t   | ¡}|jdkr$td |j¡ƒ‚|jr4|jdkr<tdƒ‚|jdk	r`|jdkr`td |j¡ƒ‚|jdk	r„|jdkr„td |j¡ƒ‚|jdkrº|j|j }| 	d	¡d
 }|jdk|j|fS |jdk	rÞ|jdkrÞtd |j¡ƒ‚|j
dksô|j
dk�r|jdk�rd}nd}n
t|j
ƒ}|d
k �s*|dk�r8td |¡ƒ‚|jdk|j|fS dS )aï  
    Parses as RawSocket URL into it's components and returns a tuple:

     - ``isSecure`` is a flag which is ``True`` for ``rss`` URLs.
     - ``host`` is the hostname or IP from the URL.

    and for TCP/IP sockets:

     - ``tcp_port`` is the port from the URL or standard port derived from
       scheme (``rs`` => ``80``, ``rss`` => ``443``).

    or for Unix domain sockets:

     - ``uds_path`` is the path on the local host filesystem.

    :param url: A valid RawSocket URL, i.e. ``rs://localhost:9000`` for TCP/IP sockets or
        ``rs://unix:/tmp/file.sock`` for Unix domain sockets (UDS).
    :type url: str

    :returns: A 3-tuple ``(isSecure, host, tcp_port)`` (TCP/IP) or ``(isSecure, host, uds_path)`` (UDS).
    :rtype: tuple
    )r   r   z@invalid RawSocket URL: protocol scheme '{}' is not for RawSocketÚ z'invalid RawSocket URL: missing hostnameNz+invalid RawSocket URL: non-empty query '{}'z.invalid RawSocket URL: non-empty fragment '{}'r   ú:é   r   z*invalid RawSocket URL: non-empty path '{}'r   éP   i»  r	   zinvalid port {})Úurlparser   Ú	Exceptionr   r   ÚqueryÚfragmentr   ÚpathÚsplitr   r   )ÚurlÚparsedÚfpZuds_pathZtcp_portr   r   r   r   `   s.    



r   )NF)Zautobahn.utilr   Úurllibr   r   Z	wsschemesÚuses_relativeÚextendÚuses_netlocÚuses_paramsÚ
uses_queryÚuses_fragmentÚ__all__r   r   r   r   r   r   Ú<module>   s   ,