ó
æNXc           @  sÎ   d  Z  d d l m Z d d l Z d d l 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
 e j e	 j d „  e j Dƒ ƒ Z d d „ Z d e j f d	 „  ƒ  YZ d
 „  Z d S(   sé   Compiler tools with improved interactive support.

Provides compilation machinery similar to codeop, but with caching support so
we can provide interactive tracebacks.

Authors
-------
* Robert Kern
* Fernando Perez
* Thomas Kluyver
iÿÿÿÿ(   t   print_functionN(   t   PyCF_ONLY_ASTc         c  s!   |  ] } t  t | ƒ j Vq d  S(   N(   t   getattrt
   __future__t   compiler_flag(   t   .0t   fname(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pys	   <genexpr>/   s   i    c         C  s2   t  j |  j d ƒ ƒ j ƒ  } d j | | d  ƒ S(   sj    Compute a (probably) unique name for code for caching.
    
    This now expects code to be unicode.
    s   utf-8s   <ipython-input-{0}-{1}>i   (   t   hashlibt   md5t   encodet	   hexdigestt   format(   t   codet   numbert   hash_digest(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyt	   code_name6   s    t   CachingCompilerc           B  sJ   e  Z d  Z d „  Z d d d „ Z d „  Z e d „  ƒ Z d d „ Z RS(	   sF   A compiler that caches code compiled from interactive statements.
    c         C  sV   t  j j |  ƒ t t d ƒ s+ i  t _ n  t t d ƒ sI t j t _ n  t t _ d  S(   Nt   _ipython_cachet   _checkcache_ori(	   t   codeopt   Compilet   __init__t   hasattrt	   linecacheR   t
   checkcacheR   t   check_linecache_ipython(   t   self(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyR   I   s    s	   <unknown>t   execc         C  s   t  | | | |  j t Bd ƒ S(   sÍ   Parse code to an AST with the current compiler flags active.
        
        Arguments are exactly the same as ast.parse (in the standard library),
        and are passed to the built-in compile function.i   (   t   compilet   flagsR   (   R   t   sourcet   filenamet   symbol(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyt	   ast_parse_   s    c         C  s   t  j |  _ d S(   s&   Reset compiler flags to default state.N(   R   t   PyCF_DONT_IMPLY_DEDENTR   (   R   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyt   reset_compiler_flagsf   s    c         C  s   |  j  S(   s;   Flags currently active in the compilation process.
        (   R   (   R   (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyt   compiler_flagsl   s    i    c         C  sh   t  | | ƒ } t | ƒ t j ƒ  g  | j ƒ  D] } | d ^ q. | f } | t j | <| t j | <| S(   sæ  Make a name for a block of code, and cache the code.
        
        Parameters
        ----------
        code : str
          The Python source code to cache.
        number : int
          A number which forms part of the code's name. Used for the execution
          counter.
          
        Returns
        -------
        The name of the cached code (as a string). Pass this as the filename
        argument to compilation, so that tracebacks are correctly hooked up.
        s   
(   R   t   lent   timet
   splitlinesR   t   cacheR   (   R   R   R   t   namet   linet   entry(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyR(   r   s    )(	   t   __name__t
   __module__t   __doc__R   R!   R#   t   propertyR$   R(   (    (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyR   E   s   		c          G  s$   t  j |  Œ  t  j j t  j ƒ d S(   sE   Call linecache.checkcache() safely protecting our cached values.
    N(   R   R   R(   t   updateR   (   t   args(    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyR   ‰   s    (   R.   R   R    t   astR   R   t	   functoolsR   R   t   operatorR&   t   reducet   or_t   all_feature_namest	   PyCF_MASKR   R   R   R   (    (    (    sO   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/compilerop.pyt   <module>   s   D