+
    ‚°ñjî  ã                   ó  € R t ^ RIt^ RIt^ RIHtHt ^ RIHtHtHt ^ RI	t
^ RIHt R R ltR R ltR	 R
 lt^ÈtR R ltR R lt]P&                  ! RR7      R R l4       tRR R lltR R ltR R ltR R ltR R ltR R ltR# )a€  Small conversions the asset system needs in more than one layer: canonical
stored-hash strings, UTC timestamps, tag normalization, and path containment
checks. The SQL predicate is deliberately case-sensitive and component-bounded,
because callers use it to choose rows for hard deletion; the Python matcher
follows ``Path.is_relative_to`` instead, including its platform case rules.
N)ÚCallableÚIterable)ÚdatetimeÚ	timedeltaÚtimezone)ÚColumnElementc                óh   € V ^8„  d   QhR\         \        ,          R\        R\         \        ,          /# )é   ÚcolumnÚprefixÚreturn)r   ÚstrÚbool)Úformats   "Ú6C:\Ai_Coding\apps\studio\ComfyUI\app\assets\helpers.pyÚ__annotate__r      s.   € ÷ ñ Üœ#ÕðÜ(+ðä”4Õñó    c           
     ó¤   € \        V4      w  r#\        P                  ! W8H  \        P                  P	                  V ^\        V4      4      V8H  4      # )u‹  SQL predicate for ``Path(column).is_relative_to(prefix)`` on this platform.

Case-SENSITIVE and component-bounded: prefix ``/a/b`` matches ``/a/b`` and
``/a/b/c`` but not ``/a/bc``, ``/a/b-other`` or ``/a/B/c``.

``LIKE`` cannot express this. SQLite's ``LIKE`` is ASCII case-insensitive by
default, so ``'/data/TEMP/f' LIKE '/data/temp/%'`` is TRUE â€” which let the
temp wipe hard-delete records under a case-different persistent directory,
and let the enrichment scan mutate rows outside the requested root.
``GLOB`` is case-sensitive but carries its own metacharacters (``*``, ``?``,
``[``) with no ESCAPE clause, so every caller would need bracket-quoting.
``substr(column, 1, n) = <prefix>`` compares under the column's BINARY
collation and has no metacharacters at all, so a path containing ``%``,
``_``, ``*``, ``?`` or ``[`` needs no escaping and cannot inject.

Only the PREFIX is normalized here. That is sound because the column holds
normalized absolute paths â€” ``records.create_content`` is the sole writer
and normalizes there. Normalizing the column in SQL is not an option anyway:
it would need a per-row Python call and would defeat the index.
)Ú_base_and_stemÚsaÚor_ÚfuncÚsubstrÚlen)r
   r   ÚbaseÚstems   &&  r   Úsql_path_under_prefixr      sC   € ô.   Ó'�J€DÜ�6Š6Ø‰Ü
�‰�‰�v˜q¤# d£)Ó,°Ñ4óð r   c                óR   € V ^8„  d   QhR\         R\        \         \         3,          /# )r	   r   r   ©r   Útuple)r   s   "r   r   r   /   s&   € ÷ Bñ Bœ3ð B¤5¬¬c¨¥?ñ Br   c                 óÀ   € \         P                  P                  V 4      pYP                  \         P                  4      '       d   V3# V\         P                  ,           3# ©N)ÚosÚpathÚabspathÚendswithÚsep)r   r   s   & r   r   r   /   s?   € Ü�7‰7�?‰?˜6Ó"€DØŸ™¤r§v¡v×.Ò.�ÐAÐA°D¼2¿6¹6µMÐAÐAr   c                ój   € V ^8„  d   QhR\         \        ,          R\        \        .\        3,          /# ©r	   Úprefixesr   )Úlistr   r   r   )r   s   "r   r   r   4   s-   € ÷ 	@ñ 	@¬¬c­ð 	@´xÄÀÄtÀÕ7Lñ 	@r   c                óÎ   aa€ V  Uu. uF  p\        V4      NK  	  pp\        R V 4       4      o\        ;QJ d    . R V 4       F  NK  	  5M! R V 4       4      oVV3R l# u upi )zæThe Python twin of sql_path_under_prefix OR'd over ``prefixes``: the same
case-sensitive string test on a stored path, for filtering rows already fetched.

