
    +j                        d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ dd	lmZ  ej        d
          Z ej        d          ZdefdZdeej                 defdZdeej                 deeef         fdZdefdZ	 	 	 ddddedeej                 dz  dedz  dedz  de dz  deeej                 ee e dz  gdf         dz  fdZ!dedefdZ"deez  de fdZ#dede
fdZ$dS )     N)Callable)BytesIO)URL)argsprocessing_interrupted)IO   )ProcessingInterruptedz%[0-9A-Fa-f]{2}z%(?![0-9A-Fa-f]{2})returnc                      t                      S )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                     | j         j        S N)hidden	unique_idr   s    r   get_node_idr      s    ?$$r   c                 t    | j         j        rdd| j         j         iS | j         j        rd| j         j        iS i S )NAuthorizationzBearer z	X-API-KEY)r   auth_token_comfy_orgapi_key_comfy_orgr   s    r   get_auth_headerr      sL    + S!Q8?+O!Q!QRR( @X_>??Ir   c                  .    t          t          dd          S )Ncomfy_api_basezhttps://api.comfy.org)getattrr   r   r   r   default_base_urlr!   &   s    4)+BCCCr   )display_callbacksecondslabelstart_tsestimated_totalr"   c          	        K   t          j                    | z   }	 t                      rt          d          t          j                    }|S|rQ|rOt	          j        t                    5   |||t          ||z
            |           ddd           n# 1 swxY w Y   ||k    rdS t          j	        t          d||z
                       d{V  )z
    Sleep in 1s slices while:
      - Checking for interruption (raises ProcessingInterrupted).
      - Optionally emitting time progress via display_callback (if provided).
    TzTask cancelledNg      ?)time	monotonicr   r   
contextlibsuppress	Exceptionintasynciosleepmin)r#   r   r$   r%   r&   r"   endnows           r   sleep_with_interruptr3   *   s7      .

W
$C	1$&& 	:'(8999nE.>$Y// X X  5#cHn2E2EWWWX X X X X X X X X X X X X X X#::EmCS3Y//000000000	1s   )BBB	mime_typec                 \    |                      d          d                                         S )z)Converts a MIME type to a file extension./)splitlower)r4   s    r   mimetype_to_extensionr:   E   s%    ??3#))+++r   path_or_objectc                     t          | t                    rt          j                            |           S t          |                                           S r   )
isinstancestrospathgetsizelengetvalue)r;   s    r   get_fs_object_sizerD   J   sB    .#&& /w~...~&&(()))r   urlc                 ,   t          d | D                       st          d | D                       rt          |           S t                              |           r+t                              |           st          | d          S t          |           S )aR  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   >   K   | ]}|                                 V  d S r   )isspace.0cs     r   	<genexpr>z!to_aiohttp_url.<locals>.<genexpr>U   s*      
$
$1199;;
$
$
$
$
$
$r   c              3   <   K   | ]}t          |          d k     V  dS )    N)ordrI   s     r   rL   z!to_aiohttp_url.<locals>.<genexpr>U   s,      +G+GaCFFTM+G+G+G+G+G+Gr   T)encoded)anyr   _HAS_PCT_ESCsearch_HAS_BAD_PCT)rE   s    r   to_aiohttp_urlrU   P   s    
 
$
$
$
$
$$$ +G+G3+G+G+G(G(G 3xx3 &(;(;C(@(@ &3%%%%s88Or   )NNN)%r.   r*   r?   rer(   collections.abcr   ior   yarlr   comfy.cli_argsr   comfy.model_managementr   comfy_api.latestr	   common_exceptionsr   compilerR   rT   boolr   type	ComfyNoder>   r   dictr   r!   floatr-   r3   r:   rD   rU   r   r   r   <module>rd      s        				 				  $ $ $ $ $ $                   9 9 9 9 9 9       4 4 4 4 4 4rz,--rz011$4 $ $ $ $
%$r|, % % % % %d2<0 T#s(^    D# D D D D !"&1 [_1 1 112< 4'1 :1 dl	1
 4Z1 R\ 2CcDjI4OPSWW1 1 1 16,S ,S , , , ,
*sW} * * * * *       r   