403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /usr/lib/python3/dist-packages/zmq/eventloop/minitornado/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3/dist-packages/zmq/eventloop/minitornado/__pycache__/stack_context.cpython-311.pyc
�

mc�co3���dZddlmZmZmZmZddlZddlZddlm	Z	Gd�de
��ZGd�d	ej��Z
e
��ZGd
�de��ZGd�d
e��ZGd�de��Zd�Zd�Zd�Zd�ZdS)a	`StackContext` allows applications to maintain threadlocal-like state
that follows execution as it moves to other execution contexts.

The motivating examples are to eliminate the need for explicit
``async_callback`` wrappers (as in `tornado.web.RequestHandler`), and to
allow some additional context to be kept for logging.

This is slightly magic, but it's an extension of the idea that an
exception handler is a kind of stack-local state and when that stack
is suspended and resumed in a new context that state needs to be
preserved.  `StackContext` shifts the burden of restoring that state
from each call site (e.g.  wrapping each `.AsyncHTTPClient` callback
in ``async_callback``) to the mechanisms that transfer control from
one context to another (e.g. `.AsyncHTTPClient` itself, `.IOLoop`,
thread pools, etc).

Example usage::

    @contextlib.contextmanager
    def die_on_error():
        try:
            yield
        except Exception:
            logging.error("exception in asynchronous operation",exc_info=True)
            sys.exit(1)

    with StackContext(die_on_error):
        # Any exception thrown here *or in callback and its descendants*
        # will cause the process to exit instead of spinning endlessly
        # in the ioloop.
        http_client.fetch(url, callback)
    ioloop.start()

Most applications shouldn't have to work with `StackContext` directly.
Here are a few rules of thumb for when it's necessary:

* If you're writing an asynchronous library that doesn't rely on a
  stack_context-aware library like `tornado.ioloop` or `tornado.iostream`
  (for example, if you're writing a thread pool), use
  `.stack_context.wrap()` before any asynchronous operations to capture the
  stack context from where the operation was started.

* If you're writing an asynchronous library that has some shared
  resources (such as a connection pool), create those shared resources
  within a ``with stack_context.NullContext():`` block.  This will prevent
  ``StackContexts`` from leaking from one request to another.

* If you want to write something like an exception handler that will
  persist across asynchronous calls, create a new `StackContext` (or
  `ExceptionStackContext`), and make your asynchronous calls in a ``with``
  block that references your `StackContext`.
�)�absolute_import�division�print_function�with_statementN�)�raise_exc_infoc��eZdZdS)�StackContextInconsistentErrorN)�__name__�
__module__�__qualname__���I/usr/lib/python3/dist-packages/zmq/eventloop/minitornado/stack_context.pyr
r
Ns�������Drr
c��eZdZd�ZdS)�_Statec�0�t��df|_dS�N)�tuple�contexts��selfs r�__init__z_State.__init__Ss�����$���
�
�
rN)rrr
rrrrrrRs#������(�(�(�(�(rrc�6�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	dS)	�StackContextaEstablishes the given context as a StackContext that will be transferred.

    Note that the parameter is a callable that returns a context
    manager, not the context itself.  That is, where for a
    non-transferable context manager you would say::

      with my_context():

    StackContext takes the function itself rather than its result::

      with StackContext(my_context):

    The result of ``with StackContext() as cb:`` is a deactivation
    callback.  Run this callback when the StackContext is no longer
    needed to ensure that it is not propagated any further (note that
    deactivating a context does not affect any instances of that
    context that are currently pending).  This is an advanced feature
    and not necessary in most applications.
    c�0�||_g|_d|_dS�NT)�context_factoryr�active)rrs  rrzStackContext.__init__ls��.�����
