Ë
    ojV  ã                   óÈ   — 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    ú>/usr/lib/python3/dist-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š   € ð	Ø�L‰L×#Ñ# BÔ'ð ˆØ�—‘ÑØœ&‘=ˆDØ�—‘ÑØœ'‘>ˆDØ�1Š9Ø�L‰L×!Ñ! " 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Ñ!ØˆD�K‰K˜‰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Ñ!Ø ˆD�L‰L˜ÑØ×$Ñ$ 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¯[©[Ö9 rˆT×Ñ˜rÓ"Ò9Ø-1¯\©\Ö: rˆT×Ñ˜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‰IˆB�ðØ!×.Ñ.¨rÑ2�
ô
 ×Ñ˜z¨5°*¸bÀ%ÕHñ	Iøô ò 	Ø�v‰v�a‰yœEŸK™KÒ'Üàûð		ûô ò ñ ðú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   