o
    >h                     @   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J | dkrd| }n+|du s$t |tkr"|tddv s$J |dur/d| |f }n|r7d| }nd| }|rAd	}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intrangeformat)hostnameportisSecurenetlocscheme r   w/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/autobahn/rawsocket/util.pyr   3   s   
&
r   c                 C   sB  t  | }|jdvrtd|j|jr|jdkrtd|jdur0|jdkr0td|j|jdurB|jdkrBtd|j|jdkr]|j|j }|	d	d
 }|jdk|j|fS |jduro|jdkrotd|j|j
du sy|j
dkr|jdkrd}nd}nt|j
}|d
k s|dkrtd||jdk|j|f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fpuds_pathtcp_portr   r   r   r   `   s.   




r   )NF)autobahn.utilr   urllibr   r   	wsschemesuses_relativeextenduses_netlocuses_params
uses_queryuses_fragment__all__r   r   r   r   r   r   <module>   s   ,