HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/thread-self/root/lib/python3/dist-packages/twisted/python/__pycache__/failure.cpython-38.pyc
U

��W[h�@s dZddlmZmZmZddlZddlZddlZddlZddl	Z	ddlm
Z
ddlmZddl
mZmZdadZGdd	�d	e�Zd$dd�Zd
ZGdd�de�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�ZgZdd�ZGdd�de�Z dd�Z!dZ"dddde j#fd d!�Z$d"d#�Z%dS)%z9
Asynchronous-friendly error mechanism.

See L{Failure}.
�)�division�absolute_import�print_functionN)�getmro)�reflect)�_PY3�NativeStringIO�c@seZdZdS)�DefaultExceptionN)�__name__�
__module__�__qualname__�rr�8/usr/lib/python3/dist-packages/twisted/python/failure.pyr
sr
�defaultcCsX|dkrtd|f��|}|dkrL|D] \}}}}}|d|||f�q&�n|dkr�|D]8\}}}}}|d|||f�|dt�||����qXn�|dkr�|D] \}}}}}|d	|||f�q�|d
�n�|dk�rT|D]x\}}}}}|d	|||f�|d�|D]\}	}
|d
|	t|
�f��q|d�|D]\}	}
|d
|	t|
�f��q2q�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)rz	%s:%s:%s
rz  File "%s", line %s, in %s
z    %s
rz%s:%d: %s(...)
zA [Capture of Locals and Globals disabled (use captureVars=True)]
rz [ Locals ]
z
  %s : %s
z
 ( Globals )
N)�
ValueError�	linecache�getline�strip�repr)�frames�write�detail�w�method�filename�linenoZ	localVarsZ
globalVars�name�valrrr�
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)rrr
�__doc__rrrrr#Vsr#cCs4t|�dkstd��d}t|�D]}t||�}q |S)aE
    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 frames: [(methodname, filename, lineno, locals, globals), ...]
    rzMust pass some framesN)�len�AssertionError�reversed�_TracebackFrame)r�tb�framerrr�
_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*|\}}}}}t||�|_||_||_dS)z�
        @param frame: (methodname, filename, lineno, locals, globals)
        @param tb_next: next inner _TracebackFrame object, or None if this
           is the innermost frame.
        N)�_Frame�tb_frame�	tb_lineno�tb_next)�selfr*r/r rr�localz�globalzrrr�__init__wsz_TracebackFrame.__init__N�rrr
r$r3rrrrr(qsr(c@seZdZdZdd�ZdS)r,z�
    A fake frame object, used by L{_Traceback}.

    @ivar f_code: fake L{code<types.CodeType>} object
    @ivar f_globals: fake f_globals dictionary (usually empty)
    @ivar f_locals: fake f_locals dictionary (usually empty)
    cCst||�|_i|_i|_dS)z�
        @param name: method/function name for this frame.
        @type name: C{str}
        @param filename: filename for this frame.
        @type name: C{str}
        N)�_Code�f_code�	f_globals�f_locals�r0r rrrrr3�sz_Frame.__init__Nr4rrrrr,�sr,c@seZdZdZdd�ZdS)r5zB
    A fake code object, used by L{_Traceback} via L{_Frame}.
    cCs||_||_dS�N)�co_name�co_filenamer9rrrr3�sz_Code.__init__Nr4rrrrr5�sr5cCst�|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__)�frrr�_extraneous�srAc@s�eZdZdZdZdZer$ejdZ	ne
ejd�Z	d.dd�Zdd	�Zd
d�Z
dd
�Zeedd�rjdd�Zned�de_edd��Zdd�Zee�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd/d&d'�Zd0d(d)�Zd1d*d+�Z d2d,d-�Z!dS)3�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.
    rNZYIELD_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}.
        �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�getattrrEr�stackr)r-�f_backr8�copyr7�items�insertr6r;r<�f_lineno�listr>r.r/�inspect�isclass�
issubclassr�mapr�qual�parents)r0�	exc_value�exc_type�exc_tbrJr)ZstackOffsetrrVr@r1r2�dZparentCsrrrr3�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)rX�__dict__rOrPr-r6r=r>r;r<r.r/�extendr)r0ZotherFailure�_r)rr@rrrrS|s 

�zFailure._extrapolatecGs$|j|�}|s tr|��n|�|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}
        )�checkr�raiseException)r0�
errorTypes�errorrrr�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)r]r^r_rQrrarb)r0rlrm�errrrrrj�s


