%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/fasteners/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/fasteners/__pycache__/process_lock.cpython-312.pyc

�

�e�=��(�ddlmZddlZddlZddlZddlZddlmZddlZddl	Z	ddl
mZddl
mZddl
m
Z
ddlmZddlmZdd	lmZej&e�Zd
�ZGd�d�ZGd
�d�Zde
eeffd�Zde
eeffd�Zde
eeffd�Zy)�)�contextmanagerN)�Path)�Callable)�Optional)�Union)�_utils)�_interprocess_mechanism)�%_interprocess_reader_writer_mechanismc��	tj|�y#t$rj}|jtjk(r%tj
j
|�s�Yd}~y|jtjk(rYd}~y�d}~wwxYw)zfCreate a directory (and any ancestor directories required).

    :param path: Directory to create
    TNF)�os�makedirs�OSError�errno�EEXIST�path�isdir�EISDIR)r�es  �8/usr/lib/python3/dist-packages/fasteners/process_lock.py�_ensure_treer%sf��

�
���D�����	��7�7�e�l�l�"��7�7�=�=��&���
�W�W����
$����	�s ��	B�=B�#B�B�Bc���eZdZdZdZdZejdfdee	e
fdeegdfde
ejfd�Zd	�Zd
�Z				ddeded
ede
edef
d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�InterProcessLockzAn interprocess lock.皙�����?�{�G�z�?Nr�
sleep_func�loggerc��d|_tj|�|_d|_||_tj|t�|_y)a
        args:
            path:
                Path to the file that will be used for locking.
            sleep_func:
                Optional function to use for sleeping.
            logger:
                Optional logger to use for logging.
        NF)	�lockfiler�canonicalize_pathr�acquiredr�pick_first_not_none�LOGr��selfrrrs    r�__init__zInterProcessLock.__init__@s?����
��,�,�T�2��	���
�$����0�0���=���c�@�	|j�y#t$r�}|jtjtjfvr+|r|j�rYd}~yt
j��tjd|j|d�z��d}~wwxYw)NTFz9Unable to acquire lock on `%(path)s` due to %(exception)s)r�	exception)�trylock�IOErrorr�EACCES�EAGAIN�expiredr�
RetryAgain�	threading�ThreadErrorr)r$�blocking�watchrs    r�_try_acquirezInterProcessLock._try_acquireSs���	��L�L�N� ���
	/��w�w�5�<�<����6�6��5�=�=�?� � �+�+�-�-��+�+�-=�9=�	�	�=>�-.�-.�/�/��
	/�s��	B�>B�9B�Bc�F�tjj|j�}|r8t|�}|r+|jjtjd|�|j�|jjrt|jd�|_yy)N�Created lock base path `%s`�a)rr�dirnamerr�logr�BLATHERr�closed�open�r$�basedir�made_basedirs   r�_do_openzInterProcessLock._do_opengss���'�'�/�/�$�)�)�,���'��0�L���������� =�w�H�
�=�=� �D�M�M�$8�$8� ����C�0�D�M�%9r&r1�delay�	max_delay�timeout�returnc���|dkrtd��|�|dkrtd��||k\r|}|j�tj|��}tj|||j
|��}|5||j||�}ddd�syd|_|jjtjd	|j|j�|j�y#1swY�cxYw)
a,Attempt to acquire the lock.

        Args:
            blocking:
                Whether to wait to try to acquire the lock.
            delay:
                When `blocking`, starting delay as well as the delay increment
                (in seconds).
            max_delay:
                When `blocking` the maximum delay in between attempts to
                acquire (in seconds).
            timeout:
                When `blocking`, maximal waiting time (in seconds).

        Returns:
            whether or not the acquisition succeeded
        r�+Delay must be greater than or equal to zeroN�-Timeout must be greater than or equal to zero��duration�rr2FT�HAcquired file lock `%s` after waiting %0.3fs [%s attempts were required])�
