
    hY                       S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKJ	r	  SSKJ
r
  SSKJr  SSKJrJrJr  SSKJr  SS	KJr  SS
KJr  \" S\S\4   S9rSqSr " S S\5      rS$S jrSr " S S\5      rS r  " S S5      r! " S S5      r" " S S5      r#/ r$S%S jr% " S S\&5      r'S r(S r)SSSS!\'RT                  4S" jr+S# r,g)&z9
Asynchronous-friendly error mechanism.

See L{Failure}.
    )annotationsN)partial)getmro)StringIO)CallableNoReturnTypeVar)Version)reflect)deprecatedProperty_T_Callable.)bound   c                      \ rS rSrSrg)DefaultException&    N)__name__
__module____qualname____firstlineno____static_attributes__r       ]/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/python/failure.pyr   r   &   s    r   r   c           
     d   US;  a  [        SU< S35      eUnUS:X  a  U  H  u  pEpgnU" U SU SU S35        M     gUS:X  aM  U  HF  u  pEpgnU" SU S	U S
U S35        U" S[        R                  " XV5      R                  5       -  5        MH     gUS:X  a#  U  H  u  pEpgnU" SXVU4-  5        M     U" S5        gUS:X  aq  U  Hj  u  pEpgnU" SXVU4-  5        U" S5        U H  u  pU" SU	 S[	        U
5       S35        M     U" S5        U H  u  pU" SU	 S[	        U
5       S35        M     Ml     gg)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   :
r   z  File "z", line z, in z    %s
r   z%s:%d: %s(...)
zA [Capture of Locals and Globals disabled (use captureVars=True)]
r   z [ Locals ]
z  z : z ( Globals )
N)
ValueError	linecachegetlinestriprepr)frameswritedetailwmethodfilenamelineno	localVars
globalVarsnamevals              r   format_framesr3   *   s   " QQ5;>
 	
 	A?E;Ff
!F81VHB/0 @F	9	?E;Ff
(6(%xrBCj9,,X>DDFFG @F 
.	.?E;Ff Hf#==> @F	
NO	9	?E;Ff Hf#==>o&	BtfCS	{"-. ''	BtfCS	{"-. ( @F 
r   z--- <exception caught here> ---c                      \ rS rSrSrSrg)NoCurrentExceptionError\   z~
Raised when trying to create a Failure from the current interpreter
exception state and there is no current exception state.
r   N)r   r   r   r   __doc__r   r   r   r   r5   r5   \   s    r   r5   c                    [        U 5      S:  d   S5       eSn[        U S   U5      n[        U5      =p#U SS  H*  n[        XA5      n[        U5      Ul        UR                  nM,     U$ )z
Construct a fake traceback object using a list of frames.

It should have the same API as stdlib to allow interaction with
other tools.

@param tbFrames: [(methodname, filename, lineno, locals, globals), ...]
r   zMust pass some framesN   )len_Frame_TracebackFrametb_next)tbFramesstackfirstTbtbsfs        r   
_TracebackrC   c   sx     x=1555 E 8A;&E"5))Gqrlr!$U+
ZZ  Nr   c                      \ rS rSrSrS rSrg)r<      ze
Fake traceback object which can be passed to functions in the standard
library L{traceback} module.
c                b    Xl         UR                  U l        UR                  U l        SU l        g)z
@param frame: _Frame object
N)tb_framef_lineno	tb_linenof_lastitb_lastir=   )selfframes     r   __init___TracebackFrame.__init__   s&     r   )rG   rK   rI   r=   Nr   r   r   r   r7   rN   r   r   r   r   r<   r<      s    
r   r<   c                      \ rS rSrSrS rSrg)r;      a(  
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                   Uu  p4pVn[        X45      U l        XPl        [        U=(       d    0 5      U l        [        U=(       d    0 5      U l        X l        SU l        [        [        5      R                  5       U l        SU l        g)z
@param frameinfo: (methodname, filename, lineno, locals, globals)
@param back: previous (older) stack frame
@type back: C{frame}
r   N)_Codef_coderH   dict	f_globalsf_localsf_backrJ   varsbuiltinscopy
f_builtinsf_trace)rL   	frameinfobackr1   r-   r.   localzglobalzs           r   rN   _Frame.__init__   sh     3</D+gm,V\r*x.--/r   )rY   r]   rU   rW   rJ   rH   rX   r^   NrP   r   r   r   r;   r;      s    r   r;   c                  $    \ rS rSrSrS rS rSrg)rT      z
A fake code object, used by L{_Traceback} via L{_Frame}.

It is intended to have the same API as the stdlib code type to allow
interoperation with other tools based on that interface.
c                    Xl         X l        SU l        SU l        SU l        / U l        SU l        SU l        SU l        SU l	        SU l
        SU l        SU l        SU l        SU l        SU l        g )Nr   r   r   )co_nameco_filename	co_lnotabco_firstlinenoco_argcountco_varnamesco_codeco_cellvars	co_constsco_flagsco_freevarsco_posonlyargcountco_kwonlyargcountco_names
