Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib/python3.5/site-packages/fasteners/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib/python3.5/site-packages/fasteners/__pycache__/_utils.cpython-35.pyc



�-�]G�@s�ddlZddlZyddlmZWn"ek
rPddlmZYnXdZeje�Zdd�Z	Gdd�de
�ZGdd	�d	e�Z
Gd
d�de
�ZGdd
�d
e
�ZdS)�N)�	monotonic�cGs%x|D]}|dk	r|SqWdS)zEReturns first of values that is *not* None (or None if all are/were).N�)�values�valrr�A/opt/alt/python35/lib/python3.5/site-packages/fasteners/_utils.py�pick_first_not_none!s
rc@sIeZdZdZddd�Zdd�Zdd�Zd	d
�ZdS)�	LockStackz�Simple lock stack to get and release many locks.

    An instance of this should **not** be used by many threads at the
    same time, as the stack that is maintained will be corrupted and
    invalid if that is attempted.
    NcCsg|_t|t�|_dS)N)�_stackr�LOG�_logger)�self�loggerrrr�__init__1s	zLockStack.__init__cCs&|j�}|r"|jj|�|S)N)�acquirer
�append)r
�lockZgottenrrr�acquire_lock5szLockStack.acquire_lockcCs|S)Nr)r
rrr�	__enter__;szLockStack.__enter__cCs{t|j�}|}x_|jrv|jj�}y|j�Wn(tk
rh|jjd||�YnX|d8}qWdS)Nz6Failed releasing lock %s from lock stack with %s locks�)�lenr
�pop�release�	Exceptionr�	exception)r
�exc_type�	exc_value�exc_tbZam_leftZtot_amrrrr�__exit__>s
zLockStack.__exit__)�__name__�
__module__�__qualname__�__doc__rrrrrrrrr	)s
r	c@seZdZdZdS)�
RetryAgainz1Exception to signal to retry helper to try again.N)rr r!r"rrrrr#Ksr#c@s7eZdZdZejddd�Zdd�ZdS)�RetryzA little retry helper object.NcCs1||_d|_||_||_||_dS)Nr)�delay�attempts�	max_delay�
sleep_func�watch)r
r%r'r(r)rrrrRs
				zRetry.__init__cOs�x�|jd7_y|||�SWqtk
r�|j|j}||jkr[|}n	|j}td|�}|jdk	r�|jj�}|dk	r�||kr�|}|j|�YqXqWdS)Nrg)r&r#r%r'�maxr)�leftoverr()r
�fn�args�kwargsZmaybe_delayZactual_delayr+rrr�__call__Zs
		zRetry.__call__)rr r!r"�time�sleeprr/rrrrr$Osr$c@smeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�	StopWatchzA really basic stop watch.NcCs||_d|_d|_dS)N)�duration�
started_at�
stopped_at)r
r3rrrrps		zStopWatch.__init__cCs-|jdkrdStd|j|j��S)Ng)r3r*�elapsed)r
rrrr+uszStopWatch.leftovercCs8|jdk	r|j}n	t�}td||j�S)Ng)r5�nowr*r4)r
Zend_timerrrr6zs	zStopWatch.elapsedcCs|j�|S)N)�start)r
rrrr�s
zStopWatch.__enter__cCst�|_dS)N)r7r5)r
rrrrrrr�szStopWatch.__exit__cCst�|_d|_dS)N)r7r4r5)r
rrrr8�szStopWatch.startcCs*|jdkrdS|j�|jkSdS)NF)r3r6)r
rrr�expired�szStopWatch.expired)rr r!r"rr+r6rrr8r9rrrrr2msr2)Zloggingr0rr7�ImportErrorZBLATHERZ	getLoggerrrr�objectr	rr#r$r2rrrr�<module>s
"