a
    ß™fbõ  ã                   @   sh   d Z ddlZ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gZ	e 
d¡Zdi dddfdd„ZdS )	z4Utilities for generating new Python code at runtime.é    Né   )Úfind_current_moduleÚmake_function_with_signaturez^[A-Za-z][A-Za-z_]*© c                 C   sJ  g }g }t |tƒr| ¡ }nt|ƒ}t ||¡D ]R}	t |	tƒrR|	d }
| |	¡ n|	}
| |	¡ t 	|
¡stt
 |
¡s0td|
› ƒ‚q0||fD ].}	|	durŒt 	|	¡s¬t
 |	¡sŒtd|	› ƒ‚qŒd |¡g}|rÜ| d|› ¡ |dd… }|du rö| j}d|› d| i}i }t|ƒD ]J\}}	|	\}}d|› }|||< | d|› d	|› ¡ | d
 |¡¡ q|r„| d|› ¡ | d|› ¡ d |¡ d¡}d |¡ d¡}tdƒ}t ¡ j}|rê|j}|j}| d¡ròtj |¡d d }nd}d}|jd }t djd| |||d¡}t||dƒ}t|||ƒ || }||_ | j!|_!|S )av  
    Make a new function from an existing function but with the desired
    signature.

    The desired signature must of course be compatible with the arguments
    actually accepted by the input function.

    The ``args`` are strings that should be the names of the positional
    arguments.  ``kwargs`` can map names of keyword arguments to their
    default values.  It may be either a ``dict`` or a list of ``(keyword,
    default)`` tuples.

    If ``varargs`` is a string it is added to the positional arguments as
    ``*<varargs>``.  Likewise ``varkwargs`` can be the name for a variable
    keyword argument placeholder like ``**<varkwargs>``.

    If not specified the name of the new function is taken from the original
    function.  Otherwise, the ``name`` argument can be used to specify a new
    name.

    Note, the names may only be valid Python variable names.
    r   zinvalid argument name: Nz, z, *Ú__Z__funcZ_kwargsú=z	, {0}={0}z, **Ú é   z.pycz.pyz<string>Ú__main__zE{0}    def {name}({sig1}):
        return __{name}__func({sig2})
    Ú
)ÚnameZsig1Zsig2Zsingle)"Ú
isinstanceÚdictÚitemsÚiterÚ	itertoolsÚchainÚtupleÚappendÚkeywordÚ	iskeywordÚ_ARGNAME_REÚmatchÚSyntaxErrorÚjoinÚ__name__Ú	enumerateÚformatÚlstripr   ÚinspectZcurrentframeÚf_backÚ__file__ÚendswithÚosÚpathÚsplitextÚf_linenoÚtextwrapÚdedentÚcompileÚevalÚ
__module__Ú__doc__)ÚfuncÚargsÚkwargsZvarargsZ	varkwargsr   Zpos_argsZkey_argsZiter_kwargsÚitemÚargnameZdef_signatureZcall_signatureZglobal_varsZ
local_varsÚidxÚkeyÚvalueZdefault_varÚmodZfrmÚfilenameÚmodnameÚlinenoÚtemplateÚcodeÚnew_funcr   r   ú4lib/python3.9/site-packages/astropy/utils/codegen.pyr      sp    







ü)r,   r   r   r   r#   Úrer'   Zintrospectionr   Ú__all__r)   r   r   r   r   r   r<   Ú<module>   s   
ÿ