%PDF- %PDF-
Mini Shell

Mini Shell

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

�

�e�.���ddlZddlZddlZddlZddlmZddlmZGd�de�Z	d�Z
d�Zd�Zejd	ejd
efd��Zy)�N)�Optional)�_utilsc���eZdZdZdZdZejejfd�Z	e
defd��Zddedefd�Z
defd	�Ze
deefd
��Zej&d��Zej&d��Zy
)�ReaderWriterLockz$An inter-thread readers writer lock.�w�rc�x�d|_tj�|_i|_|�|_||_y)aH
        Args:
            condition_cls:
                Optional custom `Condition` primitive used for synchronization.
            current_thread_functor:
                Optional function that returns the identity of the thread in case
                threads are not properly identified by threading.current_thread
        N)�_writer�collections�deque�_pending_writers�_readers�_cond�_current_thread)�self�
condition_cls�current_thread_functors   �0/usr/lib/python3/dist-packages/fasteners/lock.py�__init__zReaderWriterLock.__init__#s4����� +� 1� 1� 3�����
�"�_��
�5����returnc�,�t|j�S)zhCheck if there pending writers

        Returns:
            Whether there are pending writers.
        )�boolr
�rs r�has_pending_writersz$ReaderWriterLock.has_pending_writers4s���D�)�)�*�*r�
check_pendingc�d�|j�}|j|k(ry|r||jvSy)aCheck if caller is a writer (optionally pending writer).

        Args:
            check_pending:
                Whether to check for pending writer status.

        Returns:
            Whether the caller is the active (or optionally pending) writer.
        TF)rr
r
)rr�mes   r�	is_writerzReaderWriterLock.is_writer=s8���
!�
!�
#���<�<�2������.�.�.�.�rc�>�|j�}||jvS)zkCheck if caller is a reader.

        Returns:
            Whether the caller is an active reader.
        )rr)rrs  r�	is_readerzReaderWriterLock.is_readerOs!���
!�
!�
#���T�]�]�"�"rc�f�	|j�|jS|jr|jSy)z�Caller ownership (if any) of the lock

        Returns:
            `'w'` if caller is a writer, `'r'` if caller is a reader, None otherwise.
        N)r
�WRITERr�READERrs r�ownerzReaderWriterLock.ownerXs0��	H��<�<�#��;�;���=�=��;�;��rc#�K�|j�}||jvrtd|z��|j5	|j�|j|k(rY||j
vr |j
|dz|j
|<nF|j|k(s|jsd|j
|<n|jj���ddd�	|��|j5	|j
|}|dkDr|dz
|j
|<n|j
j|�|jj�ddd�y#1swY��xYw#t$rY�:wxYw#1swYyxYw#|j5	|j
|}|dkDr|dz
|j
|<n|j
j|�n#t$rYnwxYw|jj�ddd�w#1swYwxYwxYw�w)z�Context manager that grants a read lock.

        Will wait until no active or pending writers.

        Raises:
            RuntimeError: if a pending writer tries to acquire a read lock.
        zFWriter %s can not acquire a read lock while waiting for the write lockN�)rr
�RuntimeErrorrr
rr�wait�pop�KeyError�
notify_all)rr�me_instancess   r�	read_lockzReaderWriterLock.read_lockfs������
!�
!�
#��
��&�&�&�� C�!#� $�%�
%��Z�Z�	"���<�<�'�4�<�<�2�+=��T�]�]�*�,0�M�M�"�,=��,A��
�
�b�)���,�,�"�,�T�5M�5M�,-��
�
�b�)���
�
���!��	"�	(��J����	
(��#'�=�=��#4�L�#�a�'�,8�1�,<��
�
�b�)��
�
�)�)�"�-��
�
�%�%�'�	
(�	
(�-	"�	"��: �����	
(�	
(�����	
(��#'�=�=��#4�L�#�a�'�,8�1�,<��
�
�b�)��
�
�)�)�"�-��������
�
�%�%�'�	
(�	
(�	
(�s��9H�BE�H�E3�H�%E'�'AE�)E'�	H�E�H�	E$�!E'�#E$�$E'�'E0�,H�3
H�G7�AG�G7�	G	�G7�G	�G7�.	H�7H�<H�Hc#�K�|j�}|jd��}|j�r|std|z��|r|��y|j5|j
j
|�	t|j�dk(r>|j�2|j
d|k(r |j
j�|_	n|jj��q	ddd�	|��|j5d|_	|jj�ddd�y#1swY�ExYw#1swYyxYw#|j5d|_	|jj�ddd�w#1swYwxYwxYw�w)aContext manager that grants a write lock.

        Will wait until no active readers. Blocks readers after acquiring.

        Guaranteed for locks to be processed in fair order (FIFO).

        Raises:
            RuntimeError: if an active reader attempts to acquire a lock.
        F)rz4Reader %s to writer privilege escalation not allowedrN)
rrr!r(rr
�append�lenrr
�popleftr)r,)rr�i_am_writers   r�
write_lockzReaderWriterLock.write_lock�sX�����
!�
!�
#���n�n�5�n�9���>�>��K�� 9�;=� >�?�
?���J����
&��%�%�,�,�R�0���4�=�=�)�Q�.�4�<�<�3G��0�0��3�r�9�+/�+@�+@�+H�+H�+J�D�L�!��J�J�O�O�%�
�
"�
&�
,��
��Z�Z�,�#'�D�L��J�J�)�)�+�,�,�
&�
&��,�,��T�Z�Z�,�#'�D�L��J�J�)�)�+�,�,�,�sg�AF
�BD+�'F
�0E�4F
�"D7�"	F
�+D4�0F
�7E�<F
�
F�"E;�2	F�;F�F�F
N)T)�__name__�
__module__�__qualname__�__doc__r#r$�	threading�	Condition�current_threadr�propertyrrrr!r�strr%�
contextlib�contextmanagerr.r4�rrrrs���.�
�F�
�F� )�2�2�(1�(@�(@�6�"�+�T�+��+��t��t��$#�4�#���x��}�������,(��,(�\���!,��!,rrc�P���fd�}�s|s|St|�dk(r||d�S|S)a�A locking **method** decorator.

    It will look for a provided attribute (typically a lock or a list
    of locks) on the first argument of the function decorated (typically this
    is the 'self' object) and before executing the decorated function it
    activates the given lock or list of locks as a context manager,
    automatically releasing that lock on exit.

    NOTE(harlowja): if no attribute name is provided then by default the
    attribute named '_lock' is looked for (this attribute is expected to be
    the lock/list of locks object/s) in the instance object this decorator
    is attached to.

    NOTE(harlowja): a custom logger (which will be used if lock release
    failures happen) can be provided by passing a logger instance for keyword
    argument ``logger``.

    NOTE(paulius): This function is DEPRECATED and will be kept until the end
    of time. It is potentially used by oslo, but too specific to be recommended
    for other projects
    c�������jdd���jd��tj�����fd��}|S)N�lock�_lock�loggerc���t|��}t|ttf�rkt	j
