HOME


Mini Shell 1.0
Redirecting to https://devs.lapieza.net/iniciar-sesion Redirecting to https://devs.lapieza.net/iniciar-sesion.
DIR: /proc/1784574/root/lib/python3/dist-packages/__pycache__/
Upload File :
Current File : //proc/1784574/root/lib/python3/dist-packages/__pycache__/pyinotify.cpython-311.pyc
�

�npU�[����dZGd�de��ZGd�de��ZddlZejdkreej���ddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlmZdd	lmZmZddlZddlZddlZddlZddlZddlZ	dd
lmZn#e$rYnwxYw	ddlZddlZn
#e$rdZYnwxYw	ddl Z n
#e$rdZ YnwxYwdZ!dZ"d
a#Gd�de��Z$Gd�d��Z%Gd�de%��Z&Gd�de%��Z'd�Z(e(��Z)Gd�d��Z*dD]Z+e*e+��e,��e+<�Gd�d��Z-ie-_.ie-_/e-j0�1��D]]\Z2Z3e4e-e2e3��e-j.�5e3��e3�1��D]\Z6Z7e7e,��e6<e6e-j/e7<��^ed�e-j8�9����Z:e:e-j.d<de-j/e:<Gd�d��Z;Gd �d!e;��Z<Gd"�d#e;��Z=Gd$�d%e��Z>Gd&�d'��Z?Gd(�d)e?��Z@Gd*�d+e?��ZAGd,�d-eA��ZBGd.�d/eA��ZCGd0�d1eA��ZDGd2�d3e��ZEGd4�d5��ZFGd6�d7ejGeF��ZHGd8�d9ejIeF��ZJGd:�d;eF��ZKGd<�d=eF��ZLGd>�d?��ZMGd@�dA��ZNGdB�dCe��ZOGdD�dE��ZPGdF�dG��ZQeQ��aRGdH�dIeQ��ZSdJ�ZTdK�ZUeVdLkreU��dSdS)MzW
pyinotify

@author: Sebastien Martini
@license: MIT License
@contact: seb@dbzteam.org
c��eZdZdZdS)�PyinotifyErrorz1Indicates exceptions raised by a Pyinotify class.N)�__name__�
__module__�__qualname__�__doc__���+/usr/lib/python3/dist-packages/pyinotify.pyrrs������;�;��Dr	rc��eZdZdZd�ZdS)�UnsupportedPythonVersionErrorz0
    Raised on unsupported Python versions.
    c�B�t�|d|z��dS)zV
        @param version: Current Python version
        @type version: string
        z6Python %s is unsupported, requires at least Python 3.0N�r�__init__)�self�versions  r
rz&UnsupportedPythonVersionError.__init__(s;��
	����"7�:A�!B�	C�	C�	C�	C�	Cr	N�rrrrrrr	r
rr$s2��������C�C�C�C�Cr	r�N)�r)�deque)�datetime�	timedelta)�reducez#seb@dbzteam.org (Sebastien Martini)z0.9.6Fc��eZdZdZd�ZdS)�InotifyBindingNotFoundErrorz;
    Raised when no inotify support couldn't be found.
    c�@�d}t�||��dS)Nz!Couldn't find any inotify bindingr�r�errs  r
rz$InotifyBindingNotFoundError.__init__ls#��1������c�*�*�*�*�*r	Nrrr	r
rrhs-��������+�+�+�+�+r	rc�F�eZdZdZed���Zd�Zd�Zd�Zd�Z	d�Z
dS)	�INotifyWrapperz_
    Abstract class wrapping access to inotify's functions. This is an
    internal class.
    c��tr$t��}|���r|Str$t	��}|���r|SdSdS)zO
        Factory method instanciating and returning the right wrapper.
        N)�ctypes�_CtypesLibcINotifyWrapper�init�inotify_syscalls�_INotifySyscallsWrapper)�inotifys r
�createzINotifyWrapper.createvsh���	�/�1�1�G��|�|�~�~�
����	�-�/�/�G��|�|�~�~�
���	�	�
�
r	c�*�|���S)z<
        Return None is no errno code is available.
        )�
_get_errno�rs r
�	get_errnozINotifyWrapper.get_errno�s����� � � r	c��|���}|�dSdtj|���dtj|�d�S)NzErrno: no errno supportzErrno=z (�))r+�os�strerror�errno�	errorcode)r�codes  r
�	str_errnozINotifyWrapper.str_errno�sI���~�~�����<�,�,��"$�+�d�"3�"3�"3�"3�U�_�T�5J�5J�5J�K�Kr	c�*�|���S�N)�
_inotify_initr*s r
�inotify_initzINotifyWrapper.inotify_init�s���!�!�#�#�#r	c�^�t|t��sJ�|�|||��Sr5)�
isinstance�str�_inotify_add_watch�r�fd�pathname�masks    r
�inotify_add_watchz INotifyWrapper.inotify_add_watch�s2���(�C�(�(�(�(�(��&�&�r�8�T�:�:�:r	c�.�|�||��Sr5)�_inotify_rm_watch�rr=�wds   r
�inotify_rm_watchzINotifyWrapper.inotify_rm_watch�s���%�%�b�"�-�-�-r	N)rrrr�staticmethodr'r+r3r7r@rErr	r
rrqs����������
�
��\�
�!�!�!�L�L�L�$�$�$�;�;�;�.�.�.�.�.r	rc�2�eZdZd�Zd�Zd�Zd�Zd�Zd�ZdS)r%c��d|_dSr5��_last_errnor*s r
rz _INotifySyscallsWrapper.__init__�s������r	c��tsJ�dS)NT)r$r*s r
r#z_INotifySyscallsWrapper.init�s�������tr	c��|jSr5rIr*s r
r)z"_INotifySyscallsWrapper._get_errno�s����r	c�x�	tj��}n$#t$r}|j|_Yd}~dSd}~wwxYw|S�N���)r$r7�IOErrorr0rJ)rr=rs   r
r6z%_INotifySyscallsWrapper._inotify_init�sT��	�!�.�0�0�B�B���	�	�	�"�y�D���2�2�2�2�2�����	�����	s��
7�2�7c�~�	tj|||��}n$#t$r}|j|_Yd}~dSd}~wwxYw|SrN)r$r@rPr0rJ)rr=r>r?rDrs      r
r;z*_INotifySyscallsWrapper._inotify_add_watch�sZ��	�!�3�B��$�G�G�B�B���	�	�	�"�y�D���2�2�2�2�2�����	�����	s��
:�5�:c�|�	tj||��}n$#t$r}|j|_Yd}~dSd}~wwxYw|SrN)r$rErPr0rJ)rr=rD�retrs     r
rBz)_INotifySyscallsWrapper._inotify_rm_watch�sX��	�"�3�B��;�;�C�C���	�	�	�"�y�D���2�2�2�2�2�����	�����
s��
9�4�9N�	rrrrr#r)r6r;rBrr	r
r%r%�sn������ � � ���� � � �����������r	r%c�2�eZdZd�Zd�Zd�Zd�Zd�Zd�ZdS)r"c�"�d|_d|_dSr5)�_libc�_get_errno_funcr*s r
rz"_CtypesLibcINotifyWrapper.__init__�s����
�#����r	c�"�tsJ�d}tj�d��rd}d}	tj�|��}n#ttf$rYnwxYwtj|d���|_	tj
|_t|j	d��r*t|j	d��rt|j	d��sd	Sg|j	j
_tj|j	j
_tjtjtjg|j	j_tj|j	j_tjtjg|j	j_tj|j	j_dS)
N�c�freebsdr&T)�	use_errnor7r@rEF)r!�sys�platform�
startswith�util�find_library�OSErrorrP�CDLLrWr+rX�hasattrr7�argtypes�c_int�restype�c_char_p�c_uint32r@rE)r�
try_libc_name�	libc_names   r
r#z_CtypesLibcINotifyWrapper.init�sP���
�
�
��
��<�"�"�9�-�-�	&�%�M��	�	���0�0��?�?�I�I����!�	�	�	��D�	�����[��d�;�;�;��
�%�/�����
�N�3�3�	���
�$7�8�8�	���
�$6�7�7�	��5�+-��
��(�*0�,��
��'�17��v��17��1B��
�$�-�/5�|��
�$�,�06��f�l�/K��
�#�,�.4�l��
�#�+��ts�A�A$�#A$c�<�|jsJ�|���Sr5)rXr*s r
r)z$_CtypesLibcINotifyWrapper._get_errno�s#���#�#�#�#��#�#�%�%�%r	c�F�|j�J�|j���Sr5)rWr7r*s r
r6z'_CtypesLibcINotifyWrapper._inotify_init�s$���z�%�%�%��z�&�&�(�(�(r	c��|j�J�|�tj����}t	j|��}|j�|||��Sr5)rW�encoder]�getfilesystemencodingr!�create_string_bufferr@r<s    r
r;z,_CtypesLibcINotifyWrapper._inotify_add_watch�sV���z�%�%�%�
�?�?�3�#<�#>�#>�?�?���.�x�8�8���z�+�+�B��$�?�?�?r	c�J�|j�J�|j�||��Sr5)rWrErCs   r
rBz+_CtypesLibcINotifyWrapper._inotify_rm_watch�s(���z�%�%�%��z�*�*�2�r�2�2�2r	NrTrr	r
r"r"�sq������$�$�$����>&�&�&�)�)�)�@�@�@�3�3�3�3�3r	r"c��tjd��}tj��}|�tjd����|�|��|�d��|S)zInitialize logger instance.�	pyinotifyz0[%(asctime)s %(name)s %(levelname)s] %(message)s�)�logging�	getLogger�
StreamHandler�setFormatter�	Formatter�
addHandler�setLevel)�log�console_handlers  r
�logger_initrss��
�
�K�
(�
(�C��+�-�-�O�� � ���L�M�M�O�O�O��N�N�?�#�#�#��L�L������Jr	c�B�eZdZdZd�Zd�Zd�Zeee��Zd�Z	dS)�ProcINotifya/
    Access (read, write) inotify's variables through /proc/sys/. Note that
    usually it requires administrator rights to update them.

    Examples:
      - Read max_queued_events attribute: myvar = max_queued_events.value
      - Update max_queued_events attribute: max_queued_events.value = 42
    c�"�d|_||_dS)Nz/proc/sys/fs/inotify)�_base�_attr)r�attrs  r
rzProcINotify.__init__s��+��
���
�
�
r	c���ttj�|j|j��d��5}t
|�����cddd��S#1swxYwYdS)z�
        Gets attribute's value.

        @return: stored value.
        @rtype: int
        @raise IOError: if corresponding file in /proc/sys cannot be read.
        �rN)�openr.�path�joinr�r��int�readline)r�file_objs  r
