ML idZddlmZddlZddlZddlZddlmZddlm Z ddl m Z m Z e rddl Z GddZdd ZGd d eZd Zdd ZGddeZy)a:Interfaces for accessing metadata. We provide two implementations. * The "classic" file system implementation, which uses a directory structure of files. * A hokey sqlite backed implementation, which basically simulates the file system in an effort to work around poor file system performance on OS X. ) annotationsN)abstractmethod)Iterable) TYPE_CHECKINGAnyc~eZdZdZed dZed dZed d dZed dZeddZ eddZ y) MetadataStorez'Generic interface for metadata storage.cy)zfRead the mtime of a metadata entry. Raises FileNotFound if the entry does not exist. Nselfnames T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/mypy/metastore.pygetmtimezMetadataStore.getmtimecy)ziRead the contents of a metadata entry. Raises FileNotFound if the entry does not exist. Nr r s rreadzMetadataStore.read$rrNcy)zWrite a metadata entry. If mtime is specified, set it as the mtime of the entry. Otherwise, the current time is used. Returns True if the entry is successfully written, False otherwise. Nr )r rdatamtimes rwritezMetadataStore.write+rrcy)zDelete a metadata entryNr r s rremovezMetadataStore.remove5rrcy)zIf the backing store requires a commit, do it. But N.B. that this is not *guaranteed* to do anything, and there is no guarantee that changes are not made until it is called. Nr r s rcommitzMetadataStore.commit9rrcyNr rs rlist_allzMetadataStore.list_allBs),rrstrreturnfloatrr"r#bytesrrr"rr&rz float | Noner#boolrr"r#Noner#r*r#z Iterable[str]) __name__ __module__ __qualname____doc__rrrrrrr r rrr r sw1      &&  ,,rr cptjtjdj dS)Nascii)binasciihexlifyosurandomdecoder rr random_stringr9Fs&   BJJqM * 1 1' ::rcFeZdZd dZd dZd dZd d dZddZddZddZ y)FilesystemMetadataStorec`|jtjrd|_y||_yr) startswithr6devnullcache_dir_prefixr r?s r__init__z FilesystemMetadataStore.__init__Ks&  & &rzz 2$(D !$4D !rc|js tttjj tjj |j|Sr)r?FileNotFoundErrorintr6pathrjoinr s rrz FilesystemMetadataStore.getmtimeTsC$$#% %277##BGGLL1F1F$MNOOrcntjj|tjj|k7sJd|js t t tjj|j|d5}|jcdddS#1swYyxYw)NDon't use absolute paths!rb) r6rEnormpathabspathr?rCopenrFr)r rfs rrzFilesystemMetadataStore.readZsww%)>>[@[[>$$#% % "'',,t44d;T B a668   s B++B4Ncltjj|tjj|k7sJd|jsytjj |j|}|dzt z} tjtjj|dt|d5}|j|dddtj|||tj|||fy#1swY;xYw#t$rYywxYw)NrHF.Texist_okwb)times)r6rErJrKr?rFr9makedirsdirnamerLrreplaceutimeOSError)r rrrrE tmp_filenamerMs rrzFilesystemMetadataStore.writecsww%)>>[@[[>$$ww||D1148czMO3   KK- =lD) Q   JJ|T * eU^4     s+AD'D!9D'D$ D'' D32D3c|js ttjtjj |j|yr)r?rCr6rrErFr s rrzFilesystemMetadataStore.removews5$$#% % "'',,t44d;?? @ @sB'B)r?r"r#r*r!r%rr'r)r+r,) r-r.r/rArrrrrr r rrr;r;Js'5P (=  @rr;z CREATE TABLE IF NOT EXISTS files2 ( path TEXT UNIQUE NOT NULL, mtime REAL, data BLOB ); CREATE INDEX IF NOT EXISTS path_idx on files2(path); cnddl}|jj|}|jt|S)Nr)sqlite3.dbapi2dbapi2connect executescriptSCHEMA)db_filesqlite3dbs r connect_dbrms,    (BV IrcNeZdZd dZd dZd dZd dZdddZddZddZ dd Z y)SqliteMetadataStorec|jtjrd|_ytj|dt tj j|d|_y)NTrPzcache.db)r=r6r>rlrTrmrErFr@s rrAzSqliteMetadataStore.__init__sK  & &rzz 2DG  $t4RWW\\*:JGHrc|js t|jjd|d|f}|j}|s tt |dk(sJ|ddS)NzSELECT z FROM files2 WHERE path = ?r)rlrCexecutefetchalllen)r rfieldcurresultss r_queryzSqliteMetadataStore._querysiww#% %ggoow.IJTGT,,.#% %7|q   qz!}rcN|j|d}t|tsJ|S)Nr)ry isinstancer$)r rrs rrzSqliteMetadataStore.getmtimes' D'*%''' rcN|j|d}t|tsJ|S)Nr)ryr{r&)r rrs rrzSqliteMetadataStore.reads'{{4($&&& rNcddl}|jsy |tj}|jjd|||fy#|j$rYywxYw)NrFz@INSERT OR REPLACE INTO files2(path, mtime, data) VALUES(?, ?, ?)T)rkrltimersOperationalError)r rrrrks rrzSqliteMetadataStore.writes`ww }  GGOORud#  ''  s5A AAcj|js t|jjd|fy)Nz!DELETE FROM files2 WHERE path = ?)rlrCrsr s rrzSqliteMetadataStore.removes'ww#% % ;dWErcR|jr|jjyyr)rlrrs rrzSqliteMetadataStore.commits 77 GGNN  rc#tK|jr(|jjdD] }|d yyw)NzSELECT path FROM files2r)rlrs)r rows rr zSqliteMetadataStore.list_alls8 77ww'@A !f   s68rc)rr"rvr"r#rr!r%rr'r)r+r,) r-r.r/rAryrrrrrr r rrroros, I    F rro)r#r")rjr"r#zsqlite3.Connection)r0 __future__rr4r6r~abcrcollections.abcrtypingrrrkr r9r;rirmror rrrs`# $%)-)-X;=@m=@@ ?-?r