
    h"                     4   S 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
   \" \S5      r\" \S5      r\" \S	5      r\" \S
5      r\" \S5      r\" \5       " S S\R(                  \R*                  5      5       rS rSS/rg! \ a  r\" \5      eSrCff = f)z
An epoll() based implementation of the twisted main loop.

To install the event loop (and you should do this before any connections,
listeners or connectors are added)::

    from twisted.internet import epollreactor
    epollreactor.install()
    N)implementer)	posixbase)IReactorFDSet)logepollEPOLLHUPEPOLLERREPOLLINEPOLLOUTc                   p    \ rS rSrSr\\-  r\r	\
rS rS rS rS rS rS rS	 rS
 rS rS rS r\rSrg)EPollReactor%   a7  
A reactor that uses epoll(7).

@ivar _poller: A C{epoll} which will be used to check for I/O
    readiness.

@ivar _selectables: A dictionary mapping integer file descriptors to
    instances of C{FileDescriptor} which have been registered with the
    reactor.  All C{FileDescriptors} which are currently receiving read or
    write readiness notifications will be present as values in this
    dictionary.

@ivar _reads: A set containing integer file descriptors.  Values in this
    set will be registered with C{_poller} for read readiness notifications
    which will be dispatched to the corresponding C{FileDescriptor}
    instances in C{_selectables}.

@ivar _writes: A set containing integer file descriptors.  Values in this
    set will be registered with C{_poller} for write readiness
    notifications which will be dispatched to the corresponding
    C{FileDescriptor} instances in C{_selectables}.

@ivar _continuousPolling: A L{_ContinuousPolling} instance, used to handle
    file descriptors (e.g. filesystem files) that are not supported by
    C{epoll(7)}.
c                     [        S5      U l        [        5       U l        [        5       U l        0 U l        [        R                  " U 5      U l        [        R                  R                  U 5        g)zU
Initialize epoll object, file descriptor tracking dictionaries, and the
base class.
i   N)r   _pollerset_reads_writes_selectablesr   _ContinuousPolling_continuousPollingPosixReactorBase__init__)selfs    d/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/internet/epollreactor.pyr   EPollReactor.__init__G   sP     T{eu"+">">t"D""++D1    c                     UR                  5       nXr;  aX  UnXs;   a   X-  nU R                  R                  Xx5        OU R                  R                  Xx5        UR	                  U5        XU'   gg)z
Private method for adding a descriptor from the event loop.

It takes care of adding it if  new or modifying it if already added
for another state (read -> read/write for example).
N)filenor   modifyregisteradd)	r   xerprimaryotherselectablesevent	antieventfdflagss	            r   _addEPollReactor._addV   sf     ZZ\E {"##B.%%b0 KKO!O! r   c                     U R                  XR                  U R                  U R                  [        [
        5        g! [         aD  nUR                  [        R                  :X  a   U R                  R                  U5         SnAge SnAff = f)zB
Add a FileDescriptor for notification of data available to read.
N)r*   r   r   r   r
   r   OSErrorerrnoEPERMr   	addReader)r   readeres      r   r0   EPollReactor.addReaderp   sj    	IIT\\43D3Dgx  	ww%++% ''11&99	   ;> 
B9BBBc                     U R                  XR                  U R                  U R                  [        [
        5        g! [         aD  nUR                  [        R                  :X  a   U R                  R                  U5         SnAge SnAff = f)zC
Add a FileDescriptor for notification of data available to write.
N)r*   r   r   r   r   r
   r-   r.   r/   r   	addWriter)r   writerr2   s      r   r6   EPollReactor.addWriter   sk    	IIdkk43D3DhPW  	ww%++% ''11&99	r4   c                    UR                  5       nUS:X  a   UR                  5        H  u  pxXL d  M    O   gXr;   aR  Xs;   a  Un	U R                  R                  Xy5        OXG	 U R                  R	                  U5        UR                  U5        gg)z
Private method for removing a descriptor from the event loop.

It does the inverse job of _add, and also add a check in case of the fd
has gone away.
N)r   itemsr   r   
unregisterremove)
r   r"   r#   r$   r%   r&   r'   r(   fdesr)   s
             r   _removeEPollReactor._remove   s     ZZ\8'--/; 0 ={!##B.O''+NN2 r   c                     U R                   R                  U5      (       a  U R                   R                  U5        gU R                  XR                  U R
                  U R                  [        [        5        g)zA
Remove a Selectable for notification of data available to read.
N)	r   	isReadingremoveReaderr?   r   r   r   r
   r   )r   r1   s     r   rC   EPollReactor.removeReader   sW     "",,V44##008KKt/@/@'8	
