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: //lib/python3/dist-packages/twisted/python/__pycache__/failure.cpython-38.pyc
U

�bi�@sdZddlZddlZddlZddlZddlmZddlmZddlZddl	m
Z
dadZGdd�de
�Zd#d
d�ZdZGd
d�de
�Zdd�ZGdd�d�ZGdd�d�ZGdd�d�ZgZdd�ZGdd�de�Zdd�ZdZddddejfdd �Zd!d"�ZdS)$z9
Asynchronous-friendly error mechanism.

See L{Failure}.
�N)�getmro)�StringIO)�reflect�c@seZdZdS)�DefaultExceptionN)�__name__�
__module__�__qualname__�r
r
�8/usr/lib/python3/dist-packages/twisted/python/failure.pyrsr�defaultc	Csv|dkrtd|f��|}|dkrT|D](\}}}}}||�d|�d|�d��q&�n|dkr�|D]B\}}}}}|d|�d|�d	|�d��|d
t�||����q`n�|dkr�|D] \}}}}}|d|||f�q�|d
�n�|dk�rr|D]�\}}}}}|d|||f�|d�|D]$\}	}
|d|	�dt|
��d���q|d�|D]$\}	}
|d|	�dt|
��d���qJq�dS)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
    )r�brief�verbose�verbose-vars-not-capturedzNDetail must be default, brief, verbose, or verbose-vars-not-captured. (not %r)r
�:�
rz  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�linenoZ	localVarsZ
globalVars�name�valr
r
r�
format_frames#s6�� 

r z--- <exception caught here> ---c@seZdZdZdS)�NoCurrentExceptionErrorz�
    Raised when trying to create a Failure from the current interpreter
    exception state and there is no current exception state.
    N)rrr	�__doc__r
r
r
rr!Vsr!cCsvt|�dkstd��d}|D]}t||�}qt|d|�}t|�}}|dd�D]}t||�}t|�|_|j}qR|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�AssertionError�_Frame�_TracebackFrame�tb_next)ZstackFramesZtbFrames�stackZsfZfirstTb�tbr
r
r�
_Traceback]s


r+c@seZdZdZdd�ZdS)r'zq
    Fake traceback object which can be passed to functions in the standard
    library L{traceback} module.
    cCs||_|j|_d|_dS)z-
        @param frame: _Frame object
        N)�tb_frame�f_lineno�	tb_linenor()�self�framer
r
r�__init__�sz_TracebackFrame.__init__N�rrr	r"r1r
r
r
rr'�sr'c@seZdZdZdd�ZdS)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)
    cCs6|\}}}}}t||�|_||_i|_i|_||_dS)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/�	frameinfoZbackrrr�localz�globalzr
r
rr1�sz_Frame.__init__Nr2r
r
r
rr&�s
r&c@seZdZdZdd�ZdS)r3zB
    A fake code object, used by L{_Traceback} via L{_Frame}.
    cCs||_||_dS)N)�co_name�co_filename)r/rrr
r
rr1�sz_Code.__init__Nr2r
r
r
rr3�sr3cCst�|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__)�fr
r
r�_extraneous�srAc@s�eZdZdZdZdZejdZd-dd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
edd��Zedd��Zed�dd�Zed�dd�Zdd�Zdd�Zdd�Zed�dd �Zed�d!d"�Zd.eeed$�d%d&�Zd/d'd(�Zd0d)d*�Zd1d+d,�ZdS)2�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_VALUEFcCstdat|_d|_|_}||_t|t�r>|dkr>td��d}|dkrR|��}|dkr�t�	�\|_|_}|jdkr|t
��d}n:|dkr�t|t�r�|j|_n
t|�|_||_n||_||_t|jt
�r�|�|j�dSt|jd�r�|�|jj�|j`dS|dk�r*|�r|}nt|jdd��r*|jj}g}|_g}|_||_|�rR|j}	nt|jt
��shd}	}|�r�|	�r�|	j}	|d8}�qh|	�r|�r�|	j��}
|	j|	jk�r�i}n
|	j��}||
fD]}d|k�r�|d=�q�|
��}
|��}nd}
}|�d|	jj|	jj|	j |
|f�|	j}	�q�|dk	�r�|j}	|�r�|	j��}
|	j|	jk�rRi}n
|	j��}||
fD]}d|k�rd|d=�qdt!|
���}
t!|���}nd}
}|�"|	jj|	jj|j#|
|f�|j$}�qt%�&|j��rt'|jt��rt(|j�}
t!t)t*j+|
��|_,n
|jg|_,dS)	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__rB�_extrapolate�hasattrrD�getattrrErr)r*r,r7r6�copyr5�items�insertr4r;r<r-�listr>r.r(�inspect�isclass�
issubclassr�mapr�qual�parents)r/�	exc_value�exc_type�exc_tbrJr*ZstackOffsetrr)r@r9r:�dZparentCsr
r
rr1�s�












��






��	

zFailure.__init__cCstt�|j�|_t��\}}}g}|dk	r^|j}|jtkrV|�|jj|jj	|j
ddf�|j}q |�|j
�||_
dS)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
)rV�__dict__rOrPr,r4r=r>r;r<r.r(�extendr)r/ZotherFailure�_r*rr@r
r
rrS�s

�zFailure._extrapolatecGs|j|�}|s|��|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�errorr
r
r�trap�s
zFailure.trapcGsB|D]8}|}t�|�r*t|t�r*t�|�}||jkr|SqdS)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)rZr[r\rQrr^r_)r/rirj�errr
r
rrg�s