Unlike path_prefix_matcher, it neither normalizes nor normcases the path.
c              3   ó*   "  € T F	  w  rVx € K  	  R # 5ir!   © )Ú.0r   Ú_s   &  r   Ú	<genexpr>Ú-stored_path_under_prefixes.<locals>.<genexpr>;   s   é € Ð0©%™w˜t•d«%ùó   ‚c              3   ó*   "  € T F	  w  rVx € K  	  R # 5ir!   r-   )r.   r/   r   s   &  r   r0   r1   <   s   é € Ð,¡e™7˜1•$£eùr2   c                 ó@   <€ V S9   ;'       g    V P                  S4      # r!   )Ú
startswith)r#   ÚbasesÚstemss   &€€r   Ú<lambda>Ú,stored_path_under_prefixes.<locals>.<lambda>=   s   ø€ ˜ ™×?Ð?¨¯©¸Ó)?Ð?r   )r   Ú	frozensetr   )r)   r   Úpairsr6   r7   s   &  @@r   Ústored_path_under_prefixesr<   4   sW   ù€ ñ 3;Ó;±(¨Œ^˜FÖ#±(€EÐ;ÜÑ0©%Ó0Ó0€EßŒEÑ,¡eÓ,�E‰EÑ,¡eÓ,Ó,€EÝ?Ð?ùò <s   ‡A"c                ó”   € V ^8„  d   QhR\         \        ,          R\        \        ,          R\        \         \        ,          ,          /# )r	   r
   r)   r   )r   r   r*   r   )r   s   "r   r   r   G   s7   € ÷ ñ Üœ#ÕðÜ*.¬s­)ðä	Œ-œÕ
Õñr   c           
     ó´   a € \        ^ \        V4      \        4       Uu. uF.  p\        P                  ! V 3R lWV\        ,             4       !  NK0  	  up# u upi )zØsql_path_under_prefix OR'd over each run of at most PREFIX_BATCH_SIZE prefixes.

Run one statement per predicate and merge. Nested or overlapping prefixes can put a
row in more than one batch, so the caller dedupes.
c              3   ó<   <"  € T F  p\        SV4      x € K  	  R # 5ir!   )r   )r.   Úpr
   s   & €r   r0   Ú0sql_path_under_prefix_batches.<locals>.<genexpr>P   s   øé € Ð]Ñ;\°aÔ& v¨q×1Ð1Ó;\ùs   ƒ)Úranger   ÚPREFIX_BATCH_SIZEr   r   )r
   r)   Úis   f& r   Úsql_path_under_prefix_batchesrE   G   sR   ø€ ô �qœ#˜h›-Ô):Ô;óá;ˆAô 	�ŠÔ]¸8ÀaÔJ[ÕF[Ñ;\Ó]Ô^Ù;ñð ùò s   ž4Ac                ój   € V ^8„  d   QhR\         \        ,          R\        \        .\        3,          /# r(   )r   r   r   r   )r   s   "r   r   r   U   s)   € ÷ ñ ¤(¬3¥-ð ´H¼c¸UÄD¸[Õ4Iñ r   c                ór  aa	a
€ \         P                  ^,          oR\        4       R\        4       /o	R. R. /pV  F»  p\         P                  P	                  \         P                  P                  V4      4      pVP                  S4      pS	V,          P                  V4       W,          P                  VP                  \         P                  4      '       d   TMV\         P                  ,           4       K½  	  VP                  4        UUu/ uF  w  rVV\        V4      bK  	  uppo
R VV	V
3R llpV# u uppi )a†  Return ``path -> Path(path).is_relative_to(<any prefix>)``, with the prefixes
normalized once.

