
    3j                        S SK r S SKrS SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  S	S
KJr  \R*                  " S5      r\R*                  " S5      rS\4S jrS\\R6                     S\4S jrS\\R6                     S\\\4   4S jrS\\R6                     S\4S jr S\\R6                     S\\\4   4S jr!S\4S jr"   S"SS.S\#S\\R6                     S-  S\S-  S\#S-  S\$S-  S\\\R6                     \\$\$S-  /S4   S-  4S jjjr%S\S\4S jr&S\\-  S\$4S jr'S \S\
4S! jr(g)#    N)Callable)BytesIO)URL)args)get_deploy_environmentprocessing_interrupted)IO   )ProcessingInterruptedz%[0-9A-Fa-f]{2}z%(?![0-9A-Fa-f]{2})returnc                      [        5       $ )z3Return True if user/runtime requested interruption.r        =/home/wildlama/comfy/ComfyUI/comfy_api_nodes/util/_helpers.pyis_processing_interruptedr      s    !##r   node_clsc                 .    U R                   R                  $ N)hidden	unique_idr   s    r   get_node_idr      s    ??$$$r   c                     U R                   R                  (       a  SSU R                   R                   30$ U R                   R                  (       a  SU R                   R                  0$ 0 $ )NAuthorizationzBearer z	X-API-KEY)r   auth_token_comfy_orgapi_key_comfy_orgr   s    r   get_auth_headerr      sS    ++78??+O+O*P!QRR((X__>>??Ir   c                 @    U R                   R                  =(       d    S$ )zSource of the prompt that triggered this API node.

Defaults to "comfyui-api" when the submitting client didn't identify itself,
i.e. a direct API call to this server.
zcomfyui-api)r   comfy_usage_sourcer   s    r   get_usage_sourcer!   '   s     ??-->>r   c                 H    0 [        U 5      E[        5       [        U 5      S.E$ )a  Common headers (auth, deploy environment, usage source) for Comfy API requests.

Centralizes the shared header set so every Comfy API request sends a consistent
set and new shared headers only need to be added in one place. Intended for
relative/cloud URLs resolved against ``default_base_url()``; because the result
includes auth, callers must not attach it to arbitrary absolute/presigned URLs.
)z	Comfy-EnvzComfy-Usage-Source)r   r   r!   r   s    r   get_comfy_api_headersr#   0   s,    
(
#+-.x8 r   c                  $    [        [        SS5      $ )Ncomfy_api_basezhttps://api.comfy.org)getattrr   r   r   r   default_base_urlr'   ?   s    4)+BCCr   )display_callbacksecondslabelstart_tsestimated_totalr(   c          	        #    [         R                  " 5       U -   n [        5       (       a  [        S5      e[         R                  " 5       nUbF  U(       a?  U(       a8  [        R
                  " [        5         U" X[        Xs-
  5      U5        SSS5        Xv:  a  g[        R                  " [        SXg-
  5      5      I Sh  vN   M  ! , (       d  f       N@= f N7f)z
Sleep in 1s slices while:
  - Checking for interruption (raises ProcessingInterrupted).
  - Optionally emitting time progress via display_callback (if provided).
zTask cancelledNg      ?)time	monotonicr   r   
contextlibsuppress	Exceptionintasynciosleepmin)r)   r   r*   r+   r,   r(   endnows           r   sleep_with_interruptr9   C   s      ..
W
$C
$&&'(899nnE.>$$Y/ #cn2EW 0:mmCSY/000 
 0/ 	1s*   A4C6C3C?C C
CC	mime_typec                 F    U R                  S5      S   R                  5       $ )z)Converts a MIME type to a file extension./)splitlower)r:   s    r   mimetype_to_extensionr@   ^   s    ??3#))++r   path_or_objectc                     [        U [        5      (       a  [        R                  R	                  U 5      $ [        U R                  5       5      $ r   )
isinstancestrospathgetsizelengetvalue)rA   s    r   get_fs_object_sizerJ   c   s6    .#&&ww~..~&&())r   urlc                    [        S U  5       5      (       d  [        S U  5       5      (       a  [        U 5      $ [        R                  U 5      (       a$  [        R                  U 5      (       d
  [        U SS9$ [        U 5      $ )aF  If `url` appears to be already percent-encoded (contains at least one valid %HH
escape and no malformed '%' sequences) and contains no raw whitespace/control
characters preserve the original encoding byte-for-byte (important for signed/presigned URLs).
Otherwise, return `URL(url)` and allow yarl to normalize/quote as needed.c              3   @   #    U  H  oR                  5       v   M     g 7fr   )isspace.0cs     r   	<genexpr>!to_aiohttp_url.<locals>.<genexpr>n   s     
$199;;s   c              3   >   #    U  H  n[        U5      S :  v   M     g7f)    N)ordrO   s     r   rR   rS   n   s     +G3aCFTM3s   T)encoded)anyr   _HAS_PCT_ESCsearch_HAS_BAD_PCT)rK   s    r   to_aiohttp_urlr\   i   se    
 
$
$$$+G3+G(G(G3x3(;(;C(@(@3%%s8Or   )NNN))r4   r0   rE   rer.   collections.abcr   ior   yarlr   comfy.cli_argsr   comfy.deploy_environmentr   comfy.model_managementr	   comfy_api.latestr
   common_exceptionsr   compilerY   r[   boolr   type	ComfyNoderD   r   dictr   r!   r#   r'   floatr3   r9   r@   rJ   r\   r   r   r   <module>rl      s     	 	  $    ; 9  4zz,-zz01$4 $
%$r||, % %d2<<0 T#s(^ ?tBLL1 ?c ?D$6 4S> D# D !"&1 [_112<< 4'1 :1 dl	1
 4Z1 R\\ 2CcDjI4OPSWW16,S ,S ,
*sW} * *  r   