B
    îq\@  ã               @   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   sP  g }g }t |tƒr| ¡ }nt|ƒ}xbt ||¡D ]R}	t |	tƒrT|	d }
| |	¡ n|	}
| |	¡ t 	|
¡svt
 |
¡s2td |
¡ƒ‚q2W x:||fD ].}	|	dk	r’t 	|	¡s²t
 |	¡s’td |	¡ƒ‚q’W d |¡g}|rä| d |¡¡ |dd… }|dkrþ| j}d |¡| i}i }xRt|ƒD ]F\}}	|	\}}d |¡}|||< | d ||¡¡ | d	 |¡¡ qW |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: {0}Nz, z, *{0}z__{0}__funcz
_kwargs{0}z	, {0}={1}z	, {0}={0}z, **{0}Ú é   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ÚformatÚjoinÚ__name__Ú	enumerateÚ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.7/site-packages/astropy/utils/codegen.pyr      sn    







)r*   r   r   r   r!   Úrer%   Zintrospectionr   Ú__all__r'   r   r   r   r   r   r:   Ú<module>   s   
