
    h&              
          % S r SSKrSSKrSSKrSSKJr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JrJrJrJrJrJrJrJrJrJrJr  SSKJrJr  SS	KJ r J!r!J"r"J#r#J$r$J%r%  SS
K&J'r(J)r*J+r,  SSK-J.r.J/r/  SSK0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9J:r:J;r;J<r<J=r=J>r>J?r?  SSK@JArA  SSKBJCrC  SSKDJErE  SSKFJGrG  SSKHJIrJ  SSKKJLrLJMrN  SSKOJPrPJQrQJRrR  \(       a  SSKSJTrT  SSKDJUrU  \LR                  " 5       (       a  SSKWJXrX  OSrX\C" 5       rY\YR                  S5      r[\YR                  S5      r\\YR                  S5      r]\" \35       " S S5      5       r^\" \=5       " S S5      5       r_\" \=5       " S S 5      5       r`\S!\4   ra\\a\\bS!4   \\c\b4   4   rd\" S"\\c\a\\bS!4   \\c\b4   4   5      re " S# S$5      rf\" \8\95       " S% S&5      5       rg\" S'\\c\e4   5      rh\\S!\4   \\bS!4   \\c\b4   4   ri\YR                  S(5      rj\" \6\;\?5       " S) S*\g5      5       rk\LR                  " 5       (       a	  \" \k\:5        \" \25       " S+ S,\5      5       rl " S- S.\ R                  5      rn/ ro\\c   \pS/'   g)0z8
Very basic functionality for a Reactor implementation.
    N)ABCabstractmethod)heapifyheappopheappush)format_stack)	FrameType)TYPE_CHECKINGAnyCallableDictListNewTypeOptionalSequenceSetTupleUnioncast)classImplementsimplementer)abstractdefererrorfdescmainthreads)ComplexResolverSimplifierGAIResolverSimpleResolverComplexifier)DeferredDeferredList)IAddress
IConnectorIDelayedCallIHostnameResolver	IProtocolIReactorCoreIReactorFromThreadsIReactorPluggableNameResolverIReactorPluggableResolverIReactorThreadsIReactorTimeIReadDescriptorIResolverSimpleIWriteDescriptor_ISupportsExitSignalCapturing)ClientFactory)Logger)reflect)Failure)callWithLogger)platformseconds   )SignalHandling_WithoutSignalHandling_WithSignalHandling)Client)
threadable)
ThreadPoolzUnexpected error in main loopzwhile calling from threadz*While calling system event trigger handlerc                   :   \ rS rSr% SrSr\\   \S'   Sr	\\
\      \S'   \4S\S\S\4   S	\
\   S
\\\4   S\S /S4   S\S /S4   S\/ \4   SS4S jjrS\4S jrSS jrS\SS4S jrS\SS4S jrSS jrS\4S jrSS S\4S jrSS S\4S jrS\4S jrSrg)DelayedCallW   FN_reprcreatortimefunc.argskwcancelresetr8   returnc                     XX44u  U l         U l        U l        U l        X`l        XPl        Xpl        S=U l        U l        SU l	        U R                  (       a  [        5       SS U l        gg)a  
@param time: Seconds from the epoch at which to call C{func}.
@param func: The callable to call.
@param args: The positional arguments to pass to the callable.
@param kw: The keyword arguments to pass to the callable.
@param cancel: A callable which will be called with this
    DelayedCall before cancellation.
@param reset: A callable which will be called with this
    DelayedCall after changing this DelayedCall's scheduled
    execution time. The callable should adjust any necessary
    scheduling details to ensure this DelayedCall is invoked
    at the new appropriate time.
@param seconds: If provided, a no-argument callable which will be
    used to determine the current time any time that information is
    needed.
r           N)rE   rF   rG   rH   resetter	cancellerr8   	cancelledcalleddelayed_timedebugr   rD   )selfrE   rF   rG   rH   rI   rJ   r8   s           \/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/internet/base.py__init__DelayedCall.__init__a   s`    4 48t3G0	49di'((::'>#2.DL     c                 4    U R                   U R                  -   $ )z
Return the time at which this call will fire

@return: The number of seconds after the epoch at which this call is
    scheduled to be made.
