Ë
    ojo2  ã                   óB  — d Z ddlZddl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mZmZ ddlmZ dd	lmZ d
dlmZmZ g fd„Z G d„ de«      Zd„ Zdeeg df   gdf   deg df   deg df   fd„Z ee«       G d„ de
j8                  e
j:                  «      «       Zy)aC  
This module provides base support for Twisted to interact with the glib/gtk
mainloops.

The classes in this module should not be used directly, but rather you should
import gireactor or gtk3reactor for GObject Introspection based applications,
or glib2reactor or gtk2reactor for applications using legacy static bindings.
é    N)ÚAnyÚCallableÚDictÚSet)Úimplementer)Ú	posixbase)ÚFileDescriptor)ÚIReactorFDSetÚIReadDescriptorÚIWriteDescriptor)Úlog)ÚMonkeyPatcheré   )Ú_IWakerÚ
_UnixWakerc                 óš   — | D ],  }t         j                  j                  |«      €Œ#t        |«      ‚ |D ]  }dt         j                  |<   Œ y)a[  
    Check whether the given modules were imported, and if requested, ensure
    they will not be importable in the future.

    @param moduleNames: A list of module names we make sure aren't imported.
    @type moduleNames: C{list} of C{str}

    @param preventImports: A list of module name whose future imports should
        be prevented.
    @type preventImports: C{list} of C{str}

    @param errorMessage: Message to use when raising an C{ImportError}.
    @type errorMessage: C{str}

    @raise ImportError: with given error message if a given module name
        has already been imported.
    N)ÚsysÚmodulesÚgetÚImportError)ÚmoduleNamesÚerrorMessageÚpreventImportsÚnames       ú</usr/lib/python3/dist-packages/twisted/internet/_glibbase.pyÚensureNotImportedr      sP   € ð$ ò ,ˆÜ�;‰;�?‰?˜4Ó Ñ,Ü˜lÓ+Ð+ð,ð
 ò !ˆØ Œ�‰�DÒñ!ó    c                   ó.   ‡ — e Zd ZdZˆ fd„Zdˆ fd„Zˆ xZS )Ú	GlibWakerz/
    Run scheduled events after waking up.
    c                 ó0   •— t         ‰| �  «        || _        y ©N)ÚsuperÚ__init__Úreactor)Úselfr$   Ú	__class__s     €r   r#   zGlibWaker.__init__<   s   ø€ Ü‰ÑÔØˆ�r   c                 óV   •— t         ‰| �  «        | j                  j                  «        y r!   )r"   ÚdoReadr$   Ú	_simulate)r%   r&   s    €r   r(   zGlibWaker.doRead@   s   ø€ Ü‰‰ÔØ�‰×ÑÕ r   )ÚreturnN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r#   r(   Ú__classcell__©r&   s   @r   r   r   7   s   ø„ ñô÷!ñ !r   r   c                  óL   — ddl m}  t        «       }|j                  | dd«       |S )aV  
    Integrate glib's wakeup file descriptor usage and our own.

    Python supports only one wakeup file descriptor at a time and both Twisted
    and glib want to use it.

    This is a context manager that can be wrapped around the whole glib
    reactor main loop which makes our signal handling work with glib's signal
    handling.
    r   )Ú_ossighelperÚ_wakeup_fd_is_activeT)Úgir2   r   ÚaddPatch)Ú
signalGlueÚpatchers     r   Ú_signalGluer8   E   s&   € õ .ä‹o€GØ×Ñ�ZÐ!7¸Ô>Ø€Nr   ÚidleAddÚloopQuitr*   c                 ó   ‡ ‡— ˆ ˆfd„S )z�
    Combine the C{glib.idle_add} and C{glib.MainLoop.quit} functions into a
    function suitable for crashing the reactor.
    c                  ó   •—  ‰ ‰«      S r!   © ©r9   r:   s   €€r   ú<lambda>z_loopQuitter.<locals>.<lambda>^   s   ø€ ‘7˜8Ó$€ r   r=   r>   s   ``r   Ú_loopQuitterr@   W   s   ù€ ô %Ð$r   c            	       ó¼   ‡ — e Zd ZdZdefd„Zddedededdfˆ fd„Zˆ fd	„Z	d