�get_valzProcINotify.get_vals����"�'�,�,�t�z�4�:�6�6��
<�
<�	,���x�(�(�*�*�+�+�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,�	,����	,�	,�	,�	,�	,�	,s�!A'�'A+�.A+c���ttj�|j|j��d��5}|�t|��dz��ddd��dS#1swxYwYdS)z�
        Sets new attribute's value.

        @param nval: replaces current value by nval.
        @type nval: int
        @raise IOError: if corresponding file in /proc/sys cannot be written.
        �w�
N)r�r.r�r�r�r��writer:)r�nvalr�s   r
�set_valzProcINotify.set_val&s����"�'�,�,�t�z�4�:�6�6��
<�
<�	-���N�N�3�t�9�9�t�+�,�,�,�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-�	-����	-�	-�	-�	-�	-�	-s�&A,�,A0�3A0c�>�d|j|���fzS)Nz<%s=%d>)r�r�r*s r
�__repr__zProcINotify.__repr__3s���D�J������7�7�7r	N)
rrrrrr�r��property�valuer�rr	r
r�r�sm�����������	,�	,�	,�	-�	-�	-�
�H�W�g�&�&�E�8�8�8�8�8r	r�)�max_queued_events�max_user_instances�max_user_watchesc
�j�eZdZdZdddddddd	d
ddd
d�dddd�ddddddd�d�Zd�Zee��ZdS)�EventsCodesa�
    Set of codes corresponding to each kind of events.
    Some of these flags are used to communicate with inotify, whereas
    the others are sent to userspace by inotify notifying some events.

    @cvar IN_ACCESS: File was accessed.
    @type IN_ACCESS: int
    @cvar IN_MODIFY: File was modified.
    @type IN_MODIFY: int
    @cvar IN_ATTRIB: Metadata changed.
    @type IN_ATTRIB: int
    @cvar IN_CLOSE_WRITE: Writtable file was closed.
    @type IN_CLOSE_WRITE: int
    @cvar IN_CLOSE_NOWRITE: Unwrittable file closed.
    @type IN_CLOSE_NOWRITE: int
    @cvar IN_OPEN: File was opened.
    @type IN_OPEN: int
    @cvar IN_MOVED_FROM: File was moved from X.
    @type IN_MOVED_FROM: int
    @cvar IN_MOVED_TO: File was moved to Y.
    @type IN_MOVED_TO: int
    @cvar IN_CREATE: Subfile was created.
    @type IN_CREATE: int
    @cvar IN_DELETE: Subfile was deleted.
    @type IN_DELETE: int
    @cvar IN_DELETE_SELF: Self (watched item itself) was deleted.
    @type IN_DELETE_SELF: int
    @cvar IN_MOVE_SELF: Self (watched item itself) was moved.
    @type IN_MOVE_SELF: int
    @cvar IN_UNMOUNT: Backing fs was unmounted.
    @type IN_UNMOUNT: int
    @cvar IN_Q_OVERFLOW: Event queued overflowed.
    @type IN_Q_OVERFLOW: int
    @cvar IN_IGNORED: File was ignored.
    @type IN_IGNORED: int
    @cvar IN_ONLYDIR: only watch the path if it is a directory (new
                      in kernel 2.6.15).
    @type IN_ONLYDIR: int
    @cvar IN_DONT_FOLLOW: don't follow a symlink (new in kernel 2.6.15).
                          IN_ONLYDIR we can make sure that we don't watch
                          the target of symlinks.
    @type IN_DONT_FOLLOW: int
    @cvar IN_EXCL_UNLINK: Events are not generated for children after they
                          have been unlinked from the watched directory.
                          (new in kernel 2.6.36).
    @type IN_EXCL_UNLINK: int
    @cvar IN_MASK_ADD: add to the mask of an already existing watch (new
                       in kernel 2.6.14).
    @type IN_MASK_ADD: int
    @cvar IN_ISDIR: Event occurred against dir.
    @type IN_ISDIR: int
    @cvar IN_ONESHOT: Only send event once.
    @type IN_ONESHOT: int
    @cvar ALL_EVENTS: Alias for considering all of the events.
    @type ALL_EVENTS: int
    ������ �@��iii)�	IN_ACCESS�	IN_MODIFY�	IN_ATTRIB�IN_CLOSE_WRITE�IN_CLOSE_NOWRITE�IN_OPEN�
IN_MOVED_FROM�IN_MOVED_TO�	IN_CREATE�	IN_DELETE�IN_DELETE_SELF�IN_MOVE_SELFi i@i�)�
IN_UNMOUNT�
IN_Q_OVERFLOW�
IN_IGNOREDiiii i@l)�
IN_ONLYDIR�IN_DONT_FOLLOW�IN_EXCL_UNLINK�IN_MASK_ADD�IN_ISDIR�
IN_ONESHOT)�OP_FLAGS�EVENT_FLAGS�
SPECIAL_FLAGSc�`�|}d}|tzr|tz
}d}|tj|zS)a>
        Returns the event name associated to mask. IN_ISDIR is appended to
        the result when appropriate. Note: only one event is returned, because
        only one event can be raised at a given time.

        @param mask: mask.
        @type mask: int
        @return: event name.
        @rtype: str
        z%sz%s|IN_ISDIR)r�r��
ALL_VALUES)r?�ms�names   r
�masknamezEventsCodes.maskname�s;�������(�?�	!����B� �D��k�,�R�0�0�0r	N)rrrr�FLAG_COLLECTIONSr�rFrr	r
r�r�Ds�������7�7�z(�'�'�'�'�'�'�'�'�'�'�'�%
�%
� (�'�'�(
�(
�(�'�'�'�'�'�	*
�	*
�)���@1�1�1�$�|�H�%�%�H�H�Hr	r�c��||zSr5r)�x�ys  r
�<lambda>r��s
���Q��r	�
ALL_EVENTSc�$�eZdZdZd�Zd�Zd�ZdS)�_Eventzw
    Event structure, represent events raised by the system. This
    is the base class and should be subclassed.

    c�N�|���D]}t|g|�R��dS)z�
        Attach attributes (contained in dict_) to self.

        @param dict_: Set of attributes.
        @type dict_: dictionary
        N)�items�setattr)r�dict_�tpls   r
rz_Event.__init__�s>���;�;�=�=�	 �	 �C��D��3������	 �	 r	c�p�d}t|j���d����D]�\}}|�d��r�|dkrt	t||����}nt
|t��r|sd}|dt�	|���t�
d���t�|����z
}��t�
d	���t�|j
j���|�dt�
d
����}|S)zS
        @return: Generic event string representation.
        @rtype: str
        �c��|dS�Nrr�r�s r
r�z!_Event.__repr__.<locals>.<lambda>�s
��q��t�r	��key�_r?z''� �=�<�>)�sorted�__dict__r�r_�hex�getattrr9r:�
output_format�
field_name�punctuation�field_value�
class_name�	__class__r)r�sr�r�s    r
r�z_Event.__repr__�s:��

��!�$�-�"5�"5�"7�"7�^�^�L�L�L�		@�		@�K�D�%����s�#�#�
���v�~�~��G�D�$�/�/�0�0����E�3�'�'�
��
���
�A�m�6�6�t�<�<�<�+�7�7��<�<�<�+�7�7��>�>�>�@�
@�A�A�)�4�4�S�9�9�9�(�3�3�D�N�4K�L�L�L��1�1�(�4�4�S�9�9�9�
;���r	c� �t|��Sr5)�reprr*s r
�__str__z_Event.__str__�s���D�z�z�r	N)rrrrrr�r�rr	r
r�r��sK��������
 � � ����.����r	r�c��eZdZdZd�Zd�ZdS)�	_RawEventzm
    Raw event, it contains only the informations provided by the system.
    It doesn't infer anything.
    c���d|_||||�d��d�}t�||��t�t
|����dS)a�
        @param wd: Watch Descriptor.
        @type wd: int
        @param mask: Bitmask of events.
        @type mask: int
        @param cookie: Cookie.
        @type cookie: int
        @param name: Basename of the file or directory against which the
                     event was raised in case where the watched directory
                     is the parent directory. None if the event was raised
                     on the watched item itself.
        @type name: string or None
        N�)rDr?�cookier�)�_str�rstripr�rr}�debugr:)rrDr?r�r��ds      r
rz_RawEvent.__init__�sc�� ��	�����[�[��&�&�
(�
(��	����a� � � ��	�	�#�d�)�)�����r	c�\�|j�t�|��|_|jSr5)r�r�r�r*s r
r�z_RawEvent.__str__s%���9�����t�,�,�D�I��y�r	N)rrrrrr�rr	r
r�r��s<�����������2����r	r�c��eZdZdZd�ZdS)�Eventa�
    This class contains all the useful informations about the observed
    event. However, the presence of each field is not guaranteed and
    depends on the type of event. In effect, some fields are irrelevant
    for some kind of event (for example 'cookie' is meaningless for
    IN_CREATE whereas it is mandatory for IN_MOVE_TO).

    The possible fields are:
      - wd (int): Watch Descriptor.
      - mask (int): Mask.
      - maskname (str): Readable event name.
      - path (str): path of the file or directory being watched.
      - name (str): Basename of the file or directory against which the
              event was raised in case where the watched directory
              is the parent directory. None if the event was raised
              on the watched item itself. This field is always provided
              even if the string is ''.
      - pathname (str): Concatenation of 'path' and 'name'.
      - src_pathname (str): Only present for IN_MOVED_TO events and only in
              the case where IN_MOVED_FROM events are watched too. Holds the
              source pathname from where pathname was moved from.
      - cookie (int): Cookie.
      - dir (bool): True if the event was raised against a directory.

    c��t�||��t�|j��|_t
r|j|_	|jrNtj	�
tj	�|j	|j����|_dStj	�
|j	��|_dS#t$r%}t�|��Yd}~dSd}~wwxYw)zH
        Concretely, this is the raw event plus inferred infos.
        N)r�rr�r�r?�COMPATIBILITY_MODE�
event_namer�r.r��abspathr�r>�AttributeErrorr}r�)r�rawrs   r
rzEvent.__init__7s���	����c�"�"�"�#�,�,�T�Y�7�7��
��	,�"�m�D�O�		��y�
;� "��������T�Y�=A�Y�1H�1H�!I�!I��
�
�
�!#�����	� :� :��
�
�
���	�	�	�
�I�I�c�N�N�N�N�N�N�N�N�N�����	���s�AC�))C�
D�C>�>DNrrr	r
r�r�s-��������2����r	r�c��eZdZdZd�ZdS)�ProcessEventErrorzD
    ProcessEventError Exception. Raised on ProcessEvent error.
    c�<�t�||��dS)zT
        @param err: Exception error description.
        @type err: string
        Nrrs  r
rzProcessEventError.__init__O� ��
	����c�*�*�*�*�*r	Nrrr	r
r�r�Ks-��������+�+�+�+�+r	r�c��eZdZdZd�Zd�ZdS)�
_ProcessEventz*
    Abstract processing event class.
    c�v�|j|jtzz
}tj�|��}|�td|z���t
|d|zd��}|�||��St
|d|�d��dzd��}|�||��S|�|��S)a
        To behave like a functor the object must be callable.
        This method is a dispatch method. Its lookup order is:
          1. process_MASKNAME method
          2. process_FAMILY_NAME method
          3. otherwise calls process_default

        @param event: Event to be processed.
        @type event: Event object
        @return: By convention when used from the ProcessEvent class:
                 - Returning False or None (default value) means keep on
                 executing next chained functors (see chain.py example).
                 - Returning True instead means do not execute next
                   processing functions.
        @rtype: bool
        @raise ProcessEventError: Event object undispatchable,
                                  unknown event.
        NzUnknown mask 0x%08x�process_�process_IN_r�r�)	r?r�r�r��getr�r��split�process_default)r�event�
stripped_maskr��meths     r
�__call__z_ProcessEvent.__call__[s���&�
�e�j�8�&;�<�
��)�-�-�m�<�<����#�$9�M�$I�J�J�J��t�Z�(�2�D�9�9�����4��;�;���t�]�X�^�^�C�-@�-@��-C�C�T�J�J�����4��;�;���#�#�E�*�*�*r	c� �d|jjzS)Nz<%s>)r�rr*s r
r�z_ProcessEvent.__repr__~s�����/�/�/r	N)rrrrrr�rr	r
rrWs=��������!+�!+�!+�F0�0�0�0�0r	rc�J�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zdd�Zd
S)
�_SysProcessEventa�
    There is three kind of processing according to each event:

      1. special handling (deletion from internal container, bug, ...).
      2. default treatment: which is applied to the majority of events.
      3. IN_ISDIR is never sent alone, he is piggybacked with a standard
         event, he is not processed as the others events, instead, its
         value is captured and appropriately aggregated to dst event.
    c�>�||_||_i|_i|_dS)z�

        @param wm: Watch Manager.
        @type wm: WatchManager instance
        @param notifier: Notifier.
        @type notifier: Notifier instance
        N)�_watch_manager�	_notifier�
_mv_cookie�_mv)r�wm�notifiers   r
rz_SysProcessEvent.__init__�s%��!���!����������r	c�0�tj��}|j|jfD]s}t	|�����D]O}|||dz
t
d���kr*t�d||d��||=�P�tdS)zh
        Cleanup (delete) old (>1mn) records contained in self._mv_cookie
        and self._mv.
        r�)�minuteszCleanup: deleting entry %srN)	r�nowrr�list�keysrr}r�)r�	date_cur_�seq�ks    r
�cleanupz_SysProcessEvent.cleanup�s���
�L�N�N�	��O�T�X�.�	�	�C��#�(�(�*�*�%�%�
�
����A��q�	�)�Y�q�-A�-A�-A�A�A��I�I�:�C��F�1�I�F�F�F��A���
�	�	r	c�.�|jtz�r�|j�|j��}t
j�|j|j��}|j	�r�|�
|���s�|jj}|||j|jd|j	|j
���}|�
|��}|��A|dk�r:t
j�|���r	tj|��D]�}t
j�||��}|j�|����=t
j�|��rt$}	n0t
j�|��rt$tz}	n��t'||	d|��}
|j�|
����nC#t,$r6}d}t.�|t3|��z��Yd}~nd}~wwxYw|�|��S)z�
        If the event affects a directory and the auto_add flag of the
        targetted watch is set to True, a new watch is added on this
        new directory, with the same attribute values than those of
        this watch.
        F��proc_fun�rec�auto_add�exclude_filterNrz(process_IN_CREATE, invalid directory: %s)r?r�r�	get_watchrDr.r�r�r�r$r%�	add_watchr"r�isdir�listdir�get_wd�isfiler�r�r�append_eventrbr}r�r:r)
r�	raw_event�watch_�created_dir�addw�addw_ret�created_dir_wdr��inner�flags�raweventr�msgs
             r
�process_IN_CREATEz"_SysProcessEvent.process_IN_CREATE�s	���>�H�$�&	2��(�2�2�9�<�@�@�F��'�,�,�v�{�I�N�C�C�K���#
2�v�'<�'<�[�'I�'I�#
2��*�4�� �4��V�[�)/��$)�F�O�/5�/D�F�F�F��"*���k�!:�!:��#�/�n�q�6H�6H��G�M�M�+�.�.�7I�2�$&�J�{�$;�$;�B�B�D�$&�G�L�L��d�$C�$C�E�#�2�9�9�%�@�@�L� (� "�w�~�~�e�4�4�)�(1���!#����u�!5�!5�)�(1�H�(<���!)�'0����4�'P�'P�H� �N�7�7��A�A�A�A�B�� #�2�2�2�H���	�	�#��C���.�1�1�1�1�1�1�1�1�����2�����#�#�I�.�.�.s�)CF?�?
G?�	,G:�:G?c�P�|j�|j��}|j}tj�tj�||j����}|tj	��f|j
|j<|�|d|ji��S)zL
        Map the cookie with the source path (+ date for cleaning).
        r�)
rr&rDr�r.�normpathr�r�rrrr�r)rr-r.�path_�src_paths     r
�process_IN_MOVED_FROMz&_SysProcessEvent.process_IN_MOVED_FROM�s����$�.�.�y�|�<�<������7�#�#�B�G�L�L��	��$G�$G�H�H��-5�x�|�~�~�,F���	�(�)��#�#�I��)�:J�/K�L�L�Lr	c�d�|j�|j��}|j}tj�tj�||j����}|j�	|j
��}d|j
i}|�/|tj��f|j
|d<|d|d<nZ|jtzrK|jrD|�|��s/|j�||j|jdd|j���|�||��S)z^
        Map the source path with the destination path (+ date for
        cleaning).
        r�Nr�src_pathnameTr!)rr&rDr�r.r9r�r�rrr�rrrr?r�r$r%r'r"r)rr-r.r:�dst_path�mv_�	to_appends       r
�process_IN_MOVED_TOz$_SysProcessEvent.process_IN_MOVED_TO�s&��
�$�.�.�y�|�<�<������7�#�#�B�G�L�L��	��$G�$G�H�H���o�!�!�)�"2�3�3���y�/�0�	��?� (�(�,�.�.�9�D�H�S��V��),�A��I�n�%�%��n�x�'�		P�F�O�		P��'�'��1�1�		P�
��)�)�(�F�K�39�?�.2�T�9?�9N�
*�
P�
P�
P��#�#�I�y�9�9�9r	c�&�|j�|j��}|j}|j�|��}|r�|d}||_|tjjz
}t|��}|jj	�
��D]N}|j�|��r2tj�||j|d���|_�On�t�d|j|tj�tj�|jtjj������|j�d��s|xjdz
c_|�|��S)a
        STATUS: the following bug has been fixed in recent kernels (FIXME:
        which version ?). Now it raises IN_DELETE_SELF instead.

        Old kernels were bugged, this event raised when the watched item
        were moved, so we had to update its path, but under some circumstances
        it was impossible: if its parent directory and its destination
        directory wasn't watched. The kernel (see include/linux/fsnotify.h)
        doesn't bring us enough informations like the destination path of
        moved items.
        rNz�The pathname '%s' of this watch %s has probably changed and couldn't be updated, so it cannot be trusted anymore. To fix this error move directories/files only between watched parents directories, in this case e.g. put a watch on '%s'.z
-unknown-path)rr&rDr�rrr.�sep�len�watches�valuesr_r�r}�errorr9�pardir�endswithr)rr-r.r;r@�	dest_path�src_path_lenr�s        r
�process_IN_MOVE_SELFz%_SysProcessEvent.process_IN_MOVE_SELF�sm���$�.�.�y�|�<�<���;���h�l�l�8�$�$���	/��A��I�#�F�K�
����#�H��x�=�=�L��(�0�7�7�9�9�
L�
L���6�$�$�X�.�.�L��W�\�\�)�Q�V�L�M�M�5J�K�K�A�F��
L�

�I�I�-�
�k�6��g�&�&�r�w�|�|�F�K�46�G�N�(D�(D�E�E�

F�
F�
F��;�'�'��8�8�
/�����.����#�#�I�.�.�.r	c�.�td|ji��S)z{
        Only signal an overflow, most of the common flags are irrelevant
        for this event (path, wd, name).
        r?)r�r?)rr-s  r
�process_IN_Q_OVERFLOWz&_SysProcessEvent.process_IN_Q_OVERFLOW's��
�f�i�n�-�.�.�.r	c�n�|�|��}|j�|j��|S)a&
        The watch descriptor raised by this event is now ignored (forever),
        it can be safely deleted from the watch manager dictionary.
        After this event we can be sure that neither the event queue nor
        the system will raise an event associated to this wd again.
        )rr�	del_watchrD)rr-�event_s   r
�process_IN_IGNOREDz#_SysProcessEvent.process_IN_IGNORED.s5���%�%�i�0�0����%�%�i�l�3�3�3��
r	Nc�R�|j�|j��}|jtt
zzr|j}nt|jtz��}|j|j|j	|j
|d�}tr||d<|�|�|��t|��S)z�
        Commons handling for the followings events:

        IN_ACCESS, IN_MODIFY, IN_ATTRIB, IN_CLOSE_WRITE, IN_CLOSE_NOWRITE,
        IN_OPEN, IN_DELETE, IN_DELETE_SELF, IN_UNMOUNT.
        )rDr?r�r��dir�is_dir)rr&rDr?r�r�rU�boolr�r�r�r��updater�)rr-rAr.�dir_r�s      r
rz _SysProcessEvent.process_default9s����$�.�.�y�|�<�<���>�^�l�:�;�	3��:�D�D��	���1�2�2�D� �|�"����"���	���
�	#�"�E�(�O�� ��L�L��#�#�#��U�|�|�r	r5)
rrrrrrr7r<rBrMrOrSrrr	r
rr�s������������
�
�
�./�./�./�`M�M�M�:�:�:�<(/�(/�(/�T/�/�/�	�	�	������r	rc�<�eZdZdZdZd	d�Zd�Zd�Zd�Zd�Z	d�Z
dS)
�ProcessEventaQ
    Process events objects, can be specialized via subclassing, thus its
    behavior can be overriden:

    Note: you should not override __init__ in your subclass instead define
    a my_init() method, this method will be called automatically from the
    constructor of this class with its optionals parameters.

      1. Provide specialized individual methods, e.g. process_IN_DELETE for
         processing a precise type of event (e.g. IN_DELETE in this case).
      2. Or/and provide methods for processing events by 'family', e.g.
         process_IN_CLOSE method will process both IN_CLOSE_WRITE and
         IN_CLOSE_NOWRITE events (if process_IN_CLOSE_WRITE and
         process_IN_CLOSE_NOWRITE aren't defined though).
      3. Or/and override process_default for catching and processing all
         the remaining types of events.
    Nc�.�||_|jdi|��dS)a�
        Enable chaining of ProcessEvent instances.

        @param pevent: Optional callable object, will be called on event
                       processing (before self).
        @type pevent: callable
        @param kargs: This constructor is implemented as a template method
                      delegating its optionals keyworded arguments to the
                      method my_init().
        @type kargs: dict
        Nr)�pevent�my_init)rr]�kargss   r
rzProcessEvent.__init__fs)����������u�����r	c��dS)a=
        This method is called from ProcessEvent.__init__(). This method is
        empty here and must be redefined to be useful. In effect, if you
        need to specifically initialize your subclass' instance then you
        just have to override this method in your subclass. Then all the
        keyworded arguments passed to ProcessEvent.__init__() will be
        transmitted as parameters to this method. Beware you MUST pass
        keyword arguments though.

        @param kargs: optional delegated arguments from __init__().
        @type kargs: dict
        Nr)rr_s  r
r^zProcessEvent.my_initus	��	
�r	c�|�d}|j�|�|��}|st�||��SdS�NF)r]rr)rr	�
stop_chainings   r
rzProcessEvent.__call__�sJ���
��;�"�!�K�K��.�.�M��	7� �)�)�$��6�6�6�	7�	7r	c��|jSr5)r]r*s r
�
nested_peventzProcessEvent.nested_pevent�s
���{�r	c�:�t�d��dS)a�
        By default this method only reports warning messages, you can overredide
        it by subclassing ProcessEvent and implement your own
        process_IN_Q_OVERFLOW method. The actions you can take on receiving this
        event is either to update the variable max_queued_events in order to
        handle more simultaneous events or to modify your code in order to
        accomplish a better filtering diminishing the number of raised events.
        Because this method is defined, IN_Q_OVERFLOW will never get
        transmitted as arguments to process_default calls.

        @param event: IN_Q_OVERFLOW event.
        @type event: dict
        zEvent queue overflowed.N)r}�warning�rr	s  r
