Ë
    pPêj,  ã                  óp   — d Z ddlmZ ddlZddlZddlmZ ddlmZ  ed¬«       G d„ d	«      «       Z	dd
„Z
y)a  Interface for accessing the file system with automatic caching.

The idea is to cache the results of any file system state reads during
a single transaction. This has two main benefits:

* This avoids redundant syscalls, as we won't perform the same OS
  operations multiple times.

* This makes it easier to reason about concurrent FS updates, as different
  operations targeting the same paths can't report different state during
  a transaction.

Note that this only deals with reading state, not writing.

Properties maintained by the API:

* The contents of the file are always from the same or later time compared
  to the reported mtime of the file, even if mtime is queried after reading
  a file.

* Repeating an operation produces the same result as the first one during
  a transaction.

* Call flush() to start a new transaction (flush the caches).

The API is a bit limited. It's easy to add new cached operations, however.
You should perform all file system reads through the API to actually take
advantage of the benefits.
é    )ÚannotationsN)Ú
mypyc_attr)Úhash_digestT)Úallow_interpreted_subclassesc                  ó†   — e 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d
„Zdd„Zddd„Zdd„Zdd„Zdd„Zy)ÚFileSystemCachec                ó2   — g | _         | j                  «        y ©N)Úpackage_rootÚflush©Úselfs    úQ/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/mypy/fscache.pyÚ__init__zFileSystemCache.__init__+   s   € ð (*ˆÔØ�
‰
�ó    c                ó   — || _         y r
   )r   )r   r   s     r   Úset_package_rootz FileSystemCache.set_package_root1   s
   € Ø(ˆÕr   c                ó’   — i | _         i | _        i | _        i | _        i | _        i | _        i | _        i | _        t        «       | _	        y)z/Start another transaction and empty all caches.N)
Ústat_or_none_cacheÚlistdir_cacheÚlistdir_error_cacheÚisfile_case_cacheÚexists_case_cacheÚ
read_cacheÚread_error_cacheÚ
hash_cacheÚsetÚfake_package_cacher   s    r   r   zFileSystemCache.flush4   sJ   € àDFˆÔà35ˆÔØ79ˆÔ Ø24ˆÔØ24ˆÔØ,.ˆŒØ68ˆÔØ*,ˆŒÜ,/«EˆÕr   c                ó  — || j                   v r| j                   |   S d }	 t        j                  |«      }|| j                   |<   |S # t        $ r6 | j	                  |«      r"	 | j                  |«      }n# t        $ r Y nw xY wY ŒOw xY wr
   )r   ÚosÚstatÚOSErrorÚinit_under_package_rootÚ
_fake_init©r   ÚpathÚsts      r   Ústat_or_nonezFileSystemCache.stat_or_noneA   s“   € Ø�4×*Ñ*Ñ*Ø×*Ñ*¨4Ñ0Ð0àˆð	Ü—‘˜“ˆBð )+ˆ×Ñ Ñ%Øˆ	øô ò 	Ø×+Ñ+¨DÔ1ðØŸ™¨Ó.‘BøÜò Ùðüð		ús5   ¡A ÁBÁ"A4Á3BÁ4	B Á=BÁ?B Â BÂBc                ó  — | j                   syt        j                  j                  |«      \  }}|dk7  ryt        j                  j	                  |«      j                  «       sy| j                  |«      }|€yt        j                  |j                  «      syd}t        j                  j                  t        j                  «       «      \  }}t        j                  j                  |«      \  }}||k7  ryt        j                  j                  |«      rt        j                  j                  |«      }t        j                  j                  |«      }| j                   D ]#  }	|j                  |	«      sŒ||	|z   k(  rd} |S d}Œ% |S )aÏ  Is this path an __init__.py under a package root?

        This is used to detect packages that don't contain __init__.py
        files, which is needed to support Bazel.  The function should
        only be called for non-existing files.

        It will return True if it refers to a __init__.py file that
        Bazel would create, so that at runtime Python would think the
        directory containing it is a package.  For this to work you
        must pass one or more package roots using the --package-root
        flag.

        As an exceptional case, any directory that is a package root
        itself will not be considered to contain a __init__.py file.
        This is different from the rules Bazel itself applies, but is
        necessary for mypy to properly distinguish packages from other
        directories.

        See https://docs.bazel.build/versions/master/be/python.html,
        where this behavior is described under legacy_create_init.
        Fú__init__.pyT)r   r    r&   ÚsplitÚbasenameÚisidentifierr(   r!   ÚS_ISDIRÚst_modeÚ
splitdriveÚgetcwdÚisabsÚrelpathÚnormpathÚ
startswith)
r   r&   Údirnamer,   r'   ÚokÚcurrent_driveÚ_ÚdriveÚroots
             r   r#   z'FileSystemCache.init_under_package_rootR   sD  € ð, × Ò ØÜŸG™GŸM™M¨$Ó/Ñˆ�Ø�}Ò$ØÜ�w‰w×Ñ Ó(×5Ñ5Ô7àà×Ñ˜wÓ'ˆØˆ:Øä—<‘< §
