o
    /.]                     @   sT   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddd	Zdd
dZdS )z0Define the misc handler for InfluxDBClient test.    )absolute_import)division)print_function)unicode_literalsN	127.0.0.1c              
   C   s   g }t  }z>t| D ]'}t }|dg}|| |tjtjd ||df | d |d< q
W |D ]\}}|	  |
| q5n|D ]\}}|	  |
| qFw | t|ks]J |S )a  Determine free ports on provided interface.

    Get `num_ports` free/available ports on the interface linked to the `ip`
    :param int num_ports: The number of free ports to get
    :param str ip: The ip on which the ports have to be taken
    :return: a set of ports number
       r   )setrangesocketappendZ
setsockoptZ
SOL_SOCKETZSO_REUSEADDRZbindZgetsocknamecloseaddlen)Z	num_portsipZ
sock_portsZports_sockZcurport r   5/usr/lib/python3/dist-packages/influxdb/tests/misc.pyget_free_ports   s(   
r   c                 C   sL   t  t jt j}z||| f}|s|t j |dkW |  S |  w )z/Check if given TCP port is open for connection.r   )r   ZAF_INETZSOCK_STREAMZ
connect_exZshutdownZ	SHUT_RDWRr   )r   r   r   resultr   r   r   is_port_open)   s   r   )r   )	__doc__Z
__future__r   r   r   r   r   r   r   r   r   r   r   <module>   s   