rOz"ProcessEvent.process_IN_Q_OVERFLOW�s��	���-�.�.�.�.�.r	c��dS)ae
        Default processing event method. By default does nothing. Subclass
        ProcessEvent and redefine this method in order to modify its behavior.

        @param event: Event to be processed. Can be of any type of events but
                      IN_Q_OVERFLOW events (see method process_IN_Q_OVERFLOW).
        @type event: Event instance
        Nrrhs  r
rzProcessEvent.process_default�s	��	
�r	r5)rrrrr]rr^rrerOrrr	r
r[r[Rs���������"�F�
�
�
�
�

�

�

�
7�
7�
7����/�/�/� 	
�	
�	
�	
�	
r	r[c� �eZdZdZdd�Zd�ZdS)�PrintAllEventsz�
    Dummy class used to print events strings representations. For instance this
    class is used from command line to print all received events to stdout.
    Nc�0�|�tj}||_dS)z~
        @param out: Where events will be written.
        @type out: Object providing a valid file object interface.
        N)r]�stdout�_out)r�outs  r
r^zPrintAllEvents.my_init�s��
�;��*�C���	�	�	r	c��|j�t|����|j�d��|j���dS)a$
        Writes event string representation to file object provided to
        my_init().

        @param event: Event to be processed. Can be of any type of events but
                      IN_Q_OVERFLOW events (see method process_IN_Q_OVERFLOW).
        @type event: Event instance
        r�N)rnr�r:�flushrhs  r
rzPrintAllEvents.process_default�sJ��	
�	����E�
�
�#�#�#��	��������	�������r	r5�rrrrr^rrr	r
rkrk�sA����������������r	rkc��eZdZdZd�Zd�ZdS)�ChainIfTruezc
    Makes conditional chaining depending on the result of the nested
    processing instance.
    c��||_dS�zJ
        Method automatically called from base class constructor.
        N��_func)r�funcs  r
r^zChainIfTrue.my_init�s����
�
�
r	c�.�|�|��Sr5rwrhs  r
rzChainIfTrue.process_default�s���:�:�e�$�$�$�$r	Nrrrr	r
rtrt�s<�����������%�%�%�%�%r	rtc�8�eZdZdZd�Zd�Zd�Zd�Zd�Zd
d�Z	d	S)�StatszH
    Compute and display trivial statistics about processed events.
    c�t�tj��|_i|_tj��|_dSrv)�time�_start_time�_stats�	threading�Lock�_stats_lockr*s r
r^z
Stats.my_init�s/�� �9�;�;������$�>�+�+����r	c�8�|j���	|j�d��}|D]*}|j�|d��}|dz|j|<�+	|j���dS#|j���wxYw)z$
        Processes |event|.
        �|rr�N)r��acquirer�rr�r�release)rr	�eventsr��counts     r
