o
    i1                  	   @   s   d dl Z d dlmZmZ d dlmZ dedefddZdd	ed
edeeef fddZdefddZ	de
e dB de
e fddZd	edefddZdS )    N)datetimetimezone)Sequencestatesreturnc                 C   s@   dd | D }|sdS |D ]}t |dds|j  S q|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                 S   s*   g | ]}t |d drtj|jr|qS )	file_pathN)getattrospathisfiler   ).0s r   0/mnt/c/Users/fbmor/ComfyUI/app/assets/helpers.py
<listcomp>   s    
z)select_best_live_path.<locals>.<listcomp> needs_verifyFr   )r   r   )r   aliver   r   r   r   select_best_live_path   s   

r   !r   escapec                 C   s4   |  ||| } |  d|d  d|d } | |fS )zcEscapes %, _ and the escape char in a LIKE prefix.

    Returns (escaped_prefix, escape_char).
    %_)replace)r   r   r   r   r   escape_sql_like_string   s   r   c                   C   s   t tjjddS )zENaive UTC timestamp (no tzinfo). We always treat DB datetimes as UTC.N)tzinfo)r   nowr   utcr   r   r   r   r   get_utc_now$   s   r   tagsc                 C   s   t tdd | p	g D S )z}
    Normalize a list of tags by:
      - Stripping whitespace and converting to lowercase.
      - Removing duplicates.
    c                 s   s(    | ]}|pd   r|   V  qdS )r   N)striplower)r   tr   r   r   	<genexpr>/   s   & z!normalize_tags.<locals>.<genexpr>)listdictfromkeys)r   r   r   r   normalize_tags)   s   r'   c                 C   sl   |    } | rd| vrtd| dd\}}|dks+t|dks+td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                 s   s    | ]	}|d vr|V  qdS )0123456789abcdefNr   )r   cr   r   r   r#   >   s    z'validate_blake3_hash.<locals>.<genexpr>)r    r!   
ValueErrorsplitlenany)r   algodigestr   r   r   validate_blake3_hash2   s   r4   )r   )r	   r   r   typingr   strr   tupler   r   r$   r'   r4   r   r   r   r   <module>   s     
	