o
    ØÝ2go  ã                   @  sZ   d Z ddlmZ ddlZddlmZmZmZ ddlm	Z	 G dd„ deƒZ
G dd	„ d	ƒZdS )
z+Watch parts of the file system for changes.é    )ÚannotationsN)ÚAbstractSetÚIterableÚ
NamedTuple)ÚFileSystemCachec                   @  s&   e Zd ZU ded< ded< ded< dS )ÚFileDataÚfloatÚst_mtimeÚintÚst_sizeÚstrÚhashN)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r   r   úF/home/garg/my-data/venv/lib/python3.10/site-packages/mypy/fswatcher.pyr      s   
 r   c                   @  sj   e Zd ZdZd&dd„Zd'd	d
„Zd(dd„Zd)dd„Zd)dd„Zd*dd„Z	d+dd„Z
d,dd„Zd-d#d$„Zd%S ).ÚFileSystemWatchera+  Watcher for file system changes among specific paths.

    All file system access is performed using FileSystemCache. We
    detect changed files by stat()ing them all and comparing hashes
    of potentially changed files. If a file has both size and mtime
    unmodified, the file is assumed to be unchanged.

    An important goal of this class is to make it easier to eventually
    use file system events to detect file changes.

    Note: This class doesn't flush the file system cache. If you don't
    manually flush it, changes won't be seen.
    Úfsr   ÚreturnÚNonec                 C  s   || _ tƒ | _i | _d S ©N)r   ÚsetÚ_pathsÚ
_file_data)Úselfr   r   r   r   Ú__init__#   s   
zFileSystemWatcher.__init__ú!dict[str, tuple[float, int, str]]c                 C  s   dd„ | j  ¡ D ƒS )Nc                 S  s   i | ]\}}|d ur||“qS r   r   )Ú.0ÚkÚvr   r   r   Ú
<dictcomp>)   s    z4FileSystemWatcher.dump_file_data.<locals>.<dictcomp>)r   Úitems©r   r   r   r   Údump_file_data(   s   z FileSystemWatcher.dump_file_dataÚpathr   Údatar   c                 C  s   || j |< d S r   )r   )r   r&   r'   r   r   r   Úset_file_data+   s   zFileSystemWatcher.set_file_dataÚpathsúIterable[str]c                 C  s4   |D ]}|| j vrd | j|< q|  j t|ƒO  _ d S r   )r   r   r   ©r   r)   r&   r   r   r   Úadd_watched_paths.   s
   

€z#FileSystemWatcher.add_watched_pathsc                 C  s2   |D ]}|| j v r| j |= q|  jt|ƒ8  _d S r   )r   r   r   r+   r   r   r   Úremove_watched_paths6   s
   
€z&FileSystemWatcher.remove_watched_pathsÚstúos.stat_resultc                 C  s&   | j  |¡}t|j|j|ƒ| j|< d S r   )r   Úhash_digestr   r	   r   r   )r   r&   r.   r0   r   r   r   Ú_update<   s   zFileSystemWatcher._updateúAbstractSet[str]c                 C  sÈ   t ƒ }|D ]\}| j| }| j |¡}|d u r%|d ur$| |¡ d | j|< q|d u r5| |¡ |  ||¡ q|j|jksEt|jƒt|jƒkra| j 	|¡}|  ||¡ |j|jks\||j
kra| |¡ q|S r   )r   r   r   Ústat_or_noneÚaddr1   r   r
   r	   r0   r   )r   r)   Úchangedr&   Úoldr.   Únew_hashr   r   r   Ú_find_changed@   s&   


€
 
€zFileSystemWatcher._find_changedc                 C  s   |   | j¡S )zGReturn paths that have changes since the last call, in the watched set.)r8   r   r$   r   r   r   Úfind_changedZ   s   zFileSystemWatcher.find_changedÚremoveú	list[str]Úupdatec                 C  s   |   |¡ |  |¡ |  |¡S )a/  Alternative to find_changed() given explicit changes.

        This only calls self.fs.stat() on added or updated files, not
        on all files.  It believes all other files are unchanged!

        Implies add_watched_paths() for add and update, and
        remove_watched_paths() for remove.
        )r-   r,   r8   )r   r:   r<   r   r   r   Úupdate_changed^   s   
	

z FileSystemWatcher.update_changedN)r   r   r   r   )r   r   )r&   r   r'   r   r   r   )r)   r*   r   r   )r&   r   r.   r/   r   r   )r)   r*   r   r2   )r   r2   )r:   r;   r<   r;   r   r2   )r   r   r   Ú__doc__r   r%   r(   r,   r-   r1   r8   r9   r=   r   r   r   r   r      s    







r   )r>   Ú
__future__r   ÚosÚtypingr   r   r   Úmypy.fscacher   r   r   r   r   r   r   Ú<module>   s    