+
    :1j                    l   R t ^ RIHt ^ RIt^ RIt^ RIHtHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^RIHtHtHtHt ^R	IHt ^R
IHt ^RIHt ]'       d   ^ RIHt ^RIHt ^RIHt ]P>                  ! ] 4      t!R t"R R lt#R R lt$R R lt%R R lt&R R lt'R R lt(R R lt)R R lt*R  R! lt+R# )"z
Handles all caching logic including:
  - Retrieving from cache
  - Saving to cache
  - Determining whether not certain items have expired and need to be refreshed
)annotationsN)datetimetimezonewraps)Path)TYPE_CHECKING)user_cache_dir)APP_NAMENOTICES_CACHE_FNNOTICES_CACHE_SUBDIR%NOTICES_DECORATOR_DISPLAY_INTERVAL_NS)json)
CondaError)ChannelNoticeResponse)Sequence)PathType)ChannelNoticec                6   a  \        S 4      R  V 3R ll4       pV# )c                    V ^8  d   QhRRRR/# )   urlstrname )formats   "3lib/python3.14/site-packages/conda/notices/cache.py__annotate__%cached_response.<locals>.__annotate__*   s      S      c                v   < \        4       p\        WV4      pV'       d   V# S! W4      pVe   \        WB4       V# N)get_notices_cache_dirget_notice_response_from_cachewrite_notice_response_to_cache)r   r   	cache_dir	cache_valreturn_valuefuncs   &&   r   wrapper cached_response.<locals>.wrapper)   s=    )+	23iH	C#*<Cr   r   )r(   r)   s   f r   cached_responser+   (   s     
4[  Nr   c                    V ^8  d   QhRRRR/# )r   channel_notice_responser   returnboolr   )r   s   "r   r   r   :   s      2	r   c                   aa \         P                  ! \        P                  4      oR V3R llo\        ;QJ d)    V3R lV P
                   4       F  '       g   K   R# 	  R# ! V3R lV P
                   4       4      # )z
This checks the contents of the cache response to see if it is expired.

If for whatever reason we encounter an exception while parsing the individual
messages, we assume an invalid cache and return true.
c                    V ^8  d   QhRRRR/# )r   
expired_atzdatetime | Noner.   r/   r   )r   s   "r   r   6is_notice_response_cache_expired.<locals>.__annotate__E   s        o  $  r   c                   < V f   R# V S8  # )z?If there is no "expired_at" field present assume it is expired.Tr   )r2   nows   &r   is_channel_notice_expiredCis_notice_response_cache_expired.<locals>.is_channel_notice_expiredE   s    Cr   c              3  H   <"   T F  pS! VP                   4      x  K  	  R # 5ir!   )r2   ).0chnr6   s   & r   	<genexpr>3is_notice_response_cache_expired.<locals>.<genexpr>K   s$      2C 	"#..112s   "TF)r   r5   r   utcanynotices)r-   r6   r5   s   &@@r    is_notice_response_cache_expiredr@   :   sj     ,,x||
$C    3 *2233 3 3 *22  r   c                   V ^8  d   QhRR/# r   r.   r   r   )r   s   "r   r   r   Q   s      t r   c                     \        \        \        \        R7      4      p V \        ,          p VP	                  RRR7       V#   \
         d   p\        RT RT 24      hRp?ii ; i)zDReturns the location of the notices cache directory as a Path object)	appauthorT)parentsexist_okzKError encountered while attempting to create cache directory.
  Directory: z
  Exception: N)r   r	   r
   r   mkdirOSErrorr   )r%   cache_subdirexcs      r   r"   r"   Q   sv    ^HABI33L
4$7   
(> *5"
 	

s   A A#AA#c                   V ^8  d   QhRR/# rB   r   )r   s   "r   r   r   `   s       r   c                 v    \        4       p V \        ,          pVP                  4       '       g   \        V4       V# )a  
Return path of notices cache

If the file does not exist, we create it with natural filesystem timestamps,
then set only the modification time to be in the past. This ensures notices
are checked and displayed immediately rather than waiting for the full
display interval.
)r"   r   is_file_clear_cache_file)r%   notices_caches     r   get_notices_cache_filerP   `   s4     &'I 00M  ""-(r   c               (    V ^8  d   QhRRRRRRRR/# )r   r   r   r   r%   r   r.   zChannelNoticeResponse | Noner   )r   s   "r   r   r   r   s,        	  $( ! r   c                H   \         P                  ! W4      p\        P                  P	                  V4      '       dT   \        V4      ;_uu_ 4       p\        P                  ! V4      pRRR4       \        WX4      p\        V4      '       g   V# R# R#   + '       g   i     L3; i)z;Retrieves a notice response object from cache if it exists.N)	r   get_cache_keyospathisfileopenr   loadr@   )r   r   r%   	cache_keyfpdatachn_ntc_resps   &&&    r   r#   r#   r   sq     &33CCI	ww~~i  )__99R=D ,S=/== > !_s   BB!	c               $    V ^8  d   QhRRRRRR/# )r   r-   r   r%   r   r.   Noner   )r   s   "r   r   r      s$     	9 	92	9?C	9		9r   c                    \         P                  ! V P                  V4      p\        VR4      ;_uu_ 4       p\        P
                  ! V P                  V4       RRR4       R#   + '       g   i     R# ; i)z3Writes our notice data to our local cache location.wN)r   rS   r   rW   r   dump	json_data)r-   r%   rY   rZ   s   &&  r   r$   r$      sT     &33##YI 
i				)33R8 
			s   "A""A3	c               $    V ^8  d   QhRRRRRR/# )r   
