HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/twisted/python/__pycache__/failure.cpython-312.pyc
�

�bi��,�dZddlZddlZddlZddlZddlmZddlmZddlZddl	m
Z
dadZGd�de
�Zdd	�Zd
ZGd�de
�Zd
�ZGd�d�ZGd�d�ZGd�d�ZgZd�ZGd�de�Zd�ZdZddddej8fd�Zd�Zy)z9
Asynchronous-friendly error mechanism.

See L{Failure}.
�N)�getmro)�StringIO)�reflect�c��eZdZy)�DefaultExceptionN)�__name__�
__module__�__qualname__���8/usr/lib/python3/dist-packages/twisted/python/failure.pyrrs��r
rc
�V�|dvrtd|�d���|}|dk(r|D]\}}}}}||�d|�d|�d���y|dk(rM|D]G\}}}}}|d|�d	|�d
|�d��|dtj||�j�z��Iy|dk(r$|D]\}}}}}|d
|||fz��|d�y|dk(rp|D]j\}}}}}|d
|||fz�|d�|D]\}	}
|d|	�dt	|
��d���|d�|D]\}	}
|d|	�dt	|
��d����lyy)a�
    Format and write frames.

    @param frames: is a list of frames as used by Failure.frames, with
        each frame being a list of
        (funcName, fileName, lineNumber, locals.items(), globals.items())
    @type frames: list
    @param write: this will be called with formatted strings.
    @type write: callable
    @param detail: Four detail levels are available:
        default, brief, verbose, and verbose-vars-not-captured.
        C{Failure.printDetailedTraceback} uses the latter when the caller asks
        for verbose, but no vars were captured, so that an explicit warning
        about the missing data is shown.
    @type detail: string
    )�default�brief�verbose�verbose-vars-not-capturedzKDetail must be default, brief, verbose, or verbose-vars-not-captured. (not �)r�:�
rz  File "z", line z, in z    %s
rz%s:%d: %s(...)
zA [Capture of Locals and Globals disabled (use captureVars=True)]
rz [ Locals ]
z  z : z
 ( Globals )
N)�
ValueError�	linecache�getline�strip�repr)�frames�write�detail�w�method�filename�lineno�	localVars�
globalVars�name�vals           r�
format_framesr'#s���"�Q�Q��5;�
>�
�	
�	�A�
���?E�;�F�H�f�i��
��
�!�F�8�1�V�H�B�/�0�@F�	�9�	�?E�;�F�H�f�i��
���
�(�6�(�%��x�r�B�C�
�j�9�,�,�X�v�>�D�D�F�F�G�@F�
�.�	.�?E�;�F�H�f�i��
� �H�f�f�#=�=�>�@F�	�
N�O�	�9�	�?E�;�F�H�f�i��
� �H�f�f�#=�=�>�
�o��&�	��c��B�t�f�C��S�	�{�"�-�.�'�
���'�	��c��B�t�f�C��S�	�{�"�-�.�(�@F�
r
z--- <exception caught here> ---c��eZdZdZy)�NoCurrentExceptionErrorz�
    Raised when trying to create a Failure from the current interpreter
    exception state and there is no current exception state.
    N)r	r
r�__doc__rr
rr)r)Vs��r
r)c��t|�dkDsJd��d}|D]}t||�}�t|d|�}t|�x}}|ddD]*}t||�}t|�|_|j}�,|S)a�
    Construct a fake traceback object using a list of frames. Note that
    although frames generally include locals and globals, this information
    is not kept by this method, since locals and globals are not used in
    standard tracebacks.

    @param stackFrames: [(methodname, filename, lineno, locals, globals), ...]
    @param tbFrames: [(methodname, filename, lineno, locals, globals), ...]
    rzMust pass some framesN�)�len�_Frame�_TracebackFrame�tb_next)�stackFrames�tbFrames�stack�sf�firstTb�tbs      r�
_Tracebackr7]s����x�=�1��5�5�5��
�E����r�5�!���
�8�A�;��&�E�"�5�)�)�G�b��q�r�l���r�5�!��$�U�+��
�
�Z�Z����Nr
c��eZdZdZd�Zy)r/zq
    Fake traceback object which can be passed to functions in the standard
    library L{traceback} module.
    c�B�||_|j|_d|_y)z-
        @param frame: _Frame object
        N)�tb_frame�f_lineno�	tb_linenor0)�self�frames  r�__init__z_TracebackFrame.__init__�s����
��������r
N�r	r
rr*r?rr
rr/r/�s���
r
r/c��eZdZdZd�Zy)r.aD
    A fake frame object, used by L{_Traceback}.

    @ivar f_code: fake L{code<types.CodeType>} object
    @ivar f_lineno: line number
    @ivar f_globals: fake f_globals dictionary (usually empty)
    @ivar f_locals: fake f_locals dictionary (usually empty)
    @ivar f_back: previous stack frame (towards the caller)
    c�n�|\}}}}}t||�|_||_i|_i|_||_y)z�
        @param frameinfo: (methodname, filename, lineno, locals, globals)
        @param back: previous (older) stack frame
        @type back: C{frame}
        N)�_Code�f_coder;�	f_globals�f_locals�f_back)r=�	frameinfo�backr%r!r"�localz�globalzs        rr?z_Frame.__init__�s>��3<�/��h�����D�(�+�����
������
���r
Nr@rr
rr.r.�s���r
r.c��eZdZdZd�Zy)rCzB
    A fake code object, used by L{_Traceback} via L{_Frame}.
    c� �||_||_y)N)�co_name�co_filename)r=r%r!s   rr?z_Code.__init__�s�����#��r
Nr@rr
rrCrC�s���$r
rCc�D�tj|j�|S)a
    Mark the given callable as extraneous to inlineCallbacks exception
    reporting; don't show these functions.

    @param f: a function that you NEVER WANT TO SEE AGAIN in ANY TRACEBACK
        reported by Failure.

    @type f: function

    @return: f
    )�_inlineCallbacksExtraneous�append�__code__)�fs r�_extraneousrU�s���%�%�a�j�j�1��Hr
c���eZdZdZdZdZejdZdd�Z	d�Z
d�Zd�Zd	�Z
ed
��Zed��Zdefd
�Zdefd�Zd�Zd�Zd�Zdefd�Zdefd�Zddededefd�Zdd�Zdd�Zdd�Zy)�Failurea�
    A basic abstraction for an error that has occurred.

    This is necessary because Python's built-in error mechanisms are
    inconvenient for asynchronous communication.

    The C{stack} and C{frame} attributes contain frames.  Each frame is a tuple
    of (funcName, fileName, lineNumber, localsItems, globalsItems), where
    localsItems and globalsItems are the contents of
    C{locals().items()}/C{globals().items()} for that frame, or an empty tuple
    if those details were not captured.

    @ivar value: The exception instance responsible for this failure.
    @ivar type: The exception's class.
    @ivar stack: list of frames, innermost last, excluding C{Failure.__init__}.
    @ivar frames: list of frames, innermost first.
    rN�YIELD_VALUEc��tdzat|_dx|_x|_}||_t	|t
�r
|�t
d��d}|�|j�}|�;tj�\|_|_}|j�
t��d}nJ|�:t	|t�r|j|_nt|�|_||_n||_||_t	|jt�r|j|j�yt|jd�r2|j|jj �|j`y|�2|r|}n-t#|jdd�r|jj$}gx}|_gx}|_||_|r
|j,}	nt	|jt�sdx}	}|r	r|	j.}	|dz}|r|	r�	r�|r�|	j0j3�}
|	j0|	j4uri}n|	j4j3�}||
fD]
}d|vs�|d=�|
j7�}
|j7�}ndx}
}|j9d|	j:j<|	j:j>|	j@|
|f�|	j.}	|	r��|��|j,}	|r�|	j0j3�}
|	j0|	j4uri}n|	j4j3�}||
fD]
}d|vs�|d=�tC|
j7��}
tC|j7��}ndx}
}|jE|	j:j<|	j:j>|jF|
|f�|jH}|���tKjL|j�rXtO|jt�r>tQ|j�}
tCtStTjV|
��|_,y|jg|_,y)	a-
        Initialize me with an explanation of the error.

        By default, this will use the current C{exception}
        (L{sys.exc_info}()).  However, if you want to specify a
        particular kind of failure, you can pass an exception as an
        argument.

        If no C{exc_value} is passed, then an "original" C{Failure} will
        be searched for. If the current exception handler that this
        C{Failure} is being constructed in is handling an exception
        raised by L{raiseException}, then this C{Failure} will act like
        the original C{Failure}.

        For C{exc_tb} only L{traceback} instances or L{None} are allowed.
        If L{None} is supplied for C{exc_value}, the value of C{exc_tb} is
        ignored, otherwise if C{exc_tb} is L{None}, it will be found from
        execution context (ie, L{sys.exc_info}).

        @param captureVars: if set, capture locals and globals of stack
            frames.  This is pretty slow, and makes no difference unless you
            are going to use L{printDetailedTraceback}.
        r,Nz$Strings are not supported by Failurer�__failure__�
__traceback__�__builtins__r)-�count�type�value�captureVars�
isinstance�str�	TypeError�_findFailure�sys�exc_infor)�	Exception�	__class__rW�_extrapolate�hasattrrZ�getattrr[rr3r6r:rGrF�copyrE�items�insertrDrNrOr;�listrRr<r0�inspect�isclass�
issubclassr�mapr�qual�parents)r=�	exc_value�exc_type�exc_tbr`r6�stackOffsetrr3rTrJrK�d�parentCss              rr?zFailure.__init__�s���2��	����
�&*�*��	�*�D�J��&����i��%�(�*:��B�C�C������)�)�+�I���(+����%�D�I�t�z�2��y�y� �-�/�/��K�
�
��)�Y�/�%�/�/��	�!��O��	�"�D�J� �D�I�"�D�J��d�j�j�'�*����d�j�j�)���4�:�:�}�-�

���d�j�j�4�4�5��
�
�&��
�:��������_�d�;��Z�Z�-�-��!�!��������
�
���
����A��D�J�J��0�#�"�A���a����A��1��K�	�a��������*���:�:����,� �G��k�k�.�.�0�G� �&��A�%��*��n�-�)� �����!�-�-�/��#%�%����L�L���H�H�$�$��H�H�(�(��J�J����	
����A�1�4�n����A�������*���:�:����,� �G��k�k�.�.�0�G� �&��A�%��*��n�-�)��f�l�l�n�-���w�}�}��/��#%�%����M�M��H�H�$�$��H�H�(�(��L�L����
����B�1�n�2�?�?�4�9�9�%�*�T�Y�Y�	�*J��d�i�i�(�H���G�L�L�(� ;�<�D�L� �I�I�;�D�Lr
c��tj|j�|_tj�\}}}g}|�u|j}|j
tvrH|j|j
j|j
j|jddf�|j}|��u|j|j�||_
y)a,
        Extrapolate from one failure into another, copying its stack frames.

        @param otherFailure: Another L{Failure}, whose traceback information,
            if any, should be preserved as part of the stack presented by this
            one.
        @type otherFailure: L{Failure}
        Nr)rl�__dict__rerfr:rDrQrRrNrOr<r0�extendr)r=�otherFailure�_r6rrTs      rrizFailure._extrapolate�s����	�	�,�"7�"7�8��
��<�<�>���1�b����n����A��x�x�9�9��
�
��X�X�%�%�q�x�x�';�';�R�\�\�2�r�R�����B�
�n�	�
�
�d�k�k�"���r
c�H�|j|�}|s|j�|S)a�
        Trap this failure if its type is in a predetermined list.

        This allows you to trap a Failure in an error callback.  It will be
        automatically re-raised if it is not a type that you expect.

        The reason for having this particular API is because it's very useful
        in Deferred errback chains::

            def _ebFoo(self, failure):
                r = failure.trap(Spam, Eggs)
                print('The Failure is due to either Spam or Eggs!')
                if r == Spam:
                    print('Spam did it!')
                elif r == Eggs:
                    print('Eggs did it!')

        If the failure is not a Spam or an Eggs, then the Failure will be
        'passed on' to the next errback. In Python 2 the Failure will be
        raised; in Python 3 the underlying exception will be re-raised.

        @type errorTypes: L{Exception}
        )�check�raiseException)r=�
errorTypes�errors   r�trapzFailure.trap�s(��0��
�
�J�'������!��r
c��|D]P}|}tj|�r%t|t�rt	j
|�}||jvs�N|cSy)a
        Check if this failure's type is in a predetermined list.

        @type errorTypes: list of L{Exception} classes or
                          fully-qualified class names.
        @returns: the matching L{Exception} type, or None if no match.
        N)rprqrrrgrrtru)r=r�r��errs    rr�z
Failure.check�sL�� �E��C����u�%�*�U�I�*F��l�l�5�)���d�l�l�"��� �r
c�L�|jj|j��)zf
        raise the original exception, preserving traceback
        information if available.
        )r_�with_tracebackr6�r=s rr�zFailure.raiseException�s��
�j�j�'�'����0�0r
c�d�|j|j|j|j�S)aJ
        Throw the original exception into the given generator,
        preserving traceback information if available.

        @return: The next value yielded from the generator.
        @raise StopIteration: If there are no more values in the generator.
        @raise anything else: Anything that the generator raises.
        )�throwr^r_r6)r=�gs  r�throwExceptionIntoGeneratorz#Failure.throwExceptionIntoGenerator�s#���w�w�t�y�y�$�*�*�d�g�g�6�6r
c���tj�d}|syd}|}|jr|}|j}|jr�|j}|j|j
jur|jjd�S|jjr0|jj|j|jk7ry|rI|j}|j|jjur|jjd�S|jj}|r>|j|jjur|jjd�Syy)zV
        Find the failure that represents the exception currently in context.
        ���Nr=)rerfr0r:rDr�rSrF�get�co_code�tb_lasti�_yieldOpcoder�rG)�clsr6�secondLastTb�lastTb�	lastFramer>s      rrdzFailure._findFailure�sC��
�\�\�^�B�
���������n�n�!�L��^�^�F��n�n��O�O�	����s�1�1�:�:�:��%�%�)�)�&�1�1�� � �(�(�Y�-=�-=�-E�-E��O�O�.
�
�
�
�.�
�
� �)�)�E��|�|�s�>�>�G�G�G��~�~�)�)�&�1�1����"�"���U�\�\�S�%D�%D�%M�%M�M��>�>�%�%�f�-�-�N�5r
�returnc��djtj|j�tj|j�|j��S)Nz<{} {}: {}>)�formatrrtrhr^�getErrorMessager�s r�__repr__zFailure.__repr__&sA���#�#��L�L����(��L�L����#�� � �"�
�	
r
c�(�d|j�zS)Nz[Failure instance: %s])�getBriefTracebackr�s r�__str__zFailure.__str__-s��'�$�*@�*@�*B�B�Br
c��|jr|jS|jj�}|jD�cgc]*}|d|d|dt	|d�t	|d�g��,c}|d<d|d<|j
�C|j
D�cgc]*}|d|d|dt	|d�t	|d�g��,c}|d	<d|d
<|Scc}wcc}w)z(Avoid pickling objects in the traceback.rr,��rrNr6r3�pickled)r�r}rlr�
_safeReprVarsr3)r=�c�vs   r�__getstate__zFailure.__getstate__0s���<�<��=�=� ��M�M��� ���[�[�	
�!��
�!���!���!���a��d�#��a��d�#�
�!�	
��(����$���:�:�!����	�$�A�
�a�D��a�D��a�D�!�!�A�$�'�!�!�A�$�'��$�	�A�g�J���)�����;	
��"	s�/C�/Cc��|j�|_t|jdd�rd|j_yy)z�
        Remove references to other objects, replacing them with strings.

        On Python 3, this will also set the C{__traceback__} attribute of the
        exception instance to L{None}.
        r[N)r�r}rkr_r[r�s r�cleanFailurezFailure.cleanFailureUs5���)�)�+��
��4�:�:���5�'+�D�J�J�$�6r
c��|j�|jSt|j�dkDr t|j|j�Sy)a�
        Get an object that represents this Failure's stack that can be passed
        to traceback.extract_tb.

        If the original traceback object is still present, return that. If this
        traceback object has been lost but we still have the information,
        return a fake traceback object (see L{_Traceback}). If there is no
        traceback information at all, return None.
        Nr)r6r-rr7r3r�s r�getTracebackObjectzFailure.getTracebackObjectas@���7�7���7�7�N�
����
��
!��d�j�j�$�+�+�6�6�r
c��t|jt�r|jj�St	j
|j�S)zJ
        Get a string of the exception which caused this Failure.
        )rar_rWr�r�safe_strr�s rr�zFailure.getErrorMessagers:���d�j�j�'�*��:�:�-�-�/�/�����
�
�+�+r
c�Z�t�}|j|��|j�S)N)�file)r�printBriefTraceback�getvalue)r=�ios  rr�zFailure.getBriefTracebackzs&��
�Z��� � �b� �)��{�{�}�r
�elideFrameworkCoderc�^�t�}|j|||��|j�S)N)r�r�r)r�printTracebackr�)r=r�rr�s    r�getTracebackzFailure.getTracebacks2��
�Z������(:�6�	�	
��{�{�}�r
c	���|�ddlm}|j}|j}|dk(r|jsd}n|}|dk(r*|d|j
|jxrdxsdfz�nj|d	k(r]|jrd
}nd}||�dtj|j��dtj|j��d
��n|d�|jrH|s.t|jtd||�|t�d
��t|j||�n
|d	k(s|d�|d	k(sH|tj |j��dtj|j��d
��t#|jt$�r.|jd�|jj'|||�|dk(r|d|j
z�yy)a
        Emulate Python's standard error reporting mechanism.

        @param file: If specified, a file-like object to which to write the
            traceback.

        @param elideFrameworkCode: A flag indicating whether to attempt to
            remove uninteresting frames from within Twisted itself from the
            output.

        @param detail: A string indicating how much information to include
            in the traceback.  Must be one of C{'brief'}, C{'default'}, or
            C{'verbose'}.
        Nr)�logrrz*--- Failure #%d%s---
