σ
ίΘ[c           @` sΔ   d  Z  d d l m Z m Z m Z m 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 d l m Z d g Z e
 j d	  Z d i  d d d d
  Z d S(   u4   Utilities for generating new Python code at runtime.i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNi   (   t   find_current_modulei   (   t   sixu   make_function_with_signatureu   ^[A-Za-z][A-Za-z_]*c      	   C` s  g  } g  } t  j r9 | r9 | r9 t d j |    n  t | t  rZ t  j |  } n t |  } x t j	 | |  D]y }	 t |	 t
  r¨ |	 d }
 | j |	  n |	 }
 | j |	  t j |
  sΪ t j |
  ry t d j |
    qy qy WxZ | | f D]L }	 |	 d k	 rt j |	  s4t j |	  rOt d j |	    qOqqWd j |  g } | r| j d j |   n  | } | d k r£|  j } n  i |  d j |  6} i  } xn t |  D]` \ } }	 |	 \ } } d j |  } | | | <| j d j | |   | j d	 j |   qΜW| re| j d
 j |   | j d
 j |   n  d j |  j d  } d j |  j d  } t d  } t j   j } | rχ| j } | j } | j d  rt j j |  d d } qn d } d } | j d } t j  d j d | d | d | d |  } t! | | d  } t" | | |  | | } | | _# |  j$ | _$ | S(   uv  
    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.
    u(   keyword arguments not allowed after *{0}i    u   invalid argument name: {0}u   , u   , *{0}u   __{0}__funcu
   _kwargs{0}u	   , {0}={1}u	   , {0}={0}u   , **{0}u    i   u   .pycu   .pyu   <string>u   __main__uE   {0}    def {name}({sig1}):
        return __{name}__func({sig2})
    u   
t   namet   sig1t   sig2u   singleN(%   R   t   PY2t   SyntaxErrort   formatt
   isinstancet   dictt	   iteritemst   itert	   itertoolst   chaint   tuplet   appendt   keywordt	   iskeywordt   _ARGNAME_REt   matcht   Nonet   joint   __name__t	   enumeratet   lstripR   t   inspectt   currentframet   f_backt   __file__t   endswitht   ost   patht   splitextt   f_linenot   textwrapt   dedentt   compilet   evalt
   __module__t   __doc__(   t   funct   argst   kwargst   varargst	   varkwargsR   t   pos_argst   key_argst   iter_kwargst   itemt   argnamet   def_signaturet   call_signaturet   global_varst
   local_varst   idxt   keyt   valuet   default_vart   modt   frmt   filenamet   modnamet   linenot   templatet   codet   new_func(    (    s4   lib/python2.7/site-packages/astropy/utils/codegen.pyt   make_function_with_signature   st    	

		 
	(    (   R+   t
   __future__R    R   R   R   R   R   R   R"   t   reR&   t   introspectionR   t   externR   t   __all__R(   R   R   RF   (    (    (    s4   lib/python2.7/site-packages/astropy/utils/codegen.pyt   <module>   s   "		