rE   rS   rU   s    rV   getTimeDelayedCall.getTime   s     yy4,,,,rY   c                    U R                   (       a  [        R                  eU R                  (       a  [        R                  eU R                  U 5        SU l         U R                  (       a  [        U 5      U l        U ?	U ?
U ?g)z
Unschedule this call

@raise AlreadyCancelled: Raised if this call has already been
    unscheduled.

@raise AlreadyCalled: Raised if this call has already been made.
r9   N)rQ   r   AlreadyCancelledrR   AlreadyCalledrP   rT   reprrC   rF   rG   rH   r\   s    rV   rI   DelayedCall.cancel   s\     >>((([[%%%NN4 DNzz!$Z
	49dgrY   secondsFromNowc                 0   U R                   (       a  [        R                  eU R                  (       a  [        R                  eU R                  5       U-   nX R                  :  a  SU l        X l        U R                  U 5        gX R                  -
  U l        g)a)  
Reschedule this call for a different time

@param secondsFromNow: The number of seconds from the time of the
    C{reset} call at which this call will be scheduled.

@raise AlreadyCancelled: Raised if this call has been cancelled.
@raise AlreadyCalled: Raised if this call has already been made.
rM   N)	rQ   r   r`   rR   ra   r8   rE   rS   rO   )rU   rd   newTimes      rV   rJ   DelayedCall.reset   sl     >>((([[%%%lln~5G"$'!#	d#$+ii$7!rY   secondsLaterc                    U R                   (       a  [        R                  eU R                  (       a  [        R                  eU =R
                  U-  sl        U R
                  S:  a"  U R                  5         U R                  U 5        gg)a!  
Reschedule this call for a later time

@param secondsLater: The number of seconds after the originally
    scheduled time for which to reschedule this call.

@raise AlreadyCancelled: Raised if this call has been cancelled.
@raise AlreadyCalled: Raised if this call has already been made.
rM   N)rQ   r   r`   rR   ra   rS   activate_delayrO   )rU   rh   s     rV   delayDelayedCall.delay   sf     >>((([[%%%-  3&##%d# 'rY   c                 P    U =R                   U R                  -  sl         SU l        g )NrM   r[   r\   s    rV   rj   DelayedCall.activate_delay   s    		T&&&	rY   c                 J    U R                   =(       d    U R                  (       + $ )zDetermine whether this call is still pending

@return: True if this call has not yet been made or cancelled,
    False otherwise.
)rQ   rR   r\   s    rV   activeDelayedCall.active   s     NN1dkk22rY   otherc                 4    U R                   UR                   :*  $ )z
Implement C{<=} operator between two L{DelayedCall} instances.

Comparison is based on the C{time} attribute (unadjusted by the
delayed time).
rE   rU   rr   s     rV   __le__DelayedCall.__le__   s     yyEJJ&&rY   c                 4    U R                   UR                   :  $ )z
Implement C{<} operator between two L{DelayedCall} instances.

Comparison is based on the C{time} attribute (unadjusted by the
delayed time).
rt   ru   s     rV   __lt__DelayedCall.__lt__   s     yy5::%%rY   c                    U R                   b  U R                   $ [        U S5      (       ay  [        U R                  SS5      nUc;  [        U R                  SS5      nUb!  [        U R                  SS5      nUb  U SU 3nUc   [        R
                  " U R                  5      nOSnU R                  5       nS[        U 5      U R                  U-
  U R                  U R                  4-  /nUGb  UR                  SUS	45        U R                  (       aq  UR                  S
R                  U R                   Vs/ s H  n[        R
                  " U5      PM     sn5      5        U R                  (       a  UR                  S
5        U R                  (       af  UR                  S
R                  U R                  R!                  5        VVs/ s H   u  pgU S[        R
                  " U5       3PM"     snn5      5        UR                  S5        U R"                  b-  UR                  SSR                  U R"                  5      -  5        UR                  S5        SR                  U5      $ s  snf s  snnf )zo
Implement C{repr()} for L{DelayedCall} instances.

@returns: String containing details of the L{DelayedCall}.
NrF   __qualname____name__im_class.z.<DelayedCall 0x%x [%ss] called=%s cancelled=%s (z, =)z

traceback at creation: 

%sz    > )rC   hasattrgetattrrF   r4   	safe_reprr8   idrE   rR   rQ   extendrG   appendjoinrH   itemsrD   )rU   rF   imClassnowLekvs           rV   __repr__DelayedCall.__repr__   s    ::!::4   499nd;D|tyy*d;#%diiTBG*")!D62|((3Dlln<$xS$++t~~FG
 HHc4%&yy$))#L)QG$5$5a$8)#LMN77HHTNwwIIEIWW]]_U_6AA3a 1 1! 456_U
 HHSM<<#HH8FKK<UVW	wwqz $M Vs   7 I('I-)rC   rG   rR   rQ   rP   rD   rS   rF   rH   rO   r8   rE   rK   N)r}   
__module__r|   __firstlineno__rT   rC   r   str__annotations__rD   r   runtimeSecondsfloatr   r   objectr   rW   r]   rI   rJ   rk   rj   boolrp   rv   ry   r   __static_attributes__ rY   rV   rA   rA   W   s7    EE8C= (,GXhsm$+ (6!/!/ sCx !/ v	!/
 f!/ -$./!/ -.!/ "e)$!/ 
!/F- -.(8E 8d 8.$% $D $( 3 3'M 'd '&M &d &.# .rY   rA   c                       \ rS rSrSrSS jrS\S\S\4S jrS\S	\	\   SS4S
 jr
S\\\4   S\S	\	\   SS4S jr SS\S\\   S\	\   4S jjrSrg)ThreadedResolveri  a  
L{ThreadedResolver} uses a reactor, a threadpool, and
L{socket.gethostbyname} to perform name lookups without blocking the
reactor thread.  It also supports timeouts indepedently from whatever
timeout logic L{socket.gethostbyname} might have.

@ivar reactor: The reactor the threadpool of which will be used to call
    L{socket.gethostbyname} and the I/O thread of which the result will be
    delivered.
rK   Nc                     Xl         0 U l        g N)reactor_runningQueries)rU   r   s     rV   rW   ThreadedResolver.__init__(  s      	rY   nameerrc                 R    [         R                  " SU< SU 35      n[        U5      $ )Naddress z not found: )r   DNSLookupErrorr5   )rU   r   r   lookupErrors       rV   _failThreadedResolver._fail.  s*    **XdX\#+OP{##rY   lookupDeferredc                     U R                   U   u  p4U R                   U	 UR                  U R                  US5      5        g )Nztimeout error)r   errbackr   )rU   r   r   userDeferred
cancelCalls        rV   _cleanupThreadedResolver._cleanup2  s<    #'#7#7#G   0TZZo>?rY   resultc                 ,    U R                   U   u  pEU R                   U	 UR                  5         [        U[        5      (       a/  UR	                  U R                  X!R                  5       5      5        g UR                  U5        g ! [         a     g f = fr   )	r   rI   
isinstancer5   r   r   getErrorMessagecallbackKeyError)rU   r   r   r   r   r   s         rV   _checkTimeoutThreadedResolver._checkTimeout7  s    	.'+';';N'K$L $$^4&'**$$TZZ6L6L6N%OP%%f-  		s   B 
BBtimeoutc                    U(       a  [        U5      nOSn[        5       n[        R                  " [	        [
        U R                  5      [	        [        U R                  5      R                  5       [        R                  U5      n[	        [        U R                  5      R                  X0R                  X5      nXF4U R                  U'   UR                  U R                   X5      nU$ )a	  
See L{twisted.internet.interfaces.IResolverSimple.getHostByName}.

Note that the elements of C{timeout} are summed and the result is used
as a timeout for the lookup.  Any intermediate timeout or retry logic
is left up to the platform via L{socket.gethostbyname}.
<   )sumr!   r   deferToThreadPoolr   r)   r   r,   getThreadPoolsocketgethostbynamer-   	callLaterr   r   addBothr   )rU   r   r   timeoutDelayr   r   r   _s           rV   getHostByNameThreadedResolver.getHostByNameG  s     w<LL&.j 22$dll3$,,/==?  	
 ,5??--

 1=/I^,*22
 rY   )r   r   )r   ReactorBaserK   N)r9         -   )r}   r   r|   r   __doc__rW   r   r5   r   r!   r   r   r   r   intr   r   r   rY   rV   r   r     s    	$# $C $G $@S @(3- @D @
.CL).14.FNsm.	." 3A"*3-	# rY   r   c                   <    \ rS rSr SS\S\\   S\\   4S jjrSr	g)	BlockingResolverif  r   r   rK   c                      [         R                  " U5      n[        R                  " U5      $ ! [         a6    SU< S3n[
        R                  " U5      n[        R                  " U5      s $ f = f)Nr   z
 not found)r   r   r   succeedOSErrorr   r   fail)rU   r   r   addressmsgr   s         rV   r   BlockingResolver.getHostByNameh  se    	***40G ==))  	#THJ/C&&s+C::c?"	#s   . =A.-A.r   Nr   )
r}   r   r|   r   r   r   r   r!   r   r   r   rY   rV   r   r   f  s2     3A
*
*"*3-
*	#
* 
*rY   r   ._ThreePhaseEventTriggerHandlec            
           \ rS rSrSrSS jrS\S\S\S	\S\	4
S
 jr
S\	SS4S jrS\	SS4S jrS\	SS4S jrSS jrS\SS4S jrSrg)_ThreePhaseEventi  a  
Collection of callables (with arguments) which can be invoked as a group in
a particular order.

This provides the underlying implementation for the reactor's system event
triggers.  An instance of this class tracks triggers for all phases of a
single type of event.

@ivar before: A list of the before-phase triggers containing three-tuples
    of a callable, a tuple of positional arguments, and a dict of keyword
    arguments

@ivar finishedBefore: A list of the before-phase triggers which have
    already been executed.  This is only populated in the C{'BEFORE'} state.

@ivar during: A list of the during-phase triggers containing three-tuples
    of a callable, a tuple of positional arguments, and a dict of keyword
    arguments

@ivar after: A list of the after-phase triggers containing three-tuples
    of a callable, a tuple of positional arguments, and a dict of keyword
    arguments

@ivar state: A string indicating what is currently going on with this
    object.  One of C{'BASE'} (for when nothing in particular is happening;
    this is the initial value), C{'BEFORE'} (when the before-phase triggers
    are in the process of being executed).
rK   Nc                 <    / U l         / U l        / U l        SU l        g )NBASE)beforeduringafterstater\   s    rV   rW   _ThreePhaseEvent.__init__  s    575746

rY   phasecallablerG   kwargsc                 v    US;  a  [        S5      e[        X5      R                  X#U45        [        XX445      $ )a  
Add a trigger to the indicate phase.

@param phase: One of C{'before'}, C{'during'}, or C{'after'}.

@param callable: An object to be called when this event is triggered.
@param args: Positional arguments to pass to C{callable}.
@param kwargs: Keyword arguments to pass to C{callable}.

@return: An opaque handle which may be passed to L{removeTrigger} to
    reverse the effects of calling this method.
r   r   r   invalid phase)r   r   r   r   )rU   r   r   rG   r   s        rV   
addTrigger_ThreePhaseEvent.addTrigger  s@    & 55?++##XV$<=,et-LMMrY   handlec                 B    [        U SU R                  -   5      " U5        g)a#  
Remove a previously added trigger callable.

@param handle: An object previously returned by L{addTrigger}.  The
    trigger added by that call will be removed.

@raise ValueError: If the trigger associated with C{handle} has already
    been removed or if C{handle} is not a valid handle.
removeTrigger_N)r   r   )rU   r   s     rV   removeTrigger_ThreePhaseEvent.removeTrigger  s     	&34V<rY   c                      Uu  p#pEUS;  a  [        S5      e[        X5      R                  X4U45        g! [        [        4 a    [	        S5      ef = f)z6
Just try to remove the trigger.

@see: removeTrigger
r   r   zinvalid trigger handleN)r   r   remove	TypeError
ValueErrorrU   r   r   r   rG   r   s         rV   removeTrigger_BASE#_ThreePhaseEvent.removeTrigger_BASE  sb    	B,2)ET 99//D ''(@A :& 	7566	7s	   5 Ac                     Uu  p#pEUS:w  a  U R                  U5      $ X4U4U R                  ;   a  [        R                  " S[        SS9  gU R                  U5        g)z
Remove the trigger if it has yet to be executed, otherwise emit a
warning that in the future an exception will be raised when removing an
already-executed trigger.

@see: removeTrigger
r   zdRemoving already-fired system event triggers will raise an exception in a future version of Twisted.r   )category
stacklevelN)r   finishedBeforewarningswarnDeprecationWarningr   s         rV   removeTrigger_BEFORE%_ThreePhaseEvent.removeTrigger_BEFORE  sa     )/%H**622F#t':'::MM<+	 ##F+rY   c                    SU l         / U l        / nU R                  (       a  U R                  R                  S5      u  p#nU R                  R	                  X#U45        Sn[
           U" U0 UD6nSSS5        [        U[        5      (       a  UR	                  U5        U R                  (       a  M  [        U5      R                  U R                  5        g! , (       d  f       Nl= f)z(
Call the triggers added to this event.
BEFOREr   N)r   r   r   popr   _systemEventHandlerr   r!   r"   addCallback_continueFiring)rU   beforeResultsr   rG   r   r   s         rV   	fireEvent_ThreePhaseEvent.fireEvent  s     
 02kk%)[[__Q%7"HF&&'?@F$!4262 %&(++$$V, kkk 	]#//0D0DE	 %$s   %	C
C"ignoredc                     SU l         / U l        U R                  U R                  4 H@  nU(       d  M  UR	                  S5      u  p4n[
           U" U0 UD6  SSS5        U(       a  M4  MB     g! , (       d  f       N= f)z:
Call the during and after phase triggers for this event.
r   r   N)r   r   r   r   r  r  )rU   r  r   r   rG   r   s         rV   r	   _ThreePhaseEvent._continueFiring  sf     
 [[$**,E%).1&(d-f- ) % - )(s   	A,,
A:	)r   r   r   r   r   r   )r}   r   r|   r   r   rW   r   _ThreePhaseEventTriggerCallabler   r   r   r   r   r  r  r	  r   r   rY   rV   r   r     s    :NN 2N 	N
 N 
