a
    Df                  
   @   s>  d Z ddlZzddlZW nJ eyb   ddlZddlZedZejd dke_dd e_	[[Y n0 e
ZddlZejZdd Zd	d
 ZdZzddlmZ W nV   ddlZddlZejejejeZeje ddlmZ [[[Y n0 ed ZZdi dfddZdd Zdd ZG dd de Z!dddZ"dS )z(
ppft common: a set of common utilities
    Nsix   c                 C   s   | S N )xr   r   X/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/lib/python3.9/site-packages/ppft/common.py<lambda>(       r   c                 C   sH   t | ds| S z| dW S  tyB   tdd | D d  Y S 0 d S )Ndecodeasciic                 S   s   g | ]}|qS r   r   ).0ir   r   r   
<listcomp>2   r	   zstr_.<locals>.<listcomp>z{B})hasattrr
   UnicodeDecodeErrorrepr)byter   r   r   str_-   s
    r   c                 C   s6   t | ds| S | ds"| dS tt| d d S )Nencodez]{B}zlatin-1)r   endswithr   byteseval)stringr   r   r   b_3   s    r   zCopyright (c) 2005-2012 Vitalii Vanovschi.
Copyright (c) 2015-2016 California Institute of Technology.
Copyright (c) 2016-2024 The Uncertainty Quantification Foundation.   )__version__z.dev0r   Tc                 C   s$   t j| |||d}||_|  |S )zStarts a thread)nametargetargskwargs)	threadingThreaddaemonstart)r   r   r   r    r#   threadr   r   r   start_threadH   s    r&   c                 C   s>   g }| t t u r|S | jD ]}|t| q||  |S r   )typeobject	__bases__extendget_class_hierarchyappend)ZclazzclassesZ
base_classr   r   r   r+   P   s    

r+   c                 C   s4   t | j}|D ] }||ks(||d r dS qdS )N.FT)str
__module__
startswith)argmodulesZargs_modulemoduler   r   r   is_not_importedZ   s
    
r5   c                   @   s"   e Zd ZdZd	ddZdd ZdS )

portnumberz`port selector

Usage:
    >>> pick = portnumber(min=1024,max=65535)
    >>> print( pick() )
    r      c                 C   s   || _ || _d| _d| _dS )a#  select a port number from a given range.

The first call will return a random number from the available range,
and each subsequent call will return the next number in the range.

Inputs:
    min -- minimum port number  [default = 0]
    max -- maximum port number  [default = 65536]
        N)minmaxfirstcurrent)selfr9   r:   r   r   r   __init__j   s
    
zportnumber.__init__c                 C   sr   dd l }| jdk r2|| j| j| _| j| _| jS |  jd7  _| j| jkrT| j| _| j| jkrhtd| jS d S )Nr   r   zRange exhausted)randomr<   randintr9   r:   r;   RuntimeError)r=   r?   r   r   r   __call__z   s    
zportnumber.__call__N)r   r7   )__name__r0   __qualname____doc__r>   rB   r   r   r   r   r6   b   s   
r6      r7   c                 C   s   t | | S )zselect a random port number

Inputs:
    min -- minimum port number  [default = 1024]
    max -- maximum port number  [default = 65536]
    )r6   )r9   r:   r   r   r   
randomport   s    rG   )rF   r7   )#rE   r!   r   ImportErrortypessys
ModuleTypeversion_infoPY3bintlongioIOBasefiler   r   	copyrightZ__info__r   versionospathdirnameabspath__file__parentr,   rstripr&   r+   r5   r(   r6   rG   r   r   r   r   <module>   s>   



*