
    +j              	           S SK r S SKJrJr  S SKJr  S\S\4S jrSS\S\S\\\4   4S	 jjrS\4S
 jr	S\
\   S-  S\
\   4S jrS\S\4S jrg)    N)datetimetimezone)Sequencestatesreturnc                 8   U  Vs/ s HI  n[        USS5      (       d  M  [        R                  R                  UR                  5      (       d  MG  UPMK     nnU(       d  gU H#  n[        USS5      (       a  M  UR                  s  $    US   R                  $ s  snf )z
Return the best on-disk path among cache states:
  1) Prefer a path that exists with needs_verify == False (already verified).
  2) Otherwise, pick the first path that exists.
  3) Otherwise return empty string.
	file_pathN needs_verifyFr   )getattrospathisfiler	   )r   salives      2/home/wildlama/comfy/ComfyUI/app/assets/helpers.pyselect_best_live_pathr      s     A1k4( 	
-/WW^^AKK-H 	
 
 
 q.%00;;  8s   B,BBr   escapec                     U R                  XU-   5      n U R                  SUS-   5      R                  SUS-   5      n X4$ )z[Escapes %, _ and the escape char in a LIKE prefix.

Returns (escaped_prefix, escape_char).
%_)replace)r   r   s     r   escape_sql_like_stringr      sC    
 	
		&6/*A			#v|$,,S&3,?A9    c                  d    [         R                  " [        R                  5      R	                  SS9$ )zENaive UTC timestamp (no tzinfo). We always treat DB datetimes as UTC.N)tzinfo)r   nowr   utcr    r   r   get_utc_nowr    $   s#    <<%--T-::r   tagsc                 ^    [        [        R                  S U =(       d    /  5       5      5      $ )zm
Normalize a list of tags by:
  - Stripping whitespace and converting to lowercase.
  - Removing duplicates.
c              3      #    U  HB  o=(       d    S R                  5       (       d  M"  UR                  5       R                  5       v   MD     g7f)r
   N)striplower).0ts     r   	<genexpr>!normalize_tags.<locals>.<genexpr>/   s.     [*A'rIZ/aggioo//*s
   !A%A)listdictfromkeys)r!   s    r   normalize_tagsr-   )   s$     [$*"*[[\\r   c                    U R                  5       R                  5       n U (       a  SU ;  a  [        S5      eU R                  SS5      u  pUS:w  d&  [	        U5      S:w  d  [        S U 5       5      (       a  [        S5      eU SU 3$ )zeValidate and normalize a blake3 hash string.

Returns canonical 'blake3:<hex>' or raises ValueError.
:zhash must be 'blake3:<hex>'   blake3@   c              3   4   #    U  H  oS ;  d  M
  Uv   M     g7f)0123456789abcdefNr   )r&   cs     r   r(   'validate_blake3_hash.<locals>.<genexpr>>   s     @&Q-?$?qq&s   		)r$   r%   
ValueErrorsplitlenany)r   algodigests      r   validate_blake3_hashr=   2   s~    
 	
	A1677773?LDv;"@&@@@677V1VHr   )!)r   r   r   typingr   strr   tupler   r    r*   r-   r=   r   r   r   <module>rB      s    	 ' ( s (c 3 sCx ;X ;
]cT) ]d3i ]C C r   