'N0
=$A 
=d 
=B)F B4 B,+H ,T ,*F"
.v 
.$ 
.rY   r   c                       \ rS rSr% Sr\" 5       r\\S'   \	" \5      r
\\S'   S\S\4S jrS\S\4S jr\S\4S j5       rS	rg
)PluggableResolverMixini	  z
A mixin which implements the pluggable resolver reactor interfaces.

@ivar resolver: The installed L{IResolverSimple}.
@ivar _nameResolver: The installed L{IHostnameResolver}.
resolver_nameResolverrK   c                     [         R                  " U5      (       d   eU R                  nXl        [        U5      U l        U$ )z
See L{IReactorPluggableResolver}.

@param resolver: see L{IReactorPluggableResolver}.

@return: see L{IReactorPluggableResolver}.
)r/   
providedByr  _SimpleResolverComplexifierr  )rU   r  oldResolvers      rV   installResolver&PluggableResolverMixin.installResolver  s<     ))(3333mm 8BrY   c                 J    U R                   nXl         [        U5      U l        U$ )z
See L{IReactorPluggableNameResolver}.

@param resolver: See L{IReactorPluggableNameResolver}.

@return: see L{IReactorPluggableNameResolver}.
)r  _ComplexResolverSimplifierr  )rU   r  previousNameResolvers      rV   installNameResolver*PluggableResolverMixin.installNameResolver%  s(      $11%28<##rY   c                     U R                   $ )zL
Implementation of read-only
L{IReactorPluggableNameResolver.nameResolver}.
)r  r\   s    rV   nameResolver#PluggableResolverMixin.nameResolver2  s     !!!rY   )r  r  N)r}   r   r|   r   r   r   r  r/   r   r  r  r&   r  r  propertyr!  r   r   rY   rV   r  r  	  sj     !1 2Ho2'B8'LM$L O $,= $BS $ "/ " "rY   r  _SystemEventIDzwhile handling timed callc                     ^  \ rS rSr% SrSrSrSrSrSr	\
" 5       r\\S'   Sr SNU 4S	 jjrSr\\S
'   S\S\4S jrS\4S jrS\SS4S jrS\SS4S jrSOS\SS4S jjrSNS jrSrSNS jrSNS jrS\\   SS4S jrS\SS4S jrS\SS4S jr S\SS4S jr!S\SS4S jr"S\#\$\\4      4S jr%S\#\   4S jr&S\#\   4S jr' SPS\(S \)\*   S\+\(   4S! jjr,SNS" jr-SNS# jr.SQS$\*S%\\/   SS4S& jjr0SQS$\*S%\\/   SS4S' jjr1SQS$\*S%\\/   SS4S( jjr2SNS) jr3SRS\SS4S* jjr4S+\(SS4S, jr5S-\(S+\(S.\6S/\74   S0\8S1\8S\94S2 jr:S3\9SS4S4 jr;S.\6S/\74   S0\8S1\8S\\9   4S5 jr<SOS\SS4S6 jjr=SNS7 jr>\?" \@5      rAS\S.\6S/\74   S0\8S8\8S\B4
S9 jrCS:\BSS4S; jrDS:\BSS4S< jrES\)\F   4S= jrGSNS> jrHS\\   4S? jrISNS@ jrJ\KR                  " 5       (       aY  \Mc   eSrNSrOSrPSNSA jrQSB\6S/\74   S0\8S1\8SS4SC jrRSNSD jrSSNSE jrTSNSF jrUS\M4SG jrVSH\6S/\74   S0\8S1\8SS4SI jrWSJ\*SS4SK jrXSMrYU =rZ$ SB\6S/\74   S0\8S1\8SS4SL jrRSMrYU =rZ$ )Sr   iA  a  
Default base class for Reactors.