ValueErrorr?r�	StopWatch�Retryrr3r rr8r9r�elapsed�attempts)r$r1r@rArBr2�r�gottens        r�acquirezInterProcessLock.acquirets���,�1�9��J�K�K���7�Q�;��L�M�M��I���I��
�
��� � �'�2���L�L��	�$(�O�O�5�
B��
�	;��t�(�(�(�E�:�F�	;��� �D�M��K�K�O�O�F�N�N�7�8<�	�	�!�M�M�O�Q�Z�Z�
9��	;�	;�s�5C,�,C5c�`�|j�"|jj�d|_yy�N)r�close�r$s r�	_do_closezInterProcessLock._do_close�s(���=�=�$��M�M���!� �D�M�%r&c�n�|j�}|s"tjd|jz��|S)N�FUnable to acquire a file lock on `%s` (when used as a context manager))rRr/r0r)r$rQs  r�	__enter__zInterProcessLock.__enter__�s>���������'�'�)<�>B�i�i�)H�I�
I��r&c��|jstjd��	|j�d|_	|j	�|j
j
tjd|j�y#t$r)|j
jd|j�YywxYw#t$rD}d|jf}|j
j|�tj|�|�d}~wwxYw)z%Release the previously acquired lock.z#Unable to release an unaquired lockF�*Unlocked and closed file lock open on `%s`�.Could not close the file handle opened on `%s`�1Could not unlock the acquired lock opened on `%s`N)
r r/r0�unlockrWrr8rr9rr*r(�	Exception)r$r�msgs   r�releasezInterProcessLock.release�s����}�}��'�'�(M�N�N�	4��K�K�M�"�D�M�
4���� �
��������!(�)-���4��	�
D����%�%�'8�9=���D�
D���	4�E�t�y�y�P�C��K�K�!�!�#�&��'�'��,�!�3��	4�s(�B6�B�/B3�2B3�6	D�??C>�>Dc�$�|j�yrT)rb)r$�exc_type�exc_val�exc_tbs    r�__exit__zInterProcessLock.__exit__�s�����r&c�T�tjj|j�SrT)rr�existsrVs rrizInterProcessLock.exists�s���w�w�~�~�d�i�i�(�(r&c�B�tj|j�yrT)r	r)rrVs rr)zInterProcessLock.trylock�s���'�'��
�
�6r&c�B�tj|j�yrT)r	r_rrVs rr_zInterProcessLock.unlock�s���&�&�t�}�}�5r&�TrrN)�__name__�
__module__�__qualname__�__doc__�	MAX_DELAY�DELAY_INCREMENT�time�sleeprr�strr�floatr�logging�Loggerr%r3r?�boolrRrWrZrbrgrir)r_�r&rrr:s�����I��O�8<�z�z�48�>��T�3�Y�'�>�%�u�g�t�m�4�>�"�'�.�.�1�>�&�(1�"&�#�#&�+/�	*��*��*�!�*�"�%��	*�59�	*�X!�
�4�,�)�7�6r&rc��eZdZdZdZdZejdfdee	e
fdeegdfde
ejfd�Zedd	��Zedd
��Zd�Zd�Z				dd
ededededef
d�Z				dd
ededededef
d�Z			dd�Zd�Zd�Zd�Zy)�InterProcessReaderWriterLockz$An interprocess readers writer lock.rrNrrrc��d|_tj|�|_||_tj
|t�|_y)a
        Args:
            path:
                Path to the file that will be used for locking.
            sleep_func:
                Optional function to use for sleeping.
            logger:
                Optional logger to use for logging.
        N)rrrrrr!r"rr#s    rr%z%InterProcessReaderWriterLock.__init__�s8����
��,�,�T�2��	�$����0�0���=��r&c#�K�|jd||d��	d��|j�y#|j�wxYw�w)z&Context manager that grans a read lockTN�r1r@rArB)�acquire_read_lock�release_read_lock)r$r@rAs   r�	read_lockz&InterProcessReaderWriterLock.read_lock�sE����	
����E�)2�D�	�	B�	%���"�"�$��D�"�"�$�s�A�.�A�A�Ac#��K�|jd||d��}|s"tjd|jz��	d��|j	�y#|j	�wxYw�w)z'Context manager that grans a write lockTNrrY)�acquire_write_lockr/r0r�release_write_lock)r$r@rArQs    r�
write_lockz'InterProcessReaderWriterLock.write_lock�ss�����(�(�$�e�3<�d�)�L����'�'�)<�>B�i�i�)H�I�
I�	&���#�#�%��D�#�#�%�s�:A'�A�A'�A$�$A'c��	tj|j|�}|ry|r|j�rytj��#t$r4}t	j
dj
|j|���d}~wwxYw)Nz'Unable to acquire lock on {} due to {}!TF)r
r)rr`r/r0�formatrr-rr.)r$r1r2�	exclusiverQrs      rr3z)InterProcessReaderWriterLock._try_acquires���	P�:�B�B�4�=�=�R[�\�F�
���5�=�=�?�����!�!���	P��'�'�9�@�@����A�N�P�
P��	P�s� A�	B	�/B�B	c�,�tjj|j�}|r8t|�}|r+|jjtjd|�|j�%tj|j�|_yy)Nr5)rrr7rrr8rr9rr
�
get_handler<s   rr?z%InterProcessReaderWriterLock._do_opensi���'�'�/�/�$�)�)�,���'��0�L���������� =�w�H��=�=� �A�L�L�T�Y�Y�W�D�M�!r&r1r@rArBrCc�.�|j||||d��S)a3Attempt to acquire a reader's lock.

        Args:
            blocking:
                Whether to wait to try to acquire the lock.
            delay:
                When `blocking`, starting delay as well as the delay increment
                (in seconds).
            max_delay:
                When `blocking` the maximum delay in between attempts to
                acquire (in seconds).
            timeout:
                When `blocking`, maximal waiting time (in seconds).

        Returns:
            whether or not the acquisition succeeded
        F�r���_acquire�r$r1r@rArBs     rr�z.InterProcessReaderWriterLock.acquire_read_locks��,�}�}�X�u�i��E�}�R�Rr&c�.�|j||||d��S)a3Attempt to acquire a writer's lock.

        Args:
            blocking:
                Whether to wait to try to acquire the lock.
            delay:
                When `blocking`, starting delay as well as the delay increment
                (in seconds).
            max_delay:
                When `blocking` the maximum delay in between attempts to
                acquire (in seconds).
            timeout:
                When `blocking`, maximal waiting time (in seconds).

        Returns:
            whether or not the acquisition succeeded
        Tr�r�r�s     rr�z/InterProcessReaderWriterLock.acquire_write_lock6s��,�}�}�X�u�i��D�}�Q�Qr&c���|dkrtd��|�|dkrtd��||k\r|}|j�tj|��}tj|||j