„ Z
d„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zˆ xZS )ÚGlibReactorBasea7  
    Base class for GObject event loop reactors.

    Notification for I/O events (reads and writes on file descriptors) is done
    by the gobject-based event loop. File descriptors are registered with
    gobject with the appropriate flags for read/write/disconnect notification.

    Time-based events, the results of C{callLater} and C{callFromThread}, are
    handled differently. Rather than registering each event with gobject, a
    single gobject timeout is registered for the earliest scheduled event, the
    output of C{reactor.timeout()}. For example, if there are timeouts in 1, 2
    and 3.4 seconds, a single timeout is registered for 1 second in the
    future. When this timeout is hit, C{_simulate} is called, which calls the
    appropriate Twisted-level handlers, and a new timeout is added to gobject
    by the C{_reschedule} method.

    To handle C{callFromThread} events, we use a custom waker that calls
    C{_simulate} whenever it wakes up.

    @ivar _sources: A dictionary mapping L{FileDescriptor} instances to
        GSource handles.

    @ivar _reads: A set of L{FileDescriptor} instances currently monitored for
        reading.

    @ivar _writes: A set of L{FileDescriptor} instances currently monitored for
        writing.

    @ivar _simtag: A GSource handle for the next L{simulate} call.
    r*   c                 ó   — t        | «      S r!   )r   ©r%   s    r   Ú_wakerFactoryzGlibReactorBase._wakerFactory„   s   € Ü˜‹Ðr   Úglib_moduleÚ
gtk_moduleÚuseGtkNc                 óú  •— d | _         t        «       | _        t        «       | _        i | _        || _        |j                  j                  |j                  j                  z  |j                  j                  z  | _
        |j                  j                  | _        |j                  j                  | _        | j                  | j                  z  | _        | j                  | j                  z  | _        t"        ‰| �I  «        | j
                  j&                  | _        | j
                  j*                  | _        | j
                  j/                  «       | _        | j0                  j2                  | _        | j0                  j6                  | _        | j
                  j;                  «       | _        t?        | j
                  j@                  | j<                  jB                  «      | _"        | j<                  jF                  | _$        y r!   )%Ú_simtagÚsetÚ_readsÚ_writesÚ_sourcesÚ_glibÚIOConditionÚHUPÚERRÚNVALÚ_POLL_DISCONNECTEDÚINÚ_POLL_INÚOUTÚ	_POLL_OUTÚINFLAGSÚOUTFLAGSr"   r#   Úsource_removeÚ_source_removeÚtimeout_addÚ_timeout_addÚmain_context_defaultÚcontextÚpendingÚ_pendingÚ	iterationÚ
_iterationÚMainLoopÚloopr@   Úidle_addÚquitÚ_crashÚrunÚ_run)r%   rF   rG   rH   r&   s       €r   r#   zGlibReactorBase.__init__‡   si  ø€ ØˆŒÜ,/«EˆŒÜ.1«eˆŒØ35ˆŒØ ˆŒ
ð ×#Ñ#×'Ñ'Ø×%Ñ%×)Ñ)ñ*à×%Ñ%×*Ñ*ñ+ð 	Ôð
 $×/Ñ/×2Ñ2ˆŒØ$×0Ñ0×4Ñ4ˆŒð
 —}‘} t×'>Ñ'>Ñ>ˆŒØŸ™¨×)@Ñ)@Ñ@ˆŒä‰ÑÔà"Ÿj™j×6Ñ6ˆÔØ ŸJ™J×2Ñ2ˆÔà—z‘z×6Ñ6Ó8ˆŒØŸ™×,Ñ,ˆŒØŸ,™,×0Ñ0ˆŒØ—J‘J×'Ñ'Ó)ˆŒ	Ü" 4§:¡:×#6Ñ#6¸¿	¹	¿¹ÓGˆŒØ—I‘I—M‘Mˆ�	r   c                 óR   •‡ — t         ‰‰ �  «        ˆ fd„}‰ j                  d|«       y)zq
        Make sure the reactor's signal handlers are installed despite any
        outside interference.
        c                  ón   •— ‰ j                   j                  «        ‰ j                   j                  «        y r!   )Ú_signalsÚ	uninstallÚinstallrD   s   €r   ÚreinitSignalsz:GlibReactorBase._reallyStartRunning.<locals>.reinitSignalsº   s#   ø€ Ø�M‰M×#Ñ#Ô%Ø�M‰M×!Ñ!Õ#r   r   N)r"   Ú_reallyStartRunningÚ	callLater)r%   rq   r&   s   ` €r   rr   z#GlibReactorBase._reallyStartRunning¨   s%   ù€ ô 	‰Ñ#Ô%ô	$ð 	�‰�q˜-Õ(r   c                 ó¸   ‡‡— t        ‰d«      rˆˆfd„}‰j                  «       }n‰}‰}| j                  j                  || j                  j                  ||«      S )NÚfilenoc                 ó   •—  ‰‰|«      S r!   r=   )ÚignoredÚ	conditionÚcallbackÚsources     €€r   Úwrapperz*GlibReactorBase.input_add.<locals>.wrapperÌ   s   ø€ Ù ¨	Ó2Ð2r   )Úhasattrru   rO   Úio_add_watchÚPRIORITY_DEFAULT_IDLE)r%   rz   rx   ry   r{   ru   s    ` `  r   Ú	input_addzGlibReactorBase.input_addÉ   sV   ù€ Ü�6˜8Ô$õ3ð —]‘]“_‰FàˆFØˆGØ�z‰z×&Ñ&ØØ�J‰J×,Ñ,ØØó	