@ivar _stopped: A flag which is true between paired calls to C{reactor.run}
    and C{reactor.stop}.  This should be replaced with an explicit state
    machine.
@ivar _justStopped: A flag which is true between the time C{reactor.stop}
    is called and the time the shutdown system event is fired.  This is
    used to determine whether that event should be fired after each
    iteration through the mainloop.  This should be replaced with an
    explicit state machine.
@ivar _started: A flag which is true from the time C{reactor.run} is called
    until the time C{reactor.run} returns.  This is used to prevent calls
    to C{reactor.run} on a running reactor.  This should be replaced with
    an explicit state machine.
@ivar running: See L{IReactorCore.running}
@ivar _registerAsIOThread: A flag controlling whether the reactor will
    register the thread it is running in as the I/O thread when it starts.
    If C{True}, registration will be done, otherwise it will not be.
@ivar _exitSignal: See L{_ISupportsExitSignalCapturing._exitSignal}

@ivar _installSignalHandlers: A flag which indicates whether any signal
    handlers will be installed during startup.  This includes handlers for
    SIGCHLD to monitor child processes, and SIGINT, SIGTERM, and SIGBREAK

@ivar _signals: An object which knows how to install and uninstall the
    reactor's signal-handling behavior.
TFN_signalstwisted.internet.reactorrK   c                   > [         TU ]  5         / U l        0 U l        / U l        / U l        SU l        SU l        SU l        SU l	        SU l
        [        5       U l        S U l        U R                  SSU R                  5        U R                  SSU R                   5        U R                  SSU R"                  5        [$        R&                  " 5       (       a  U R)                  5         U R+                  5         g )Nr   Fr   startupshutdown)superrW   threadCallQueue_eventTriggers_pendingTimedCalls_newTimedCalls_cancellationsrunning_started_justStopped_startedBeforeset_internalReaderswakeraddSystemEventTrigger_reallyStartRunningcrashdisconnectAllr7   supportsThreads_initThreadsinstallWaker)rU   	__class__s    rV   rW   ReactorBase.__init__o  s    24;=5713!# +.%

 	""8Y8P8PQ""8ZD""8Z9K9KL##%%rY   _installSignalHandlersinstallSignalHandlersc                 D    U(       a  U R                  5       $ [        5       $ )z
Get an appropriate signal handling object.

@param installSignalHandlers: Indicate whether to even try to do any
    signal handling.  If C{False} then the result will be a no-op
    implementation.
)_signalsFactoryr;   rU   rB  s     rV   _makeSignalHandlingReactorBase._makeSignalHandling  s     !''))%''rY   c                 X    [        U R                  U R                  U R                  5      $ )z{
Get a signal handling object that implements the basic behavior of
stopping the reactor on SIGINT, SIGBREAK, and SIGTERM.
)r<   sigIntsigBreaksigTermr\   s    rV   rD  ReactorBase._signalsFactory  s&    
 #KKMMLL
 	
