
    VhV                         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y)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                   n    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y)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                  j                  |        y)zo
        Initialize polling object, file descriptor tracking dictionaries, and
        the base class.
        N)r	   _poller_selectables_reads_writesr   PosixReactorBase__init__)selfs    L/home/dcms/DCMS/lib/python3.12/site-packages/twisted/internet/pollreactor.pyr   zPollReactor.__init__C   s7    
 v""++D1    c                 6   	 | j                   j                  |       d}|| j                  v r	|t        z  }|| j
                  v r	|t        z  }|dk7  r| j                   j                  ||       y|| j                  v r| j                  |= yy# t        $ r Y zw xY w)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    	LL##B' &=D'>D19LL!!"d+T&&&%%b) '  		s   B 	BBc                     	 |j                         }||    ||v r||= | j	                  |       y y # t        $ r- | j                  j                         D ]  \  }}||u s n Y y Y Ow xY wN)filenoBaseExceptionr   itemsr    )r   
selectablemdictr   fdess        r   _dictRemovezPollReactor._dictRemove`   s    	""$B "I ;b	$$R(   		 !--335 D% 	 		s   1 -A'A'&A'c                     |j                         }|| j                  vr0|| j                  |<   d| j                  |<   | j                  |       yy)z@Add a FileDescriptor for notification of data available to read.   N)r#   r   r   r    )r   readerr   s      r   	addReaderzPollReactor.addReaderu   sI    ]]_T[[ $*Db!DKKO$$R( !r   c                     |j                         }|| j                  vr0|| j                  |<   d| j                  |<   | j                  |       yy)zAAdd a FileDescriptor for notification of data available to write.r+   N)r#   r   r   r    )r   writerr   s      r   	addWriterzPollReactor.addWriter}   sJ    ]]_T\\!$*Db! DLL$$R( "r   c                 :    | j                  || j                        S )z?Remove a Selectable for notification of data available to read.)r)   r   )r   r,   s     r   removeReaderzPollReactor.removeReader   s    44r   c                 :    | j                  || j                        S )z@Remove a Selectable for notification of data available to write.)r)   r   )r   r/   s     r   removeWriterzPollReactor.removeWriter   s    55r   c                     | j                  | j                  D cg c]  }| j                  |    c}| j                  D cg c]  }| j                  |    c}      S c c}w c c}w )zD
        Remove all selectables, and return a list of them.
        )
_removeAllr   r   r   r   r   s     r   	removeAllzPollReactor.removeAll   sU     -1[[9rTr"9-1\\:rTr":
 	
9:s   A A"
c                 f   |t        |dz        }	 | j                  j                  |      }| j                  }|D ].  \  }}	 | j                  |   }t        j                  |||||       0 y# t        $ r+}|j                  d   t
        j                  k(  rY d}~y d}~ww xY w# t        $ r Y tw xY w)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	!!'*A ## 	IIB!..r2

 z5*b%H	I  	vvayEKK'		   s/   A- B$-	B!6 BBB!$	B0/B0c                 Z    | j                   D cg c]  }| j                  |    c}S c c}w r"   )r   r   r7   s     r   
getReaderszPollReactor.getReaders   s%    04<"!!"%<<<   (c                 Z    | j                   D cg c]  }| j                  |    c}S c c}w r"   )r   r   r7   s     r   
getWriterszPollReactor.getWriters   s%    04="!!"%===rI   N)__name__
__module____qualname____doc__r   r   r   _POLL_DISCONNECTEDr   _POLL_INr   	_POLL_OUTr   r    r)   r-   r0   r2   r4   r8   rF   doIterationrH   rK    r   r   r   r   $   sb    2 !7*X5HI	2*$)*))56
I, K=>r   r   c                  4    t               } ddlm}  ||        y)zInstall the poll() reactor.r   )installReactorN)r   twisted.internet.mainrV   )prV   s     r   installrY      s    A41r   rY   )rO   r=   selectr   r   r   r   r   r   r;   r	   zope.interfacer
   twisted.internetr   twisted.internet.interfacesr   twisted.pythonr   r   _PollLikeMixinr   rY   __all__rT   r   r   <module>ra      sq       ' & 5  ]M>),,i.F.F M> M>` )
$r   