cache_filer   channel_noticesSequence[ChannelNotice]r.   r^   r   )r   s   "r   r   r      s$     * **'>*	*r   c           	        V Uu0 uF  q"P                   kK  	  pp\        V 4      ;_uu_ 4       pVP                  4       pRRR4       \        \	        R\        XP                  4       4      4      4      pVP                  V4      p\        V R4      ;_uu_ 4       pVP                  RP                  V4      4       RRR4       R# u upi   + '       g   i     L; i  + '       g   i     R# ; i)z;Insert channel notice into our database marking it as read.Nr`   
)	idrW   readsetfilter
splitlinesunionwritejoin)rd   re   r:   
notice_idsrZ   contentscontents_uniquecontents_news   &&      r   mark_channel_notices_as_viewedru      s     %44OS&&OJ4	j		R	 
 &s8+>+>+@'ABCO"((4L 
j#		"
<() 
	 5		 
		s   CC!CC	C,	c               $    V ^8  d   QhRRRRRR/# )r   rd   r   re   rf   r.   zset[str]r   )r   s   "r   r   r      s$     4 44'>44r   c           	     8   V Uu0 uF  q"P                   kK  	  pp\        V 4      ;_uu_ 4       pVP                  4       pRRR4       \        \	        R\        XP                  4       4      4      4      pVP                  V4      # u upi   + '       g   i     LR; i)zCReturn the ids of the channel notices which have already been seen.N)ri   rW   rj   rk   rl   rm   intersection)rd   re   r:   rq   rZ   rr   rs   s   &&     r   get_viewed_channel_notice_idsry      su     %44OS&&OJ4	j		R	 
 &s8+>+>+@'ABCO""?33 5		s   BB		B	c                   V ^8  d   QhRR/# )r   r.   r^   r   )r   s   "r   r   r      s      T r   c                 $   \        4       p V \        ,          pV P                  4        F@  pVP                  4       '       g   K  W!8X  d    \	        V4       K/   VP                  4        KB  	  R#   \
         d     KT  i ; i  \
         d     Kf  i ; i)a[  
Invalidate the notices cache so notices will be retrieved and displayed
on the next command invocation.

For the ``notices.cache`` file we rewind its mtime into the past instead
of removing it. On Windows the file can be transiently locked (e.g. by
antivirus or lingering file handles), in which case ``unlink()`` raises
``PermissionError`` and the cache would otherwise remain with a recent
``touch()``-ed mtime, suppressing notices on subsequent runs.

Per-channel cached response files are still removed when possible, but
any ``OSError`` raised while unlinking them is ignored for the same
reason.
N)r"   r   iterdirrM   rN   rH   unlink)r%   rO   rd   s      r   clear_cacher~      s     &'I 00M'')
!!##&!*-!!# *  
  s$   
A.B .A=<A= BBc                    V ^8  d   QhRRRR/# )r   rd   r   r.   r^   r   )r   s   "r   r   r      s     ? ?( ?t ?r   c                2   \        V 4      p \        V R 4      ;_uu_ 4       pVP                  R4       RRR4       V P                  4       pVP                  \
        ,
          p\        P                  ! WP                  V3R7       R#   + '       g   i     L\; i)r`    N)ns)	r   rW   ro   statst_mtime_nsr   rT   utimest_atime_ns)rd   rZ   r   past_mtime_nss   &   r   rN   rN      sh    j!J	j#		"
 
??D$$'LLMHHZ--}=> 
	s   BB	),__doc__
__future__r   loggingrT   r   r   	functoolsr   pathlibr   typingr   platformdirsr	   base.constantsr
   r   r   r   common.serializer   
exceptionsr   typesr   collections.abcr   common.pathr   r   	getLogger__name__loggerr+   r@   r"   rP   r#   r$   ru   ry   r~   rN   r   r   r   <module>r      s    #  	 '     '  $ # ((&$			8	$$.$ 	9*"4B?r   