File: //lib/python3/dist-packages/twisted/internet/__pycache__/inotify.cpython-38.pyc
U
W[c9 � @ s� d Z ddlmZ ddlZddlZddlmZ ddlmZ ddl m
Z
mZ dZdZ
d Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZdZeeB Z eeB Z!e
eB Z"e
eB eB eB eB eB eB eB eB Z#edfe
dfedfedfedfed fed!fed"fed#fed$fed%fed&fed'fed(fed)fed*fed+fed,fed-fed.fgZ$d/d0� Z%G d1d2� d2e&�Z'G d3d4� d4ee&�Z(ej)Z)d4d0d5d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIdJdKdLgZ*dS )Ma
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
� )�print_functionN)�fdesc)�FileDescriptor)�log�_inotify� � � � � � �@ � � i i i i i @ i � i i i i @l �accessZmodifyZattribZclose_writeZ
close_nowrite�openZ
moved_fromZmoved_toZcreate�deleteZdelete_selfZ move_selfZunmountZqueue_overflowZignoredZonly_dirZdont_followZmask_add�is_dirZone_shotc C s( g }t D ]\}}|| @ r|�|� q|S )zh
Auxiliary function that converts a hexadecimal mask into a series
of human readable flags.
)�_FLAG_TO_HUMAN�append)�mask�s�k�v� r �:/usr/lib/python3/dist-packages/twisted/internet/inotify.py�humanReadableMaskm s
r c @ s( e Zd ZdZeddfdd�Zdd� ZdS )�_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 C s, |� � | _|| _|| _|d kr"g }|| _d S )N)�asBytesMode�pathr �autoAdd� callbacks)�selfr r r r! r r r �__init__� s
z_Watch.__init__c C s$ |� � }| jD ]}|| ||� qdS )zL
Callback function used by L{INotify} to dispatch an event.
N)r r! )r"