¡
Ô+ØØˆô Ÿ7™7×-Ñ-¬b¯i©i«kÓ:Ñˆ�qÜ—7‘7×%Ñ% dÓ+‰ˆˆqØ�MÒ!ØÜ�7‰7�=‰=˜ÔÜ—7‘7—?‘? 4Ó(ˆDÜ�w‰w×Ñ Ó%ˆØ×%Ñ%ò 	ˆDØ�‰˜tÕ$Ø˜4 (™?Ò*à�BØð ˆ	ð ‘Bð	ð ˆ	r   c                óF  — t         j                  j                  |«      \  }}|dk(  sJ |«       ‚t         j                  j                  |«      rJ |«       ‚t         j                  j	                  |«      }t        j
                  |«      }t        |«      }t
        j                  dz  |t
        j                  <   d|t
        j                  <   d|t
        j                  <   d|t
        j                  <   t        j                  |«      }| j                  j                  |«       |S )zãPrime the cache with a fake __init__.py file.

        This makes code that looks for path believe an empty file by
        that name exists.  Should only be called after
        init_under_package_root() returns True.
        r*   i$  é   r   )r    r&   r+   Úexistsr4   r!   ÚlistÚS_IFREGÚST_MODEÚST_INOÚST_NLINKÚST_SIZEÚstat_resultr   Úadd)r   r&   r6   r,   r'   Úseqs         r   r$   zFileSystemCache._fake_init‹   sÜ   € ô ŸG™GŸM™M¨$Ó/Ñˆ�Ø˜=Ò(Ð.¨$Ó.Ð(Ü—7‘7—>‘> $Ô'Ð-¨Ó-Ð'Ü—'‘'×"Ñ" 7Ó+ˆÜ�W‰W�WÓˆä ›8ˆÜ ŸL™L¨5Ñ0ˆŒD�L‰LÑØˆŒD�K‰KÑØˆŒD�M‰MÑØˆŒD�L‰LÑÜ�^‰^˜CÓ ˆà×Ñ×#Ñ# GÔ,Øˆ	r   c                óú  — t         j                  j                  |«      }|| j                  v r4| j                  |   }|| j                  v rd|vr|j                  d«       |S || j                  v rt        | j                  |   «      ‚	 t        j                  |«      }|| j                  |<   || j                  v rd|vr|j                  d«       |S # t        $ r}t        |«      | j                  |<   |‚d }~ww xY w)Nr*   )