co_nlocalsco_stacksize)rL   r1   r-   s      r   rN   _Code.__init__   sw    #"#!"r   c                    g)N))NNNNr   rL   s    r   co_positions_Code.co_positions   s    *r   )rk   rn   rm   ro   rh   rj   rp   rq   rs   ri   rg   rt   ru   rr   rv   rl   N)r   r   r   r   r7   rN   rz   r   r   r   r   rT   rT      s    $+r   rT   c                D    [         R                  U R                  5        U $ )z
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   _extraneousr      s     %%ajj1Hr   c                     \ rS rSrSrSrSrS#S jr\S 5       r	\	R                  S 5       r	\" \" SS	S
S5      5      S 5       r\R                  S 5       r\S 5       r\R                  S 5       rS r\S$S j5       rS rS rS%S jr\S 5       rS&S jrS&S jrS rS rS rS rS rS&S jrS&S jrS'S(S jjr S)S jr!S*S  jr"S*S! jr#S"r$g)+Failure   a  
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{frame} attribute contain the traceback 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.

Local/global variables in C{frame} will only be captured if
C{captureVars=True} when constructing the L{Failure}.

@ivar value: The exception instance responsible for this failure.

@ivar type: The exception's class.

@ivar stack: Deprecated, always an empty list.  Equivalent information can
    be extracted from C{import traceback;
    traceback.extract_stack(your_failure.tb)}