rzStats.process_default�s���	
�� � �"�"�"�	'��^�)�)�#�.�.�F�$�
4�
4�
�����
�A�6�6��*/�!�)���J�'�'�
4�
��$�$�&�&�&�&�&��D��$�$�&�&�&�&���s�AA>�>Bc���|j���	|j���|j���S#|j���wxYwr5)r�r�r��copyr�r*s r
�_stats_copyzStats._stats_copy�s`���� � �"�"�"�	'��;�#�#�%�%���$�$�&�&�&�&��D��$�$�&�&�&�&���s�A
�
A(c	���|���}ttj��|jz
��}d}|dkrt	|��dz}nUd|cxkrdkrnnd|dz|dzfz}n7d|cxkrdkrnnd|dz|dzdzfz}n|dkrd|dz|dzdzfz}||d	<g}t|���d
����D]P\}}|�dt�	|���d
t�
|�������Qdt�|jj
���d�|���d�}|S)Nr��<�seciz	%dmn%dseci�Qz%dh%dmnz%dd%dh�ElapsedTimec��|dSr�rr�s r
r�z Stats.__repr__.<locals>.<lambda>
s
��Q�q�T�r	r�r�r�r�z >)r�r�r~rr:r�r��appendr�r�r�r�r�rr�)r�stats�elapsed�elapsed_str�l�evr�r�s        r
r�zStats.__repr__�s���� � �"�"���d�i�k�k�D�$4�4�5�5�����R�<�<��g�,�,��.�K�K�
�7�
!�
!�
!�
!�T�
!�
!�
!�
!�
!�%��2��w��|�(D�D�K�K�
�W�
$�
$�
$�
$�u�
$�
$�
$�
$�
$�#�w��~��$��"�7L�&M�M�K�K�
��
�
�"�g��o��%��4�7O�%P�P�K�*��m��������
�
�>�>�B�B�B�	D�	D�I�B��
�H�H�H��!9�!9�"�!=�!=�!=�!=�!.�!:�!:�5�!A�!A�!A�C�
D�
D�
D�
D�	D�'�1�1�$�.�2I�J�J�J���������
%���r	c�L�tjtjztjztjz}tj||d��}tj|t|���tj
������tj|��dS)z�
        Dumps statistics.

        @param filename: filename where stats will be dumped, filename is
                         created and must not exist prior to this call.
        @type filename: string
        �N)r.�O_WRONLY�O_CREAT�
O_NOFOLLOW�O_EXCLr�r��bytesr��locale�getpreferredencoding�close)r�filenamer4r=s    r
�dumpz
Stats.dumpsq����B�J�&�r�}�4�R�Y�>��
�W�X�u�f�
-�
-��
���U�4�<�<�>�>�6�+F�+H�+H�I�I�J�J�J�
�������r	�-c	�|���|���}|sdSt|�����}||z�dtt�d|z����dzz���fd�}d�t|t|�	��d��������}|S)	Nr�z%%-26s%%-%ds%%s�@r�c	����t�|d��t�dt|d�z��z��t�d|dzd��fzS)Nrr�r�z%d�yellow)r�r�r�r��simple)r��fmt�unitys ��r
ryzStats.__str__.<locals>.func'sm����-�2�2�1�Q�4�8�8�'�3�3�C�#�a��d�U�l�:K�:K�4K�L�L�'�.�.�t�a��d�{�H�E�E�G�G�
Gr	r�c��|dSr�rr�s r
r�zStats.__str__.<locals>.<lambda>+s
��A�a�D�r	r�)
r��maxrGrEr�r�r��mapr�r�)r�scaler��mryr�r�r�s      @@r
r�z
Stats.__str__s������ � �"�"���	��2������������	���3�}�'@�'@��u��'M�'M�#N�#N�%&�$'�(��	G�	G�	G�	G�	G�	G�
�I�I�c�$��u�{�{�}�}�.�.� I� I� I�J�J�K�K���r	N)r�)
rrrrr^rr�r�r�r�rr	r
r|r|�s}��������,�,�,�'�'�'�'�'�'����.��������r	r|c��eZdZdZd�ZdS)�
NotifierErrorz8
    Notifier Exception. Raised on Notifier error.

    c�<�t�||��dS)zW
        @param err: Exception string's description.
        @type err: string
        Nrrs  r
rzNotifierError.__init__4rr	Nrrr	r
r�r�/s-��������+�+�+�+�+r	r�c��eZdZdZ		dd�Zd�Zd�Zdd�Zdd	�Zd
�Z	d�Z
dejejejfd�Z
d
�Zdd�Zd�ZdS)�Notifierz.
    Read notifications, process events.

    Nrc���||_|j���|_tj��|_|j�|jtj��d|_t��|_
t|j|��|_||_
|�t��|_
||_||_||_d|_t'��|_dS)aC
        Initialization. read_freq, threshold and timeout parameters are used
        when looping.

        @param watch_manager: Watch Manager.
        @type watch_manager: WatchManager instance
        @param default_proc_fun: Default processing method. If None, a new
                                 instance of PrintAllEvents will be assigned.
        @type default_proc_fun: instance of ProcessEvent
        @param read_freq: if read_freq == 0, events are read asap,
                          if read_freq is > 0, this thread sleeps
                          max(0, read_freq - (timeout / 1000)) seconds. But if
                          timeout is None it may be different because
                          poll is blocking waiting for something to read.
        @type read_freq: int
        @param threshold: File descriptor will be read only if the accumulated
                          size to read becomes >= threshold. If != 0, you likely
                          want to use it in combination with an appropriate
                          value for read_freq because without that you would
                          keep looping without really reading anything and that
                          until the amount of events to read is >= threshold.
                          At least with read_freq set you might sleep.
        @type threshold: int
        @param timeout: see read_freq above. If provided, it must be set in
                        milliseconds. See
                        https://docs.python.org/3/library/select.html#select.poll.poll
        @type timeout: int
        )rOrONF)r�get_fd�_fd�select�poll�_pollobj�register�POLLIN�_piper�_eventqr�
_sys_proc_fun�_default_proc_funrk�
_read_freq�
_threshold�_timeout�	_coalesce�set�	_eventset�r�
watch_manager�default_proc_fun�	read_freq�	threshold�timeouts      r
rzNotifier.__init__As���>,����&�-�-�/�/�����
�
��
��
���t�x���7�7�7���
��w�w���-�d�.A�4�H�H���!1����#�%3�%5�%5�D�"�#���#�����
����������r	c�:�|j�|��dS)z�
        Append a raw event to the event queue.

        @param event: An event.
        @type event: _RawEvent instance.
        N)r�r�rhs  r
r,zNotifier.append_eventys ��	
����E�"�"�"�"�"r	c��|jSr5)r�r*s r
r"zNotifier.proc_fun�s���%�%r	Tc�N�||_|s|j���dSdS)a
        Coalescing events. Events are usually processed by batchs, their size
        depend on various factors. Thus, before processing them, events received
        from inotify are aggregated in a fifo queue. If this coalescing
        option is enabled events are filtered based on their unicity, only
        unique events are enqueued, doublons are discarded. An event is unique
        when the combination of its fields (wd, mask, cookie, name) is unique
        among events of a same batch. After a batch of events is processed any
        events is accepted again. By default this option is disabled, you have
        to explictly call this function to turn it on.

        @param coalesce: Optional new coalescing value. True by default.
        @type coalesce: Bool
        N)r�r��clear)r�coalesces  r
�coalesce_eventszNotifier.coalesce_events�s7��"����	#��N� � �"�"�"�"�"�	#�	#r	c�6�		|�|j}|j�|��}n8#tj$r&}|jdtjkrYd}~�U�d}~wwxYw|r|jd|ddkrdS|ddtj	zS)aw
        Check for new events available to read, blocks up to timeout
        milliseconds.

        @param timeout: If specified it overrides the corresponding instance
                        attribute _timeout. timeout must be sepcified in
                        milliseconds.
        @type timeout: int

        @return: New events to read.
        @rtype: bool
        TNrFr�)
r�r�r�r�rH�argsr0�EINTRr�r�)rr�rSrs    r
�check_eventszNotifier.check_events�s���	�
��?�"�m�G��m�(�(��1�1����
�<�
�
�
��8�A�;�%�+�-�-��H�H�H�H������	
�����	�t�z�!�}��A��q�	�1�1��5��1�v�a�y�6�=�(�(s�#'�A�A�A�Ac��tjddg��}tj|jtj|d��dkrdS|d}||jkr)t�d|j||j��dS	tj
|j|��}n!#t$r}t|���d}~wwxYwt�d|��d}||kr�d}tjd	||||z���\}}}	}
tjd
|
z|||z||z|
z���\}|���}t!|||	|��}
|jrMt%|
��}||jvr4|j�|��|j�|
��n|j�|
��|||
zz
}||k��dSdS)zN
        Read events from device, build _RawEvents, and enqueue them.
        �irr�rONzF(fd: %d) %d bytes available to read but threshold is fixed to %d byteszEvent queue size: %dr��iIIIz%ds)�array�fcntl�ioctlr��termios�FIONREADr�r}r�r.�read�	Exceptionr��struct�unpack�decoder�r�r:r��addr�r�)r�buf_�
queue_sizer�r6�rsum�s_sizerDr?r��	fname_len�bname�unamer5�raweventstrs               r
�read_eventszNotifier.read_events�s���{�3���$�$���;�t�x��!1�4��;�;�r�A�A��F��!�W�
����'�'��I�I�*�+/�8�Z��o�
'�
'�
'�
�F�	%�����*�-�-�A�A���	%�	%�	%���$�$�$�����	%�����	�	�(�*�5�5�5����Z����F�*0�-��89�$�t�F�{�:J�8K�+M�+M�'�B��f�i��]�5�9�#4�#$�T�F�]�4�&�=�9�3L�%L�#M�O�O�F�E��L�L�N�N�E� ��T�6�5�9�9�H��~�
.�!�(�m�m���d�n�4�4��N�&�&�{�3�3�3��L�'�'��1�1�1����#�#�H�-�-�-��F�Y�&�&�D�'�Z������s�B�
B9�%B4�4B9c��|j�r	|j���}|jjr+t�dt
|��z���X|j�|j��}|�G|j	tzs8|j	tzs(t�dt
|������|�
|��}|r|jr|�|��n|�|��|j��	|j
���|jr|j���dSdS)z�
        Routine for processing events from queue by calling their
        associated proccessing method (an instance of ProcessEvent).
        It also does internal processings, to keep the system updated.
        zEvent ignored: %sNz0Unable to retrieve Watch object associated to %s)r��popleftr�
ignore_eventsr}r�r�r&rDr?r�r�rgr�r"r�rr�r�r�)rr-r.�revents    r
�process_eventszNotifier.process_events�sL���l�	/���,�,�.�.�I��"�0�
��	�	�-��Y���?�@�@�@���(�2�2�9�<�@�@�F�����-�)G��!���3�1��K�K� R� $�Y���1�1�1���'�'�	�2�2�F��
/�&�/�
/�����'�'�'�'��&�&�v�.�.�.�%�l�	/�&	
��"�"�$�$�$��>�	#��N� � �"�"�"�"�"�	#�	#r	c	���������Vd}tj�tjd��pd}tj�||dz����dkr3tj����rd�z}t|������fd�}|���dkr�tjtj	ztj
ztjz}	tj�|	d	��}
tj
|
tttj����d
zt#j������tj|
��t)j�fd���dSdS)a
        pid_file: file where the pid will be written. If pid_file=None the pid
                  is written to /var/run/<sys.argv[0]|pyinotify>.pid, if
                  pid_file=False no pid_file is written.
        stdin, stdout, stderr: files associated to common streams.
        Nz	/var/run/rrtz.pidFz-Cannot daemonize: pid file %s already exists.c���tj��}|dkrjtj��tj��}|dkr)tjd��tjd��n)tjd��ntjd��tj�tj��}tj|d��tj�tj	tj
zd��}tj|d��tj�tj	tj
zd��}tj|d��dS)Nr�/�r�r�r�)r.�fork�setsid�chdir�umask�_exitr��O_RDONLY�dup2r�r�)�pid�fd_inp�fd_out�fd_err�stderr�stdinrms    ���r
�fork_daemonz)Notifier.__daemonize.<locals>.fork_daemons�����'�)�)�C��q����	�����g�i�i���1�H�H��H�S�M�M�M��H�U�O�O�O�O��H�Q�K�K�K�K��������W�U�B�K�0�0�F��G�F�A�����W�V�R�[���%;�V�D�D�F��G�F�A�����W�V�R�[���%;�V�D�D�F��G�F�A�����r	r�r�c�,��tj���Sr5)r.�unlink)�pid_files�r
r�z&Notifier.__daemonize.<locals>.<lambda>6s���R�Y�x�%8�%8�r	)r.r��basenamer]�argvr��lexistsr�r�r�r�r�r�r�r�r:�getpidr�r�r��atexitr�)rrrrmr�dirnamer	rrr4�fd_pids ````      r
�__daemonizezNotifier.__daemonizeso��������!�G��w�'�'�����4�4�C��H��w�|�|�G�X��->�?�?�H��u��������!:�!:��A�H�L�C���$�$�$�	�	�	�	�	�	�	�6	��
�
�
��u����K��
�*�2�=�8���B�E��W�X�u�f�5�5�F��H�V�e�C��	���$4�$4�t�$;�$*�$?�$A�$A�C�C�
D�
D�
D��H�V�����O�8�8�8�8�9�9�9�9�9��r	c���|jdkrWtj��}|j||z
z
}|dkr3t�d|��tj|��dSdSdS)NrzNow sleeping %d seconds)r�r~r}r��sleep)r�ref_time�cur_time�sleep_amounts    r
�_sleepzNotifier._sleep8sq���?�Q����y�{�{�H��?�h��.A�B�L��a����	�	�3�\�B�B�B��
�<�(�(�(�(�(��� �r	Fc��|r
|jdi|��		|���|�||��durn|tj��}|���r)|�|��|���n*#t$rt�d��YnwxYw��|�	��dS)a<
        Events are read only one time every min(read_freq, timeout)
        seconds at best and only if the size to read is >= threshold.
        After this method returns it must not be called again for the same
        instance.

        @param callback: Functor called after each event processing iteration.
                         Expects to receive the notifier object (self) as first
                         parameter. If this function returns True the loop is
                         immediately terminated otherwise the loop method keeps
                         looping.
        @type callback: callable object or function
        @param daemonize: This thread is daemonized if set to True.
        @type daemonize: boolean
        @param args: Optional and relevant only if daemonize is True. Remaining
                     keyworded arguments are directly passed to daemonize see
                     __daemonize() method. If pid_file=None or is set to a
                     pathname the caller must ensure the file does not exist
                     before this method is called otherwise an exception
                     pyinotify.NotifierError will be raised. If pid_file=False
                     it is still daemonized but the pid is not written in any
                     file.
        @type args: various
        r�NTzPyinotify stops monitoring.r)
�_Notifier__daemonizer�r~r�rr��KeyboardInterruptr}r��stop)r�callback�	daemonizer�rs     r
�loopz
Notifier.loopAs���2�	%��D��$�$�t�$�$�$�
	�
��#�#�%�%�%��(�x�x��~�~��/E�/E���9�;�;���$�$�&�&�'��K�K��)�)�)��$�$�&�&�&���$�
�
�
��	�	�7�8�8�8���
����
	�	
�	�	�����s�#B�AB�$B.�-B.c��|j�?|j�|j��tj|j��d|_d|_dS)z�
        Close inotify's instance (close its file descriptor).
        It destroys all existing watches, pending events,...
        This method is automatically called at the end of loop().
        Afterward it is invalid to access this instance.
        N)r�r��
unregisterr.r�r�r*s r
rz
Notifier.stoposK���8���M�$�$�T�X�.�.�.��H�T�X�����D�H�!����r	�NrrN)Tr5rb)rrrrrr,r"r�r�r�r�r.�devnullrrrrrr	r
r�r�<s���������HI�&*�6�6�6�6�p#�#�#�&�&�&�#�#�#�#�&)�)�)�)�@)'�)'�)'�V#�#�#�:$(�r�z�"�*��:�6:�6:�6:�6:�p)�)�)�,�,�,�,�\"�"�"�"�"r	r�c�0�eZdZdZ		dd�Zd�Zd�Zd�ZdS)	�ThreadedNotifierav
    This notifier inherits from threading.Thread for instanciating a separate
    thread, and also inherits from Notifier, because it is a threaded notifier.

    Note that every functionality provided by this class is also provided
    through Notifier class. Moreover Notifier should be considered first because
    it is not threaded and could be easily daemonized.
    Nrc�B�tj�|��tj��|_t
�||||||��t
j��|_|j	�
|jdtj��dS)ax
        Initialization, initialize base classes. read_freq, threshold and
        timeout parameters are used when looping.

        @param watch_manager: Watch Manager.
        @type watch_manager: WatchManager instance
        @param default_proc_fun: Default processing method. See base class.
        @type default_proc_fun: instance of ProcessEvent
        @param read_freq: if read_freq == 0, events are read asap,
                          if read_freq is > 0, this thread sleeps
                          max(0, read_freq - (timeout / 1000)) seconds.
        @type read_freq: int
        @param threshold: File descriptor will be read only if the accumulated
                          size to read becomes >= threshold. If != 0, you likely
                          want to use it in combination with an appropriate
                          value set for read_freq because without that you would
                          keep looping without really reading anything and that
                          until the amount of events to read is >= threshold. At
                          least with read_freq you might sleep.
        @type threshold: int
        @param timeout: see read_freq above. If provided, it must be set in
                        milliseconds. See
                        https://docs.python.org/3/library/select.html#select.poll.poll
        @type timeout: int
        rN)
r��Threadrr��_stop_eventr�r.�piper�r�r�r�r�r�s      r
rzThreadedNotifier.__init__�s���8	��!�!�$�'�'�'�$�?�,�,������$�
�/?��#�W�	.�	.�	.��W�Y�Y��
��
���t�z�!�}�f�m�<�<�<�<�<r	c��|j���tj|jdd��t
j�|��t�	|��|j
�|jd��tj|jd��tj|jd��dS)zK
        Stop notifier's loop. Stop notification. Join the thread.
        r�sstoprN)
r&r�r.r�r�r�r%r�r�rr�rr�r*s r
rzThreadedNotifier.stop�s���	
�������
����A���(�(�(�����d�#�#�#��
�
�d�����
� � ���A��/�/�/�
����A�����
����A������r	c�6�|j���s|���tj��}|���r)|�|��|���|j����}dSdS)a
        Thread's main loop. Don't meant to be called by user directly.
        Call inherited start() method instead.

        Events are read only once time every min(read_freq, timeout)
        seconds at best and only if the size of events to read is >= threshold.
        N)r&�isSetr�r~r�rr�)rrs  r
rzThreadedNotifier.loop�s����"�(�(�*�*�	#����!�!�!��y�{�{�H�� � �"�"�
#����H�%�%�%�� � �"�"�"��"�(�(�*�*�	#�	#�	#�	#�	#r	c�.�|���dS)a
        Start thread's loop: read and process events until the method
        stop() is called.
        Never call this method directly, instead call the start() method
        inherited from threading.Thread, which then will call run() in
        its turn.
        N)rr*s r
�runzThreadedNotifier.run�s��	
�	�	�����r	r )rrrrrrrr,rr	r
r#r#}sj��������HI�&*�$=�$=�$=�$=�L
 �
 �
 �#�#�#�&����r	r#c�$�eZdZdZ		dd�Zd�ZdS)�
AsyncNotifierz�
    This notifier inherits from asyncore.file_dispatcher in order to be able to
    use pyinotify along with the asyncore framework.

    Nrc��t�||||||��tj�||j|��dS)z�
        Initializes the async notifier. The only additional parameter is
        'channel_map' which is the optional asyncore private map. See
        Notifier class for the meaning of the others parameters.

        N)r�r�asyncore�file_dispatcherr�)rr�r�r�r�r��channel_maps       r
rzAsyncNotifier.__init__�sM��	���$�
�/?��#�W�	.�	.�	.�� �)�)�$���+�F�F�F�F�Fr	c�V�|���|���dS)z�
        When asyncore tells us we can read from the fd, we proceed processing
        events. This method can be overridden for handling a notification
        differently.

        N)r�r�r*s r
�handle_readzAsyncNotifier.handle_read�s.��	
�������������r	)NrrNN)rrrrrr4rr	r
r.r.�sO��������
HI�8<�
G�
G�
G�
G�����r	r.c�,�eZdZdZ			dd�Zd�Zd�ZdS)�TornadoAsyncNotifierz"
    Tornado ioloop adapter.

    Nrc	��||_||_t�||||||��|�|j|j|j��dS)a?
        Note that if later you must call ioloop.close() be sure to let the
        default parameter to all_fds=False.

        See example tornado_notifier.py for an example using this notifier.

        @param ioloop: Tornado's IO loop.
        @type ioloop: tornado.ioloop.IOLoop instance.
        @param callback: Functor called at the end of each call to handle_read
                         (IOLoop's read handler). Expects to receive the
                         notifier object (self) as single parameter.
        @type callback: callable object or function
        N)�io_loop�handle_read_callbackr�r�add_handlerr�r4�READ)	rr��iolooprr�r�r�r�r2s	         r
rzTornadoAsyncNotifier.__init__�s^�� ���$,��!����$�
�/?��#�W�	.�	.�	.����4�8�T�%5�v�{�C�C�C�C�Cr	c�x�|j�|j��t�|��dSr5)r8�remove_handlerr�r�rr*s r
rzTornadoAsyncNotifier.stops2����#�#�D�H�-�-�-��
�
�d�����r	c��|���|���|j�|�|��dSdS)z0
        See comment in AsyncNotifier.

        N�r�r�r9�rr��kwargss   r
r4z TornadoAsyncNotifier.handle_readsS��
	
�������������$�0��%�%�d�+�+�+�+�+�1�0r	)NNrrNN�rrrrrrr4rr	r
r6r6�s_��������8<�JN�!�D�D�D�D�,���,�,�,�,�,r	r6c�*�eZdZdZ		dd�Zd�Zd�ZdS)�AsyncioNotifierz0

    asyncio/trollius event loop adapter.

    Nrc��||_||_t�||||||��|�|j|j��dS)a�

        See examples/asyncio_notifier.py for an example usage.

        @param loop: asyncio or trollius event loop instance.
        @type loop: asyncio.BaseEventLoop or trollius.BaseEventLoop instance.
        @param callback: Functor called at the end of each call to handle_read.
                         Expects to receive the notifier object (self) as
                         single parameter.
        @type callback: callable object or function

        N)rr9r�r�
add_readerr�r4)rr�rrr�r�r�r�s        r
rzAsyncioNotifier.__init__#sX����	�$,��!����$�
�/?��#�W�	.�	.�	.������$�"2�3�3�3�3�3r	c�x�|j�|j��t�|��dSr5)r�
remove_readerr�r�rr*s r
rzAsyncioNotifier.stop7s2���	�����)�)�)��
�
�d�����r	c��|���|���|j�|�|��dSdSr5r@rAs   r
r4zAsyncioNotifier.handle_read;sQ���������������$�0��%�%�d�+�+�+�+�+�1�0r	)NNrrNrCrr	r
rErEsX��������
6:�JN�4�4�4�4�(���,�,�,�,�,r	rEc�"�eZdZdZdZd�Zd�ZdS)�WatchzE
    Represent a watch, i.e. a file or directory being watched.

    )rDr�r?r"r$r%rUc��||_||_||_||_||_||_tj�|j��|_dS)a�
        Initializations.

        @param wd: Watch descriptor.
        @type wd: int
        @param path: Path of the file or directory being watched.
        @type path: str
        @param mask: Mask.
        @type mask: int
        @param proc_fun: Processing callable object.
        @type proc_fun:
        @param auto_add: Automatically add watches on new directories.
        @type auto_add: bool
        @param exclude_filter: Boolean function, used to exclude new
                               directories from being automatically watched.
                               See WatchManager.__init__
        @type exclude_filter: callable object
        N)	rDr�r?r"r$r%r.r(rU)rrDr�r?r"r$r%s       r
rzWatch.__init__JsJ��&�����	���	� ��
� ��
�,����7�=�=���+�+����r	c���d��fd��jD����}t�d���t��jj���d|�dt�d����}|S)zE
        @return: String representation.
        @rtype: str
        r�c
���g|]u}|�d���t�|���t�d���t�t�|��������vS)r�r�)r_r�r�r�r�r�)�.0r�rs  �r
�
<listcomp>z"Watch.__repr__.<locals>.<listcomp>js����N�N�N������8L�8L�	N�-�":�":�4�"@�"@�"@�"/�";�";�C�"@�"@�"@�"/�";�";�G�D�DH�=J�=J�#K�#K�#K�L�N�N�Nr	r�r�)r��	__slots__r�r�r�r�r�rr�s` r
r�zWatch.__repr__es����

�H�H�N�N�N�N�#'�.�	N�N�N�
O�
O��*�5�5�c�:�:�:�)�4�4�T�^�5L�M�M�M�M��A�A�)�5�5�c�:�:�:�
<���r	N)rrrrrRrr�rr	r
rLrLBsC��������*�I�,�,�,�6����r	rLc�*�eZdZdZd�Zd�Zd�Zd�ZdS)�
ExcludeFilterz/
    ExcludeFilter is an exclusion filter.
    c� �t|t��r|�|��}nt|t��r|}nt�g|_|D]9}|j�tj|tj	�����:dS)aZ
        Examples:
          ef1 = ExcludeFilter(["/etc/rc.*", "/etc/hostname"])
          ef2 = ExcludeFilter("/my/path/exclude.lst")
          Where exclude.lst contains:
          /etc/rc.*
          /etc/hostname

        Note: it is not possible to exclude a file if its encapsulating
              directory is itself watched. See this issue for more details
              https://github.com/seb-m/pyinotify/issues/31

        @param arg_lst: is either a list of patterns or a filename from which
                        patterns will be loaded.
        @type arg_lst: list of str or str
        N)
r9r:�_load_patterns_from_filer�	TypeError�_lregexr��re�compile�UNICODE)r�arg_lst�lst�regexs    r
rzExcludeFilter.__init__{s���"�g�s�#�#�	��/�/��8�8�C�C�
���
&�
&�	��C�C��O�����	?�	?�E��L����
�5�"�*� =� =�>�>�>�>�	?�	?r	c��g}t|d��5}|���D]C}|���}|r|�d��r�.|�|���D	ddd��n#1swxYwY|S)Nr��#)r��	readlines�stripr_r�)rr�r^r��line�patterns      r
rWz&ExcludeFilter._load_patterns_from_file�s�����
�(�C�
 �
 �	$�H� �*�*�,�,�
$�
$���*�*�,�,����'�"4�"4�S�"9�"9����
�
�7�#�#�#�#�
$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$�	$����	$�	$�	$�	$��
s�AA9�9A=�A=c�0�|�|��duSr5)�match)rr_r�s   r
�_matchzExcludeFilter._match�s���{�{�4� � ��,�,r	c�L�|jD]}|�||��rdS�dS)z�
        @param path: Path to match against provided regexps.
        @type path: str
        @return: Return True if path has been matched and should
                 be excluded, False otherwise.
        @rtype: bool
        TF)rYrh)rr�r_s   r
rzExcludeFilter.__call__�s<���\�	�	�E��{�{�5�$�'�'�
��t�t�
��ur	N)rrrrrrWrhrrr	r
rUrUwsZ��������?�?�?�8	�	�	�-�-�-�����r	rUc��eZdZdZd�ZdS)�WatchManagerErrorzX
    WatchManager Exception. Raised on error encountered on watches
    operations.
    c�J�||_t�||��dS)a
        @param msg: Exception string's description.
        @type msg: string
        @param wmd: This dictionary contains the wd assigned to paths of the
                    same call for which watches were successfully added.
        @type wmd: dict
        N)�wmdr�r)rr6rms   r
rzWatchManagerError.__init__�s'��������4��%�%�%�%�%r	Nrrr	r
rkrk�s-��������	&�	&�	&�	&�	&r	rkc���eZdZdZd�fd�Zd�Zd�Zd�Zd�Ze	d���Z
d	�Zd
�Zd�Z
			dd�Zd�Z		dd�Zd�Zd�Zd�Zd�Zdd�Zd�Zd�Zd�Ze	eed��ZdS)�WatchManagera
    Provide operations for watching files and directories. Its internal
    dictionary is used to reference watched items. When used inside
    threaded code, one must instanciate as many WatchManager instances as
    there are ThreadedNotifier instances.

    c��dSrbr�r�s r
r�zWatchManager.<lambda>�s��5�r	c�>�d|_||_i|_t���|_|j�t
���|j���|_|jdkr+d}t||j�
��z���dS)aR
        Initialization: init inotify, init watch manager dictionary.
        Raise OSError if initialization fails, raise InotifyBindingNotFoundError
        if no inotify binding was found (through ctypes or from direct access to
        syscalls).

        @param exclude_filter: boolean function, returns True if current
                               path must be excluded from being watched.
                               Convenient for providing a common exclusion
                               filter for every call to add_watch.
        @type exclude_filter: callable object
        FNrz-Cannot initialize new instance of inotify, %s)�_ignore_events�_exclude_filter�_wmdrr'�_inotify_wrapperrr7r�rbr3)rr%rs   r
rzWatchManager.__init__�s���$���-�����	� .� 5� 5� 7� 7���� �(�-�/�/�/��(�5�5�7�7����8�a�<�<�A�C��#�� 5� ?� ?� A� A�A�B�B�B��<r	c�8�tj|j��dS)a
        Close inotify's file descriptor, this action will also automatically
        remove (i.e. stop watching) all its associated watch descriptors.
        After a call to this method the WatchManager's instance become useless
        and cannot be reused, a new instance must then be instanciated. It
        makes sense to call this method in few situations for instance if
        several independant WatchManager must be instanciated or if all watches
        must be removed and no other watches need to be added.
        N)r.r�r�r*s r
r�zWatchManager.close�s��	��������r	c��|jS)zs
        Return assigned inotify's file descriptor.

        @return: File descriptor.
        @rtype: int
        )r�r*s r
r�zWatchManager.get_fd�s���x�r	c�6�|j�|��S)zz
        Get watch from provided watch descriptor wd.

        @param wd: Watch descriptor.
        @type wd: int
        )rur)rrDs  r
r&zWatchManager.get_watch�s���y�}�}�R� � � r	c��	|j|=dS#t$r5}t�dt	|��z��Yd}~dSd}~wwxYw)z�
        Remove watch entry associated to watch descriptor wd.

        @param wd: Watch descriptor.
        @type wd: int
        z)Cannot delete unknown watch descriptor %sN)ru�KeyErrorr}rHr:)rrDrs   r