ð 	
r   c                 óJ   — t        j                  || j                  |||«       y)z@
        Called by event loop when an I/O event occurs.
        T)r   ÚcallWithLoggerÚ_doReadOrWrite)r%   rz   rx   s      r   Ú_ioEventCallbackz GlibReactorBase._ioEventCallbackÚ   s#   € ô 	×Ñ˜6 4×#6Ñ#6¸ÀÈ	ÔRØr   c                 óÖ   — ||v ry|}||v r#| j                  | j                  |   «       ||z  }| j                  ||| j                  «      | j                  |<   |j	                  |«       y)a  
        Add the given L{FileDescriptor} for monitoring either for reading or
        writing. If the file is already monitored for the other operation, we
        delete the previous registration and re-register it for both reading
        and writing.
        N)r\   rN   r   rƒ   Úadd)r%   rz   ÚprimaryÚotherÚprimaryFlagÚ	otherFlagÚflagss          r   Ú_addzGlibReactorBase._addá   si   € ð �WÑØØˆØ�U‰?Ø×Ñ §¡¨fÑ 5Ô6Ø�YÑˆEØ $§¡¨v°u¸d×>SÑ>SÓ Tˆ�‰�fÑØ�‰�FÕr   c                 ó~   — | j                  || j                  | j                  | j                  | j                  «       y)zS
        Add a L{FileDescriptor} for monitoring of data available to read.
        N)r‹   rL   rM   rY   rZ   ©r%   Úreaders     r   Ú	addReaderzGlibReactorBase.addReaderñ   s(   € ð 	�	‰	�&˜$Ÿ+™+ t§|¡|°T·\±\À4Ç=Á=ÕQr   c                 ó~   — | j                  || j                  | j                  | j                  | j                  «       y)zO
        Add a L{FileDescriptor} for monitoring ability to write data.
        N)r‹   rM   rL   rZ   rY   ©r%   Úwriters     r   Ú	addWriterzGlibReactorBase.addWriter÷   s(   € ð 	�	‰	�&˜$Ÿ,™,¨¯©°T·]±]ÀDÇLÁLÕQr   c                 ó,   — t        | j                  «      S )zW
        Retrieve the list of current L{FileDescriptor} monitored for reading.
        )ÚlistrL   rD   s    r   Ú
getReaderszGlibReactorBase.getReadersý   s   € ô �D—K‘KÓ Ð r   c                 ó,   — t        | j                  «      S )zW
        Retrieve the list of current L{FileDescriptor} monitored for writing.
        )r•   rM   rD   s    r   Ú
getWriterszGlibReactorBase.getWriters  s   € ô �D—L‘LÓ!Ð!r   c                 óN   — | j                  | j                  | j                  «      S )zJ
        Remove monitoring for all registered L{FileDescriptor}s.
        )Ú