The startup prune tests every catalogued row against every owned prefix, and
``Path.is_relative_to`` walks the path's parents on each call, so a pathlib
check there costs rows x prefixes x depth. A normcase'd, separator-bounded
string prefix keeps its component bounds and platform case rules.
FTc                ó0   € V ^8„  d   QhR\         R\        /# )r	   r#   r   )r   r   )r   s   "r   r   Ú)path_prefix_matcher.<locals>.__annotate__k   s   € ÷ ]ñ ]”cð ]œdñ ]r   c                 óö   <€ \         P                  P                  \         P                  P                  V 4      4      pVP	                  S4      pVSV,          9   ;'       g    VP	                  SV,          4      # r!   )r"   r#   Únormcaser$   r5   )r#   Ú	candidateÚ	is_doubleÚdoubleÚexactÚstem_tupless   &  €€€r   ÚmatchesÚ$path_prefix_matcher.<locals>.matchesk   s]   ø€ Ü—G‘G×$Ñ$¤R§W¡W§_¡_°TÓ%:Ó;ˆ	Ø×(Ñ(¨Ó0ˆ	Ø˜E )Õ,Ñ,×\Ð\°	×0DÑ0DÀ[ÐQZÕE[Ó0\Ð\r   )r"   r&   Úsetr#   rK   r$   r5   ÚaddÚappendr%   Úitemsr   )r)   r7   r   r   rM   ÚkeyÚvaluerQ   rN   rO   rP   s   &       @@@r   Úpath_prefix_matcherrY   U   së   ú€ ô �V‰V�a�Z€FØ#(¬#«%°´s³uÐ"=€EØ$)¨2¨t°RÐ#8€EÛˆÜ�w‰w×Ñ¤§¡§¡°Ó 7Ó8ˆØ—O‘O FÓ+ˆ	ØˆiÕ×Ñ˜TÔ"ØÕ×Ñ¨¯©´b·f±f×(=Ò(=¡À4Ì"Ï&É&Å=ÖQñ	 ð
 8=·{±{´}ÔE±}©¨�3œ˜e›Ò$±}ÒE€K÷]ò ]ð
 €Nùó Fs   ÄD3)Úmaxsizec                ón   € V ^8„  d   QhR\         \        R3,          R\        \        .\        3,          /# )r	   r)   .r   )r   r   r   r   )r   s   "r   r   r   t   s-   € ÷ )ñ )¤E¬#¨s¨(¥Oð )¼Ä#ÀÌÀÕ8Mñ )r   c                ó   € \        V 4      # )a¤  path_prefix_matcher, built once per distinct prefix tuple, for callers that check
every scanned file against the same folders.

Keyed on the raw prefixes: normalizing them in the key would bring back the per-call
cost this avoids. A folder-config change is just a new key.

Precondition: the prefixes are absolute. That is not checked. main.py and
extra_model_paths make their folders absolute, but folder_paths' setters and
add_model_folder_path store whatever they are given, so a custom node can register a
relative one. A relative prefix is resolved against the working directory once, on
first use, and that resolution is then frozen for as long as the key is unchanged.
)rY   )r)   s   &r   Úcached_prefix_matcherr]   s   s   € ô ˜xÓ(Ð(r   c                ó^   € V ^8„  d   QhR\         R\         R\        \         \         3,          /# )r	   ÚsÚescaper   r   )r   s   "r   r   r   „   s)   € ÷ ñ œcð ¬3ð ¼¼sÄC¸x½ñ r   c                ó˜   € V P                  WV,           4      p V P                  RVR,           4      P                  RVR,           4      p W3# )z[Escapes %, _ and the escape char in a LIKE prefix.

Returns (escaped_prefix, escape_char).
Ú%r/   )Úreplace)r_   r`   s   &&r   Úescape_sql_like_stringrd   „   sC   € ð
 	
�	‰	�& 6�/Ó*€AØ	�	‰	�#�v •|Ó$×,Ñ,¨S°&¸3µ,Ó?€AØˆ9Ðr   c                ó$   € V ^8„  d   QhR\         /# )r	   r   )r   )r   s   "r   r   r   Ž   s   € ÷ ;ñ ;”Xñ ;r   c                 ój   € \         P                  ! \        P                  4      P	                  RR7      # )zENaive UTC timestamp (no tzinfo). We always treat DB datetimes as UTC.N)Útzinfo)r   Únowr   Úutcrc   r-   r   r   Úget_utc_nowrj   Ž   s#   € ä�<Š<œŸ™Ó%×-Ñ-°TÐ-Ó:Ð:r   c                ó<   € V ^8„  d   QhR\         R\         R\        /# )r	   Úmtime_nsÚctime_nsr   )Úintr   )r   s   "r   r   r   “   s&   € ÷ oñ oœcð o¬Sð o´Xñ or   c                óà   € \        4       p\        R^^4      \        V R,          R7      ,           pW28:  d   V# V^ 8¼  d0   \        \        R^^4      \        VR,          R7      ,           V4      # T# )z˜Naive UTC time of a file mtime. A future mtime falls back to the ctime, capped at now: the
creation time on Windows, the last metadata change elsewhere.i²  iè  )Úmicroseconds)rj   r   r   Úmin)rl   rm   rh   Úmades   &&  r   Úmtime_ns_to_utcrs   “   sf   € ô ‹-€CÜ�D˜!˜QÓ¤)¸ÀTÕ9IÔ"JÕJ€DØ„{ØˆàX`ÐdeÔXeŒ3Œx˜˜a Ó#¤i¸XÈÕ=MÔ&NÕNÐPSÓTÐnÐknÐnr   c                ój   € V ^8„  d   QhR\         \        ,          R,          R\         \        ,          /# )r	   ÚtagsNr   )r*   r   )r   s   "r   r   r   ž   s+   € ÷ Uñ Uœœc� TÕ)ð U¬d´3­iñ Ur   c                ó`   € \        \        P                  R T ;'       g    .  4       4      4      # )zw
Normalize a list of tags by:
  - Stripping whitespace.
  - Removing exact duplicates while preserving order and case.