rQzWatchManager.del_watchsh��	N��	�"�
�
�
���	N�	N�	N��I�I�A�C��H�H�L�M�M�M�M�M�M�M�M�M�����	N���s��
A�*A�Ac��|jS)z�
        Get a reference on the internal watch manager dictionary.

        @return: Internal watch manager dictionary.
        @rtype: dict
        )rur*s r
rFzWatchManager.watchess���y�r	c�@�tj�|��S)zW
        Format path to its internal (stored in watch manager) representation.
        )r.r�r9)rr�s  r
�
__format_pathzWatchManager.__format_paths��
�w����%�%�%r	c�"�|�|��}|r|tzs
|tz}|j�|j||��}|dkr|St||||||���}||j|<t�d|��|S)z�
        Add a watch on path, build a Watch object and insert it in the
        watch manager dictionary. Return the wd value.
        r)rDr�r?r"r$r%zNew %s)	�_WatchManager__format_pathr�rvr@r�rLrur}r�)rr�r?r"r$r%rD�watchs        r
�__add_watchzWatchManager.__add_watch!s���
�!�!�$�'�'���	�D�9�,�	��I��D�
�
"�
4�
4�T�X�t�T�
J�
J��
��6�6��I���$�T�H�'��H�H�H����	�"�
��	�	�(�E�"�"�"��	r	c�4�|rtj|��S|gSr5)�glob�iglob)rr��do_globs   r
�__globzWatchManager.__glob3s!���	��:�d�#�#�#��6�Mr	NFTc	
���i}	|�|j}|�|��D]�}
t|
t��sd|	|<�|�|
|��D]�}|�||��D]�}||��sq|�|||||��x}
|	|<|
dkrLd||
|j���fz}|rt�
|���mt||	����~d|	|<������|	S)an	
        Add watch(s) on the provided |path|(s) with associated |mask| flag
        value and optionally with a processing |proc_fun| function and
        recursive flag |rec| set to True.
        All |path| components _must_ be str (i.e. unicode) objects.
        If |path| is already watched it is ignored, but if it is called with
        option rec=True a watch is put on each one of its not-watched
        subdirectory.

        @param path: Path to watch, the path can either be a file or a
                     directory. Also accepts a sequence (list) of paths.
        @type path: string or list of strings
        @param mask: Bitmask of events.
        @type mask: int
        @param proc_fun: Processing object.
        @type proc_fun: function or ProcessEvent instance or instance of
                        one of its subclasses or callable object.
        @param rec: Recursively add watches from path on all its
                    subdirectories, set to False by default (doesn't
                    follows symlinks in any case).
        @type rec: bool
        @param auto_add: Automatically add watches on newly created
                         directories in watched parent |path| directory.
                         If |auto_add| is True, IN_CREATE is ored with |mask|
                         when the watch is added.
        @type auto_add: bool
        @param do_glob: Do globbing on pathname (see standard globbing
                        module for more informations).
        @type do_glob: bool
        @param quiet: if False raises a WatchManagerError exception on
                      error. See example not_quiet.py.
        @type quiet: bool
        @param exclude_filter: predicate (boolean function), which returns
                               True if the current path must be excluded
                               from being watched. This argument has
                               precedence over exclude_filter passed to
                               the class' constructor.
        @type exclude_filter: callable object
        @return: dict of paths associated to watch descriptors. A wd value
                 is positive if the watch was added sucessfully, otherwise
                 the value is negative. If the path was invalid or was already
                 watched it is not included into this returned dictionary.
        @rtype: dict of {str: int}
        N���rz$add_watch: cannot watch %s WD=%d, %s���)rt�_WatchManager__format_paramr9r:�_WatchManager__glob�_WatchManager__walk_rec�_WatchManager__add_watchrvr3r}rHrk)rr�r?r"r#r$r��quietr%�ret_�npath�apath�rpathrDrs               r
r'zWatchManager.add_watch9sU��^���!�!�1�N��(�(��.�.�	)�	)�E��e�S�)�)�
���T�
�����U�G�4�4�
)�
)��!�_�_�U�C�8�8�)�)�E�)�>�%�0�0�)�+/�+;�+;�E�4�<D�<D�<J�,L�,L�L��T�%�[���6�6�#I�(-�r�(,�(=�(G�(G�(I�(I�(K�$K�C� %�C� #�	�	�#�����&7��T�&B�&B� B�"�')��U���#)�
)�(�r	c#�8K�|D�]}|�|��}|�|V�n� tj�|��s�@tj�|��}t|��}|j���D]�}|dj}tj�||g��}|tj	ks<t|��|kr8t|��|kr%||tj	kr|dj
V�����dS)a(
        Get every wd from self._wmd if its path is under the path of
        one (at least) of those in lpath. Doesn't follow symlinks.

        @param lpath: list of watch descriptor
        @type lpath: list of int
        @return: list of watch descriptor
        @rtype: list of int
        Nr�)�get_pathr.r�r(r9rErur��commonprefixrDrD)r�lpathr��root�lend�iwd�cur�prefs        r
�
__get_sub_reczWatchManager.__get_sub_rec�s�����	$�	$�A��=�=��#�#�D����������7�=�=��&�&�
���7�#�#�D�)�)�D��t�9�9�D��y���(�(�
$�
$���!�f�k���w�+�+�T�3�K�8�8���2�6�>�>�c�$�i�i�4�&7�&7�&)�#�h�h��o�o�&)�$�i�2�6�&9�&9��a�&�)�O�O�O��

$�#	$�	$r	c��|�|��}|r|�|��}i}|D�]"}	|�|	��}
|
r|	dkr2d|	z}|rt�|���Bt||���|r�|j�|j|
|��}|dkrQd||	<d|
||j�	��fz}|rt�|����t||���|	|ksJ�|s|r
|j
|	}
|r||
_|r||
_d||	<t�
d|j
|	����$|S)a�
        Update existing watch descriptors |wd|. The |mask| value, the
        processing object |proc_fun|, the recursive param |rec| and the
        |auto_add| and |quiet| flags can all be updated.

        @param wd: Watch Descriptor to update. Also accepts a list of
                   watch descriptors.
        @type wd: int or list of int
        @param mask: Optional new bitmask of events.
        @type mask: int
        @param proc_fun: Optional new processing function.
        @type proc_fun: function or ProcessEvent instance or instance of
                        one of its subclasses or callable object.
        @param rec: Optionally adds watches recursively on all
                    subdirectories contained into |wd| directory.
        @type rec: bool
        @param auto_add: Automatically adds watches on newly created
                         directories in the watch's path corresponding to |wd|.
                         If |auto_add| is True, IN_CREATE is ored with |mask|
                         when the watch is updated.
        @type auto_add: bool
        @param quiet: If False raises a WatchManagerError exception on
                      error. See example not_quiet.py
        @type quiet: bool
        @return: dict of watch descriptors associated to booleans values.
                 True if the corresponding wd has been successfully
                 updated, False otherwise.
        @rtype: dict of {int: bool}
        rzupdate_watch: invalid WD=%dFz(update_watch: cannot update %s WD=%d, %sTzUpdated watch - %s)r��_WatchManager__get_sub_recr�r}rHrkrvr@r�r3rur"r$r�)rrDr?r"r#r$r��lwdr��awdr�r�wd_r.s              r
�update_watchzWatchManager.update_watch�s���>�!�!�"�%�%���	*��$�$�S�)�)�C����!	<�!	<�C��M�M�#�&�&�E��
3�C�!�G�G�3�c�9�����I�I�c�N�N�N��'��T�2�2�2��
#��+�=�=�d�h��>B�D�D����7�7� %�D��I�E� %�s�D�,A�,K�,K�,M�,M�N�O�C��!��	�	�#���� �+�C��6�6�6��c�z�z�z�z��
(�8�
(���3����
+�"*����
+�"*����D��I��I�I�*�D�I�c�N�;�;�;�;��r	c#�RK�t|t��r|D]}|V��dS|V�dS)z�
        @param param: Parameter.
        @type param: string or int
        @return: wrap param.
        @rtype: list of type(param)
        N)r9r)r�param�p_s   r
�__format_paramzWatchManager.__format_param�sM�����e�T�"�"�	��
�
�������
�
��K�K�K�K�Kr	c��|�|��}|j���D]}|dj|kr
|dcS�dS)aF
        Returns the watch descriptor associated to path. This method
        presents a prohibitive cost, always prefer to keep the WD
        returned by add_watch(). If the path is unknown it returns None.

        @param path: Path.
        @type path: str
        @return: WD or None.
        @rtype: int or None
        r�rN)r�rur�r�)rr�r�s   r
r*zWatchManager.get_wds_���!�!�$�'�'���9�?�?�$�$�	�	�C��1�v�{�d�"�"��1�v�
�
�
�#�	�	r	c�L�|j�|��}|�|jSdS)z�
        Returns the path associated to WD, if WD is unknown it returns None.

        @param wd: Watch descriptor.
        @type wd: int
        @return: Path or None.
        @rtype: string or None
        N)rurr�)rrDr.s   r
r�zWatchManager.get_paths-������r�"�"�����;���r	c#��K�|r>tj�|��stj�|��s|V�dStj|��D]
\}}}|V��dS)a3
        Yields each subdirectories of top, doesn't follow symlinks.
        If rec is false, only yield top.

        @param top: root directory.
        @type top: string
        @param rec: recursive flag.
        @type rec: bool
        @return: path of one subdirectory.
        @rtype: string
        N)r.r��islinkr(�walk)r�topr#r��dirs�filess      r
�
__walk_reczWatchManager.__walk_rec sz�����	�b�g�n�n�S�)�)�	�����s�1C�1C�	��I�I�I�I�I�%'�W�S�\�\�
�
�!��d�E��
�
�
�
�
�
r	c���|�|��}|r|�|��}i}|D]�}|j�|j|��}|dkrPd||<d||j���fz}|rt�|���ht||���||j	vr|j	|=d||<t�
d||�|������|S)a�
        Removes watch(s).

        @param wd: Watch Descriptor of the file or directory to unwatch.
                   Also accepts a list of WDs.
        @type wd: int or list of int.
        @param rec: Recursively removes watches on every already watched
                    subdirectories and subfiles.
        @type rec: bool
        @param quiet: If False raises a WatchManagerError exception on
                      error. See example not_quiet.py
        @type quiet: bool
        @return: dict of watch descriptors associated to booleans values.
                 True if the corresponding wd has been successfully
                 removed, False otherwise.
        @rtype: dict of {int: bool}
        rFz!rm_watch: cannot remove WD=%d, %sTzWatch WD=%d (%s) removed)r�r�rvrEr�r3r}rHrkrur�r�)	rrDr#r�r�r�r�r�rs	         r