rY   readerc                 \    U R                   R                  U5        U R                  U5        g)z
Add a read descriptor which is part of the implementation of the
reactor itself.

The read descriptor will not be removed by L{IReactorFDSet.removeAll}.
N)r6  add	addReaderrU   rM  s     rV   _addInternalReaderReactorBase._addInternalReader  s$     	!!&)vrY   c                 \    U R                   R                  U5        U R                  U5        g)zU
Remove a read descriptor which is part of the implementation of the
reactor itself.
N)r6  r   removeReaderrQ  s     rV   _removeInternalReader!ReactorBase._removeInternalReader  s&    
 	$$V,&!rY   c                     U R                  US9   U R                  5         U R                  R                  5         g ! U R                  R                  5         f = f)N)rB  )startRunningmainLoopr&  	uninstallrE  s     rV   runReactorBase.run  sC    0EF	&MMOMM##%DMM##%s	   < Ac                 B   U R                   (       ah  [           U R                  5         U R                  5       nU R                  =(       a    UnU R                  U5        S S S 5        U R                   (       a  Mh  [        R                  S5        g ! , (       d  f       N7= f)NzMain loop terminated.)r2  _topHandlerrunUntilCurrentr   r1  doIteration_loginfo)rU   t2ts      rV   rZ  ReactorBase.mainLoop  sf    mm$$&\\^LL'R  #  mmm 			)* s   AB
