ML i^+pdZddlmZddlZddlZddlmZddlmZedGdd Z d d Z y) aInterface 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_subclassesceZdZddZddZddZddZddZddZddZ ddZ dd Z dd Z dd Z dd Zdd ZddZddZy)FileSystemCachec2g|_|jyN) package_rootflushselfs R/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/fscache.py__init__zFileSystemCache.__init__+s(* c||_yr )r )rr s rset_package_rootz FileSystemCache.set_package_root1s (rci|_i|_i|_i|_i|_i|_i|_i|_t|_ y)z/Start another transaction and empty all caches.N) stat_or_none_cache listdir_cachelistdir_error_cacheisfile_case_cacheexists_case_cache read_cacheread_error_cache hash_cachesetfake_package_cacher s rr zFileSystemCache.flush4sJDF3579 2424,.68*,,/Erc||jvr|j|Sd} tj|}||j|<|S#t$r6|j |r" |j |}n#t$rYnwxYwYOwxYwr )rosstatOSErrorinit_under_package_root _fake_initrpathsts r stat_or_nonezFileSystemCache.stat_or_noneAs 4** ***40 0  B)+%  ++D1.B  s5AB"A43B4 B=B?BBBc|jsytjj|\}}|dk7rytjj |j sy|j |}|ytj|jsyd}tjjtj\}}tjj|\}}||k7rytjj|rtjj|}tjj|}|jD]#} |j| s|| |zk(rd}|Sd}%|S)aIs 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&splitbasename isidentifierr(r!S_ISDIRst_mode splitdrivegetcwdisabsrelpathnormpath startswith) rr&dirnamer,r'ok current_drive_driveroots rr#z'FileSystemCache.init_under_package_rootRsD,  GGMM$/ } $ww(557   w ' :<< + 77--biik: q77%%d+q M ! 77== 77??4(Dww%%% Dt$4(?*B B  rcFtjj|\}}|dk(sJ|tjj|rJ|tjj |}tj |}t |}t jdz|t j<d|t j<d|t j<d|t j<tj|}|jj||S)zPrime 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+existsr4r!listS_IFREGST_MODEST_INOST_NLINKST_SIZE stat_resultradd)rr&r6r,r'seqs rr$zFileSystemCache._fake_initsGGMM$/=(.$.(77>>$'--'''""7+ WWW 8 LL50DLLDKKDMMDLL ^^C  ##G, rctjj|}||jvr4|j|}||jvrd|vr|j d|S||j vrt|j | tj|}||j|<||jvrd|vr|j d|S#t$r}t||j |<|d}~wwxYw)Nr*) r r&r4rrappendr copy_os_errorlistdirr")rr&resresultserrs rrKzFileSystemCache.listdirsww% 4%% %$$T*Ct...=3K =)J 4++ + 8 8 >? ? jj&G $+4 4** *}G/K NN= ) -:3-?D $ $T *I s C C:C55C:ch|j|}|ytj|jSNF)r(r!S_ISREGr/r%s risfilezFileSystemCache.isfile-   t $ :||BJJ''rc`|j|sy||jvr|j|Stjj |\}}|sd|j|<y |j |}||v}|r|j||}||j|<|S#t $rd}Y2wxYw)axReturn 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)rRrr r&r+rKr" exists_caserr&prefixheadtailnamesrLs r isfile_casezFileSystemCache.isfile_cases{{4  4)) )))$/ /WW]]4( d+0D " "4 ( LL&E%-C ""40C'*t$  C s%B B-,B-c^||jvr|j|Stjj|\}}|j |r|sd|j|<y |j |}||v}|r|j||}||j|<|S#t $rd}Y2wxYw)zoReturn whether path exists - checking path components in case sensitive fashion, up to prefix. TF)rr r&r+r5rKr"rUrVs rrUzFileSystemCache.exists_cases 4)) )))$/ /WW]]4( dv&d+/D " "4 ( LL&E%-C ""40C'*t$  C s$B B,+B,ch|j|}|ytj|jSrP)r(r!r.r/r%s risdirzFileSystemCache.isdirrSrc,|j|}|duSr )r(r%s rr>zFileSystemCache.existss   t $~rc>||jvr|j|S||jvr|j||j|tjj |\}}tjj |}|dk(r||jvrd}n& t|d5}|j}ddd|j|<t||j|<|S#1swY2xYw#t$r}||j|<d}~wwxYw)Nr*rrb) rrr(r r&r+r4ropenreadr"rr)rr&r6r,datafrNs rrczFileSystemCache.reads  4?? "??4( ( 4(( (''- - $GGMM$/''""7+ } $D4K4K)KD $%$668D$ !% +D 1 $$ .1%%d+ s0$ C>0C2C>2C;7C>> DDDc^||jvr|j||j|Sr )rrc)rr&s rrzFileSystemCache.hash_digests( t & IIdOt$$rc|j|}|j|}||ytjj||SrP)r(r r&samestat)rf1f2s1s2s rsamefilezFileSystemCache.samefile$sE   r "   r " :wwB''rN)returnNone)r list[str]rnro)r&strrnzos.stat_result | None)r&rqrnbool)r&rqrnzos.stat_result)r&rqrnrp)r&rqrWrqrnrr)r&rqrnbytes)r&rqrnrq)rirqrjrqrnrr)__name__ __module__ __qualname__rrr r(r#r$rKrRr[rUr^r>rcrrmrrrr)sO ) 2"7r.,( "H0( 6% (rrct|j}|j|_|j|_|j|_|j r|j |_|Sr )r"argserrnostrerrorfilename filename2)enews rrJrJ,sH 166 CCI::CL::CL{{  Jr)r~r"rnr") __doc__ __future__rr r!mypy_extensionsr mypy.utilrrrJrwrrrsB<# &! .((/(Dr