
    +j              	           d dl Z d dlmZmZ d dlmZ dedefdZdded	edeeef         fd
ZdefdZ	de
e         dz  de
e         fdZdedefdZdS )    N)datetimetimezone)Sequencestatesreturnc                 z    d | D             }|sdS |D ]}t          |dd          s	|j        c S |d         j        S )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.
    c                 |    g | ]9}t          |d d          t          j                            |j                  7|:S )	file_pathN)getattrospathisfiler
   ).0ss     2/home/wildlama/comfy/ComfyUI/app/assets/helpers.py
<listcomp>z)select_best_live_path.<locals>.<listcomp>   sT       1k4(( .0W^^AK-H-H	       needs_verifyFr   )r   r
   )r   aliver   s      r   select_best_live_pathr      sr       E
  r  q.%00 	;	8r   !r   escapec                     |                      |||z             } |                      d|dz                                  d|dz             } | |fS )zcEscapes %, _ and the escape char in a LIKE prefix.

    Returns (escaped_prefix, escape_char).
    %_)replace)r   r   s     r   escape_sql_like_stringr      sP    
 	
		&&6/**A			#v|$$,,S&3,??Af9r   c                  f    t          j        t          j                                      d          S )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                 h    t          t                              d | pg D                                 S )z}
    Normalize a list of tags by:
      - Stripping whitespace and converting to lowercase.
      - Removing duplicates.
    c              3      K   | ]@}|pd                                  |                                                                 V  AdS )r   N)striplower)r   ts     r   	<genexpr>z!normalize_tags.<locals>.<genexpr>/   sG      [[A!'rIZIZ[aggiioo//[[[[[[r   )listdictfromkeys)r%   s    r   normalize_tagsr/   )   s1     [[$*"[[[[[\\\r   c                 :   |                                                                  } | rd| vrt          d          |                     dd          \  }}|dk    s,t	          |          dk    st          d |D                       rt          d          | d| S )zmValidate and normalize a blake3 hash string.

    Returns canonical 'blake3:<hex>' or raises ValueError.
    :zhash must be 'blake3:<hex>'   blake3@   c              3   "   K   | ]
}|d v|V  dS )0123456789abcdefNr#   )r   cs     r   r+   z'validate_blake3_hash.<locals>.<genexpr>>   s-      @@QA-?$?$?q$?$?$?$?@@r   )r(   r)   
ValueErrorsplitlenany)r   algodigests      r   validate_blake3_hashr>   2   s    
 	
		A 816777773??LD&v;;"@@&@@@@@  6777Vr   )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   