�rm_watchzWatchManager.rm_watch2s��$�!�!�"�%�%���	*��$�$�S�)�)�C����	K�	K�C��'�8�8���3�G�G�C��Q�w�w�!��S�	�:���!6�!@�!@�!B�!B�C�D�����I�I�c�N�N�N��'��T�2�2�2��d�i����I�c�N��D��I��I�I�0�#�t�}�}�S�7I�7I�J�J�J�J��r	c	�&��tj�|��}|dkriStj�|���|tt
zz}�fd�}|�|||t|�����dddd����S)ad
        Watch a transient file, which will be created and deleted frequently
        over time (e.g. pid file).

        @attention: Currently under the call to this function it is not
        possible to correctly watch the events triggered into the same
        base directory than the directory where is located this watched
        transient file. For instance it would be wrong to make these
        two successive calls: wm.watch_transient_file('/var/run/foo.pid', ...)
        and wm.add_watch('/var/run/', ...)

        @param filename: Filename.
        @type filename: string
        @param mask: Bitmask of events, should contain IN_CREATE and IN_DELETE.
        @type mask: int
        @param proc_class: ProcessEvent (or of one of its subclass), beware of
                           accepting a ProcessEvent's instance as argument into
                           __init__, see transient_file.py example for more
                           details.
        @type proc_class: ProcessEvent's instance or of one of its subclasses.
        @return: Same as add_watch().
        @rtype: Same as add_watch().
        r�c�>��t|d���dS�|jkS)Nr�F)r�r�)r	r	s �r
�cmp_namez3WatchManager.watch_transient_file.<locals>.cmp_name|s%����u�f�%�%�-��u��u�z�)�)r	)ryFc��dSrbrrqs r
r�z3WatchManager.watch_transient_file.<locals>.<lambda>�s��%�r	)r"r#r$r�r%)r.r�rr	r�r�r'rt)rr�r?�
proc_classrr�r	s      @r
�watch_transient_filez!WatchManager.watch_transient_file]s����0�'�/�/�(�+�+���b�=�=��I��7�#�#�H�-�-���	�I�%�%��	*�	*�	*�	*�	*��~�~�g�t�'1�z�+�8�2L�2L�2L�'M�'M�"'�',�e�-?�-?�	�A�A�	Ar	c��|jSr5�rsr*s r
�get_ignore_eventszWatchManager.get_ignore_events�s���"�"r	c��||_dSr5r�)rr�s  r
�set_ignore_eventszWatchManager.set_ignore_events�s��"����r	z'Make watch manager ignoring new events.)NFFFTN)NNFFT)FT)rrrrrr�r�r&rQr�rFr�r�r�r'r�r�r�r*r�r�r�r�r�r�r�rr	r
roro�s���������'9�&8�C�C�C�C�4
�
�
����!�!�!�
N�
N�
N�����X��&�&�&����$���8=�7;�!%�P�P�P�P�d!$�!$�!$�F>C�+/�F�F�F�F�P������ ������$(�(�(�(�V'A�'A�'A�R#�#�#�#�#�#��H�.�0A�F�H�H�M�M�Mr	roc�8�eZdZdZd	d�Zd�Zd�Zd�Zd�Zd�Z	dS)
�RawOutputFormatz(
    Format string representations.
    Nc��|pi|_dSr5)�format)rr�s  r
rzRawOutputFormat.__init__�s���l�����r	c��t|t��st|��}|j�|d��|z|j�dd��zS)Nr��normal)r9r:r�r)rr��	attributes   r
r�zRawOutputFormat.simple�sT���!�S�!�!�	��A���A�����	�2�.�.��2������"�-�-�.�	/r	c�.�|�|d��S)zPunctuation color.r��r�rSs  r
r�zRawOutputFormat.punctuation�����{�{�1�h�'�'�'r	c�.�|�|d��S)zField value color.�purpler�rSs  r
r�zRawOutputFormat.field_value�r�r	c�.�|�|d��S)zField name color.�bluer�rSs  r
r�zRawOutputFormat.field_name�s���{�{�1�f�%�%�%r	c�f�|j�dd��|�|d��zS)zClass name color.�redr��bold)r�rr�rSs  r
r�zRawOutputFormat.class_name�s+���{���u�b�)�)�D�K�K��6�,B�,B�B�Br	r5)
rrrrrr�r�r�r�r�rr	r
r�r��s���������#�#�#�#�/�/�/�(�(�(�(�(�(�&�&�&�C�C�C�C�Cr	r�c��eZdZdZd�ZdS)�ColoredOutputFormatz0
    Format colored string representations.
    c
�Z�ddddddddd	d
ddd
�}t�||��dS)Nzzzzzzzzzzzz)r��blackr��greenr�r�r��cyanr��uline�blink�invert)r�r)r�fs  r
rzColoredOutputFormat.__init__�sP�� � �� �!��!����� �
"�
"��	� � ��q�)�)�)�)�)r	Nrrr	r
r�r��s-��������
*�
*�
*�
*�
*r	r�c���ttdt��t��D]?}|�d��r(tt|t��|���@dadS)a�
    Use this function to turn on the compatibility mode. The compatibility
    mode is used to improve compatibility with Pyinotify 0.7.1 (or older)
    programs. The compatibility mode provides additional variables 'is_dir',
    'event_name', 'EventsCodes.IN_*' and 'EventsCodes.ALL_EVENTS' as
    Pyinotify 0.7.1 provided. Do not call this function from new programs!!
    Especially if there are developped for Pyinotify >= 0.8.x.
    r��IN_TN)r�r�r��globalsr_r�)�evnames r
�compatibility_moder��sg���K��z�2�2�2��)�)�<�<�����U�#�#�	<��K�����6�):�;�;�;�����r	c�v�
�ddlm}d}||���}|�ddddd	�
��|�dddd
d�
��|�ddddd�
��|�ddddd�
��|�ddddd���|�ddddd �
��|�d!d"dd#d$�
��|�d%d&dd'd(�
��|�d)d*d+d,d-�
��|���\�
}�
jrt
�d.���
jrtt���
j
st��at|��d/krd0}n|}t��}�
jrt!|t#��d1�2��}nt!|t%���3��}d}�
jr`�
j�d4��}|D]B}	t*j�|	d��}
|
r||
z}�*|�d5|	z���Cnt2}d6}�
jrd7�}|}�
jr�
fd8�}|}t
�d9|z��|�||�
j�
j�
j�:��|� |�;��d6S)<z�
    By default the watched path is '/tmp' and all types of events are
    monitored. Events monitoring serves forever, type c^c to stop it.
    r)�OptionParserz.usage: %prog [options] [path1] [path2] [pathn])�usagez-vz	--verbose�
store_true�verbosezVerbose mode)�action�dest�helpz-rz--recursive�	recursivez Add watches recursively on pathsz-az
--auto_addr$z,Automatically add watches on new directoriesz-gz--globr�zTreat paths as globsz-ez
--events-listzEVENT[,...]�events_listzpA comma-separated list of events to watch for - see the documentation for valid options (defaults to everything))�metavarr�r�z-sz--statsr�zDisplay dummy statisticsz-Vz	--versionrzPyinotify versionz-fz--raw-format�
raw_formatzDisable enhanced output format.z-cz	--command�store�commandzShell command to run upon event�
r�z/tmp�)r�r�)r��,z4The event '%s' specified with option -e is not validNc��tj�t|�������tj�d��tj�t|�������tj�d��tj���dS)Nr�)r]rmr�r�r"r:rq)r�s r
�cbzcommand_line.<locals>.cb$	s����J���T�!�*�*�,�,�/�/�0�0�0��J���T�"�"�"��J���S������.�.�/�/�/��J���T�"�"�"��J�������r	c�>��tj�jd���dS)NT)�shell)�
subprocess�Popenr�)r��optionss �r
r�zcommand_line.<locals>.cb.	s!�����W�_�D�9�9�9�9�9�9r	z2Start monitoring %s, (press c^c to halt pyinotify))r#r$r�)r)!�optparser��
add_option�
parse_argsr�r}r|r�print�__version__r�r�r�rEror�r�r|rkr�rr��	ALL_FLAGSrrHr�r�r�r'r�r$r�r)r�r��parserr�r�rrr?r�r��evcode�cb_funr�r�s             @r
�command_liner��s����
&�%�%�%�%�%�<�E�
�\��
&�
&�
&�F�
���d�K��$�>��;�;�;�
���d�M�,�&�=��?�?�?����d�L��%�I��K�K�K����d�H�\�!�1��3�3�3����d�O�]�(�-��/�/�/�
���d�I�l�"�5��7�7�7����d�K��$�,?��A�A�A�
���d�N�<�'�<��>�>�>����d�K��$�<��>�>�>��'�'�)�)�O�W�d�������R�������
�k������.�+�-�-�
�
�4�y�y�1�}�}������
���B��}�C��B����A�F�F�F����B��1A�1A�B�B�B��
�D���
��)�/�/��4�4���	3�	3�B� �*�.�.�r�1�5�5�F��
3���������-�/1�2�3�3�3�3�	3����F��}��	�	�	������	:�	:�	:�	:�	:����I�I�B�T�I�J�J�J��L�L��t��!2�W�=M�W^�Wc�L�d�d�d��M�M�6�M�"�"�"�"�"r	�__main__)Wrr�rrr]�version_inforr�r.r�r�r�r0r�r�rvr
�collectionsrrrr~rZr0r�r�r��	functoolsr�ImportErrorr!�ctypes.utilr$�
__author__r�r�rrr%r"rr}r��attrnamer�r�r�r�r�r��flagc�valcr�rXr��valr�rGr�r�r�r�r�rrr[rkrtr|r�r�r%r#r1r.r6rErLrUrkror�r�r�r�r�rrr	r
�<module>rs���.��	�	�	�	�	�Y�	�	�	�
C�C�C�C�C�N�C�C�C��
�
�
���f���
'�
'���
4�
4�4�����	�	�	�	�
�
�
�
�
�
�
�
���������������������
�
�
�
�������(�(�(�(�(�(�(�(�����	�	�	�	���������
�
�
�
�����	� � � � � � � ���	�	�	��D�	������M�M�M�����������
�F�F�F������������������������3�
�����+�+�+�+�+�.�+�+�+�+.�+.�+.�+.�+.�+.�+.�+.�\"�"�"�"�"�n�"�"�"�J83�83�83�83�83��83�83�83�x����k�m�m��&8�&8�&8�&8�&8�&8�&8�&8�dP�0�0�H�%�+�h�/�/�G�G�I�I�h���o&�o&�o&�o&�o&�o&�o&�o&�f�������/�5�5�7�7�+�+�K�E�4��G�K���%�%�%��� � ��&�&�&��Z�Z�\�\�+�+�	��c����	�	�$��&*���s�#�#�+��V�&�&��(<�(C�(C�(E�(E�
F�
F�
�&0���l�#�%1���z�"�(�(�(�(�(�(�(�(�V!�!�!�!�!��!�!�!�H+�+�+�+�+�F�+�+�+�\	+�	+�	+�	+�	+��	+�	+�	+�(0�(0�(0�(0�(0�(0�(0�(0�VM�M�M�M�M�}�M�M�M�`Z
�Z
�Z
�Z
�Z
�=�Z
�Z
�Z
�z�����\����8%�%�%�%�%�,�%�%�%�R�R�R�R�R�L�R�R�R�j
+�
+�
+�
+�
+�N�
+�
+�
+�~"�~"�~"�~"�~"�~"�~"�~"�B
V�V�V�V�V�y�'��V�V�V�r�����H�,�h����:',�',�',�',�',�8�',�',�',�T",�",�",�",�",�h�",�",�",�J2�2�2�2�2�2�2�2�j9�9�9�9�9�9�9�9�x&�&�&�&�&�	�&�&�&�"IH�IH�IH�IH�IH�IH�IH�IH�XC�C�C�C�C�C�C�C�: ��!�!�
�*�*�*�*�*�/�*�*�*�(���"b#�b#�b#�J�z����L�N�N�N�N�N��s6�
B�B�B� B)�)B3�2B3�7B<�<C�C