o bV@sdZddlZddlmZmZmZmZmZmZ m Z ddl m Z ddl mZddlmZddlmZe eGdd d ejejZd d Zd d gZdS) 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)POLLERRPOLLHUPPOLLINPOLLNVALPOLLOUTerrorpoll) implementer) posixbase) IReactorFDSet)logc@seZdZdZeeBeBZeZ e Z ddZ ddZ ddZdd Zd d Zd d ZddZddZddZeZddZddZdS) 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}. cCs*t|_i|_i|_i|_tj|dS)zo Initialize polling object, file descriptor tracking dictionaries, and the base class. N)r_poller _selectables_reads_writesr PosixReactorBase__init__selfr>/usr/lib/python3/dist-packages/twisted/internet/pollreactor.pyrCs zPollReactor.__init__cCsz|j|Wn tyYnwd}||jvr|tB}||jvr&|tB}|dkr3|j||dS||jvr>|j|=dSdS)z*Register/unregister an fd with the poller.rN) r unregisterKeyErrorrrrrregisterr)rfdmaskrrr_updateRegistrationNs     zPollReactor._updateRegistrationcCsnz |}||Wnty&|jD] \}}||ur nqYdSYnw||vr5||=||dSdS)N)fileno BaseExceptionritemsr)r selectablemdictrfdesrrr _dictRemove`s   zPollReactor._dictRemovecC8|}||jvr||j|<d|j|<||dSdS)z@Add a FileDescriptor for notification of data available to read.N)rrrr)rreaderrrrr addReaderu    zPollReactor.addReadercCr%)zAAdd a FileDescriptor for notification of data available to write.r&N)rrrr)rwriterrrrr addWriter}r)zPollReactor.addWritercC|||jS)z?Remove a Selectable for notification of data available to read.)r$r)rr'rrr removeReaderzPollReactor.removeReadercCr,)z@Remove a Selectable for notification of data available to write.)r$r)rr*rrr removeWriterr.zPollReactor.removeWritercs,fddjDfddjDS)zD Remove all selectables, and return a list of them. cg|]}j|qSrr.0rrrr z)PollReactor.removeAll..cr0rr1r2rrrr4r5) _removeAllrrrrrr removeAllszPollReactor.removeAllc Cs|dur t|d}z|j|}Wnty.}z|jdtjkr)WYd}~dSd}~ww|j}|D]\}}z|j|}Wn t yHYq4wt |||||q4dS)zPoll the poller for new events.Nir) intrr SelectErrorargserrnoEINTR_doReadOrWriterrr callWithLogger)rtimeoutle_drdwreventr!rrrdoPolls&   zPollReactor.doPollcfddjDS)Ncr0rr1r2rrrr4r5z*PollReactor.getReaders..)rrrrr getReaderszPollReactor.getReaderscrE)Ncr0rr1r2rrrr4r5z*PollReactor.getWriters..)rrrrr getWritersrGzPollReactor.getWritersN)__name__ __module__ __qualname____doc__rrr_POLL_DISCONNECTEDr_POLL_INr _POLL_OUTrrr$r(r+r-r/r7rD doIterationrFrHrrrrr $s"    r cCst}ddlm}||dS)zInstall the poll() reactor.r)installReactorN)r twisted.internet.mainrQ)prQrrrinstalls  rT)rLr;selectrrrrrrr9rzope.interfacer twisted.internetr twisted.internet.interfacesr twisted.pythonr r_PollLikeMixinr rT__all__rrrrs $