_removeAllrL   rM   rD   s    r   Ú	removeAllzGlibReactorBase.removeAll	  s   € ð �‰˜tŸ{™{¨D¯L©LÓ9Ð9r   c                 ó   — ||vry| j                  | j                  |   «       |j                  |«       ||v r+| j                  ||| j                  «      | j                  |<   y| j                  j                  |«       y)zÝ
        Remove monitoring the given L{FileDescriptor} for either reading or
        writing. If it's still monitored for the other operation, we
        re-register the L{FileDescriptor} for only that operation.
        N)r\   rN   Úremover   rƒ   Úpop)r%   rz   r†   r‡   rŠ   s        r   Ú_removezGlibReactorBase._remove  sl   € ð ˜Ñ ØØ×Ñ˜DŸM™M¨&Ñ1Ô2Ø�‰�vÔØ�U‰?Ø$(§N¡N°6¸5À$×BWÑBWÓ$XˆD�M‰M˜&Ò!à�M‰M×Ñ˜fÕ%r   c                 óh   — | j                  || j                  | j                  | j                  «       y)zJ
        Stop monitoring the given L{FileDescriptor} for reading.
        N)rŸ   rL   rM   rZ   r�   s     r   ÚremoveReaderzGlibReactorBase.removeReader  s"   € ð 	�‰�V˜TŸ[™[¨$¯,©,¸¿¹ÕFr   c                 óh   — | j                  || j                  | j                  | j                  «       y)zJ
        Stop monitoring the given L{FileDescriptor} for writing.
        N)rŸ   rM   rL   rY   r‘   s     r   ÚremoveWriterzGlibReactorBase.removeWriter$  s"   € ð 	�‰�V˜TŸ\™\¨4¯;©;¸¿¹ÕEr   c                 óŠ   — | j                  «        | j                  «       r#| j                  d«       | j                  «       rŒ"yy)zv
        One iteration of the event loop, for trial's use.

        This is not used for actual reactor runs.
        r   N)ÚrunUntilCurrentrb   rd   )r%   Údelays     r   ÚiteratezGlibReactorBase.iterate*  s0   € ð 	×ÑÔØ�m‰mŒoØ�O‰O˜AÔð �m‰m�or   c                 ób   — t         j                  j                  | «       | j                  «        y)z$
        Crash the reactor.
        N)r   ÚPosixReactorBaseÚcrashri   rD   s    r   rª   zGlibReactorBase.crash4  s!   € ô 	×"Ñ"×(Ñ(¨Ô.Ø�‰�r   c                 ób   — t         j                  j                  | «       | j                  «        y)z#
        Stop the reactor.
        N)r   r©   ÚstopÚwakeUprD   s    r   r¬   zGlibReactorBase.stop;  s#   € ô 	×"Ñ"×'Ñ'¨Ô-ð 	�‰�r   c                 óÔ   — t        «       5  | j                  | j                  «       | j                  |¬«       | j                  r| j                  «        ddd«       y# 1 sw Y   yxY w)z"
        Run the reactor.
        )ÚinstallSignalHandlersN)r8   ÚcallWhenRunningÚ_rescheduleÚstartRunningÚ_startedrk   )r%   r¯   s     r   rj   zGlibReactorBase.runI  sT   € ô ‹]ñ 	Ø× Ñ  ×!1Ñ!1Ô2Ø×ÑÐ4IÐÔJØ�}Š}Ø—	‘	”÷		÷ 	ñ 	ús   ‹A
AÁA'c                 ól   — t        j                  j                  | g|¢­i |¤Ž}| j                  «        |S )z,
        Schedule a C{DelayedCall}.
        )r   r©   rs   r±   )r%   ÚargsÚkwargsÚresults       r   rs   zGlibReactorBase.callLaterS  s7   € ô ×+Ñ+×5Ñ5°dÐL¸TÒLÀVÑLˆð 	×ÑÔØˆr   c                 ó  — | j                   �"| j                  | j                   «       d| _         | j                  «       }|�D| j                  t	        |dz  «      | j
                  | j                  j                  ¬«      | _         yy)z;
        Schedule a glib timeout for C{_simulate}.
        Niè  )Úpriority)rJ   r\   Útimeoutr^   Úintr)   rO   r~   )r%   rº   s     r   r±   zGlibReactorBase._reschedule]  st   € ð �<‰<Ð#Ø×Ñ §¡Ô-ØˆDŒLØ—,‘,“.ˆØÐØ×,Ñ,Ü�G˜d‘NÓ#Ø—‘ØŸ™×9Ñ9ð -ó ˆD�Lð r   c                 óD   — | j                  «        | j                  «        y)zX
        Run timers, and then reschedule glib timeout for next scheduled event.
        N)r¥   r±   rD   s    r   r)   zGlibReactorBase._simulatel  s   € ð 	×ÑÔØ×ÑÕr   )F)r   )T)r+   r,   r-   r.   r   rE   r   Úboolr#   rr   r   rƒ   r‹   r�   r“   r–   r˜   r›   rŸ   r¡   r£   r§   rª   r¬   rj   rs   r±   r)   r/   r0   s   @r   rB   rB   a   sœ   ø„ ñðB˜wó ñ" Cð "°Sð "À$ð "ÐSWõ "ôB)òB
ò"òò RòRò!ò"ò:ò&òGòFóòòóòòör   rB   )r.   r   Útypingr   r   r   r   Úzope.interfacer   Útwisted.internetr   Útwisted.internet.abstractr	   Útwisted.internet.interfacesr
   r   r   Útwisted.pythonr   Útwisted.python.monkeyr   rn   r   r   r   r   r8   r@   r©   Ú_PollLikeMixinrB   r=   r   r   ú<module>rÆ      sÀ   ðñ
ó ß +Ó +å &å &Ý 4ß XÑ XÝ Ý /ß )ð ACó !ô6!�
ô !òð$%Ø�x  D Ñ)Ð*¨DÐ0Ñ1ð%Ø=EÀbÈ$ÀhÑ=Oð%àˆb�$ˆhÑó%ñ ˆ]ÓôO�i×0Ñ0°)×2JÑ2Jó Oó ñOr   