
    `i                         d dl Z d dlmZmZmZmZmZmZmZm	Z	 d dl
mZ 	 ddedee         defdZdedee         fd	Zd
 Zd ZddefdZdS )    N)ListTupleUnionOptionalCallableAnyDictSet)CodeTypecode_objoverwite_fn_namereturnc                    | j         | j        z   }| j        d |         }d |D             }dd l}| j        |j        z  r(|                    d| j        |         z              |dz  }| j        |j        z  r(|                    d| j        |         z              |dz  }d                    |          }||n| j	        }d| d| d	}|S )
Nc                 h    g | ]/}|                     d           s|n|                    d d          0S ).	comp_arg_)
startswithreplace).0xs     _/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/depyf/utils.py
<listcomp>z*get_function_signature.<locals>.<listcomp>   sR     2 2 2"# c"" 			) )2 2 2    r   *   z**z, zdef (z):
)
co_argcountco_kwonlyargcountco_varnamesinspectco_flags
CO_VARARGSappendCO_VARKEYWORDSjoinco_name)r   r   normal_arg_count	arg_namesr    args_strfn_nameheaders           r   get_function_signaturer,      s   
  +h.HH$%6&6%67I2 2'02 2 2I NNN7-- x34DEEFFFA711  45E FFGGGAyy##H"2">HDTG,G,,h,,,FMr   codec                     | g}| j         D ]A}t          |t          |                     r"|                    t	          |                     B|S N)	co_consts
isinstancetypeextendcollect_all_code_objects)r-   code_objectsconsts      r   r4   r4      sY    6L A AeT$ZZ(( 	A 8 ? ?@@@r   c                     dd l }	 |                    | d           d S # t          $ r&}|j                            |           s Y d }~d S d }~ww xY w)Nr   T)exist_ok)osmakedirsOSErrorpathisdir)r<   r9   es      r   safe_create_directoryr?   &   s    III
D4(((((   w}}T"" 		 	 	 	 	 	s    
AA

Ac                    ddl }	 t          | d          r| j        } nht          | d          r| j        } nPt	          | |j                  r| j        } n3t          | d          r"t          | j        d          r| j        j        } nn| S )a  A callable object `fn` might have a __code__ attribute, which is a code object.
    However, `fn` might not be the owner of the code object. Only the code owner can change the code object.
    This function returns the owner of the code object.
    An example:
    class A:
        def func(self):
            return 1
    a = A()
    `a.func.__code__` is read-only. `A.func.__code__` is writable.
    We can change the code object via `a.func.__func__.__code__`.
    r   NT__func____wrapped____call__)	functoolshasattrrA   rB   r1   partialfuncrC   )fnrD   s     r   get_code_ownerrI   1   s     2z"" 	BBR'' 
	BBI-.. 	BBR$$ 	j)I)I 	%BB Ir   rH   c                     dd l }ddlm} 	 |                    |                               |          }n(# |$ r }t          | |          }|dz   }Y d }~nd }~ww xY w|S )Nr   )DecompilationError)r   z    'Failed to decompile.'
)depyfdepyf.decompilerrK   
Decompiler	decompiler,   )rH   r   rL   rK   decompiled_source_coder>   r+   s          r   decompile_ensurerQ   Q   s    LLL333333I!&!1!1" "	+;	<< 	 I I I'=MNNN!'*H!HI "!s   )6 AAAr/   )distypingr   r   r   r   r   r   r	   r
   typesr   strr,   r4   r?   rI   rQ    r   r   <module>rW      s   



 I I I I I I I I I I I I I I I I I I I I       >B X -5c]FI   08 X        @	" 	" 	" 	" 	" 	" 	" 	"r   