z
Failure.check�with_tracebackcCs|j�|j��dSr:)rIrpr)�r0rrrrk�szFailure.raiseExceptionzBdef raiseException(self):
    raise self.type, self.value, self.tbzf
        raise the original exception, preserving traceback
        information if available.
        cCs|�|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))r0�grrr�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.
        ���Nr0)rOrPr/r-r6rkr?r8�get�co_code�tb_lasti�_yieldOpcodertrW)�clsr)ZsecondLastTbZlastTbZ	lastFramer*rrrrN�s,	�zFailure._findFailurecCs"dt�|j�t�|j�|��fS)Nz<%s %s: %s>)rrarRrH�getErrorMessagerqrrr�__repr__)s
�zFailure.__repr__cCsd|��S)Nz[Failure instance: %s])�getBriefTracebackrqrrr�__str__/szFailure.__str__cCs\|jr|jS|j��}dd�|jD�|d<d|d<|jdk	rPdd�|jD�|d<d|d	<|S)
z1Avoid pickling objects in the traceback.
        c	Ss6g|].}|d|d|dt|d�t|d�g�qS�rrC��r	��
_safeReprVars��.0�vrrr�
<listcomp>:s�

�z(Failure.__getstate__.<locals>.<listcomp>rNr)c	Ss6g|].}|d|d|dt|d�t|d�g�qSrr�r�rrrr�Hs�

�rVrC�pickled)r�rgrXrrV)r0�crrr�__getstate__3s
�
	
�
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�rgrUrIrErqrrr�cleanFailureTs
zFailure.cleanFailurecCs0|jdk	r|jSt|j�dkr(t|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+rqrrr�getTracebackObjectas



zFailure.getTracebackObjectcCs"t|jt�r|j��St�|j�S)zJ
        Get a string of the exception which caused this Failure.
        )rKrIrBr{r�safe_strrqrrrr{ss
zFailure.getErrorMessagecCst�}|j|d�|��S)N)�file)�StringIO�printBriefTraceback�getvalue)r0�iorrrr}|szFailure.getBriefTracebackrcCst�}|j|||d�|��S)N)r��elideFrameworkCoder)r��printTracebackr�)r0r�rr�rrr�getTraceback�s
�zFailure.getTracebackcCs`|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�||�|dtf�t|j||�n|d	ks�|d�|d	k�s|dt�|j
�t�	|j�f�t|jt��rD|�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):
z%s
z	Failure: z%s: %s
z (chained Failure)
z*--- End of Failure #%d ---
)�twisted.pythonr�ZlogerrrrJrGr�rrr�rHrIr"rV�
traceupLength�EXCEPTION_CAUGHT_HERErarKrBr�)r0r�r�rr�rZformatDetailZ	hasFramesrrrr��sN��

�


�

zFailure.printTracebackcCs|j||dd�dS)z;
        Print a traceback as densely as possible.
        r�rN�r��r0r�r�rrrr��szFailure.printBriefTracebackcCs|j||dd�dS)zQ
        Print a traceback with detailed locals and globals information.
        rr�Nr�r�rrr�printDetailedTraceback�szFailure.printDetailedTraceback)NNNF)rr)NFr)Nr)Nr)"rrr
r$r�rVr�opcodeZopmapry�chrr3rSrnrjrU�
BaseExceptionrk�execrArtrN�classmethodr|r~r�r�r�r{r}r�r�r�r�rrrrrB�sF�
$ !
�
9!
	
�
F
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 �objrrrr��sz!_safeReprVars.<locals>.<listcomp>r)Z
varsDictItemsrrrr��sr�TFc	Cs�|||fdkrnt��}|d|jksntrnzt|d�}Wnd}YnXtd|f�ddl}|�|d�||||||�dS)z;
    Initialize failure object, possibly spawning pdb.
    )NNNrrCz
broken strz8Jumping into debugger for post-mortem of exception '%s':Nr�)rOrPrR�DO_POST_MORTEMrL�print�pdbZpost_mortem)	r0rcrdrerJZFailure__init__�excZstrreprr�rrr�
_debuginit�s
�r�cCs
tt_dS)z*
    Enable debug hooks for Failures.
    N)r�rBr3rrrr�startDebugModesr�)r)&r$Z
__future__rrrrXrOrr]r�rr�rZtwisted.python.compatrrr�rGr�rQr
r"r�r#r+�objectr(r,r5r=rAr�rBr�r�r3r�r�rrrr�<module>sB
/
+