%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/internet/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/internet/__pycache__/_glibbase.cpython-312.pyc

�

Ϫ�fo2��B�dZddlZddlmZmZmZmZddlmZddl	m
Z
ddlmZddl
mZmZmZddlmZdd	lmZd
dlmZmZgfd�ZGd
�de�Zd�Zdeegdfgdfdegdfdegdffd�Zee�Gd�de
j8e
j:��Zy)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],}tjj|���#t|��|D]}dtj|<�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�ensureNotImportedrsP��$�,���;�;�?�?�4� �,��l�+�+�,�
�!�� ����D��!�c�.��eZdZdZ�fd�Zd�fd�Z�xZS)�	GlibWakerz/
    Run scheduled events after waking up.
    c�0��t�|��||_y�N)�super�__init__�reactor)�selfr$�	__class__s  �rr#zGlibWaker.__init__<s���
������rc�V��t�|��|jj�yr!)r"�doReadr$�	_simulate)r%r&s �rr(zGlibWaker.doRead@s���
��������� r)�returnN)�__name__�
__module__�__qualname__�__doc__r#r(�
__classcell__�r&s@rrr7s�����!�!rrc�L�ddlm}t�}|j|dd�|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)�gir2r�addPatch)�
signalGlue�patchers  r�_signalGluer8Es&��.��o�G����Z�!7��>��Nr�idleAdd�loopQuitr*c������fd�S)z�
    Combine the C{glib.idle_add} and C{glib.MainLoop.quit} functions into a
    function suitable for crashing the reactor.
    c������Sr!��r9r:s��r�<lambda>z_loopQuitter.<locals>.<lambda>^s���7�8�$�rr=r>s``r�_loopQuitterr@Ws���%�$rc	���eZdZdZdefd�Zddedededdf�fd�
Z�fd	�Z	d
�Z
d�Zd�Zd
�Z
d�Zd�Zd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zdd�Zd�Zd�Zd�Z�xZS)�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|�Sr!)r�r%s r�
_wakerFactoryzGlibReactorBase._wakerFactory�s�����r�glib_module�
gtk_module�useGtkNc���d|_t�|_t�|_i|_||_|jj|jjz|jjz|_
|jj|_|jj|_|j|jz|_|j|jz|_t"�|�I�|j
j&|_|j
j*|_|j
j/�|_|j0j2|_|j0j6|_|j
j;�|_t?|j
j@|j<jB�|_"|j<jF|_$yr!)%�_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%rFrGrHr&s    �rr#zGlibReactorBase.__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��	rc�R���t�����fd�}�jd|�y)zq
        Make sure the reactor's signal handlers are installed despite any
        outside interference.
        c�n���jj��jj�yr!)�_signals�	uninstall�installrDs�r�
reinitSignalsz:GlibReactorBase._reallyStartRunning.<locals>.reinitSignals�s#����M�M�#�#�%��M�M�!�!�#rrN)r"�_reallyStartRunning�	callLater)r%rqr&s` �rrrz#GlibReactorBase._reallyStartRunning�s%���	��#�%�	$�	
���q�-�(rc����t�d�r��fd�}�j�}n�}�}|jj||jj||�S)N�filenoc�����|�Sr!r=)�ignored�	condition�callback�sources  ��r�wrapperz*GlibReactorBase.input_add.<locals>.wrapper�s�����	�2�2r)�hasattrrurO�io_add_watch�PRIORITY_DEFAULT_IDLE)r%rzrxryr{rus ` `  r�	input_addzGlibReactorBase.input_add�sV����6�8�$�
3��]�]�_�F��F��G��z�z�&�&���J�J�,�,���	
�	
rc�J�tj||j|||�y)z@
        Called by event loop when an I/O event occurs.
        T)r
�callWithLogger�_doReadOrWrite)r%rzrxs   r�_ioEventCallbackz GlibReactorBase._ioEventCallback�s#��	���6�4�#6�#6���	�R�rc���||vry|}||vr#|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\rNrr��add)r%rz�primary�other�primaryFlag�	otherFlag�flagss       r�_addzGlibReactorBase._add�si���W������U�?�����
�
�f� 5�6��Y��E� $���v�u�d�>S�>S� T��
�
�f�����F�rc�~�|j||j|j|j|j�y)zS
        Add a L{FileDescriptor} for monitoring of data available to read.
        N)r�rLrMrYrZ�r%�readers  r�	addReaderzGlibReactorBase.addReader�s(��	
�	�	�&�$�+�+�t�|�|�T�\�\�4�=�=�Qrc�~�|j||j|j|j|j�y)zO
        Add a L{FileDescriptor} for monitoring ability to write data.
        N)r�rMrLrZrY�r%�writers  r�	addWriterzGlibReactorBase.addWriter�s(��	
�	�	�&�$�,�,����T�]�]�D�L�L�Qrc�,�t|j�S)zW
        Retrieve the list of current L{FileDescriptor} monitored for reading.
        )�listrLrDs r�
getReaderszGlibReactorBase.getReaders�s���D�K�K� � rc�,�t|j�S)zW
        Retrieve the list of current L{FileDescriptor} monitored for writing.
        )r�rMrDs r�
getWriterszGlibReactorBase.getWriterss���D�L�L�!�!rc�N�|j|j|j�S)zJ
        Remove monitoring for all registered L{FileDescriptor}s.
        )�
_removeAllrLrMrDs r�	removeAllzGlibReactorBase.removeAll	s�����t�{�{�D�L�L�9�9rc��||vry|j|j|�|j|�||vr+|j|||j�|j|<y|jj|�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�removerr��pop)r%rzr�r�r�s     r�_removezGlibReactorBase._removesl���� �����D�M�M�&�1�2����v���U�?�$(�N�N�6�5�$�BW�BW�$X�D�M�M�&�!��M�M���f�%rc�h�|j||j|j|j�y)zJ
        Stop monitoring the given L{FileDescriptor} for reading.
        N)r�rLrMrZr�s  r�removeReaderzGlibReactorBase.removeReaders"��	
���V�T�[�[�$�,�,��
�
�Frc�h�|j||j|j|j�y)zJ
        Stop monitoring the given L{FileDescriptor} for writing.
        N)r�rMrLrYr�s  r�removeWriterzGlibReactorBase.removeWriter$s"��	
���V�T�\�\�4�;�;����Erc��|j�|j�r#|jd�|j�r�"yy)zv
        One iteration of the event loop, for trial's use.

        This is not used for actual reactor runs.
        rN)�runUntilCurrentrbrd)r%�delays  r�iteratezGlibReactorBase.iterate*s0��	
�����m�m�o��O�O�A���m�m�orc�b�tjj|�|j�y)z$
        Crash the reactor.
        N)r�PosixReactorBase�crashrirDs rr�zGlibReactorBase.crash4s!��	�"�"�(�(��.����
rc�b�tjj|�|j�y)z#
        Stop the reactor.
        N)rr��stop�wakeUprDs rr�zGlibReactorBase.stop;s#��	�"�"�'�'��-�	
���
rc���t�5|j|j�|j|��|jr|j�ddd�y#1swYyxYw)z"
        Run the reactor.
        )�installSignalHandlersN)r8�callWhenRunning�_reschedule�startRunning�_startedrk)r%r�s  rrjzGlibReactorBase.runIsT���]�	�� � ��!1�!1�2����4I��J��}�}��	�	��		�	�	�s�A
A�A'c�l�tjj|g|��i|��}|j�|S)z,
        Schedule a C{DelayedCall}.
        )rr�rsr�)r%�args�kwargs�results    rrszGlibReactorBase.callLaterSs7���+�+�5�5�d�L�T�L�V�L��	
�����
rc��|j�"|j|j�d|_|j�}|�D|jt	|dz�|j
|jj��|_yy)z;
        Schedule a glib timeout for C{_simulate}.
        Ni�)�priority)rJr\�timeoutr^�intr)rOr~)r%r�s  rr�zGlibReactorBase._reschedule]st���<�<�#�������-��D�L��,�,�.�����,�,��G�d�N�#�������9�9�-��D�L�rc�D�|j�|j�y)zX
        Run timers, and then reschedule glib timeout for next scheduled event.
        N)r�r�rDs rr)zGlibReactorBase._simulatels��	
�������r)F)r)T)r+r,r-r.rrEr�boolr#rrrr�r�r�r�r�r�r�r�r�r�r�r�r�rjrsr�r)r/r0s@rrBrBas�����B�w��"�C�"�S�"�$�"�SW�"�B)�B
�"�� R�R�!�"�:�
&�G�F������
�rrB)r.r�typingrrrr�zope.interfacer�twisted.internetr�twisted.internet.abstractr	�twisted.internet.interfacesr
rr�twisted.pythonr
�twisted.python.monkeyrrnrrrrr8r@r��_PollLikeMixinrBr=rr�<module>r�s���
��+�+�&�&�4�X�X��/�)�AC�!�6!�
�!��$%�
�x��D��)�*�D�0�
1�%�=E�b�$�h�=O�%�
�b�$�h��%�
�]��O�i�0�0�)�2J�2J�O��Or

Zerion Mini Shell 1.0