r   c                     U R                   R                  U5      (       a  U R                   R                  U5        gU R                  XR                  U R
                  U R                  [        [        5        g)zB
Remove a Selectable for notification of data available to write.
N)	r   	isWritingremoveWriterr?   r   r   r   r   r
   )r   r7   s     r   rG   EPollReactor.removeWriter   sW     "",,V44##008LL$++t/@/@(G	
r   c                    U R                  U R                   Vs/ s H  oR                  U   PM     snU R                   Vs/ s H  oR                  U   PM     sn5      U R                  R                  5       -   $ s  snf s  snf )z4
Remove all selectables, and return a list of them.
)
_removeAllr   r   r   r   	removeAllr   r(   s     r   rK   EPollReactor.removeAll   sr    
 OO15=2""2&=15>2""2&> %%//1	2	
=>s   A<B
c                     U R                    Vs/ s H  oR                  U   PM     snU R                  R                  5       -   $ s  snf N)r   r   r   
getReadersrL   s     r   rP   EPollReactor.getReaders   sG    ,0KK
,7bb!K
##..01 	1 
   Ac                     U R                    Vs/ s H  oR                  U   PM     snU R                  R                  5       -   $ s  snf rO   )r   r   r   
getWritersrL   s     r   rT   EPollReactor.getWriters   sG    ,0LL
,8bb!L
##..01 	1 
rR   c                 z   Uc  Sn U R                   R                  U[        U R                  5      5      nU R                  nU H-  u  pV U R                  U   n[        R                  " XtXuU5        M/     g! [         a)  nUR
                  [
        R                  :X  a   SnAge SnAff = f! [         a     Mu  f = f)z!
Poll the poller for new events.
Nr:   )r   polllenr   r-   r.   EINTR_doReadOrWriter   callWithLoggerKeyError)r   timeoutlerr_drdwr(   r&   
selectables           r   doPollEPollReactor.doPoll   s     ?G	
 !!'3t/@/@+ABA ##IBM!..r2
 "":jeL   	yyEKK'
 	  s/   /A6 
B,6
B) B$#B$$B),
B:9B:)r   r   r   r   r   N)__name__
__module____qualname____firstlineno____doc__r   r	   _POLL_DISCONNECTEDr
   _POLL_INr   	_POLL_OUTr   r*   r0   r6   r?   rC   rG   rK   rP   rT   rb   doIteration__static_attributes__ r   r   r   r   %   s]    8 "H,HI2"4""2	
	


1
1
M> Kr   r   c                  4    [        5       n SSKJn  U" U 5        g)z
Install the epoll() reactor.
r   )installReactorN)r   twisted.internet.mainrp   )prp   s     r   installrs      s     	A41r   rs   )rh   r.   selectzope.interfacer   twisted.internetr   twisted.internet.interfacesr   twisted.pythonr   getattrr   r   r	   r
   r   AttributeErrorr2   ImportErrorr   _PollLikeMixinr   rs   __all__rn   r   r   <module>r~      s      & & 5 
 FG$Evz*Hvz*Hfi(Gvz*H
 ]P9--y/G/G P Pf 9
%E  
a.s   -B B
BB