Bc                 Z    [        [        R                  " U R                  5      S-   5      e)Nz did not implement installWakerNotImplementedErrorr4   qualr?  r\   s    rV   r>  ReactorBase.installWaker  %    !LL(+LL
 	
rY   c                 \    U R                   (       a  U R                   R                  5         gg)z
Wake up the event loop.
N)r7  wakeUpr\   s    rV   rn  ReactorBase.wakeUp  s      ::JJ rY   rk   c                 Z    [        [        R                  " U R                  5      S-   5      e)zF
Do one iteration over the readers and writers which have been added.
z did not implement doIterationrh  rU   rk   s     rV   ra  ReactorBase.doIteration  s'     "LL(+KK
 	
rY   c                 Z    [        [        R                  " U R                  5      S-   5      e)Nz did not implement addReaderrh  rQ  s     rV   rP  ReactorBase.addReader  %    !LL(+II
 	
rY   writerc                 Z    [        [        R                  " U R                  5      S-   5      e)Nz did not implement addWriterrh  rU   rv  s     rV   	addWriterReactorBase.addWriter  ru  rY   c                 Z    [        [        R                  " U R                  5      S-   5      e)Nz did not implement removeReaderrh  rQ  s     rV   rU  ReactorBase.removeReader  rl  rY   c                 Z    [        [        R                  " U R                  5      S-   5      e)Nz did not implement removeWriterrh  rx  s     rV   removeWriterReactorBase.removeWriter  rl  rY   c                 Z    [        [        R                  " U R                  5      S-   5      e)Nz did not implement removeAllrh  r\   s    rV   	removeAllReactorBase.removeAll  ru  rY   c                 Z    [        [        R                  " U R                  5      S-   5      e)Nz did not implement getReadersrh  r\   s    rV   
getReadersReactorBase.getReaders  %    !LL(+JJ
 	
rY   c                 Z    [        [        R                  " U R                  5      S-   5      e)Nz did not implement getWritersrh  r\   s    rV   
getWritersReactorBase.getWriters  r  rY   r   r   c                     U(       d  [         R                  " S5      $ [        R                  " U5      (       a  [         R                  " U5      $ U R                  R                  X5      $ )z0
Return a Deferred that will resolve a hostname.z0.0.0.0)r   r   r   isIPAddressr  r   )rU   r   r   s      rV   resolveReactorBase.resolve  sK    
 ==++%%==&&}}**499rY   c                 |    U R                   (       a  [        R                  " S5      eSU l         SU l        SU l        g)z4
See twisted.internet.interfaces.IReactorCore.stop.
z&Can't stop reactor that isn't running.TN)_stoppedr   ReactorNotRunningr3  r4  r\   s    rV   stopReactorBase.stop  s4     ==))*RSS "rY   c                 Z    SU l         SU l        U R                  SSU R                  5        g)z
See twisted.internet.interfaces.IReactorCore.crash.

Reset reactor state tracking attributes and re-initialize certain
state-transition helpers which were set up in C{__init__} but later
destroyed (through use).
Fr   r)  N)r2  r1  r8  r9  r\   s    rV   r:  ReactorBase.crash  s*     ""8Y8P8PQrY   numberframec                 p    [         R                  S5        U R                  U R                  5        Xl        g)z
Handle a SIGINT interrupt.

@param number: See handler specification in L{signal.signal}
@param frame: See handler specification in L{signal.signal}
zReceived SIGINT, shutting down.Nrb  rc  callFromThreadr  _exitSignalrU   r  r  s      rV   rI  ReactorBase.sigInt'  s)     			34DII&!rY   c                 p    [         R                  S5        U R                  U R                  5        Xl        g)z
Handle a SIGBREAK interrupt.

@param number: See handler specification in L{signal.signal}
@param frame: See handler specification in L{signal.signal}
z!Received SIGBREAK, shutting down.Nr  r  s      rV   rJ  ReactorBase.sigBreak2  s)     			56DII&!rY   c                 p    [         R                  S5        U R                  U R                  5        Xl        g)z
Handle a SIGTERM interrupt.

@param number: See handler specification in L{signal.signal}
@param frame: See handler specification in L{signal.signal}
z Received SIGTERM, shutting down.Nr  r  s      rV   rK  ReactorBase.sigTerm=  s)     			45DII&!rY   c                     U R                  5       nU H0  n[        X"R                  [        [        R
                  5      5        M2     g)z2Disconnect every reader, and writer in the system.N)r  _callWithLoggerconnectionLostr5   r   CONNECTION_LOST)rU   selectablesrM  s      rV   r;  ReactorBase.disconnectAllH  s6    nn&!F--wt7K7K/L "rY   c                 F    U R                  5         U R                  U5        g)z7
See twisted.internet.interfaces.IReactorCore.iterate.
N)r`  ra  rq  s     rV   iterateReactorBase.iterateP  s     	rY   	eventTypec                 b    U R                   R                  U5      nUb  UR                  5         gg)z?
See twisted.internet.interfaces.IReactorCore.fireSystemEvent.
N)r-  getr  )rU   r  events      rV   fireSystemEventReactorBase.fireSystemEventW  s/     ##''	2OO rY   r   r   .rG   r   c                     [         R                  " U5      (       d
   U S35       eX R                  ;  a  [        5       U R                  U'   [	        UU R                  U   R
                  " X/UQ70 UD645      $ )zE
See twisted.internet.interfaces.IReactorCore.addSystemEventTrigger.
 is not callable)builtinsr   r-  r   r$  r   )rU   r   r  r   rG   r   s         rV   r8  !ReactorBase.addSystemEventTrigger_  s       **Ixj8H,II*///-=-?D	*##I.99&*.4
 	
rY   	triggerIDc                 H    Uu  p#U R                   U   R                  U5        g)zH
See twisted.internet.interfaces.IReactorCore.removeSystemEventTrigger.
N)r-  r   )rU   r  r  r   s       rV   removeSystemEventTrigger$ReactorBase.removeSystemEventTriggerv  s%     &	I&44V<rY   c                 f    U R                   (       a	  U" U0 UD6  gU R                  " SSU/UQ70 UD6$ )z?
See twisted.internet.interfaces.IReactorCore.callWhenRunning.
Nr   r)  )r1  r8  )rU   r   rG   r   s       rV   callWhenRunningReactorBase.callWhenRunning}  sE     <<d%f%--H/37= rY   c                    U R                   (       a  [        R                  " 5       eU R                  (       a  [        R                  " 5       eU R
                  R                  5         Xl        U R                  U5      U l        SU l         SU l	        U R                  (       a  [        R                  " 5         U R                  S5        g)a   
Method called when reactor starts: do some initialization and fire
startup events.

Don't call this directly, call reactor.run() instead: it should take
care of calling this.

This method is somewhat misnamed.  The reactor will not necessarily be
in the running state by the time this method returns.  The only
guarantee is that it will be on its way to the running state.

@param installSignalHandlers: A flag which, if set, indicates that
    handlers for a number of (implementation-defined) signals should be
    installed during startup.
TFr)  N)r2  r   ReactorAlreadyRunningr4  ReactorNotRestartabler&  r[  rA  rF  r  _registerAsIOThreadr>   registerAsIOThreadr  rE  s     rV   rY  ReactorBase.startRunning  s      ==--//--//!&;#001FG##))+Y'rY   c                 j    SU l         U R                  (       a  U R                  R                  5         gg)zu
Method called to transition to the running state.  This should happen
in the I{during startup} event trigger phase.
TN)r1  rA  r&  installr\   s    rV   r9  ReactorBase._reallyStartRunning  s+    
 && MM!!# 'rY   rH   c           
          US:  d
   U S35       e[        U R                  5       U-   UUUU R                  U R                  U R                  S9nU R                  R                  U5        U$ )z9
See twisted.internet.interfaces.IReactorTime.callLater.
r   z* is not greater than or equal to 0 seconds)r8   )rA   r8   _cancelCallLater_moveCallLaterSoonerr/  r   )rU   rk   r   rG   rH   delayedCalls         rV   r   ReactorBase.callLater  ss     zOeW$NOOz!LLNU"!!%%LL
 	"";/rY   r  c                     U R                   n UR                  U5      nX#   nUS:w  a!  US-
  S-  nX%   U::  a  OX%   X#'   UnUS:w  a  M!  XBU'   g ! [         a     g f = f)Nr   r9      )r.  indexr   )rU   r  heapposeltparents         rV   r   ReactorBase._moveCallLaterSooner  s|    &&	**[)C )C('a<3& L	 ( I 		s   :A 
A 
AAc                 .    U =R                   S-  sl         g Nr9   )r0  )rU   r  s     rV   r  ReactorBase._cancelCallLater  s    q rY   c                     U R                   U R                  -    Vs/ s H  nUR                  (       a  M  UPM     sn$ s  snf )zA
See L{twisted.internet.interfaces.IReactorTime.getDelayedCalls}
)r.  r/  rQ   )rU   xs     rV   getDelayedCallsReactorBase.getDelayedCalls  sA     --0C0CC
C;; C
 	
 
s   >>c                     U R                   (       d  g U R                    HQ  nUR                  (       a  U =R                  S-  sl        M+  UR                  5         [	        U R
                  U5        MS     / U l         g r  )r/  rQ   r0  rj   r   r.  )rU   calls     rV   _insertNewDelayedCalls"ReactorBase._insertNewDelayedCalls  s^     ""''D~~##q(###%00$7 ( !rY   c                     U R                  5         U R                  (       d  gU R                  S   R                  U R                  5       -
  nSn[	        S[        X!5      5      $ )z
Determine the longest time the reactor may sleep (waiting on I/O
notification, perhaps) before it must wake up to service a time-related
event.

@return: The maximum number of seconds the reactor may sleep.
Nr   i  )r  r.  rE   r8   maxmin)rU   rk   longests      rV   r   ReactorBase.timeout   sX     	##%&&''*//$,,.@  1c')**rY   c                    U R                   (       a  Sn[        U R                   5      nU R                    H)  u  p4n[           U" U0 UD6  SSS5        US-  nX:X  d  M)    O   U R                   SU2	 U R                   (       a  U R                  5         U R	                  5         U R                  5       nU R                  (       Ga5  U R                  S   R                  U::  Ga  [        U R                  5      nUR                  (       a  U =R                  S-  sl
        Mm  UR                  S:  a(  UR                  5         [        U R                  U5        M  UR                  (       a"  [        R!                  SUR                  4S jS9O["        nU   SUl        UR&                  " UR(                  0 UR*                  D6  SSS5        U R                  (       a   U R                  S   R                  U::  a  GM  U R                  S:  av  U R                  [        U R                  5      S-	  :  aP  SU l
        U R                   V	s/ s H  oR                  (       a  M  U	PM     sn	U l        [-        U R                  5        U R.                  (       a  S	U l        U R1                  S
5        gg! , (       d  f       GNg= f! , (       d  f       GN= fs  sn	f )z
Run all pending timed calls.
r   Nr9   rM   z&while handling timed call {previous()}c                 l    SSR                  U 5      R                  5       R                  SS5      -   S-   $ )Nz)
 C: from a DelayedCall created here:
 C:r   
z
 C:)r   rstripreplace)rD   s    rV   <lambda>-ReactorBase.runUntilCurrent.<locals>.<lambda>B  s;      '''*113;;D'JK 	rY   )previous2   Fr*  )r,  len_threadCallHandlerrn  r  r8   r.  rE   r   rQ   r0  rS   rj   r   rD   rb  failuresHandled%_DEFAULT_DELAYED_CALL_LOGGING_HANDLERrR   rF   rG   rH   r   r3  r  )
rU   counttotalfarH   r   r  
logHandlerr  s
             rV   r`  ReactorBase.runUntilCurrent  sD     E,,-E 00b'qKBK (
> 1 $$VeV,## 	##%lln%%%4+B+B1+E+J+Jc+Q4223D~~##q(#  3&##%00$7 << $$<,0LL  % 	 ;   		49900 7 %%4+B+B1+E+J+Jc+Q@ "$##c$*A*A&Ba&GG"#D22'2a++2'D# D++, %D  , m ('P 's$   	J*.J<KK*
J9	<
Kc                 x    U R                  [        [        [        U 5      U R                  5      5        SU l        g )NT)r  _GAIResolverr   r,   r   usingThreadsr\   s    rV   r=  ReactorBase._initThreadsk  s1    $$T/48$:L:LM !%DrY   r  c                     [        U5      (       d
   U S35       eU R                  R                  XU45        U R                  5         g)zH
See
L{twisted.internet.interfaces.IReactorFromThreads.callFromThread}.
r  N)r   r,  r   rn  rU   r  rG   r   s       rV   r  ReactorBase.callFromThreadt  sC     A;;61#%5 66;   ''&(9:KKMrY   c                     [        SSS5      U l        U R                  U R                  R                  5      U l        U R                  SSU R                  5      U l        g)z7
Create the threadpool accessible with callFromThread.
r   
   r'  r   r*  N)r?   
threadpoolr  start_threadpoolStartupIDr8  _stopThreadPoolthreadpoolShutdownIDr\   s    rV   _initThreadPoolReactorBase._initThreadPool  sR     )B0JKDO(,(<(<T__=R=R(SD%(,(B(B*d&:&:)D%rY   c                 8    U R                   R                  5         g r   )r&  r[  r\   s    rV   _uninstallHandlerReactorBase._uninstallHandler  s    MM##%rY   c                    U R                   U R                  /n[        SU5       H  n U R                  U5        M     SU l         SU l        U R
                  c   eU R
                  R                  5         SU l        g! [         a     Me  f = f)z
Stop the reactor threadpool.  This method is only valid if there
is currently a threadpool (created by L{_initThreadPool}).  It
is not intended to be called directly; instead, it will be
called by a shutdown trigger created in L{_initThreadPool}.
N)r  r  filterr  r   r  r  )rU   triggerstriggers      rV   r   ReactorBase._stopThreadPool  s     1143L3LMH!$111': 2
 )-D%(,D%??...OO  ""DO " s   A==
B
Bc                 r    U R                   c  U R                  5         U R                   c   eU R                   $ )zC
See L{twisted.internet.interfaces.IReactorThreads.getThreadPool}.
)r  r  r\   s    rV   r   ReactorBase.getThreadPool  s4     &$$&222??"rY   	_callablec                 L    U R                  5       R                  " U/UQ70 UD6  g)zD
See L{twisted.internet.interfaces.IReactorInThreads.callInThread}.
N)r   callInThread)rU   r  rG   r   s       rV   r  ReactorBase.callInThread  s%      --iI$I&IrY   sizec                 >    U R                  5       R                  US9  g)zK
See L{twisted.internet.interfaces.IReactorThreads.suggestThreadPoolSize}.
)
maxthreadsN)r   adjustPoolsize)rU   r  s     rV   suggestThreadPoolSize!ReactorBase.suggestThreadPoolSize  s      //4/@rY   c                 r    [        U5      (       d
   U S35       eU R                  R                  XU45        g )Nr  )r   r,  r   r  s       rV   r  r    s8     A;;61#%5 66;  ''&(9:rY   )r0  r-  r  rA  r6  r3  r/  r.  r&  r2  r4  r  r  r1  r,  r  r  r  r7  r   )Tr   r   )rM   )[r}   r   r|   r   r   r  r  	installedr  r  r;   r&  r:   r   rW   rA  r   rF  rD  r.   rR  rV  r\  rZ  _lockr>  rn  r   r   ra  rP  r0   ry  rU  r~  r   r   r  r  r  r   r   r   r!   r  r  r:  r	   rI  rJ  rK  r;  r  r  r   r   r   r$  r8  r  r  rY  r9  staticmethodr   r8   rA   r   r  r  r%   r  r  r   r`  r7   r<  r?   r  r  r  r=  r  r  r  r   r   r  r  r   __classcell__)r?  s   @rV   r   r   A  sS   : HILK  67Hn7)H8 $)D(