@ivar frames: list of frames, innermost first.
r   Nc                n   [         S-   q [         U l         S=U l        =U l        nX@l        Uc;  [        R
                  " 5       u  U l        U l        nU R                  c
  [        5       eOMUc>  [        U[        5      (       a  UR                  U l        O[        U5      U l        Xl        OX l        Xl        [        U R                  [        5      (       a  U R                  U R                  5        gUc<  U(       a  UnO2[        U R                  SS5      (       a  U R                  R                  nXPl        g)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}.
r9   N__traceback__)counttypevaluecaptureVarssysexc_infor5   
isinstance	Exception	__class__r   _extrapolategetattrr   rA   )rL   	exc_valueexc_typeexc_tbr   rA   s         r   rN   Failure.__init__   s    2 	
&**	*DJ&(+%DItz2yy -// !)Y//%//	 !O	"J I"Jdjj'**djj):_d;;ZZ--r   c                   [        U S5      (       a  U R                  $ / =ol        U R                  nUGb  UR                  nU R                  (       a  UR
                  R                  5       nUR
                  UR                  L a  0 nOUR                  R                  5       nXT4 H  nSU;   d  M  US	 M     [        UR                  5       5      n[        UR                  5       5      nOS=pEUR                  UR                  R                  UR                  R                  UR                  UU45        UR                  nUb  GM  U$ )N_frames__builtins__r   )hasattrr   rA   rG   r   rX   r\   rW   listitemsr~   rU   rg   rh   rI   r=   )rL   r(   rA   r   ra   rb   ds          r   r(   Failure.frames8  s   4##<< ""WWnA*::, Gkk..0G A%*n- ) flln-w}}/#%%MMHH$$HH((LL B1 n2 r   c                    Xl         g N)r   )rL   r(   s     r   r(   r   [  s    r   Twisted   
   c                    / $ r   r   ry   s    r   r?   Failure.stack_  s    	r   c                    Ag r   r   )rL   r?   s     r   r?   r   c  s    r   c                   U R                   b  U R                   $ [        R                  " U R                  5      (       ah  [	        U R                  [
        5      (       aI  [        U R                  5      n[        [        [        R                  U5      5      U l         U R                   $ U R                  /U l         U R                   $ r   )_parentsinspectisclassr   
issubclassr   r   r   mapr   qual)rL   parentCss     r   parentsFailure.parentsg  s    ==$== ??499%%*TYY	*J*Jdii(H W\\8!<=DM }} "YYKDM}}r   c                    Xl         g r   )r   )rL   r   s     r   r   r   s  s    r   c                N    [         R                   " UR                  5      U l        g)z
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}
N)r\   __dict__)rL   otherFailures     r   r   Failure._extrapolatew  s     		,"7"78r   c                    [         R                  [         5      n[        S-  qSUl        [        Ul        Xl        U R
                  Ul        SUl        U$ )z
Create a L{Failure} for an exception without a traceback.

By restricting the inputs significantly, this constructor runs much
faster.
r9   FN)r   __new__r   r   r   r   r   rA   )r   results     r   _withoutTracebackFailure._withoutTraceback  sF     )
"oo	r   c                R    U R                   " U6 nU(       d  U R                  5         U$ )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)rL   
errorTypeserrors      r   trapFailure.trap  s&    0 

J'!r   c                    U H^  nUn[         R                  " U5      (       a+  [        U[        5      (       a  [        R
                  " U5      nX0R                  ;   d  M\  Us  $    g)z
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   r   r   r   r   )rL   r   r   errs       r   r   Failure.check  sP      ECu%%*UI*F*Fll5)ll"   r   c                L    U R                   R                  U R                  5      e)zN
raise the original exception, preserving traceback
information if available.
)r   with_tracebackrA   ry   s    r   r   Failure.raiseException  s    
 jj''00r   c                j    UR                  U R                  R                  U R                  5      5      $ )a  
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   rA   )rL   gs     r   throwExceptionIntoGenerator#Failure.throwExceptionIntoGenerator  s&     wwtzz009::r   c                    SR                  [        R                  " U R                  5      [        R                  " U R                  5      U R                  5       5      $ )Nz<{} {}: {}>)formatr   r   r   r   getErrorMessagery   s    r   __repr__Failure.__repr__  sA    ##LL(LL#  "
 	
r   c                (    SU R                  5       -  $ )Nz[Failure instance: %s])getBriefTracebackry   s    r   __str__Failure.__str__  s    '$*@*@*BBBr   c                    SU;   a  UR                  S5        UR                  S5      US'   UR                  S5      US'   U R                  R                  U5        g )Nr?   r   r   r(   r   )popr   updaterL   states     r   __setstate__Failure.__setstate__  sN    eIIg!IIi0j 99X.iU#r   c                   U R                   nU R                  R                  5       nUR                  S5      US'   / US'   SU;   a  UR                  S5        U R                  (       aG  U R
                   Vs/ s H+  nUS   US   US   [        US   5      [        US	   5      /PM-     snUS
'   OU R
                  US
'   SUS'   SUS'   U$ s  snf )z
Avoid pickling objects in the traceback.

This is not called direclty by pickle, since C{BaseException}
implements reduce; instead, pickle calls C{Failure.__reduce__} which
then calls this API.
r   r   r?   r   r   r9         r   r(   NrA   pickled)r   r   r\   r   r   r(   _safeReprVars)rL   _cvs       r   __getstate__Failure.__getstate__  s     LLMM  uuZ()'
>EE) 	 %A aDaDaD!!A$'!!A$' %	AhK ++AhK $)#	s   62C
c                `    [        [        R                  [        5      SU R                  5       4$ )Nr   )r   r   r   r   ry   s    r   
__reduce__Failure.__reduce__  s%     12t7H7H7JKKr   c                    U R                  5       nUR                  S5      US'   Xl        [        U R                  SS5      (       a  SU R                  l        gg)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(   r   r   N)r   r   r   r   r   r   r   s     r   cleanFailureFailure.cleanFailure  sN     !!# 99X.i4::55'+DJJ$ 6r   c                    U R                   b  U R                   $ [        U R                  5      S:  a  [        U R                  5      $ g)aY  
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   )rA   r:   r(   rC   ry   s    r   getTracebackObjectFailure.getTracebackObject!  s:     7777N!dkk**r   c                    [        U R                  [        5      (       a  U R                  R                  5       $ [        R
                  " U R                  5      $ )z:
Get a string of the exception which caused this Failure.
)r   r   r   r   r   safe_strry   s    r   r   Failure.getErrorMessage2  s=     djj'**::--//

++r   c                T    [        5       nU R                  US9  UR                  5       $ )N)file)r   printBriefTracebackgetvalue)rL   ios     r   r   Failure.getBriefTraceback:  s&    Z  b ){{}r   c                V    [        5       nU R                  X1US9  UR                  5       $ )N)r   elideFrameworkCoder*   )r   printTracebackr   )rL   r   r*   r   s       r   getTracebackFailure.getTraceback?  s/    Z6 	 	
 {{}r   c           	        Uc  SSK Jn  UR                  nUR                  nUS:X  a  U R                  (       d  SnOUnUS:X  a4  U" SU R
                  U R                  =(       a    S=(       d    S4-  5        OuUS	:X  ag  U R                  (       a  S
nOSnU" U< S[        R                  " U R                  5      < S[        R                  " U R                  5      < S35        OU" S5        U R                  (       a  [        U R                  XV5        OUS	:X  d  U" S5        US	:X  dJ  U" [        R                  " U R                  5       S[        R                  " U R                  5       S35        [        U R                  [        5      (       a-  UR                  S5        U R                  R!                  XU5        US:X  a  U" SU R
                  -  5        gg)aT  
Emulate Python's standard error reporting mechanism.

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

@param elideFrameworkCode: Deprecated, ignored.

@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   )logr   r   z*--- Failure #%d%s---
z (pickled)  r   	Tracebackz"Traceback (failure with no frames)z: r"   z#Traceback (most recent call last):
z	Failure: z (chained Failure)
z*--- End of Failure #%d ---
)twisted.pythonr   logerrr)   r   r   r   r(   r   r   r   r   r3   r   r   r   r   )rL   r   r   r*   r   r+   formatDetail	hasFramess           r   r   Failure.printTracebackF  s~    <*::DJJYt'7'7 7L!L Y):: >F3GH w{{'	@	g..tyy97;K;KDJJ;WY
 45 ;;$++q77"kN  dii()G,<,<TZZ,H+ILM djj'**JJ-.JJ%%dGY-

:; r   c                $    U R                  XSS9  g)z+
Print a traceback as densely as possible.
r   r*   Nr   rL   r   r   s      r   r   Failure.printBriefTraceback  s     	DWEr   c                $    U R                  XSS9  g)zA
Print a traceback with detailed locals and globals information.
r   r  Nr  r	  s      r   printDetailedTracebackFailure.printDetailedTraceback  s     	DYGr   )r   r   r   r   r   rA   r   r   )NNNF)r   BaseExceptionreturnr   )r  r   )r  str)r   r   )r   intr*   r  r  r  )NFr   )Nr   )%r   r   r   r   r7   r   r   rN   propertyr(   setterr   r
   r?   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   r      s1   4 GH7r    D ]]  	2r156 7 \\  	 	 ^^   
9  ": 1 	; 	;
C$&PL
,",
?<BFHr   r   c                h    U  VVs/ s H  u  pU[         R                  " U5      4PM     snn$ s  snnf )aU  
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)varsDictItemsr1   objs      r   r   r     s/     ?LLm{T7$$S)*mLLLs   $.TFc                4   XU4S:X  at  [         R                  " 5       nUS   U R                  :X  dL  [        (       aA   [	        US   5      n[        SR                  U5      5        SSKnUR                  US   5        U" XX#U5        g! [
         a    Sn NKf = f)z3
Initialize failure object, possibly spawning pdb.
)NNNr   r9   z
broken strz8Jumping into debugger for post-mortem of exception '{}':Nr   )
r   r   r   DO_POST_MORTEMr  r  printr   pdbpost_mortem)	rL   r   r   r   r   Failure__init__excstrreprr  s	            r   
_debuginitr!    s     	V$(::lln1v'NN'c!f+ JQQ
 OOCF#DX{C ! '&'s   B BBc                 "    [         [        l        g)z"
Enable debug hooks for Failures.
N)r!  r   rN   r   r   r   startDebugModer#    s     "Gr   )r   )r   r   r  r   )-r7   
__future__r   r[   r\   r   r$   r   	functoolsr   r   r   r   typingr   r   r	   incrementalr
   r  r   twisted.python.deprecater   objectr   r   traceupLengthr   r   r3   EXCEPTION_CAUGHT_HEREr5   rC   r<   r;   rT   r}   r   r  r   r   r  rN   r!  r#  r   r   r   <module>r,     s    #     
    . .  " 7m8CK+@A		y 	+/^ : i B   8+ +<    pHm pHfM  
 $$D:"r   