|��}|5||j|||�}ddd�sy|jjtjd|j|j�|j�y#1swY�\xYw)	NrrErFrGrIFrJT)
rKr?rrLrMrr3rr8r9rrNrO)	r$r1r@rArBr�r2rPrQs	         rr�z%InterProcessReaderWriterLock._acquireNs����1�9��J�K�K���7�Q�;��L�M�M��I���I��
�
��� � �'�2���L�L��	�$(�O�O�5�
B��
�	F��t�(�(�(�E�9�E�F�	F����K�K�O�O�F�N�N�7�8<�	�	�!�M�M�O�Q�Z�Z�
9��	F�	F�s�5C&�&C/c�j�|j�'tj|j�d|_yyrT)rr
�close_handlerVs rrWz&InterProcessReaderWriterLock._do_closegs*���=�=�$�1�>�>�t�}�}�M� �D�M�%r&c��	tj|j�	|j�|jjtjd|j�y#t$r)|jjd|j�YywxYw#t$r)|jjd|j�YywxYw)zRelease the writer's lock.r\r]r^N�r
r_rrWrr8rr9rr*r(rVs rr�z/InterProcessReaderWriterLock.release_write_lockl���	4�1�8�8����G�

4���� �
��������!(�)-���4��	�
D����%�%�'8�9=���D�
D��
�	9��K�K�!�!�#-�.2�i�i�
9�	9��"�B�A(�(/B�B�/C�Cc��	tj|j�	|j�|jjtjd|j�y#t$r)|jjd|j�YywxYw#t$r)|jjd|j�YywxYw)zRelease the reader's lock.r\r]r^Nr�rVs rr�z.InterProcessReaderWriterLock.release_read_lock~r�r�)rrrl)TrrNT)rmrnrorprqrrrsrtrrrurrvrrwrxr%rr�r�r3r?ryr�r�r�rWr�r�rzr&rr|r|�s7��.��I��O�8<�z�z�48�>��T�3�Y�'�>�%�u�g�t�m�4�>�"�'�.�.�1�>�$�%��%��&��&� 
"�X�,0�)-�-0�+/�	S�$(�S�!&�S�&+�S�$)�	S�59�	S�2-1�*.�.1�,0�	R�%)�R�"'�R�',�R�%*�	R�6:�	R�0!%�'*�)-��2!�
4�$4r&r|rc�(��t|���fd�}|S)z�Acquires & releases an interprocess  **write** lock around the call into
    the decorated function

    Args:
        path: Path to the file used for locking.
    c�F���tj����fd��}|S)Nc�`���j�5�|i|��cddd�S#1swYyxYwrT)r���args�kwargs�f�locks  ��r�wrapperz=interprocess_write_locked.<locals>.decorator.<locals>.wrapper�s/������"�
*��$�)�&�)�
*�
*�
*���$�-��	functools�wraps�r�r�r�s` �r�	decoratorz,interprocess_write_locked.<locals>.decorator��%���	����	�	*�
�	*��r&�r|�rr�r�s  @r�interprocess_write_lockedr������(��-�D���r&c�(��t|���fd�}|S)z�Acquires & releases an interprocess **read** lock around the call into
    the decorated function

    Args:
        path: Path to the file used for locking.
    c�F���tj����fd��}|S)Nc�`���j�5�|i|��cddd�S#1swYyxYwrT)r�r�s  ��rr�z<interprocess_read_locked.<locals>.decorator.<locals>.wrapper�s/������!�
*��$�)�&�)�
*�
*�
*�r�r�r�s` �rr�z+interprocess_read_locked.<locals>.decorator�r�r&r�r�s  @r�interprocess_read_lockedr��r�r&c�(��t|���fd�}|S)z�Acquires & releases an interprocess lock around the call to the
    decorated function.

    Args:
        path: Path to the file used for locking.
   c�F���tj����fd��}|S)Nc�D���5�|i|��cddd�S#1swYyxYwrTrzr�s  ��rr�z7interprocess_locked.<locals>.decorator.<locals>.wrapper�s(����
*��$�)�&�)�
*�
*�
*�s��r�r�s` �rr�z&interprocess_locked.<locals>.decorator�r�r&)rr�s  @r�interprocess_lockedr��s����D�!�D���r&)�
contextlibrrr�rwr�pathlibrr/rs�typingrrr�	fastenersr�fasteners.process_mechanismr	r
�	getLoggerrmr"rrr|rur�r�r�rzr&r�<module>r�s���$&����	��������?�M��g����!���*T6�T6�n}4�}4�@�E�$��)�$4��(�5��s��#3��(�e�D�#�I�.�r&

Zerion Mini Shell 1.0