%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__/inotify.cpython-312.pyc

�

Ϫ�f;8���dZddlZddlZddlmZddlmZddlmZm	Z	dZ
dZdZd	Z
d
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZe
ezZeezZeezZ eezezezezezezezezZ!e
dfedfedfe
dfedfedfed fed!fed"fed#fed$fed%fed&fed'fed(fed)fed*fed+fed,fed-fgZ"d.�Z#Gd/�d0�Z$Gd1�d2e�Z%ejLZ&gd3�Z'y)4a
This module provides support for Twisted to linux inotify API.

In order to use this support, simply do the following (and start a reactor
at some point)::

    from twisted.internet import inotify
    from twisted.python import filepath

    def notify(ignored, filepath, mask):
        """
        For historical reasons, an opaque handle is passed as first
        parameter. This object should never be used.

        @param filepath: FilePath on which the event happened.
        @param mask: inotify event as hexadecimal masks
        """
        print("event %s on %s" % (
            ', '.join(inotify.humanReadableMask(mask)), filepath))

    notifier = inotify.INotify()
    notifier.startReading()
    notifier.watch(filepath.FilePath("/some/directory"), callbacks=[notify])
    notifier.watch(filepath.FilePath(b"/some/directory2"), callbacks=[notify])

Note that in the above example, a L{FilePath} which is a L{bytes} path name
or L{str} path name may be used.  However, no matter what type of
L{FilePath} is passed to this module, internally the L{FilePath} is
converted to L{bytes} according to L{sys.getfilesystemencoding}.
For any L{FilePath} returned by this module, the caller is responsible for
converting from a L{bytes} path name to a L{str} path name.

@since: 10.1
�N)�fdesc)�FileDescriptor)�_inotify�log������ �@��iiii i@i�iii i@l�access�modify�attrib�close_write�
close_nowrite�open�
moved_from�moved_to�create�delete�delete_self�	move_self�unmount�queue_overflow�ignored�only_dir�dont_follow�mask_add�is_dir�one_shotc�T�g}tD]\}}||zs�|j|��|S)zh
    Auxiliary function that converts a hexadecimal mask into a series
    of human readable flags.
    )�_FLAG_TO_HUMAN�append)�mask�s�k�vs    �:/usr/lib/python3/dist-packages/twisted/internet/inotify.py�humanReadableMaskr,qs5��
	�A�����1��t�8�
�H�H�Q�K��
�H�c�$�eZdZdZeddfd�Zd�Zy)�_Watcha�
    Watch object that represents a Watch point in the filesystem. The
    user should let INotify to create these objects

    @ivar path: The path over which this watch point is monitoring
    @ivar mask: The events monitored by this watchpoint
    @ivar autoAdd: Flag that determines whether this watch point
        should automatically add created subdirectories
    @ivar callbacks: L{list} of callback functions that will be called
        when an event occurs on this watch.
    FNc�`�|j�|_||_||_|�g}||_y�N)�asBytesMode�pathr'�autoAdd�	callbacks)�selfr3r'r4r5s     r+�__init__z_Watch.__init__�s2���$�$�&��	���	�������I�"��r-c�Z�|j�}|jD]}||||��y)zL
        Callback function used by L{INotify} to dispatch an event.
        N)r2r5)r6�filepath�events�callbacks    r+�_notifyz_Watch._notify�s1���'�'�)�����	-�H��T�8�V�,�	-r-)�__name__�
__module__�__qualname__�__doc__�
IN_WATCH_MASKr7r<�r-r+r/r/}s��
�#0��$�#�-r-r/c�b�eZdZdZeZdd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Ze
dddfd�Zd
�Zd�Zy)�INotifya�
    The INotify file descriptor, it basically does everything related
    to INotify, from reading to notifying watch points.

    @ivar _buffer: a L{bytes} containing the data read from the inotify fd.

    @ivar _watchpoints: a L{dict} that maps from inotify watch ids to
        watchpoints objects

    @ivar _watchpaths: a L{dict} that maps from watched paths to the
        inotify watch ids
    Nc�2�tj||��|jj�|_tj|j�tj|j�d|_d|_	d|_
i|_i|_y)N)�reactorrTr-)
rr7r�init�_fdr�setNonBlocking�_setCloseOnExec�	connected�_writeDisconnected�_buffer�_watchpoints�_watchpaths)r6rFs  r+r7zINotify.__init__�st������g�6��=�=�%�%�'���
���T�X�X�&�
���d�h�h�'����"&�����������r-c���|j�}|jj|j||�}t	||||�}||j
|<||j|<|S)a~
        Private helper that abstracts the use of ctypes.

        Calls the internal inotify API and checks for any errors after the
        call. If there's an error L{INotify._addWatch} can raise an
        INotifyError. If there's no error it proceeds creating a watchpoint and
        adding a watchpath for inverse lookup of the file descriptor from the
        path.
        )r2r�addrHr/rNrO)r6r3r'r4r5�wd�iwps       r+�	_addWatchzINotify._addWatch�sc�����!��
�]�]�
�
�t�x�x��t�
4���T�4��)�4�� #����"��!#�������	r-c���|jj|j|�|jj	|�}|j
j	|j�y)a
        Private helper that abstracts the use of ctypes.

        Calls the internal inotify API to remove an fd from inotify then
        removes the corresponding watchpoint from the internal mapping together
        with the file descriptor from the watchpath.
        N)r�removerHrN�poprOr3)r6rRrSs   r+�_rmWatchzINotify._rmWatch�sJ��	
�
�
���T�X�X�r�*����#�#�B�'�������S�X�X�&r-c���tj||�|jdk\r!	tj|j�yy#t
$r }t
j|d�Yd}~yd}~wwxYw)zR
        Release the inotify file descriptor and do the necessary cleanup
        rz'Couldn't close INotify file descriptor.N)r�connectionLostrH�os�close�OSErrorr�err)r6�reason�es   r+rZzINotify.connectionLost�s`��	�%�%�d�F�3��8�8�q�=�
F�������"����
F�����D�E�E��
F�s�A�	A1�A,�,A1c��|jS)z�
        Get the underlying file descriptor from this inotify observer.
        Required by L{abstract.FileDescriptor} subclasses.
        )rH�r6s r+�filenozINotify.fileno�s
��
�x�x�r-c�X�tj|j|j�y)zC
        Read some data from the observed file descriptors
        N)r�
readFromFDrH�_doReadrbs r+�doReadzINotify.doRead�s��	������4�<�<�0r-c�h�|xj|z
c_t|j�dk\�rttjd|jdd�\}}}}|r"|jdd|zj	d�}nd}|jd|zd|_	|j
|}|jj�}|r|j|�}|j||�|jro|tzrf|tzr]|j||jd|j ��}	|j"j%d|j&|j
|	�|t(zr!|j+|�|j-�t|j�dk\r��syy#t$rY���wxYw)zF
        Work on the data just read from the file descriptor.
        rz=LLLLr�NT�r'r4r5)rM�len�struct�unpack�rstriprN�KeyErrorr3r2�childr<r4�IN_ISDIR�	IN_CREATE�watchr'r5rF�	callLater�_addChildren�IN_DELETE_SELFrX�loseConnection)
r6�in_rRr'�cookie�size�namerSr3�new_wds
          r+rfzINotify._doRead�sw��	
