HEX
Server: LiteSpeed
System: Linux s787.bom1.mysecurecloudhost.com 4.18.0-477.13.1.lve.el8.x86_64 #1 SMP Thu Jun 1 16:40:47 EDT 2023 x86_64
User: mobilech (5348)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/__pycache__/portend.cpython-310.pyc
o

;jX�@s�dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
Zddlm
Z
dd�ZGdd�de�ZGd	d
�d
e�ZGdd�de�Zed
�fdd�Zed
�fdd�Zdd�ZGdd�de�Zddd�Zedkote�dSdS)z:
A simple library for managing the availability of ports.
�N)�abc)�timingcCs|dkrdS|dvrdS|S)z�
    Return the host on which a client can connect to the given listener.

    >>> client_host('192.168.0.1')
    '192.168.0.1'
    >>> client_host('0.0.0.0')
    '127.0.0.1'
    >>> client_host('::')
    '::1'
    z0.0.0.0z	127.0.0.1)z::z::0z	::0.0.0.0z::1�)Zserver_hostrr�;/opt/saltstack/salt/lib/python3.10/site-packages/portend.py�client_hosts
rc@s(eZdZd	dd�Zd
dd�Zdd�ZdS)�Checker��?cCs
||_dS�N��timeout)�selfrrrr�__init__)�
zChecker.__init__NcCsb|durt|tj�r|dd�\}}t��dkrt|�}t�||tjtj	�}t
t�|j
|��dS)a�
        Assert that the given addr is free
        in that all attempts to connect fail within the timeout
        or raise a PortNotFree exception.

        >>> free_port = find_available_local_port()

        >>> Checker().assert_free('localhost', free_port)
        >>> Checker().assert_free('127.0.0.1', free_port)
        >>> Checker().assert_free('::1', free_port)

        Also accepts an addr tuple

        >>> addr = '::1', free_port, 0, 0
        >>> Checker().assert_free(addr)

        Host might refer to a server bind address like '::', which
        should use localhost to perform the check.

        >>> Checker().assert_free('::', free_port)
        N��Windows)�
isinstancer�Sequence�platform�systemr�socket�getaddrinfo�	AF_UNSPEC�SOCK_STREAM�list�	itertools�starmap�_connect)r�host�port�inforrr�assert_free,szChecker.assert_freec
	Cs�t�|||�}|�|j�t�|��!z|�|�Wntjy+YWd�dSwWd�n1s6wY|dd�\}}d}	t|	jdit	�����)Nrz Port {port} is in use on {host}.r)
r�
settimeoutr�
contextlib�closing�connect�error�PortNotFree�format�locals)
r�af�socktype�proto�	canonname�sa�srrZtmplrrrrIs���zChecker._connect)rr	)�__name__�
__module__�__qualname__r
r rrrrrr(s

rc@�eZdZdS)�TimeoutN�r/r0r1rrrrr3Z�r3c@r2)r&Nr4rrrrr&^r5r&ZInfcCsn|std��t�|�}	ztdd��||�WdSty5|��r.tdjdit	�����t
�d�Ynwq)u�
    Wait for the specified port to become free (dropping or rejecting
    requests). Return when the port is free or raise a Timeout if timeout has
    elapsed.

    Timeout may be specified in seconds or as a timedelta.
    If timeout is None or ∞, the routine will run indefinitely.

    >>> free('localhost', find_available_local_port())

    >>> free(None, None)
    Traceback (most recent call last):
    ...
    ValueError: Host values of '' or None are not allowed.
    �*Host values of '' or None are not allowed.T皙�����?r
NzPort {port} not free on {host}.r)�
ValueErrorr�Timerrr r&�expiredr3r'r(�time�sleep�rrrZtimerrrr�freebs
��r>cCsn|std��t�|�}	ztdd��||�|��r%tdjdit�����t	�
d�Wn
ty5YdSwq)	uE
    Wait for the specified port to become occupied (accepting requests).
    Return when the port is occupied or raise a Timeout if timeout has
    elapsed.

    Timeout may be specified in seconds or as a timedelta.
    If timeout is None or ∞, the routine will run indefinitely.

    >>> occupied('localhost', find_available_local_port(), .1)
    Traceback (most recent call last):
    ...
    Timeout: Port ... not bound on localhost.

    >>> occupied(None, None)
    Traceback (most recent call last):
    ...
    ValueError: Host values of '' or None are not allowed.
    r6Tg�?r
z Port {port} not bound on {host}.r7Nr)r8rr9rr r:r3r'r(r;r<r&r=rrr�occupied�s
��r?cCs`t�ddtjtj�}tt|��\}}}}}t�||�}|�|�|��dd�\}}|��|S)zb
    Find a free port on localhost.

    >>> 0 < find_available_local_port() < 65536
    True
    Nrr)	rrrr�next�iter�bind�getsockname�close)�infos�familyr+�_�addr�sockrrrr�find_available_local_port�s
rJc@s4eZdZdZedd��Zedd��Zedd��ZdS)	�HostPorta
    A simple representation of a host/port pair as a string

    >>> hp = HostPort('localhost:32768')

    >>> hp.host
    'localhost'

    >>> hp.port
    32768

    >>> len(hp)
    15

    >>> hp = HostPort('[::1]:32768')

    >>> hp.host
    '::1'

    >>> hp.port
    32768
    cC�tj�d|���jS�Nz//)�urllib�parse�urlparse�hostname�rrrrr��z
HostPort.hostcCrLrM)rNrOrPrrRrrrr�rSz
HostPort.portcCsF|dd�\}}t|�}d|vrd|�d�n|}|d�|t|�g��S)Nr�:�[�])r�join�str)�clsrHZlisten_hostrZ
plain_hostrrrr�	from_addr�szHostPort.from_addrN)	r/r0r1�__doc__�propertyrr�classmethodrZrrrrrK�s

rKc
Cs�t��}dd�}|jddtd�|jdd|d�|jdd	dtd
�|�|�}z|j|jj|jj	|j
d�WdStyM}zt|t
jd�td
��d}~ww)NcSs
t�|Sr	)�globals)�keyrrr�
global_lookup�rz_main.<locals>.global_lookup�targetz	host:port)�metavar�type�func�statez-tz	--timeout)�defaultrcr
)�file�)�argparse�ArgumentParser�add_argumentrK�float�
parse_argsrdrarrrr3�print�sys�stderr�
SystemExit)�args�parserr`rrrr�_main�s
 ��rt�__main__r	)r[r;rrirorr"r�collectionsr�urllib.parserNZtemporarr�objectr�IOErrorr3r&rlr>r?rJrXrKrtr/rrrr�<module>s*2!$
(