( 
(. 
(	
 	
 T "O " "& & &+ E

 
% 
T 

 
D 


 0 
T 


? 
t 


#3 
 


4o7G&G HI 


D1 


D!12 
 3A
:
:"*3-
:	#
:#
R	"S 	"))< 	" 	"	"s 	"8I+> 	"$ 	"	"c 	"(9*= 	" 	" U  T    

 
 38$	

 
 
 

.=. =T = c*39EK	.	!($ ($ (>$" >*G&.sCx&8AGOU	&  (!K !D !
,!7 
!+% +8C-L !!%%%
##	%	c3h'	06	BH				&	#&	#: 	#	J%c3h/	J8>	JJP	J	J	Ac 	Ad 	A 	A	;c3h'	;06	;BH	;	; 	;rY   r   c                       \ rS rSrSrSrSrS\S\S\	SS4S	 jr
SS
 jr\SS j5       rSS jrSS jrSS jrS\S\\   4S jrS\SS4S jrS\SS4S jrS\4S jrS\4S jrSrg)BaseConnectori  za
Basic implementation of L{IConnector}.

State can be: "connecting", "connected", "disconnected"
Nr   factoryr   r   rK   c                 6    SU l         X0l        Xl        X l        g )Ndisconnected)r   r   r  r   )rU   r  r   r   s       rV   rW   BaseConnector.__init__  s     $
rY   c                     U R                   S:X  a  U R                  5         gU R                   S:X  a*  U R                  c   eU R                  R                  5         gg)z!Disconnect whatever our state is.
connecting	connectedN)r   stopConnecting	transportloseConnectionr\   s    rV   
disconnectBaseConnector.disconnect  sK    ::%!ZZ;&>>---NN))+ 'rY   c                     g r   r   r\   s    rV   _makeTransportBaseConnector._makeTransport  s    rY   c                    U R                   S:w  a  [        S5      eSU l         U R                  (       d!  U R                  R	                  5         SU l        U R                  5       U l        U R                  bS  U R                  R                  U R                  U R                  R                  [        R                  " 5       5      U l        U R                  R                  U 5        g)z"Start connection to remote server.r!  zcan't connect in this stater$  r9   N)r   RuntimeErrorfactoryStartedr  doStartr,  r'  r   r   r   failIfNotConnectedr   TimeoutError	timeoutIDstartedConnectingr\   s    rV   connectBaseConnector.connect  s    ::'<==!
""LL  ""#D+/+>+>+@<<#!\\33dnn??ASASAUDN 	&&t,rY   c                     U R                   S:w  a  [        R                  " S5      eU R                  c   eSU l         U R                  R	                  [        R
                  " 5       5        U ?g)zStop attempting to connect.r$  zwe're not trying to connectNr!  )r   r   NotConnectingErrorr'  r2  	UserErrorr\   s    rV   r&  BaseConnector.stopConnecting  sU    ::%**+HII~~)))#
))%//*;<NrY   c                 z    U R                   b   U R                   R                  5         U ? g g ! [         a     Nf = fr   )r4  rI   r   r\   s    rV   cancelTimeoutBaseConnector.cancelTimeout  sA    >>%%%'  &  s   - 
::addrc                 f    SU l         U R                  5         U R                  R                  U5      $ )Nr%  )r   r=  r  buildProtocol)rU   r?  s     rV   rA  BaseConnector.buildProtocol  s*     
||))$//rY   reasonc                     U R                  5         S U l        SU l        U R                  R	                  X5        U R                  S:X  a"  U R                  R                  5         SU l        g g Nr!  r   )r=  r'  r   r  clientConnectionFaileddoStopr0  rU   rC  s     rV   connectionFailedBaseConnector.connectionFailed  sW    #
++D9::'LL!"#D (rY   c                     SU l         U R                  R                  X5        U R                   S:X  a"  U R                  R                  5         SU l        g g rE  )r   r  clientConnectionLostrG  r0  rH  s     rV   r  BaseConnector.connectionLost  sD    #
))$7::'LL!"#D (rY   c                 Z    [        [        R                  " U R                  5      S-   5      e)Nz! did not implement getDestinationrh  r\   s    rV   getDestinationBaseConnector.getDestination"  s%    !LL(+QQ
 	
