Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/twisted/python/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/twisted/python/__pycache__/failure.cpython-37.pyc

B

:��]�k�@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�I/opt/alt/python37/lib64/python3.7/site-packages/twisted/python/failure.pyr
sr
�defaultcCsp|dkrtd|f��|}|dkrPx(|D] \}}}}}|d|||f�q(W�n|dkr�x@|D]8\}}}}}|d|||f�|dt�||����q^Wn�|dkr�x(|D] \}}}}}|d	|||f�q�W|d
�n�|dk�rlx�|D]�\}}}}}|d	|||f�|d�x&|D]\}	}
|d
|	t|
�f��qW|d�x&|D]\}	}
|d
|	t|
�f��qFWq�WdS)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�verbosezverbose-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
zverbose-vars-not-capturedz%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#s2


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"cCs~t|�dkstd��d}x|D]}t||�}qWt|d|�}t|�}}x.|dd�D]}t||�}t|�|_|j}qXW|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�tbrrr�
_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�framerrr�__init__�sz_TracebackFrame.__init__N)rrr
r#r2rrrrr(�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)r0�	frameinfoZbackrrr�localz�globalzrrrr2�sz_Frame.__init__N)rrr
r#r2rrrrr'�s	r'c@seZdZdZdd�ZdS)r3zB
    A fake code object, used by L{_Traceback} via L{_Frame}.
    cCs||_||_dS)N)�co_name�co_filename)r0rrrrrr2�sz_Code.__init__N)rrr
r#r2rrrrr3�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__)�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.
    rN�YIELD_VALUEFcCs"tdat|_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}	}x |�r�|	�r�|	j}	|d8}�qjWx�|	�r(|�r�|	j��}
|	j|	jk�r�i}n
|	j��}x"||
fD]}d|k�r�|d=�q�W|
��}
|��}nd}
}|�d|	jj|	jj|	j |
|f�|	j}	�q�Wx�|dk	�r�|j}	|�r�|	j��}
|	j|	jk�r`i}n
|	j��}x"||
fD]}d|k�rt|d=�qtWt!|
���}
t!|���}nd}
}|�"|	jj|	jj|j#|
|f�|j$}�q,Wt%�&|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)r0�	exc_value�exc_type�exc_tbrJr+ZstackOffsetrr*r@r9r:�dZparentCsrrrr2�s�















zFailure.__init__cCsxt�|j�|_t��\}}}g}x@|dk	r`|j}|jtkrX|�|jj|jj	|j
ddf�|j}q"W|�|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)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.trapcGsBx<|D]4}|}t�|�r,t|t�r,t�|�}||jkr|SqWdS)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_)r0rirj�errrrrrg�s


z
Failure.check�with_tracebackcCs|j�|j��dS)N)rIrmr+)r0rrrrh�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}|}x|jr0|}|j}qW|j}|j|jjkrR|j�d�S|jj	rn|jj	|j
|jkrrdS|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-r4rhr?r6�get�co_code�tb_lasti�_yieldOpcoderpr7)�clsr+ZsecondLastTbZlastTbZ	lastFramer1rrrrNs*
	zFailure._findFailurecCs"dt�|j�t�|j�|��fS)Nz<%s %s: %s>)rr^rRrH�getErrorMessage)r0rrr�__repr__>s
zFailure.__repr__cCsd|��S)Nz[Failure instance: %s])�getBriefTraceback)r0rrr�__str__DszFailure.__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)rr$��r	)�
_safeReprVars)�.0�vrrr�
<listcomp>Psz(Failure.__getstate__.<locals>.<listcomp>rNr+c	Ss6g|].}|d|d|dt|d�t|d�g�qS)rr$r{r|r	)r})r~rrrrr�^sr*r$�pickled)r�rdrVrr*)r0�crrr�__getstate__Hs

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�rdrUrIrE)r0rrr�cleanFailureis
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*)r0rrr�getTracebackObjectvs


zFailure.getTracebackObjectcCs"t|jt�r|j��St�|j�S)zJ
        Get a string of the exception which caused this Failure.
        )rKrIrBrwr�safe_str)r0rrrrw�s
zFailure.getErrorMessagecCst�}|j|d�|��S)N)�file)�StringIO�printBriefTraceback�getvalue)r0�iorrrry�szFailure.getBriefTracebackrcCst�}|j|||d�|��S)N)r��elideFrameworkCoder)r��printTracebackr�)r0r�rr�rrr�getTraceback�szFailure.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)�logrzverbose-vars-not-capturedz*--- 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!r*�
traceupLength�EXCEPTION_CAUGHT_HEREr^rKrBr�)r0r�r�rr�rZformatDetailZ	hasFramesrrrr��sF



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.
        r)rN)r�)r0r�r�rrr�printDetailedTraceback�szFailure.printDetailedTraceback)NNNF)rr)NFr)Nr)Nr)"rrr
r#r�r*r�opcode�opmapru�chrr2rSrkrgrU�
BaseExceptionrh�execrArprN�classmethodrxrzr�r�r�rwryr�r�r�r�rrrrrB�s@
# !
9!
	

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�objrrrr��sz!_safeReprVars.<locals>.<listcomp>r)Z
varsDictItemsrrrr}�sr}TFc	Cs�|||fdkrnt��}|d|jksntrnyt|d�}Wnd}YnXtd|f�ddl}|�|d�||||||�dS)z;
    Initialize failure object, possibly spawning pdb.
    )NNNrr$z
broken strz8Jumping into debugger for post-mortem of exception '%s':Nr{)rOrPrR�DO_POST_MORTEMrL�print�pdbZpost_mortem)	r0r`rarbrJZFailure__init__�excZstrreprr�rrr�
_debuginits

r�cCs
tt_dS)z*
    Enable debug hooks for Failures.
    N)r�rBr2rrrr�startDebugModesr�)r)&r#�
__future__rrrrVrOrrZr�rr�rZtwisted.python.compatrrr�rGr�rQr
r!r�r"r,�objectr(r'r3r=rAr�rBr}r�r2r�r�rrrr�<module>s@
/'
+