ó
ćNXc           @   s<  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 m Z d d l m	 Z	 d d l
 m Z d d l m Z m Z d d l m Z m Z m Z m Z m Z e j Z e j Z e d e   d	 e   d
 e j    Z e j d d e j d e j d e j d e j d e j d e j d e j Z e j d d e j d e j  d e j d e j! d e j" d e j# d e j! Z$ e$ j% d  Z& e& j' j( d e j) d e j* d e j)  d e+ f d     YZ, d   Z- e j. e j/ j0 d d   Z1 e j2 j3 e1  Z1 e j. e j/ j0 d d   Z4 e j. e j5    Z6 e6 j7 d  d Z8 e j9 d k se j: d k se j;   d k rd n d  Z< i d! d" 6d! d# 6d$ d% 6d& d' 6d( d) 6d* d+ 6d, d- 6d. d/ 6d0 d1 6d2 d3 6d4 d5 6d6 d7 6d8 d9 6d: d; 6d< d= 6d> d? 6d@ dA 6dB dC 6dD dE 6e8 dF 6e6 dG 6e4 dH 6dI dJ 6dK dL 6dM dN 6e j= dO 6e< dP 6Z> dQ   Z? dR   Z@ i e, e jA dS  dT 6e, e jB  dU 6e, dV    dW 6e, dX    g g  eC dY dZ  D] ZD e, e? eD  ^ qşd[ 6g  eC dZ  D] ZD e, e@ eD  ^ qäd\ 6ZE d]   ZF d^ e f d_     YZG d` e	 f da     YZH d S(b   sh   Classes for handling input/output prompts.

Authors:

* Fernando Perez
* Brian Granger
* Thomas Kluyver
i˙˙˙˙N(   t	   Formatter(   t   Configurable(   t   release(   t	   coloransit	   py3compat(   t   Unicodet   Instancet   Dictt   Boolt   Intt   normalt   inpt   nocolort   NoColort	   in_promptt	   in_numbert
   in_prompt2t	   in_normalt
   out_promptt
   out_numbert   Linuxt   LightBGt   LazyEvaluatec           B   s;   e  Z d  Z d   Z d   Z d   Z d   Z d   Z RS(   s   This is used for formatting strings with values that need to be updated
    at that time, such as the current time or working directory.c         O   s   | |  _  | |  _ | |  _ d  S(   N(   t   funct   argst   kwargs(   t   selfR   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   __init__X   s    		c         K   s&   |  j  j |  |  j |  j |  j    S(   N(   R   t   updateR   R   (   R   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   __call__]   s    c         C   s   t  |     S(   N(   t   str(   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   __str__a   s    c         C   s   t  j |     S(   N(   R   t   unicode_type(   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   __unicode__d   s    c         C   s   t  |    |  S(   N(   t   format(   R   t   format_spec(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt
   __format__g   s    (   t   __name__t
   __module__t   __doc__R   R   R   R!   R$   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR   U   s   				c            sG   t  j d d j t t  j   j      } | j   f d   |  S(   s}    Replace in 'text' all occurences of any key in the given
    dictionary by its corresponding value.  Returns the new string.s   (%s)t   |c            s     |  j  |  j   |  j   !S(   N(   t   stringt   startt   end(   t   mo(   t   dict(    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   <lambda>t   s    (   t   ret   compilet   joint   mapt   escapet   keyst   sub(   R-   t   textt   regex(    (   R-   sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   multiple_replacej   s    .t   HOMEs   //////:::::ZZZZZ,,,~~~t   USERt    t   .i    t   ntt   clit   #t   $s#   {color.number}{count}{color.prompt}s   %ns   \#s   {count}s   \Ns   {dots}s   \Ds   {time}s   \Ts   {cwd}s   \ws
   {cwd_last}s   \Ws
   {cwd_x[0]}s   \X0s
   {cwd_x[1]}s   \X1s
   {cwd_x[2]}s   \X2s
   {cwd_x[3]}s   \X3s
   {cwd_x[4]}s   \X4s
   {cwd_x[5]}s   \X5s
   {cwd_y[0]}s   \Y0s
   {cwd_y[1]}s   \Y1s
   {cwd_y[2]}s   \Y2s
   {cwd_y[3]}s   \Y3s
   {cwd_y[4]}s   \Y4s
   {cwd_y[5]}s   \Y5s   \hs   \Hs   \us   \s   \\s   
s   \ns   s   \rs   \vs   \$c         C   sH   t  j   j t d  } t j j | j t j  |   } | pG t j S(   s   Return the last depth elements of the current working directory.

    $HOME is always replaced with '~'.
    If depth==0, the full path is returned.t   ~(   R   t   getcwdt   replaceR9   t   ost   sepR1   t   split(   t   deptht   cwdt   out(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   cwd_filtÔ   s    #c         C   sž   t  j   } | j t d  j t j  } d | k rY t |  |  d k rY |  d 7}  n  d } t j	 d k r t |  |  k r t j
 j |  d } n  | d j | |   } | p˝ t j S(   s   Return the last depth elements of the current working directory.

    $HOME is always replaced with '~'.
    If depth==0, the full path is returned.RA   i   R;   t   win32i    t   /(   R   RB   RC   R9   RF   RD   RE   t   lent   syst   platformt   patht
   splitdriveR1   (   RG   t   full_cwdRH   t	   drivepartRI   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt	   cwd_filt2Ţ   s    "!s   %H:%M:%St   timeRH   c           C   s   t  j   j t j  d S(   Ni˙˙˙˙(   R   RB   RF   RD   RE   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR.   ő   s    t   cwd_lastc           C   s   t  j   j t d  S(   NRA   (   R   RB   RC   R9   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR.   ö   s    i   i   t   cwd_xt   cwd_yc         C   s.   |  s |  j  d  r d St |  j   d  S(   sX   Get the length of the last line. More intelligent than
    len(s.splitlines()[-1]).
    s   
s   i    i˙˙˙˙(   s   
s   (   t   endswithRM   t
   splitlines(   t   s(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   _lenlastlineű   s    t   UserNSFormatterc           B   s    e  Z d  Z d   Z d   Z RS(   sU   A Formatter that falls back on a shell's user_ns and __builtins__ for name resolutionc         C   s   | |  _  d  S(   N(   t   shell(   R   R^   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR     s    c         C   sg   y t  j |  | | |  SWn t k
 r- n Xx. |  j j t f D] } | | k rA | | SqA Wd | S(   Ns   <ERROR: '%s' not found>(   R    t	   get_valuet	   ExceptionR^   t   user_nst   __builtins__(   R   t   keyR   R   t	   container(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR_   	  s    (   R%   R&   R'   R   R_   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR]     s   	t   PromptManagerc           B   s:  e  Z d  Z e d d e Z e e j d e Z e	 d d e Z
 d   Z e d d  Z d   Z e	 d	 d e d d
 Z e	 d d e d d Z e	 d d e d d Z e e d e d d Z e   Z e   Z e   Z e   Z d   Z d   Z d d  Z d   Z e d  Z e d  Z e d d  Z  RS(   s>   This is the primary interface for producing IPython's prompts.s1   IPython.core.interactiveshell.InteractiveShellABCt
   allow_noneR   t   configc         C   s>   |  j  j |  x' d d d d g D] } |  j |  q# Wd  S(   Nt   int   in2RI   t   rewrite(   t   color_scheme_tablet   set_active_schemet   update_prompt(   R   t   namet	   new_valuet   pname(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   _color_scheme_changed  s    t   helps  
        This maps field names used in the prompt templates to functions which
        will be called when the prompt is rendered. This allows us to include
        things like the current time in the prompts. Functions are only called
        if they are used in the prompt.
        c         C   s
   t  j   S(   N(   t   lazily_evaluatet   copy(   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   _lazy_evaluate_fields_default)  s    s	   In [\#]: s<   Input prompt.  '\#' will be transformed to the prompt numbers	      .\D.: s   Continuation prompt.s	   Out[\#]: s<   Output prompt. '\#' will be transformed to the prompt numbersf   
        If True (default), each prompt will be right-aligned with the
        preceding one.
        c         C   s    i d d 6d d 6d d 6d d 6S(   Ni    Rh   Ri   RI   Rj   (    (   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   _invisible_chars_defaultA  s    c         K   s˛   t  t |   j d | |  t j t t t g |  j  |  _	 t
 |  |  _ |  j d |  j  |  j d |  j  |  j d |  j  |  j d  |  j |  j d d d g  d  S(	   NR^   Rh   Ri   RI   Rj   t   in_templatet   in2_templatet   out_template(   t   superRe   R   R   t   ColorSchemeTablet   PColNoColorst	   PColLinuxt   PColLightBGt   color_schemeRk   R]   t
   _formatterRm   Rw   Rx   Ry   t   on_trait_changet   _update_prompt_trait(   R   R^   R   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR   D  s    	c         C   sj   | d k	 r% t t |  |  j | <n  t |  j | d t  t |  j | d t  } | |  j | <d S(   s  This is called when a prompt template is updated. It processes
        abbreviations used in the prompt template (like \#) and calculates how
        many invisible characters (ANSI colour escapes) the resulting prompt
        contains.
        
        It is also called for each prompt on changing the colour scheme. In both
        cases, traitlets should take care of calling this automatically.
        t   colorN(	   t   NoneR8   t   prompt_abbreviationst	   templatesR\   t   _rendert   Truet   Falset   invisible_chars(   R   Rn   t   new_templatet   invis_chars(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyRm   T  s
    	c         C   s   | d  } |  j  | |  d  S(   Ni÷˙˙˙(   Rm   (   R   t	   traitnameR   Rn   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR   e  s    
c   	      K   sq  | d k r |  j  d |  S| rť |  j j } | d k rm t d } | j | j | j | _ | _ | _ qÝ t d } | j	 | j
 | j | _ | _ | _ | d k rÝ | j | _ qÝ n" t d } d \ | _ | _ | _ |  j j } t d | d	 | d
 d t t |   d |  j d |  j  } | j |  j  | j |  | j |  j | | j } |  j j | |  S(   sN   Render but don't justify, or update the width or txtwidth attributes.
        Rj   R   RI   R
   R   Ri   R   R;   t   countt   dotsR<   t   widtht   txtwidth(   R;   R;   R;   (   t   _render_rewriteRk   t   active_colorst   color_listsR   R   R
   t   numbert   promptR   R   R   R   R^   t   execution_countR-   RM   R   R   R   R   t   lazy_evaluate_fieldsR   R   R"   (	   R   Rn   R   R   t   schemet   colorsR   t   fmtargsR   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR   i  s*    
)
&
c         C   sf   | r? |  j  j } | j j d d  j d d  } | j } n d \ } } | d j |  j d  | S(   s   Render the ---> rewrite prompt.s   R;   s   s   -> t   -(   R;   R;   (   Rk   R   R   RC   R
   t   rjustR   (   R   R   R   t   color_promptt   color_normal(    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyR     s    !c         K   sš   |  j  | d | | } | r+ |  j | n d } t |  | |  _ | d k rY |  j n | } | r˘ | d k r˘ d | k r˘ d | k r˘ | j |  j |  } n  t |  | |  _ | S(   sÇ  
        Render the selected prompt.
        
        Parameters
        ----------
        name : str
          Which prompt to render. One of 'in', 'in2', 'out', 'rewrite'
        color : bool
          If True (default), include ANSI escape sequences for a coloured prompt.
        just : bool
          If True, justify the prompt to the width of the last prompt. The
          default is stored in self.justify.
        **kwargs :
          Additional arguments will be passed to the string formatting operation,
          so they can override the values that would otherwise fill in the
          template.
        
        Returns
        -------
        A string containing the rendered prompt.
        R   i    Rh   s   
s   N(   R   R   R\   R   R   t   justifyR   R   (   R   Rn   R   t   justR   t   resR   (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   render  s    *N(!   R%   R&   R'   R   R   R^   R   R{   Rk   R   R   Rq   R   R   Ru   Rw   Rx   Ry   R   R    R   R	   R   R   R   Rv   R   R   Rm   R   R   R   RŁ   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyRe     s6   														%(I   R'   RD   R/   t   socketRN   RU   R)   R    t   traitlets.config.configurableR   t   IPython.coreR   t   IPython.utilsR   R   t	   traitletsR   R   R   R   R	   t   InputTermColorst   InputColorst
   TermColorst   ColorsR-   t   NoColorsR   t   ColorSchemeR   R|   t   Greent
   LightGreent   Normalt   Redt   LightRedR}   Rt   R~   R   R   t   Bluet	   LightBluet   objectR   R8   t   str_to_unicodet   environt   getR9   RP   t   realpathR:   t   gethostnamet   HOSTNAMERF   t   HOSTNAME_SHORTRn   RO   t   getuidt   ROOT_SYMBOLt   versionR   RJ   RT   t   strftimeRB   t   ranget   xRs   R\   R]   Re   (    (    (    sL   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/prompts.pyt   <module>	   sŚ   (		'														
	 <

	
	-,		