z (pickled) � r�	Tracebackz"Traceback (failure with no frames)z: rz#Traceback (most recent call last):
z	Failure: z (chained Failure)
z*--- End of Failure #%d ---
)�twisted.pythonr��logerrrr`r]r�rrr�r^r_r'r3�
traceupLength�EXCEPTION_CAUGHT_HERErtrarWr�)r=r�r�rr�r�formatDetail�	hasFramess        rr�zFailure.printTraceback�s����<�*��:�:�D��J�J���Y��t�'7�'7�7�L�!�L��Y��
�)��:�:���� >��F�3�G�H�
��w�
��{�{�'�	�@�	�
��g�.�.�t�y�y�9�7�;K�;K�D�J�J�;W�Y�
�

�4�5��;�;�%��d�j�j�-���9�1�l�K��*�+�2�.�/��$�+�+�q�,�7��7�"�
�k�N��� �
����d�i�i�(�)��G�,<�,<�T�Z�Z�,H�+I��L�M��d�j�j�'�*��J�J�-�.��J�J�%�%�d�,>��G��Y��
�-��
�
�:�;�r
c�,�|j||d��y)z;
        Print a traceback as densely as possible.
        r�rN�r��r=r�r�s   rr�zFailure.printBriefTraceback�s��	
���D�"4�W��Er
c�,�|j||d��y)zQ
        Print a traceback with detailed locals and globals information.
        rr�Nr�r�s   r�printDetailedTracebackzFailure.printDetailedTraceback�s��	
���D�"4�Y��Gr
)NNNF)rr)NFr)Nr)r	r
rr*r�r3�opcode�opmapr�r?rir�r�r�rUr��classmethodrdrbr�r�r�r�r�r�r��intr�r�r�r�rr
rrWrW�s����$�G��E��<�<�
�.�L�d'�L�:�:� 1��7��7��8.��8.�t
�#�
�C��C�#�J
,��",��,��3��
�s����TW��C<�JF�Hr
rWc�b�|D��cgc]\}}|tj|�f��c}}Scc}}w)aq
    Convert a list of (name, object) pairs into (name, repr) pairs.

    L{twisted.python.reflect.safe_repr} is used to generate the repr, so no
    exceptions will be raised by faulty C{__repr__} methods.

    @param varsDictItems: a sequence of (name, value) pairs as returned by e.g.
        C{locals().items()}.
    @returns: a sequence of (name, repr) pairs.
    )r�	safe_repr)�
varsDictItemsr%�objs   rr�r��s1��?L�L�m�{��c�T�7�$�$�S�)�*�m�L�L��Ls�!+TFc�(�|||fdk(rmtj�}|d|jk(sGtrA	t	|d�}t
dj|��ddl}|j|d�||||||�y#t
$rd}Y�LwxYw)z;
    Initialize failure object, possibly spawning pdb.
    )NNNrr,z
broken strz8Jumping into debugger for post-mortem of exception '{}':Nr�)
rerfrh�DO_POST_MORTEMrb�
BaseException�printr��pdb�post_mortem)	r=rvrwrxr`�Failure__init__�exc�strreprr�s	         r�
_debuginitr��s���	�8�V�$�(:�:��l�l�n���1�v����'�N�
'��c�!�f�+��
�J�Q�Q���
�

��O�O�C��F�#��D�)�X�v�{�C��!�
'�&��
'�s�B�B�Bc�"�tt_y)z*
    Enable debug hooks for Failures.
    N)r�rWr?rr
r�startDebugModer�s��"�G�r
)r)r*rlrprrerr�rr�r�rr]r�rgrr'r�r)r7r/r.rCrQrUr�rWr�r�r?r�r�rr
r�<module>r�s�������
���
�"�	���
�	�y�	�+/�`:���i��#�L����2$�$� ��

� MH�m�MH�`M� ��
�
����$�$�
D�:"r