
    \dV                         d Z ddlZddlmZmZmZmZmZmZ	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZ  ee           G d d	ej        ej                              Zd
 Zd	dgZdS )z
A poll() 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 pollreactor
    pollreactor.install()
    N)POLLERRPOLLHUPPOLLINPOLLNVALPOLLOUTerrorpoll)implementer)	posixbase)IReactorFDSet)logc                   p    e Zd ZdZeez  ez  ZeZ	e
Zd Zd Zd Zd Zd Zd Zd Zd	 Zd
 ZeZd Zd ZdS )PollReactora^  
    A reactor that uses poll(2).

    @ivar _poller: A L{select.poll} which will be used to check for I/O
        readiness.

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

    @ivar _reads: A dictionary mapping integer file descriptors to arbitrary
        values (this is essentially a set).  Keys in this dictionary will be
        registered with C{_poller} for read readiness notifications which will
        be dispatched to the corresponding L{FileDescriptor} instances in
        C{_selectables}.

    @ivar _writes: A dictionary mapping integer file descriptors to arbitrary
        values (this is essentially a set).  Keys in this dictionary will be
        registered with C{_poller} for write readiness notifications which will
        be dispatched to the corresponding L{FileDescriptor} instances in
        C{_selectables}.
    c                     t                      | _        i | _        i | _        i | _        t
          j                            |            dS )zo
        Initialize polling object, file descriptor tracking dictionaries, and
        the base class.
        N)r	   _poller_selectables_reads_writesr   PosixReactorBase__init__selfs    <lib/python3.11/site-packages/twisted/internet/pollreactor.pyr   zPollReactor.__init__C   sB    
 vv"++D11111    c                    	 | j                             |           n# t          $ r Y nw xY wd}|| j        v r
|t          z  }|| j        v r
|t          z  }|dk    r| j                             ||           dS || j        v r
| j        |= dS dS )z*Register/unregister an fd with the poller.r   N)	r   
unregisterKeyErrorr   r   r   r   registerr   )r   fdmasks      r   _updateRegistrationzPollReactor._updateRegistrationN   s    	L##B'''' 	 	 	D	 &=D'>D199L!!"d+++++T&&&%b))) '&s    
**c                     	 |                                 }||          n8# t          $ r+ | j                                        D ]\  }}||u r nY d S Y nw xY w||v r||= |                     |           d S d S )N)filenoBaseExceptionr   itemsr!   )r   
selectablemdictr   fdess        r   _dictRemovezPollReactor._dictRemove`   s    	""$$B "III 		 		 		 !-3355  D%%E &
 	 E		 ;;b	$$R((((( ;s    /AAc                     |                                 }|| j        vr+|| j        |<   d| j        |<   |                     |           dS dS )z@Add a FileDescriptor for notification of data available to read.   N)r#   r   r   r!   )r   readerr   s      r   	addReaderzPollReactor.addReaderu   sV    ]]__T[  $*Db!DKO$$R((((( ! r   c                     |                                 }|| j        vr+|| j        |<   d| j        |<   |                     |           dS dS )zAAdd a FileDescriptor for notification of data available to write.r+   N)r#   r   r   r!   )r   writerr   s      r   	addWriterzPollReactor.addWriter}   sW    ]]__T\!!$*Db! DL$$R((((( "!r   c                 8    |                      || j                  S )z?Remove a Selectable for notification of data available to read.)r)   r   )r   r,   s     r   removeReaderzPollReactor.removeReader   s    444r   c                 8    |                      || j                  S )z@Remove a Selectable for notification of data available to write.)r)   r   )r   r/   s     r   removeWriterzPollReactor.removeWriter   s    555r   c                 t                            fd j        D              fd j        D                       S )zD
        Remove all selectables, and return a list of them.
        c                 *    g | ]}j         |         S  r   .0r   r   s     r   
<listcomp>z)PollReactor.removeAll.<locals>.<listcomp>   s!    999rTr"999r   c                 *    g | ]}j         |         S r7   r8   r9   s     r   r;   z)PollReactor.removeAll.<locals>.<listcomp>   s!    :::rTr":::r   )
_removeAllr   r   r   s   `r   	removeAllzPollReactor.removeAll   sM     9999T[999::::T\:::
 
 	
r   c                 Z   |t          |dz            }	 | j                            |          }n4# t          $ r'}|j        d         t
          j        k    rY d}~dS  d}~ww xY w| j        }|D ]<\  }}	 | j        |         }n# t          $ r Y  w xY wt          j        |||||           =dS )zPoll the poller for new events.Ni  r   )intr   r	   SelectErrorargserrnoEINTR_doReadOrWriter   r   r   callWithLogger)r   timeoutle_drdwr   eventr&   s           r   doPollzPollReactor.doPoll   s    'D.))G	!!'**AA 	 	 	vayEK''		
 # 	I 	IIB!.r2

     z5*b%HHHH	I 	Is,   1 
A"AAA"4B
BBc                 *      fd j         D             S )Nc                 *    g | ]}j         |         S r7   r8   r9   s     r   r;   z*PollReactor.getReaders.<locals>.<listcomp>   s!    <<<"!"%<<<r   )r   r   s   `r   
getReaderszPollReactor.getReaders   s    <<<<<<<<r   c                 *      fd j         D             S )Nc                 *    g | ]}j         |         S r7   r8   r9   s     r   r;   z*PollReactor.getWriters.<locals>.<listcomp>   s!    ==="!"%===r   )r   r   s   `r   
getWriterszPollReactor.getWriters   s    ========r   N)__name__
__module____qualname____doc__r   r   r   _POLL_DISCONNECTEDr   _POLL_INr   	_POLL_OUTr   r!   r)   r-   r0   r2   r4   r>   rL   doIterationrO   rR   r7   r   r   r   r   $   s         2 !7*X5HI	2 	2 	2* * *$) ) )*) ) )) ) )5 5 56 6 6
 
 
I I I, K= = => > > > >r   r   c                  D    t                      } ddlm}  ||            dS )zInstall the poll() reactor.r   )installReactorN)r   twisted.internet.mainr\   )pr\   s     r   installr_      s3    A444444N1r   r_   )rV   rC   selectr   r   r   r   r   r   rA   r	   zope.interfacer
   twisted.internetr   twisted.internet.interfacesr   twisted.pythonr   r   _PollLikeMixinr   r_   __all__r7   r   r   <module>rg      s1                      ' & & & & & & & & & & & 5 5 5 5 5 5       ]M> M> M> M> M>),i.F M> M> M>`   )
$r   