�����rc��d|_dS�NF�rrs r�_deactivatezStackContext._deactivateq�
������rc��|���}|j�|��|���dSr)rr�append�	__enter__)r�contexts  r�enterzStackContext.enterusA���&�&�(�(���
���W�%�%�%��������rc�f�|j���}|�|||��dSr)r�pop�__exit__)r�type�value�	tracebackr(s     r�exitzStackContext.exitzs3���-�#�#�%�%������u�i�0�0�0�0�0rc���tj|_|jd|fz|f|_|jt_	|���n#|jt_�xYw|jS�Nr)�_stater�old_contexts�new_contextsr)r#rs rr'zStackContext.__enter__�se��"�O���!�.�q�1�T�G�;�T�B����+���	��J�J�L�L�L�L��	�"�/�F�O�������s�A�A%c�0�	|�|||��tj}|jt_||jurtd���d|_dS#tj}|jt_||jurtd���d|_wxYw�NzWstack_context inconsistency (may be caused by yield within a "with StackContext" block))r0r3rr4r5r
�rr-r.r/�final_contextss     rr,zStackContext.__exit__�s���	%��I�I�d�E�9�-�-�-�#�_�N�"�/�F�O��T�%6�6�6�3�:�;�;�;�
!%�D�����$�_�N�"�/�F�O��T�%6�6�6�3�:�;�;�;�
!%�D��$�$�$�$s�A�>BN)
rrr
�__doc__rr#r)r0r'r,rrrrrXsx��������&���
������
1�1�1� � � �%�%�%�%�%rrc�0�eZdZdZd�Zd�Zd�Zd�Zd�ZdS)�ExceptionStackContextaASpecialization of StackContext for exception handling.

    The supplied ``exception_handler`` function will be called in the
    event of an uncaught exception in this context.  The semantics are
    similar to a try/finally clause, and intended use cases are to log
    an error, close a socket, or similar cleanup actions.  The
    ``exc_info`` triple ``(type, value, traceback)`` will be passed to the
    exception_handler function.

    If the exception handler returns true, the exception will be
    consumed and will not be propagated to other exception handlers.
    c�"�||_d|_dSr)�exception_handlerr)rr>s  rrzExceptionStackContext.__init__�s��!2�������rc��d|_dSr!r"rs rr#z!ExceptionStackContext._deactivate�r$rc�8�|�|�|||��SdSr)r>�rr-r.r/s    rr0zExceptionStackContext.exit�s(�����)�)�$��y�A�A�A��rc�|�tj|_|jd|f|_|jt_|jSr2)r3rr4r5r#rs rr'zExceptionStackContext.__enter__�s4��"�O���!�.�q�1�4�8����+�����rc��	|�S|�|||��tj}|jt_||jurtd���d|_S	tj}|jt_||jurtd���d|_dS#tj}|jt_||jurtd���d|_wxYwr7)r>r3rr4r5r
r8s     rr,zExceptionStackContext.__exit__�s��
	%����-�-�d�E�9�E�E�#�_�N�"�/�F�O��T�%6�6�6�3�:�;�;�;�
!%�D��� �$�_�N�"�/�F�O��T�%6�6�6�3�:�;�;�;�
!%�D�����$�_�N�"�/�F�O��T�%6�6�6�3�:�;�;�;�
!%�D��$�$�$�$s�B�>CN)	rrr
r:rr#r0r'r,rrrr<r<�sl��������������B�B�B� � � �%�%�%�%�%rr<c��eZdZdZd�Zd�ZdS)�NullContextz�Resets the `StackContext`.

    Useful when creating a shared resource on demand (e.g. an
    `.AsyncHTTPClient`) where the stack that caused the creating is
    not relevant to future operations.
    c�\�tj|_t��dft_dSr)r3rr4rrs rr'zNullContext.__enter__�s��"�O��� �7�7�D�/����rc�(�|jt_dSr)r4r3rrAs    rr,zNullContext.__exit__�s���+����rN)rrr
r:r'r,rrrrErE�s<��������*�*�*�,�,�,�,�,rrEc�
�td�|dD����}|d}|�|js|jd}|�|j�|}|�6|jd}|�#|jrn|j|_|jd}|�#|}|�6||fS)z*Remove deactivated handlers from the chainc� �g|]}|j�	|��Srr")�.0�hs  r�
<listcomp>z'_remove_deactivated.<locals>.<listcomp>�s��?�?�?�!�a�h�?�A�?�?�?rrr)rrr4)r�stack_contexts�head�ctx�parents     r�_remove_deactivatedrQ�s����?�?�x��{�?�?�?�@�@�N��A�;�D�
�
�4�;�
�� ��#���
�4�;�
��C�

�/��!�!�$��� ��}�
��%�2�C���(��+�F�	� ����/�
�D�!�!rc������t�d��r�Stjg��dds�dds��fd�}d|_|S��fd�}d|_|S)a
Returns a callable object that will restore the current `StackContext`
    when executed.

    Use this whenever saving a callback to be executed later in a
    different execution context (either in a different thread or
    asynchronously in the same thread).
    N�_wrappedrrc���	tj}�dt_�|i|��|t_S#|t_wxYwr2)r3r)�args�kwargs�
current_state�cap_contexts�fns   ��r�null_wrapperzwrap.<locals>.null_wrappersH���
0� &��
�".�q�/����r�4�*�6�*�*�"/�����-���/�/�/�/s	�%5�ATc����d}	tj}t�d��x�d<}|t_d}d}d}|d}|D]C}		|	���|dz
}�#t	j��}|	jd}Y�AxYw|�,	�|i|��}n"#t	j��}|d}YnxYw|�t||��}n`|dkrF|dz}||}
	|
j|�n'#t	j��}|
jd}YnxYw|dk�Fd}|�t||��}|dkrt|��|t_n#|t_wxYw|S)Nr�NNNr)
r3rrQr)�sys�exc_infor4�_handle_exceptionr0r)
rUrV�retrWr�exc�top�last_ctx�stack�n�crXrYs
           ��r�wrappedzwrap.<locals>.wrappeds������>	,�"�O�M�*=�\�!�_�)M�)M�M�L��O�h�'�F�O�%�C��C��H��Q�K�E��
,�
,��,��G�G�I�I�I���M�H�H��,��,�.�.�C��.��+�C�C�C�����{�&��"�d�-�f�-�-�C�C��&��,�.�.�C�"�1�+�C�C�C������'��S�1�1�����l�l���M�H��h��A�����������!�l�n�n���n�Q�/���������l�l��C��?�+�C��5�5�C��(�(�(��s�#�#�#�+�F�O�O��m�F�O�+�+�+�+��
sT�AE�
A$�#E�$"B�E�B�E�B6�4+E� 
C+�*E�+"D�
4E�E)�hasattrr3rrS)rYrZrgrXs`  @r�wrapri�s�����
�z�W�R��,�,�z��	��O�$�L���?�1��
�l�1�o�a�&8�
�	0�	0�	0�	0�	0�	0�!%�����A�A�A�A�A�A�F�G���Nrc�x�|�7	|j|�rd}n#tj��}YnxYw|jd}|�7|S)Nr\r)r0r]r^r4)�tailras  rr_r_`sW��
�
�	!��t�y�#��
)�(����	!��,�.�.�C�C�C����� ��#���
��Js��(c�N�|5|��cddd��S#1swxYwYdS)a�Run a coroutine ``func`` in the given `StackContext`.

    It is not safe to have a ``yield`` statement within a ``with StackContext``
    block, so it is difficult to use stack context with `.gen.coroutine`.
    This helper function runs the function in the correct context while
    keeping the ``yield`` and ``with`` statements syntactically separate.

    Example::

        @gen.coroutine
        def incorrect():
            with StackContext(ctx):
                # ERROR: this will raise StackContextInconsistentError
                yield other_coroutine()

        @gen.coroutine
        def correct():
            yield run_with_stack_context(StackContext(ctx), other_coroutine)

    .. versionadded:: 3.1
    Nr)r(�funcs  r�run_with_stack_contextrnmsw��,
����t�v�v���������������������s�
��)r:�
__future__rrrrr]�	threading�utilr�	Exceptionr
�localrr3�objectrr<rErQrir_rnrrr�<module>rus���"3�3�jQ�P�P�P�P�P�P�P�P�P�P�P�
�
�
�
����� � � � � � �	�	�	�	�	�I�	�	�	�(�(�(�(�(�Y�_�(�(�(�
�����I%�I%�I%�I%�I%�6�I%�I%�I%�X-%�-%�-%�-%�-%�F�-%�-%�-%�`,�,�,�,�,�&�,�,�,�"�"�"�4`�`�`�F
�
�
�����r

Youez - 2016 - github.com/yon3zu
LinuXploit