HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/__pycache__/portend.cpython-310.pyc
o

�N�gN�@sdZddlmZmZddlZddlZddlZddlZddlZddl	Z	ddl
Z
zddlmZWn
e
y;ddlZYnwddlmZdd�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�Zed�fdd�ZeZed�fdd�ZeZdd�ZGdd�de�Zdd�Zedkr�e�dSdS)z:
A simple library for managing the availability of ports.
�)�print_function�divisionN)�abc)�timingcCs|dkrdS|dvrdS|S)zDReturn the host on which a client can connect to the given listener.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)�selfr
rrr�__init__'�
zChecker.__init__NcCsb|durt|tj�r|dd�\}}t��dkrt|�}t�||tjtj	�}t
t�|j
|��dS)aJ
		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�sr rZtmplrrrrIs���zChecker._connect)r
r)�__name__�
__module__�__qualname__rr"rrrrrr	&s

r	c@�eZdZdS)�TimeoutN�r1r2r3rrrrr5Z�r5c@r4)r(Nr6rrrrr(^r7r(ZInfcCsr|std��t�|�}|��s.ztdd��||�WdSty)t�d�Ynw|��rt	dj
dit�����)uG
	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())
	�*Host values of '' or None are not allowed.皙�����?rNzPort {port} not free on {host}.r)�
ValueErrorr�Timer�expiredr	r"r(�time�sleepr5r)r*�rr r
Ztimerrrr�freebs
��	r@cCsr|std��t�|�}|��s.ztdd��||�t�d�Wn
ty)YdSw|��rt	dj
dit�����)u�
	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.
	r8g�?rr9Nz Port {port} not bound on {host}.r)r:rr;r<r	r"r=r>r(r5r)r*r?rrr�occupied�s
��	rAcCs`t�ddtjtj�}tt|��\}}}}}t�||�}|�|�|��dd�\}}|��|S)zV
	Find a free port on localhost.

	>>> 0 < find_available_local_port() < 65536
	True
	Nrr)	rrrr�next�iter�bind�getsockname�close)�infos�familyr-�_�addr�sockr rrr�find_available_local_port�s
rLc@s(eZdZdZedd��Zedd��ZdS)�HostPortz�
	A simple representation of a host/port pair as a string

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

	>>> hp.host
	'localhost'

	>>> hp.port
	32768

	>>> len(hp)
	15
	cCs|�d�\}}}|S�N�:)�	partition�rr�sepr rrrr�sz
HostPort.hostcCs|�d�\}}}t|�SrN)rP�intrQrrrr �sz
HostPort.portN)r1r2r3�__doc__�propertyrr rrrrrM�s
rMc
Cs�t��}dd�}|jddtd�|jdd|d�|jdd	dtd
�|��}z|j|jj|jj	|j
d�WdStyL}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)�defaultr[r)�file�)�argparse�ArgumentParser�add_argumentrM�float�
parse_argsr\rYrr r
r5�print�sys�stderr�
SystemExit)�parserrX�argsr
rrr�_main�s ��rl�__main__) rTZ
__future__rrr=rrargrr$r�collectionsr�ImportErrorZtemporarr�objectr	�IOErrorr5r(rdr@Zwait_for_free_portrAZwait_for_occupied_portrL�strrMrlr1rrrr�<module>s:�
4