c              3   ó„   "  € T F6  q;'       g    R P                  4       '       g   K$  VP                  4       x € K8  	  R# 5i)Ú N)Ústrip)r.   Úts   & r   r0   Ú!normalize_tags.<locals>.<genexpr>¤   s'   é € ÐS±*¨AÇ'À'ÀrÇÁ×ARœi˜aŸg™gŸi˜i³*ùs   ‚A �A ¨A )r*   ÚdictÚfromkeys)ru   s   &r   Únormalize_tagsr~   ž   s&   € ô ”—‘ÑS°$·*°*¸"°*ÓSÓSÓTÐTr   c                ó0   € V ^8„  d   QhR\         R\         /# )r	   Údigestr   ©r   )r   s   "r   r   r   §   s   € ÷ ñ œ3ð ¤3ñ r   c                 ó   € R V  2# )zblake3:r-   )r€   s   &r   Úto_stored_hashrƒ   §   s   € Ø�V�HÐÐr   c                ó0   € V ^8„  d   QhR\         R\         /# )r	   r_   r   r�   )r   s   "r   r   r   «   s   € ÷ ñ œCð ¤Cñ r   c                ó`  € V P                  4       P                  4       p V '       d   RV 9  d   \        R4      hV P                  R^4      w  rVR8w  gK   \	        V4      ^@8w  g;   \
        ;QJ d    R V 4       F  '       g   K   RM	  RM! R V 4       4      '       d   \        R4      hV RV 2# )zeValidate and normalize a blake3 hash string.

Returns canonical 'blake3:<hex>' or raises ValueError.
Ú:zhash must be 'blake3:<hex>'Úblake3c              3   ó6   "  € T F  qR 9  g   K  Vx € K  	  R# 5i)Ú0123456789abcdefNr-   )r.   Úcs   & r   r0   Ú'validate_blake3_hash.<locals>.<genexpr>·   s   é € Ð@™&�QÐ-?Ñ$?�qŠq›&ùs   ‚�
TF)ry   ÚlowerÚ
ValueErrorÚsplitr   Úany)r_   Úalgor€   s   &  r   Úvalidate_blake3_hashr‘   «   sŽ   € ð
 	
�‰‹	�‰Ó€Aß�˜1”ÜÐ6Ó7Ð7Ø—7‘7˜3 “?�L€Dà�ÔÜˆv‹;˜"Ôß‹3Ñ@™&Ó@�3�3Š3Ñ@™&Ó@×@Ò@äÐ6Ó7Ð7ØˆV�1�V�HÐÐr   )Ú!)Ú__doc__Ú	functoolsr"   Úcollections.abcr   r   r   r   r   Ú
sqlalchemyr   Úsqlalchemy.sqlr   r   r   r<   rC   rE   rY   Ú	lru_cacher]   rd   rj   rs   r~   rƒ   r‘   r-   r   r   Ú<module>r™      sƒ   ðñó Û 	ß .ß 2Ñ 2ã Ý (õõ<Bõ
	@ð  Ð õõð< ×Ò˜TÔ"ô)ó #ð)÷ õ;õ
oõUõ÷r   