+
    :1j,                        R t ^ RIHt ^ RIt^ RIt^ RIHt ^ RIHt ^ RI	t	^ RI
t
]'       d   ^ RIHt ^RIHt ]P                  ! ]4      tRsRt] ! R R	4      4       tRR
 lt ! R R4      tR# )zf
Cache suitable for shards, not allowed to change because they are named
after their own sha256 hash.
)annotationsN)	dataclass)TYPE_CHECKING)Path)	ShardDictzrepodata_shards.dbc                  B    ] tR t^t$ R R ltR]R&   R]R&   R]R&   RtR	# )
AnnotatedRawShardc               $    V ^8  d   QhRRRRRR/# )   urlstrpackagecompressed_shardbytes )formats   ";lib/python3.14/site-packages/conda/_private/shards/cache.py__annotate__AnnotatedRawShard.__annotate__!   s!     	1 	1C 	1# 	1 	1    c                	r    R V9  d   \        R4      hR V9   d   \        R4      hWn        W n        W0n        R# )z://zurl must contain '://'zpackage must not contain '://'N)
ValueErrorr   r   r   )selfr   r   r   s   &&&&r   __init__AnnotatedRawShard.__init__!   s:    566G=>> 0r   r   r   r   r   r   )r   r   r   N)__name__
__module____qualname____firstlineno__r   __annotations____static_attributes__r   r   r   r   r      s    	1 
HLr   r   c                   \         P                  ! V RRR7      p\         P                  Vn        T;_uu_ 4       p VP	                  R4      P                  4       ^ ,          pV'       d7   VP                  4       P                  R4      '       d   VP	                  R4       VP	                  R4       RRR4       V#   \         P                   d    Rp Lri ; i  + '       g   i     T# ; i)	ze
Get database connection.

dburi: uri-style sqlite database filename; accepts certain ?= parameters.
Tg      >@)uritimeoutzPRAGMA journal_mode = WALNwalzPRAGMA synchronous = NORMALzPRAGMA foreign_keys = ON)	sqlite3connectRowrow_factoryexecutefetchoneDatabaseErrorlower
startswith)dburiconncmodes   &   r   r&   r&   1   s     ??5dD9D{{D		9989BBDQGD DJJL++E22II34			,- 
 K $$ 	D	 
 Ks:   C&B:!C)$C"C:CCCCC(	c                  |    ] tR t^DtRtRR R lltR tR tR tR t	RR lt
R	 R
 ltR R ltR R ltR tR tRtR# )
ShardCachezA
Handle caching for individual shards (not the index of shards).
c                   V ^8  d   QhRR/# )r
   baser   r   )r   s   "r   r   ShardCache.__annotate__I   s     $ $T $r   c                6    Wn         V P                  VR7       R# )z0
base: directory and filename prefix for cache.
createN)r5   r&   )r   r5   r9   s   &&&r   r   ShardCache.__init__I   s     	F#r   c                	    V # Nr   r   s   &r   	__enter__ShardCache.__enter__P   s    r   c                	&    V P                  4        R # r<   )close)r   exc_typeexc_valexec_tbs   &&&&r   __exit__ShardCache.__exit__S   s    

r   c                p    V P                   '       d$   V P                   P                  4        RV n         R# R# )zF
Clean up connection. ShardCache can no longer be used after close().
N)r/   rA   r=   s   &r   rA   ShardCache.closeV   s'     999IIOODI r   c                0    \        V P                  RR7      # )z5
Copy cache with new connection. Useful for threads.
Fr8   )r3   r5   r=   s   &r   copyShardCache.copy^   s     $))E22r   c                   V P                   \        ,          P                  4       p\        V4      V n        V'       g   R#  V P                  ;_uu_ 4       pVP                  R4       RRR4       R#   + '       g   i     R# ; i  \        P                   d   p\        TR4      pT'       d   T'       d    TP                  \        P                  8X  dq   \        P                  RY54        T P                  4        M0  \         d#   p\        P                  RY54       Rs Rp?MRp?ii ; iT P                  TRR7      u Rp?# h Rp?ii ; i)	zr
Args:
    create: if True, create table if not exists.
    retry: remove cache, log warning, and retry on error.