rY   c                     SR                  [        R                  " U R                  5      [	        U 5      U R
                  U R                  5       5      $ )Nz<{} instance at 0x{:x} {} {}>)formatr4   rj  r?  r   r   rO  r\   s    rV   r   BaseConnector.__repr__'  s?    .55LL(tHJJ!	
 	
rY   )r  r0  r   r   r   r4  r'  r   )rK   r=   )r}   r   r|   r   r   r4  r0  r2   r   r   rW   r)  r   r,  r6  r&  r=  r#   r   r'   rA  r5   rI  r  rO  r   r   r   r   rY   rV   r  r    s     IN$/4?J	,  - 0( 0x	/B 0
$w $4 $$W $ $
 


# 
rY   r  c                       \ rS rSr% SrSr\R                  \S'   Sr	\R                  \S'   S\R                  4S jrS\\   4S jrS	rg)
BasePorti0  zaBasic implementation of a ListeningPort.

Note: This does not actually implement IListeningPort.
NaddressFamily
socketTyperK   c                     [         R                   " U R                  U R                  5      nUR                  S5        [        R
                  " UR                  5       5        U$ )NF)r   rV  rW  setblockingr   _setCloseOnExecfileno)rU   ss     rV   createInternetSocketBasePort.createInternetSocket9  sA    MM$,,doo>	eahhj)rY   c                 Z    [        S[        R                  " U R                  5      -  5      e)zRaises a RuntimeErrorzdoWrite called on a %s)r/  r4   rj  r?  r\   s    rV   doWriteBasePort.doWrite?  s     3gll4>>6RRSSrY   r   )r}   r   r|   r   r   rV  r   AddressFamilyr   rW  
SocketKindr]  r   r5   r`  r   r   rY   rV   rU  rU  0  sL    
 +/M6''.$(J!!(fmm T'* TrY   rU  __all__)qr   r  r   r   abcr   r   heapqr   r   r   	tracebackr   typesr	   typingr
   r   r   r   r   r   r   r   r   r   r   r   zope.interfacer   r   twisted.internetr   r   r   r   r   r   twisted.internet._resolverr   r  r   r  r    r  twisted.internet.deferr!   r"   twisted.internet.interfacesr#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   twisted.internet.protocolr2   twisted.loggerr3   twisted.pythonr4   twisted.python.failurer5   twisted.python.logr6   r  twisted.python.runtimer7   r8   r   r&  r:   r;   r<   twisted.internet.tcpr=   r>   r<  twisted.python.threadpoolr?   rb  failureHandlerr_  r  r  rA   r   r   r  r   r   _ThreePhaseEventTriggerr   r   r  r$  _ThreadCallr  r   r  FileDescriptorrU  rd  r   r   rY   rV   <module>r{     s  

    # , , "     8 I I 
 :    " 4 ! " * @ F Q Q+ &4Jx !!"AB(()DE ))*VW  \@ @ @F _G G GT _* * * #+38"4 #U63;%7c6k9JJ  !(#	#.fck0BDfDU
UV! G. G.T *,EF." ." G."b )56S1S+TUHS#X&fck(:Df<MMN(,(;(;<W(X % \<)FGA
;( A
; HA
;H K1 Zb
C b
 b
JTx&& T( c rY   