³ò
Ü‘RMc           @   sÌ  d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d d d „ Z d e f d „  ƒ  YZ d „  Z	 d e
 f d „  ƒ  YZ d	 „  Z d
 „  Z d  d k Z d d e i i d d „ Z h  Z d „  Z d „  Z d „  Z d i g  Z e d ƒ D]† Z e d e e ƒ j o
 d j n pH d e e ƒ j o
 d j n p$ d e e ƒ j o
 d j n o e e ƒ p d qý [ ƒ Z d Z d „  Z d Z d Z d „  Z  d „  Z! d d „ Z# d S(    iÿÿÿÿNt    c         C   sÎ   t  |  t ƒ p |  i } n |  } | d j o d Sn | i d d ƒ } g  } xI d D]A } | | | i | d d | d ƒ | | } | i | ƒ qW W| \ } } | | f t | ƒ t | ƒ j  } | S(   sO   Render a docstring as a string of lines.
        The argument is either a docstring or an object.
        Note that we don't use a sequence, since we want
        the docstring to line up left, regardless of
        indentation. The shorter triple quotes are
        choosen automatically.
        The result is returned as a 1-tuple.s   \s   \\s   """s   '''i    N(   s   """s   '''(   t
   isinstancet   strt   __doc__t   Nonet   replacet   appendt   len(   t   funct
   indent_strt   closing_strt   doct   comparet   qt   txtt   doc2(    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   render_docstr   s     ."t   NiceCompilec           B   s#   e  Z d  Z d „  Z d d „ Z RS(   s—    Compiling parameterized strings in a way that debuggers
        are happy. We provide correct line numbers and a real
        __file__ attribute.
    c         C   sÉ   t  | ƒ t j o
 | } n | i d ƒ } | p t i i t i d ƒ } n | |  _ | i	 d ƒ p | i	 d ƒ o | d  } n t i i
 | ƒ o" | |  _ t | ƒ i ƒ  |  _ n
 d  |  _ d  S(   Nt   __file__iÿÿÿÿs   .pycs   .pyo(   t   typeR   t   gett   ost   patht   abspatht   syst   argvt   srcnamet   endswitht   existst   filet   readt   srctextR   (   t   selft   namespace_or_filenameR   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   __init__)   s    
	 	c   
   
   C   sv  |  i  oc y |  i  i | ƒ } Wn, t j
 o  d |  i } t | ƒ ‚ n X|  i  |  i d ƒ d } n d } x@ | i d ƒ D]/ } | i ƒ  } | o | i d ƒ o Pqƒ qƒ W| o) | d i ƒ  o | d 8} d | } n | d j	 o d | | | } n d | | } t
 | |  i d ƒ } |  i o< t |  i ƒ }	 | d j	 o | |	 _ n t | |	 ƒ } n | S(	   s   instance NiceCompile (src, args) -- formats src with args
            and returns a code object ready for exec. Instead of <string>,
            the code object has correct co_filename and line numbers.
            Indentation is automatically corrected.
        s.   Source text not found in %s - use a raw strings   
i   i    t   #s   if 1:
t   execN(   R   t   indext
   ValueErrorR   t   countt   splitt   stript
   startswitht   isspaceR   t   compilet   MyStrt   __sourceargs__t   newcode_withfilename(
   R    t   srct   argst   pt   msgt   prelinest   linet   contentt   cR   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   __call__<   s4    
 	

N(   t   __name__t
   __module__R   R"   R   R8   (    (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyR   $   s   	c         C   s˜   t  i |  ƒ } t | d ƒ o t | i ƒ } nD y t  i |  ƒ } Wn- t j
 o d Sn t j
 o d Sn Xt | d ƒ o | | i	 Sn | S(   s|    similar to inspect.getsource, but trying to
    find the parameters of formatting generated methods and
    functions.
    t
   __source__R.   N(
   t   inspectt   getfilet   hasattrR   R;   t	   getsourcet   IOErrorR   t   IndentationErrorR.   (   t   objectt   nameR0   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyR?   c   s    	R-   c           B   s   e  Z d  Z RS(   s/    custom string which allows to add attributes. (   R9   R:   R   (    (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyR-   |   s   c         K   sÝ   g  } t  |  ƒ D]" } | d  d j o | | q q ~ } x2 | D]* } | | j o t |  | ƒ | | <qC qC Wt i | d | d | d | d | d | d | d	 | d
 | d | d | d | d | d | d ƒ S(   Ni   t   co_t   co_argcountt
   co_nlocalst   co_stacksizet   co_flagst   co_codet	   co_constst   co_namest   co_varnamest   co_filenamet   co_namet   co_firstlinenot	   co_lnotabt   co_freevarst   co_cellvars(   t   dirt   getattrt   newt   code(   t   fromcodet   kwargst   _[1]t   xt   namesRC   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   newcode   s(    < c         C   sr   g  } t  |  ƒ } xA |  i D]6 } t | | ƒ o t | | ƒ } n | i | ƒ q Wt |  d t | ƒ d | ƒS(   NRJ   RM   (   R   RJ   R   R/   R   R\   t   tuple(   t   coRM   t   newconstlistt   cotypeR7   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyR/   •   s    
 R$   i    c         C   s_   |  | | | f } y t  | } Wn8 t j
 o, t i i |  | | | ƒ } | t  | <n X| S(   sš   
    A version of compile() that caches the code objects it returns.
    It uses py.code.compile() to allow the source to be displayed in tracebacks.
    (   t   compile2_cachet   KeyErrort   pyRV   R,   (   t   sourcet   filenamet   modet   flagst   dont_inheritt   keyR^   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   compile2£   s    c         B   s1  e  |  e i i ƒ pU e  |  e ƒ o |  g } n e |  ƒ } | i d ƒ e i i d i | ƒ ƒ }  n e i	 d ƒ } | i
 } | | i j o
 g  } n | i ƒ  } | i ƒ  g  } | D] } | | | q¾ ~ } |  i d d d i | ƒ f d d | ƒ }  h  }	 |  i ƒ  | i |	 U|	 d	 }
 |
 | Œ  S(
   sÐ   Compiles the source code (a string or a list/generator of lines)
    which should be a definition for a function named 'resultname'.
    The caller's global dict and local variable bindings are captured.
    R    s   
i   t   befores   def container(%s):s   , t   afters   # no unindent
    return %st	   container(   R   Rc   RV   t   SourceR   t   listR   t   joinR   t	   _getframet   f_localst	   f_globalst   keyst   sortt	   putaroundR,   (   Rd   t
   resultnamet   linest   callert   localst
   localnamesRY   Ri   t   valuest   dRm   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   compile_templateº   s(    	

%	
c         C   sU   t  i |  i |  i | |  i |  i ƒ } |  i o  h  | _ | i i |  i ƒ n | S(   s"   Make a renamed copy of a function.(   RU   t   functiont	   func_codet   func_globalst   func_defaultst   func_closuret	   func_dictt   update(   R   t   newnamet   f(    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   func_with_new_nameÛ   s    	
	c            s   ‡  f d †  } | S(   s:   A function decorator which changes the name of a function.c            s   t  |  ˆ  ƒ S(   N(   Rˆ   (   R   (   R†   (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   decorateç   s    (    (   R†   R‰   (    (   R†   s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   func_renamerå   s    i   t   0t   9t   at   zt   At   Zt   _ix   c         C   sU   t  |  ƒ i t ƒ }  |  p" d |  d j o
 d j n o d |  }  n |  t  S(   NR‹   i    RŒ   R‘   (   R   t	   translatet   PY_IDENTIFIERt   PY_IDENTIFIER_MAX(   t   stuff(    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   valid_identifierñ   s    *i   i   c         C   s#   t  |  d |  ƒ }  |  i t @d j S(   NR€   i    (   RT   RH   t
   CO_VARARGS(   R   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   has_varargsú   s    c         C   s#   t  |  d |  ƒ }  |  i t @d j S(   NR€   i    (   RT   RH   t   CO_VARKEYWORDS(   R   (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   has_varkeywordsþ   s    c         C   sÃ   t  |  d d  ƒ } | d  j oY t  |  d d  ƒ } t  |  d d  ƒ } | d  j	 o$ | d  j	 o d | i | f } qx n y |  i i } Wn t j
 o d } n Xd | p d | | p d f S(	   NR:   R9   t   class_s   %s.%siÿÿÿÿs	   (%s:%d)%st   ?t   UNKNOWN(   RT   R   R9   R€   RO   t   AttributeError(   t   fnRC   t   modt   clst   firstlineno(    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pyt   nice_repr_for_func  s    ($   R   R   R<   RU   t   autopathRc   R   RB   R   R?   R   R-   R\   R/   t
   __future__t
   generatorst   compiler_flagRj   Ra   R~   Rˆ   RŠ   Rp   RY   t   ranget   it   chrR“   R”   R–   R—   R™   R˜   Rš   R   R£   (    (    (    s)   /64/home/arigo/u/pypy/tool/sourcetools.pys   <module>	   s.   0?				!	
	œ			