�	��5}t
|�D]1\}}|j|�r�tjd|dzz���|g|��i|��cddd�S|}|5�|g|��i|��cddd�S#1swYyxYw#1swYyxYw)N)rEzUnable to acquire lock %sr')
�getattr�
isinstance�tuple�listr�	LockStack�	enumerate�acquire_lockr9�ThreadError)
r�args�kwargs�
attr_value�stack�irC�	attr_name�frEs
       ���r�wrapperz*locked.<locals>.decorator.<locals>.wrapper�s���� ��y�1�J��*�u�d�m�4��%�%�V�4�4��#,�Z�#8�N���4�$�1�1�$�7�"+�"7�"7�9C�FG�!�e�9M�#N�N�N��T�3�D�3�F�3�4�4�"���4��T�3�D�3�F�3�4�4�4�4��4�4�s�#B)�'B)�B5�)B2�5B>��get�	functools�wraps)rUrVrTrErPs` @@�r�	decoratorzlocked.<locals>.decorator�sC����J�J�v�w�/�	����H�%��	����	�	4�
�	4��rr'r�r1�rOrPr[s ` r�lockedr^�s5���.�.�T����t�9��>��T�!�W�%�%��rc�P���fd�}�s|s|St|�dk(r||d�S|S)a�Acquires & releases a read lock around call into decorated method.

    NOTE(harlowja): if no attribute name is provided then by default the
    attribute named '_lock' is looked for (this attribute is expected to be
    a :py:class:`.ReaderWriterLock`) in the instance object this decorator
    is attached to.

    NOTE(paulius): This function is DEPRECATED and will be kept until the end
    of time. It is potentially used by oslo, but too specific to be recommended
    for other projects
    c�l�����jdd��tj����fd��}|S)NrCrDc���t|��}|j�5�|g|��i|��cddd�S#1swYyxYw�N)rGr.�rrOrP�rw_lockrTrUs    ��rrVz/read_locked.<locals>.decorator.<locals>.wrappersB����d�I�.�G��"�"�$�
0���/��/��/�
0�
0�
0���4�=rW�rUrVrTrPs` @�rr[zread_locked.<locals>.decorator��5����J�J�v�w�/�	�	����	�	0�
�	0�
�rr'rr\r]s ` r�read_lockedrh��5���	��T����t�9��>��T�!�W�%�%��rc�P���fd�}�s|s|St|�dk(r||d�S|S)a�Acquires & releases a write lock around call into decorated method.

    NOTE(harlowja): if no attribute name is provided then by default the
    attribute named '_lock' is looked for (this attribute is expected to be
    a :py:class:`.ReaderWriterLock` object) in the instance object this
    decorator is attached to.

    NOTE(paulius): This function is DEPRECATED and will be kept until the end
    of time. It is potentially used by oslo, but too specific to be recommended
    for other projects
    c�l�����jdd��tj����fd��}|S)NrCrDc���t|��}|j�5�|g|��i|��cddd�S#1swYyxYwrb)rGr4rcs    ��rrVz0write_locked.<locals>.decorator.<locals>.wrapper$sB����d�I�.�G��#�#�%�
0���/��/��/�
0�
0�
0�rerWrfs` @�rr[zwrite_locked.<locals>.decorator!rgrr'rr\r]s ` r�write_lockedrmrirrCrc#�K�|jd�}	|��|r|j�yy#|r|j�wwxYw�w)a�Context manager that attempts to acquire a lock without a timeout, and
    releases it on exit (if acquired).

    Args:
        lock:
            A lock to try to acquire.

    Returns:
        Whether the lock was acquired.

    # NOTE(harlowja): the keyword argument for 'blocking' does not work
    # in py2.x and only is fixed in py3.x (this adjustment is documented
    # and/or debated in http://bugs.python.org/issue10789); so we'll just
    # stick to the format that works in both (oddly the keyword argument
    # works in py2.x but only with reentrant locks).

    NOTE(paulius): This function is DEPRECATED and will be kept until the end
    of time. It is potentially used by oslo, but too specific to be recommended
    for other projects
    FN)�acquire�release)rC�
was_lockeds  r�try_lockrr7sC����,���e�$�J������L�L�N���:��L�L�N��s�A�-�A�A�A)rr>rYr9�typingr�	fastenersr�objectrr^rhrmr?�Lockrrrr@rr�<module>rwsf��(������Z,�v�Z,�z4�n �F �F����9�>�>��d���r

Zerion Mini Shell 1.0