
    X-Ph                    |    d Z ddlmZ ddlZddlmZmZ ddlm	Z	 ddl
mZ  G d de	          Z G d	 d
          ZdS )z+Watch parts of the file system for changes.    )annotationsN)IterableSet)
NamedTuple)FileSystemCachec                  .    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__     N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypy/fswatcher.pyr	   r	      s+         OOOLLLIIIIIr   r	   c                  Z    e Zd ZdZddZddZddZd dZd dZd!dZ	d"dZ
d#dZ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                H    || _         t                      | _        i | _        d S N)r   set_paths
_file_data)selfr   s     r   __init__zFileSystemWatcher.__init__$   s     #68r   !dict[str, tuple[float, int, str]]c                H    d | j                                         D             S )Nc                    i | ]
\  }}|||S r   r   ).0kvs      r   
<dictcomp>z4FileSystemWatcher.dump_file_data.<locals>.<dictcomp>*   s    JJJAAM1MMMr   )r    itemsr!   s    r   dump_file_dataz FileSystemWatcher.dump_file_data)   s$    JJ!6!6!8!8JJJJr   pathr   datar	   c                    || j         |<   d S r   )r    )r!   r-   r.   s      r   set_file_datazFileSystemWatcher.set_file_data,   s     $r   pathsIterable[str]c                p    |D ]}|| j         vr
d | j        |<   | xj         t          |          z  c_         d S r   )r   r    r   r!   r1   r-   s      r   add_watched_pathsz#FileSystemWatcher.add_watched_paths/   sG     	- 	-D4;&& )-%s5zz!r   c                l    |D ]}|| j         v r| j         |= | xj        t          |          z  c_        d S r   )r    r   r   r4   s      r   remove_watched_pathsz&FileSystemWatcher.remove_watched_paths7   sC     	* 	*Dt&&OD)s5zz!r   stos.stat_resultc                    | j                             |          }t          |j        |j        |          | j        |<   d S r   )r   hash_digestr	   r   r   r    )r!   r-   r8   r;   s       r   _updatezFileSystemWatcher._update=   s9    g))$// (bj+ N Nr   AbstractSet[str]c                V   t                      }|D ]}| j        |         }| j                            |          }|"||                    |           d | j        |<   N|,|                    |           |                     ||           ||j        |j        k    s*t          |j                  t          |j                  k    r`| j        	                    |          }|                     ||           |j        |j        k    s||j
        k    r|                    |           |S r   )r   r    r   stat_or_noneaddr<   r   r   r   r;   r   )r!   r1   changedr-   oldr8   new_hashs          r   _find_changedzFileSystemWatcher._find_changedA   s   %% 	* 	*D/$'C%%d++Bz?KK%%%,0DOD);KK%%%LLr****Z3;..#bk2B2Bc#,FWFW2W2W  $w22488HLLr***zS[00H4H4HD)))r   c                6    |                      | j                  S )zGReturn paths that have changes since the last call, in the watched set.)rD   r   r+   s    r   find_changedzFileSystemWatcher.find_changed[   s    !!$+...r   remove	list[str]updatec                    |                      |           |                     |           |                     |          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.
        )r7   r5   rD   )r!   rG   rI   s      r   update_changedz FileSystemWatcher.update_changed_   s@     	!!&)))v&&&!!&)))r   N)r   r   r   r   )r   r#   )r-   r   r.   r	   r   r   )r1   r2   r   r   )r-   r   r8   r9   r   r   )r1   r2   r   r=   )r   r=   )rG   rH   rI   rH   r   r=   )r   r   r   __doc__r"   r,   r0   r5   r7   r<   rD   rF   rK   r   r   r   r   r      s         "9 9 9 9
K K K K% % % %" " " "" " " "O O O O   4/ / / /* * * * * *r   r   )rL   
__future__r   oscollections.abcr   r   AbstractSettypingr   mypy.fscacher   r	   r   r   r   r   <module>rS      s    1 1 " " " " " " 				 8 8 8 8 8 8 8 8       ( ( ( ( ( (    z   X* X* X* X* X* X* X* X* X* X*r   