�������$�,�,��2�%�%+�]�]�7�D�L�L��2�<N�%O�"�B��f�d���|�|�B��d��3�:�:�5�A�����<�<��T�	��4�D�L�
��'�'��+���8�8�'�'�)�D���z�z�$�'���K�K��d�#��{�{�t�h��4�)�3C�����s�x�x�����$������&�&�q�$�*;�*;�T�=N�=N�v�=V�W��n�$��
�
�b�!��#�#�%�I�$�,�,��2�%���
��
�s�F$�$	F1�0F1c���	|jj�}|D]�}|j�rz|j	||j
d|j��}|j|ttz�|jjd|j|j|�|j�s��|j|ttz���y#t$rYywxYw)a�
        This is a very private method, please don't even think about using it.

        Note that this is a fricking hack... it's because we cannot be fast
        enough in adding a watch to a directory and so we basically end up
        getting here too late if some operations have already been going on in
        the subdir, we basically need to catchup.  This eventually ends up
        meaning that we generate double events, your app must be resistant.
        NTrjr)r3�childrenr]�isdirrsr'r5r<rqrrrFrtrurN�isfile�IN_CLOSE_WRITE)r6rS�listdir�frRs     r+ruzINotify._addChildren#s���	��h�h�'�'�)�G��	;�A��w�w�y��Z�Z�����$�#�-�-�Z�X�����A�x�)�3�4����&�&�q�$�*;�*;�T�=N�=N�r�=R�S��x�x�z����A�y�>�9�:�	;���	�
�		�s�C�	C(�'C(Fc���|r=|j�D])}|j�s�|j||||d���+y|j|�}|r|S|tz}|j||||�S)aL
        Watch the 'mask' events in given path. Can raise C{INotifyError} when
        there's a problem while adding a directory.

        @param path: The path needing monitoring
        @type path: L{FilePath}

        @param mask: The events that should be watched
        @type mask: L{int}

        @param autoAdd: if True automatically add newly created
                        subdirectories
        @type autoAdd: L{bool}

        @param callbacks: A list of callbacks that should be called
                          when an event happens in the given path.
                          The callback should accept 3 arguments:
                          (ignored, filepath, mask)
        @type callbacks: L{list} of callables

        @param recursive: Also add all the subdirectories in this path
        @type recursive: L{bool}
        F)�	recursiveN)�walkrrs�
_isWatchedrvrT)r6r3r'r4r5r�rprRs        r+rsz
INotify.watchEsv��4�����
Q���;�;�=��J�J�u�d�G�Y�%�J�P�
Q�����&�B���	��.�(�D��>�>�$��g�y�A�Ar-c��|j�}|j|�}|�t|�d���|j|�y)z�
        Remove the watch point monitoring the given path

        @param path: The path that should be ignored
        @type path: L{FilePath}
        Nz is not watched)r2r�rorX)r6r3rRs   r+�ignorezINotify.ignorersC�����!��
�_�_�T�
"��
�:��d�X�_�5�6�6��M�M�"�r-c�Z�|j�}|jj|d�S)z�
        Helper function that checks if the path is already monitored
        and returns its watchdescriptor if so or None otherwise.

        @param path: The path that should be checked
        @type path: L{FilePath}
        N)r2rO�get)r6r3s  r+r�zINotify._isWatched�s+�����!�����#�#�D�$�/�/r-r1)r=r>r?r@rr7rTrXrZrcrgrfrurArsr�r�rBr-r+rDrD�sV����H��*�(
'�	F��1�)&�V ;�F'���QV�+B�Z�	0r-rD)rDr,rA�	IN_ACCESS�	IN_MODIFY�	IN_ATTRIB�IN_CLOSE_NOWRITEr��IN_OPEN�
IN_MOVED_FROM�IN_MOVED_TOrr�	IN_DELETErv�IN_MOVE_SELF�
IN_UNMOUNT�
IN_Q_OVERFLOW�
IN_IGNORED�
IN_ONLYDIR�IN_DONT_FOLLOW�IN_MASK_ADDrq�
IN_ONESHOT�IN_CLOSE�IN_MOVED�
IN_CHANGED)(r@r[rl�twisted.internetr�twisted.internet.abstractr�twisted.pythonrrr�r�r�r�r�r�r�r�rrr�rvr�r�r�r�r�r�r�rqr�r�r�r�rAr%r,r/rD�INotifyError�__all__rBr-r+�<module>r�s���
!�H
�
�"�4�(�
�	��	��	�����
���
����	��	�����
�
��
�
�
�
�
�������
�
��,�,���;�&��
��
"�
���������	�
���
����������������]�#���'��f���L�!��*���������]�#��;������$�%��������]�#��*��
�x�����)��0	
�-�-�<n0�n�n0�b�$�$���r-

Zerion Mini Shell 1.0