NzCREATE TABLE IF NOT EXISTS shards (url TEXT PRIMARY KEY, package TEXT, shard BLOB, timestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP)sqlite_errorcodez%s '%s'; remove and retry.z %s '%s'; use alternate filename.zrepodata_shards_1.dbF)r9   retry)r5   SHARD_CACHE_NAMEas_urir&   r/   r)   r%   r+   hasattrrM   SQLITE_NOTADBlogwarningremove_cacheOSError)r   r9   rN   r.   r0   ehas_errorcodes   &&&    r   r&   ShardCache.connectd   s     --557EN		 a		E  $$ 	
 $A'9:M"(:(:g>S>S(S8%C>%%' >KK BEM'=$>
 ||6|??%	sr   B A1'B 1B	<B B EE65E,C=<E=D*D% E%D**E?EEEc                   V ^8  d   QhRR/# )r
   	raw_shardr   r   )r   s   "r   r   r6      s       1 r   c                    V P                   ;_uu_ 4       pVP                  RVP                  VP                  VP                  34       RRR4       R#   + '       g   i     R# ; i)zd
Args:
    url: of shard
    package: package name
    raw_shard: msgpack.zst compressed shard data
zCINSERT OR IGNORE INTO SHARDS (url, package, shard) VALUES (?, ?, ?)N)r/   r)   r   r   r   )r   r[   r0   s   && r   insertShardCache.insert   sD     YYY!IIU	 1 193M3MN YYYs   4AA$	c                   V ^8  d   QhRR/# )r
   returnzShardDict | Noner   )r   s   "r   r   r6      s      / r   c           	     	.   V P                   ;_uu_ 4       pVP                  R V34      P                  4       pV'       d8   \        P                  ! \
        P                  ! VR,          \        R7      4      MR uuRRR4       #   + '       g   i     R# ; i)z&SELECT shard FROM shards WHERE url = ?shardmax_output_sizeN)r/   r)   r*   msgpackloads	zstandard
decompressZSTD_MAX_SHARD_SIZE)r   r   r0   rows   &&  r   retrieveShardCache.retrieve   sj    YYY!))DsfMVVXC  ((G6I  YYYs   A#BB	c                    V ^8  d   QhRRRR/# )r
   urlsz	list[str]r`   zdict[str, ShardDict | None]r   )r   s   "r   r   r6      s      i 4O r   c                   V'       g   / # \         P                  ! 4       pRRP                  R\        V4      ,          4       R2pV P                  ;_uu_ 4       pVP                  W14       Uu/ uFG  pVR,          V'       d3   \        P                  ! VP                  VR,          \        R7      4      MRbKI  	  ppVuuRRR4       # u upi   + '       g   i     R# ; i)	zt
Query database for cached shard urls.

Return a dict of urls in cache mapping to the Shard or None if not present.
z,SELECT url, shard FROM shards WHERE url IN (,z) ORDER BY urlr   rb   rc   N)?)
rg   ZstdDecompressorjoinlenr/   r)   re   rf   rh   ri   )r   rn   dctxqueryr0   rj   results   &&     r   retrieve_multipleShardCache.retrieve_multiple   s     I ))+>sxxQTUYQZHZ?[>\\jkYYY! 99U13 2C E
  $MMOOCLBUOV 	
 2  3  Y3 YYs$   C-C8C:CCC	c                    V P                   ;_uu_ 4       pVP                  R4       RRR4       R#   + '       g   i     R# ; i)z8
Truncate the database by removing all rows from tables
zDELETE FROM shardsN)r/   r)   )r   r0   s   & r   clear_cacheShardCache.clear_cache   s(     YYY!II*+ YYYs	   1A	c                   V P                  4         V P                  \        ,          P                  4        R#   \         dC    T P                  \        ,          P                  T P                  \         R2,          4        R# i ; i)z$
Remove the sharded cache database.
z.conda_trashN)rA   r5   rO   unlinkrV   renamer=   s   &r   rU   ShardCache.remove_cache   sd     	

	YY))113 	YY))11		/0==	s   %9 A	BB)r5   r/   N)T)TT)r   r   r   r   __doc__r   r>   rE   rA   rJ   r&   r]   rk   rx   r{   rU   r    r   r   r   r3   r3   D   s?    $3'R2,r   r3   i   )zcache.db)r   
__future__r   loggingr%   dataclassesr   typingr   re   rg   pathlibr   r   	getLoggerr   rS   rO   ri   r   r&   r3   r   r   r   <module>r      sr   
 #   !    !!'  
   "&P Pr   