File manager - Edit - /usr/lib/python3/dist-packages/twisted/internet/__pycache__/inotify.cpython-310.pyc
Back
o �b<8 � @ s| d Z ddlZddlZddlmZ ddlmZ ddlmZm Z dZ dZdZd Z d ZdZdZd ZdZdZdZdZdZdZdZdZdZdZdZdZe eB ZeeB ZeeB Z eeB eB eB eB eB eB eB eB Z!e dfedfedfe dfedfedfed fed!fed"fed#fed$fed%fed&fed'fed(fed)fed*fed+fed,fed-fgZ"d.d/� Z#G d0d1� d1�Z$G d2d3� d3e�Z%ej&Z&g d4�Z'dS )5a 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� � � � � � �@ � � i i i i i @ i � i i i 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 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�humanReadableMaskq 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 u rg }|| _d S �N)�asBytesMode�pathr% �autoAdd� callbacks)�selfr/ r% r0 r1 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. r1 )r2 �filepath�events�callbackr) r) r* �_notify� s �z_Watch._notify)�__name__� __module__�__qualname__�__doc__� IN_WATCH_MASKr3 r7 r) r) r) r* r, } s r, c @ sx e Zd ZdZeZddd�Zdd� Zdd� Zd d � Zdd� Z d d� Z dd� Zdd� Ze dddfdd�Zdd� Zdd� ZdS )�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 C sT t j| |d� | j�� | _t�| j� t�| j� d| _d| _ d| _ i | _i | _d S )N)�reactorr T� ) r r3 r �init�_fdr �setNonBlocking�_setCloseOnExec� connected�_writeDisconnected�_buffer�_watchpoints�_watchpaths)r2 r>