r    r&   r4   r   r   Úappendr   Úcopy_os_errorÚlistdirr"   )r   r&   ÚresÚresultsÚerrs        r   rK   zFileSystemCache.listdir¢   sõ   € Ü�w‰w×Ñ Ó%ˆØ�4×%Ñ%Ñ%Ø×$Ñ$ TÑ*ˆCà�t×.Ñ.Ñ.°=ÈÑ3KØ—
‘
˜=Ô)ØˆJØ�4×+Ñ+Ñ+Ü × 8Ñ 8¸Ñ >Ó?Ð?ð	Ü—j‘j Ó&ˆGð
 $+ˆ×Ñ˜4Ñ à�4×*Ñ*Ñ*¨}ÀGÑ/KØ�N‰N˜=Ô)Øˆøô ò 	ä-:¸3Ó-?ˆD×$Ñ$ TÑ*ØˆIûð	ús   Â	C Ã	C:ÃC5Ã5C:c                óh   — | j                  |«      }|€yt        j                  |j                  «      S ©NF)r(   r!   ÚS_ISREGr/   r%   s      r   ÚisfilezFileSystemCache.isfile¸   ó-   € Ø×Ñ˜tÓ$ˆØˆ:ØÜ�|‰|˜BŸJ™JÓ'Ð'r   c                ó`  — | j                  |«      sy|| j                  v r| j                  |   S t        j                  j	                  |«      \  }}|sd| j                  |<   y	 | j                  |«      }||v }|r| j                  ||«      }|| j                  |<   |S # t        $ r d}Y Œ2w xY w)ax  Return whether path exists and is a file.

        On case-insensitive filesystems (like Mac or Windows) this returns
        False if the case of path's last component does not exactly match
        the case found in the filesystem.

        We check also the case of other path components up to prefix.
        For example, if path is 'user-stubs/pack/mod.pyi' and prefix is 'user-stubs',
        we check that the case of 'pack' and 'mod.py' matches exactly, 'user-stubs' will be
        case insensitive on case insensitive filesystems.

        The caller must ensure that prefix is a valid file system prefix of path.
        F)rR   r   r    r&   r+   rK   r"   Úexists_case©r   r&   ÚprefixÚheadÚtailÚnamesrL   s          r   Úisfile_casezFileSystemCache.isfile_case¾   s¾   € ð �{‰{˜4Ô àØ�4×)Ñ)Ñ)Ø×)Ñ)¨$Ñ/Ð/Ü—W‘W—]‘] 4Ó(‰
ˆˆdÙØ+0ˆD×"Ñ" 4Ñ(Øð	Ø—L‘L Ó&ˆEð ˜%�-ˆCñ à×"Ñ" 4¨Ó0ˆCØ'*ˆ×Ñ˜tÑ$Øˆ
øô ò 	ØŠCð	ús   Á%B ÂB-Â,B-c                ó^  — || j                   v r| j                   |   S t        j                  j                  |«      \  }}|j	                  |«      r|sd| j                   |<   y	 | j                  |«      }||v }|r| j                  ||«      }|| j                   |<   |S # t        $ r d}Y Œ2w xY w)zoReturn whether path exists - checking path components in case sensitive
        fashion, up to prefix.
        TF)r   r    r&   r+   r5   rK   r"   rU   rV   s          r   rU   zFileSystemCache.exists_caseâ   sº   € ð �4×)Ñ)Ñ)Ø×)Ñ)¨$Ñ/Ð/Ü—W‘W—]‘] 4Ó(‰
ˆˆdØ�‰˜vÔ&©dà+/ˆD×"Ñ" 4Ñ(Øð	Ø—L‘L Ó&ˆEð ˜%�-ˆCñ à×"Ñ" 4¨Ó0ˆCØ'*ˆ×Ñ˜tÑ$Øˆ
øô ò 	ØŠCð	ús   Á$B ÂB,Â+B,c                óh   — | j                  |«      }|€yt        j                  |j                  «      S rP   )r(   r!   r.   r/   r%   s      r   ÚisdirzFileSystemCache.isdirú   rS   r   c                óŠ   — | j                  |«      }|€y|r-t        j                  j                  |«      }|| j                  vS y)NFT)r(   r    r&   r6   r   )r   r&   Ú	real_onlyr'   r6   s        r   r>   zFileSystemCache.exists   sC   € Ø×Ñ˜tÓ$ˆØˆ:ØÙÜ—g‘g—o‘o dÓ+ˆGØ $×"9Ñ"9Ð9Ð9Ør   c                ó>  — || j                   v r| j                   |   S || j                  v r| j                  |   ‚| j                  |«       t        j                  j                  |«      \  }}t        j                  j                  |«      }|dk(  r|| j                  v rd}n&	 t        |d«      5 }|j                  «       }d d d «       | j                   |<   t        |«      | j                  |<   |S # 1 sw Y   Œ2xY w# t        $ r}|| j                  |<   ‚ d }~ww xY w)Nr*   r   Úrb)r   r   r(   r    r&   r+   r4   r   ÚopenÚreadr"   r   r   )r   r&   r6   r,   ÚdataÚfrN   s          r   rd   zFileSystemCache.read	  s  € Ø�4—?‘?Ñ"Ø—?‘? 4Ñ(Ð(Ø�4×(Ñ(Ñ(Ø×'Ñ'¨Ñ-Ð-ð 	×Ñ˜$ÔäŸG™GŸM™M¨$Ó/Ñˆ�Ü—'‘'×"Ñ" 7Ó+ˆà�}Ò$¨°D×4KÑ4KÑ)KØ‰DðÜ˜$ Ó%ð $¨ØŸ6™6›8�D÷$ð !%ˆ�‰˜ÑÜ +¨DÓ 1ˆ�‰˜ÑØˆ÷$ð $ûäò Ø.1�×%Ñ% dÑ+Øûðús0   Â$C> Â0C2ÃC> Ã2C;Ã7C> Ã>	DÄDÄDc                ó^   — || j                   vr| j                  |«       | j                   |   S r
   )r   rd   )r   r&   s     r   r   zFileSystemCache.hash_digest$  s(   € Ø�t—‘Ñ&Ø�I‰I�dŒOØ�‰˜tÑ$Ð$r   c                ó�   — | j                  |«      }| j                  |«      }|�|€yt        j                  j                  ||«      S rP   )r(   r    r&   Úsamestat)r   Úf1Úf2Ús1Ús2s        r   ÚsamefilezFileSystemCache.samefile)  sE   € Ø×Ñ˜rÓ"ˆØ×Ñ˜rÓ"ˆØˆ:˜˜ØÜ�w‰w×Ñ  BÓ'Ð'r   N)ÚreturnÚNone)r   ú	list[str]ro   rp   )r&   Ústrro   zos.stat_result | None)r&   rr   ro   Úbool)r&   rr   ro   zos.stat_result)r&   rr   ro   rq   )r&   rr   rW   rr   ro   rs   )F)r&   rr   r`   rs   ro   rs   )r&   rr   ro   Úbytes)r&   rr   ro   rr   )rj   rr   rk   rr   ro   rs   )Ú__name__Ú
__module__Ú__qualname__r   r   r   r(   r#   r$   rK   rR   r[   rU   r^   r>   rd   r   rn   © r   r   r   r   )   sO   „ óó)ó2óó"7óró.ó,(ó"óHó0(ôóó6%ô
(r   r   c                óÊ   — t        | j                  Ž }| j                  |_        | j                  |_        | j                  |_        | j
                  r| j
                  |_        |S r
   )r"   ÚargsÚerrnoÚstrerrorÚfilenameÚ	filename2)ÚeÚnews     r   rJ   rJ   1  sH   € Ü
�1—6‘6Ð
€CØ—‘€C„IØ—:‘:€C„LØ—:‘:€C„LØ‡{‚{ØŸ™ˆŒØ€Jr   )r   r"   ro   r"   )Ú__doc__Ú
__future__r   r    r!   Úmypy_extensionsr   Ú	mypy.utilr   r   rJ   rx   r   r   ú<module>r…      sB   ðñõ< #ã 	Û å &å !ñ ¨Ô.÷D(ð D(ó /ðD(ôNr   