z
Failure.checkcCs|j�|j��dS)zf
        raise the original exception, preserving traceback
        information if available.
        N)rI�with_tracebackr*�r/r
r
rrh�szFailure.raiseExceptioncCs|�|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.
        )�throwrHrIr*)r/�gr
r
r�throwExceptionIntoGenerator�sz#Failure.throwExceptionIntoGeneratorcCs�t��d}|sdSd}|}|jr.|}|j}q|j}|j|jjkrN|j�d�S|jj	rj|jj	|j
|jkrndS|r�|j}|j|jjkr�|j�d�S|jj
}|r�|j|jjkr�|j�d�SdS)zV
        Find the failure that represents the exception currently in context.
        ���Nr/)rOrPr(r,r4rhr?r6�get�co_code�tb_lasti�_yieldOpcoderqr7)�clsr*ZsecondLastTbZlastTbZ	lastFramer0r
r
rrN�s0	��zFailure._findFailure)�returncCs"d�t�|j�t�|j�|���S)Nz<{} {}: {}>)�formatrr^rRrH�getErrorMessagernr
r
r�__repr__&s


�zFailure.__repr__cCsd|��S)Nz[Failure instance: %s])�getBriefTracebackrnr
r
r�__str__-szFailure.__str__cCs\|jr|jS|j��}dd�|jD�|d<d|d<|jdk	rPdd�|jD�|d<d|d	<|S)
z(Avoid pickling objects in the traceback.c	Ss6g|].}|d|d|dt|d�t|d�g�qS�rr#��r��
_safeReprVars��.0�vr
r
r�
<listcomp>6s�

�z(Failure.__getstate__.<locals>.<listcomp>rNr*c	Ss6g|].}|d|d|dt|d�t|d�g�qSr~r�r�r
r
rr�Gs�

�r)r#�pickled)r�rdrVrr))r/�cr
r
r�__getstate__0s
�

�
zFailure.__getstate__cCs$|��|_t|jdd�r d|j_dS)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}.
        rEN)r�rdrUrIrErnr
r
r�cleanFailureUs
zFailure.cleanFailurecCs4|jdk	r|jSt|j�dkr,t|j|j�SdSdS)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)r*r$rr+r)rnr
r
r�getTracebackObjectas


zFailure.getTracebackObjectcCs"t|jt�r|j��St�|j�S)zJ
        Get a string of the exception which caused this Failure.
        )rKrIrBrzr�safe_strrnr
r
rrzrs
zFailure.getErrorMessagecCst�}|j|d�|��S)N)�file)r�printBriefTraceback�getvalue)r/�ior
r
rr|zszFailure.getBriefTracebackr)�elideFrameworkCoderrxcCst�}|j|||d�|��S)N)r�r�r)r�printTracebackr�)r/r�rr�r
r
r�getTracebacks�zFailure.getTracebackcCsd|dkrddlm}|j}|j}|dkr4|js4d}n|}|dkr^|d|j|jrRdpTdf�nD|d	kr�|jrrd
}nd}|d|t�	|j
�t�	|j�f�n|d
�|jr�|s�t|j
td�||�|t�d��t|j||�n|d	ks�|d�|d	k�s |t�|j
��dt�	|j��d��t|jt��rH|�d�|j�|||�|dk�r`|d|j�dS)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%s: %s: %s
z#Traceback (most recent call last):
rz	Failure: z: z (chained Failure)
z*--- End of Failure #%d ---
)�twisted.pythonr�ZlogerrrrJrGr�rrr�rHrIr r)�
traceupLength�EXCEPTION_CAUGHT_HEREr^rKrBr�)r/r�r�rr�rZformatDetailZ	hasFramesr
r
rr��sJ����
$

zFailure.printTracebackcCs|j||dd�dS)z;
        Print a traceback as densely as possible.
        r
�rN�r��r/r�r�r
r
rr��szFailure.printBriefTracebackcCs|j||dd�dS)zQ
        Print a traceback with detailed locals and globals information.
        rr�Nr�r�r
r
r�printDetailedTraceback�szFailure.printDetailedTraceback)NNNF)rr)NFr)Nr)Nr)rrr	r"r�r)�opcode�opmaprvr1rSrkrgrhrArq�classmethodrNrLr{r}r�r�r�rzr|�intr�r�r�r�r
r
r
rrB�s2

'


:%
E
rBcCsdd�|D�S)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.
    cSsg|]\}}|t�|�f�qSr
)rZ	safe_repr)r�r�objr
r
rr��sz!_safeReprVars.<locals>.<listcomp>r
)Z
varsDictItemsr
r
rr��sr�TFc	Cs�|||fdkrvt��}|d|jksvtrvzt|d�}Wntk
rPd}YnXtd�|��ddl}|�	|d�||||||�dS)z;
    Initialize failure object, possibly spawning pdb.
    )NNNrr#z
broken strz8Jumping into debugger for post-mortem of exception '{}':Nr)
rOrPrR�DO_POST_MORTEMrL�
BaseException�printry�pdbZpost_mortem)	r/r`rarbrJZFailure__init__�excZstrreprr�r
r
r�
_debuginit�s
��r�cCs
tt_dS)z*
    Enable debug hooks for Failures.
    N)r�rBr1r
r
r
r�startDebugModesr�)r)r"rVrZrrOrr�rr�r�rrGr�rQrr r�r!r+r'r&r3r=rAr�rBr�r�r1r�r�r
r
r
r�<module>sD
0&
