
AHc           @   s$  d  Z  d d k l Z d e i d Z e i Z e i Z d d k	 Z	 d d k
 Z
 d d k Z d d k Z d d k Z d d k l Z d d k l Z d d k l Z d d	 k l Z d d
 k Td d k l Z e i   Z e i Z e i Z e i e i d d e i  d e i  d e i  d e i  d e i  d e i  d e i   e i d d e i! d e i" d e i! d e i# d e i$ d e i% d e i# Z& e i e&  e& i' d  Z( e( i) i* d e i+ d e i, d e i+  e i e(  [ [ d   Z- e
 i. i/ d d  Z0 e
 i. i/ d  Z1 e i2   Z3 e3 i4 d  d Z5 d e
 i6 d j p e
 i7   d j Z8 h d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) e
 i9 d* 6d+ e0 d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d8 6d9 d: 6d; d< 6d= d> 6d? d@ 6dA dB 6e5 dC 6e3 dD 6e1 dE 6dF dG 6dH dI 6dJ dK 6e dL 6e8 dM 6Z: e: i'   Z; d! e; d <d! e; d  <e i Z< xP e= e<  D]B Z> e> d dN j o+ dO e> Z? e@ e< e>  e: e? <dP e; e? <q`q`We; aA dQ   ZB dR eC f dS     YZD dT eD f dU     YZE dV eD f dW     YZF dX eD f dY     YZG dZ d\ d[     YZH d S(]   sa   
Classes for handling input/output prompts.

$Id: Prompts.py 3026 2008-02-07 16:03:16Z vivainio $i(   t   Releases   %s <%s>t   FernandoN(   t	   ColorANSI(   t   ItplNS(   t   Struct(   t   Macro(   t   *(   t   TryNextt   NoColort	   in_promptt	   in_numbert
   in_prompt2t	   in_normalt
   out_promptt
   out_numbert   normalt   Linuxt   LightBGc            sG   t  i d d i t t  i   i      } | i   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     |  i  |  i   |  i   !S(    (   t   stringt   startt   end(   t   mo(   t   dict(    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   <lambda>^   s    (   t   ret   compilet   joint   mapt   escapet   keyst   sub(   R   t   textt   regex(    (   R   sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   multiple_replaceT   s    .t   HOMEs   //////:::::ZZZZZ,,,~~~t   USERt   .i    s   $#t   nts6   ${self.col_num}${self.cache.prompt_count}${self.col_p}s   %ns   \#s   ${self.cache.prompt_count}s   \Ns(   ${"."*len(str(self.cache.prompt_count))}s   \Ds   ${os.getcwd()}s   \ws   ${time.strftime("%H:%M:%S")}s   \ts   ${os.getcwd().split("%s")[-1]}s   \Ws    ${os.getcwd().replace("%s","~")}s   \X0s   ${self.cwd_filt(1)}s   \X1s   ${self.cwd_filt(2)}s   \X2s   ${self.cwd_filt(3)}s   \X3s   ${self.cwd_filt(4)}s   \X4s   ${self.cwd_filt(5)}s   \X5s   ${self.cwd_filt2(0)}s   \Y0s   ${self.cwd_filt2(1)}s   \Y1s   ${self.cwd_filt2(2)}s   \Y2s   ${self.cwd_filt2(3)}s   \Y3s   ${self.cwd_filt2(4)}s   \Y4s   ${self.cwd_filt2(5)}s   \Y5s   \hs   \Hs   \us   \s   \\s   
s   \ns   s   \rs   \vs   \$t   _s   \C_t    c         C   s   y t  |   } Wni t j
 o? y |  i d d  } Wq| t j
 o } d | } q| Xn  t j
 o } d | } n X| S(   s   Convert to a string, without ever raising an exception.

    If str(arg) fails, <ERROR: ... > is returned, where ... is the exception
    error message.t   utf_8t   replaces   <ERROR: %s>(   t   strt   UnicodeErrort   encodet	   Exception(   t   argt   outt   msg(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   str_safe   s    t
   BasePromptc           B   sw   e  Z d  Z d   Z d   Z e e e d d Z e d  Z d   Z	 d   Z
 d   Z d	   Z d
   Z d   Z RS(   s,   Interactive prompt similar to Mathematica's.c         C   s   |  i  S(   N(   t   _p_template(   t   self(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   _get_p_template   s    c         C   s   | |  _  |  i   d  S(   N(   R4   t	   set_p_str(   R5   t   val(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   _set_p_template   s    	t   docs#   Template for prompt string creationc         C   sD   | |  _  | |  _ t i d  |  _ | |  _ | |  _ |  i   d  S(   Ns   (\s*)$(   t   cachet   sepR   R   t   rspacet   pad_leftt
   p_templateR7   (   R5   R;   R<   t   promptR>   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   __init__   s    				c         C   s   d d k  } d d k } t   } y_ t d d t t |  i  d f |  i i |  |  _	 t t t
 |  i  |  i i |  |  _ Wn+ d G|  i GH|  i |  _	 |  i |  _ n Xd S(   s    Set the interpolating prompt strings.

        This must be called every time the color settings change, because the
        prompt_specials global may have changed.iNs   %s%s%ss   ${self.sep}${self.col_p}s   ${self.col_norm}s)   Illegal prompt template (check $ usage!):(   t   ost   timet   localsR   R"   t   prompt_specialsR?   R;   t   user_nst   p_strt   prompt_specials_nocolort   p_str_nocolor(   R5   RB   RC   t   loc(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR7      s    			c         C   s   t  i i |  d S(   NR(   (   t   syst   stdoutt   write(   R5   R1   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRM     s    c         C   si   t  |  i  } |  i oH t |  t t  |  i   } d t t |  i i   | } | | S| Sd S(   s   Return a string form of the prompt.

        This for is useful for continuation and output prompts, since it is
        left-padded to match lengths with the primary one (if the
        self.pad_left attribute is set).s   %%%ssN(   R2   RG   R>   t   lenRI   R+   R;   t   last_prompt(   R5   t   out_strt   esc_padt   format(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   __str__  s    
 	c         C   sR   t  i   i t d  } t  i i | i t  i  |  } | o | St  i Sd 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   ~N(   RB   t   getcwdR*   R#   R<   R   t   split(   R5   t   deptht   cwdR0   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   cwd_filt*  s
    #c         C   s   t  i   } | i t d  i t  i  } d | j o% t |  | d j o | d 7} n d } t i d j o- t |  | j o t  i	 i
 |  d } n | d i | |  } | o | St  i Sd 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.RT   i   R(   t   win32i    t   /N(   RB   RU   R*   R#   RV   R<   RN   RK   t   platformt   patht
   splitdriveR   (   R5   RW   t   full_cwdRX   t	   drivepartR0   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt	   cwd_filt27  s    $#c         C   s   t  |  i  S(   sT   Implement boolean behavior.

        Checks whether the p_str attribute is non-empty(   t   boolR?   (   R5   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   __nonzero__K  s    (   t   __name__t
   __module__t   __doc__R6   R9   t   propertyR?   t   FalseRA   R7   RM   RS   RY   Ra   Rc   (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR3      s   								t   Prompt1c           B   s;   e  Z d  Z d d e d  Z d   Z d   Z d   Z RS(   s2   Input interactive prompt similar to Mathematica's.s   
s	   In [\#]: c         C   s   t  i |  | | | |  d  S(   N(   R3   RA   (   R5   R;   R<   R@   R>   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRA   U  s    c         C   sq   |  i    |  i i i } | i |  _ | i |  _ | i |  _	 |  i i
 d d  i
 d d  |  _ | i |  _ d  S(   Ns   R(   s   (   R7   R;   t   color_tablet   active_colorsR	   t   col_pR
   t   col_numR   t   col_normR*   t   col_p_niR   t   col_norm_ni(   R5   t   Colors(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt
   set_colorsX  s    
$c         C   sA   |  i  i d 7_ t |  i  i d  d |  i  _ t |  i  S(   Ni   s   
i(   R;   t   prompt_countR2   RI   RV   RO   RG   (   R5   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRS   c  s    "c         C   s`   t  |  i i  } t |  i i |  i    } d |  i d t |  | d d | |  i f S(   s   Print a string of the form '--->' which lines up with the previous
        input string. Useful for systems which re-write the user input when
        handling automatically special syntaxes.s	   %s%s>%s%st   -i   t    (	   R+   R;   RO   RN   R=   t   searcht   groupRo   Rp   (   R5   t   currt   nrspaces(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   auto_rewriteh  s    (   Rd   Re   Rf   t   TrueRA   Rr   RS   Rz   (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRi   R  s
   		t	   PromptOutc           B   s)   e  Z d  Z d d e d  Z d   Z RS(   s3   Output interactive prompt similar to Mathematica's.R(   s	   Out[\#]: c         C   s7   t  i |  | | | |  |  i p d   |  _ n d  S(   Nc           S   s   d  S(   R(   (    (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR   x  s    (   R3   RA   R?   RS   (   R5   R;   R<   R@   R>   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRA   u  s    
c         C   sA   |  i    |  i i i } | i |  _ | i |  _ | i |  _	 d  S(   N(
   R7   R;   Rj   Rk   R   Rl   R   Rm   R   Rn   (   R5   Rq   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRr   z  s
    
(   Rd   Re   Rf   R{   RA   Rr   (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR|   r  s   t   Prompt2c           B   s/   e  Z d  Z d e d  Z d   Z d   Z RS(   s    Interactive continuation prompt.s	      .\D.: c         C   s)   | |  _  | |  _ | |  _ |  i   d  S(   N(   R;   R?   R>   R7   (   R5   R;   R@   R>   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRA     s    			c         C   s   d d  k  } d d  k } t   } t d d t t |  i  d f |  i i |  |  _	 t t t
 |  i  |  i i |  |  _ d  S(   Nis   %s%s%ss   ${self.col_p2}s   $self.col_norm(   RB   RC   RD   R   R"   RE   R?   R;   RF   RG   RH   RI   (   R5   RB   RC   RJ   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR7     s    			c         C   sM   |  i    |  i i i } | i |  _ | i |  _ | i |  _	 | i
 |  _ d  S(   N(   R7   R;   Rj   Rk   R   t   col_p2R   Rn   R   Rl   R   Rm   (   R5   Rq   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRr     s    
(   Rd   Re   Rf   R{   RA   R7   Rr   (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR}     s   	t   CachedOutputc        	   B   sn   e  Z d  Z d d d d d d d e d  Z d   Z d   Z d d  Z d   Z	 e	 Z
 d	   Z d
   Z RS(   s  Class for printing output from calculations while keeping a cache of
    reults. It dynamically creates global variables prefixed with _ which
    contain these results.

    Meant to be used as a sys.displayhook replacement, providing numbered
    prompts and cache services.

    Initialize with initial and final values for cache counter (this defines
    the maximum size of the cache.R   s   
R(   c         C   s  d } | d j o d |  _  d } n> | | j  o' d |  _  d } t d | d d n
 d |  _  | |  _ | |  _ | |  _ | i |  _ | i |  _ | i |  _ | d j o | i d  d j p, | i d  d j p | i d	  d j o
 d
 } n |	 i d  d j p, |	 i d  d j p |	 i d	  d j o
 d }	 qKn |  i	 | d d
  |  _
 |  i	 |	 d d  |  _ |  i	 |
 d d  |  _ t |  _ t |  d | d |  i
 d | |  _ t |  d |  i d | |  _ t |  d d d |  i d | |  _ |  i |  d |  _ d |  _ | |  _ | |  _ | |  _ d \ |  _ |  _ |  _ t t d g  h  g  |  _  h |  i d 6|  i d 6|  i d 6} |  i i! |  d  S(   Ni   i    s6   caching was disabled (min value for cache size is %s).t   leveli   s   %nis   \#s   \Ns   >>> s   ... s	   In [\#]: s	      .\D.: s	   Out[\#]: R(   R<   R@   R>   R'   t   __t   ___(   R(   R(   R(   (    ("   t   do_full_cachet   warnt
   cache_sizet	   input_sept   shellRF   t
   input_histt   loggert   findt   _set_prompt_strt   ps1_strt   ps2_strt
   ps_out_strt   PromptColorsRj   Ri   t   prompt1R}   t   prompt2R|   t
   prompt_outRr   Rs   RO   t   Pprintt
   output_sept   output_sep2R'   R   R   R   t   typet   pprint_typest   update(   R5   R   R   R   t   colorsR   R   R   t   ps1t   ps2t   ps_outR>   t   cache_size_mint
   to_user_ns(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRA     sT    	
					,
,						$c         C   s,   | d  j o |  i o | S| Sn | Sd  S(   N(   t   NoneR   (   R5   RG   t	   cache_deft   no_cache_def(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR     s
    
c         C   s^   | i    d j o
 t a n t a |  i i |  |  i i   |  i i   |  i	 i   d S(   sY   Set the active color scheme and configure colors for the three
        prompt subsystems.t   nocolorN(
   t   lowerRH   RE   t   prompt_specials_colorRj   t   set_active_schemeR   Rr   R   R   (   R5   R   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyRr     s    
c      	   C   sX  d t  i j o( y |  i d =Wq8 t j
 o q8 Xn | d j	 ot i i } y# |  i |  i	 i
 d  o d SWn t j
 o n X| |  i  |  i i i   } |  i o | |  n |  i |  } | d j	 o
 | } n | |  i d j	 o |  i |  n |  i i o |  i i t |  d  n | |  i  t i i   n d S(   s   Printing with history cache management.
        
        This is invoked everytime the interpreter needs to print, and is
        activated by setting the variable sys.displayhook to it.R'   s   ;
Nt   _oht   output(   t   __builtin__t   __dict__RF   t   KeyErrorR   t   Termt   coutRM   R   Rs   t   endswitht
   IndexErrorR   R   t   hookst   generate_output_promptR   t   displayR   R   t
   log_outputt	   log_writet   reprR   t   flush(   R5   R/   t
   cout_writet	   outpromptt   manipulated_val(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   __call__  s2    			

c         C   s>   y t  i i |  SWn# t j
 o |  i i i |  SXd S(   s   Default printer method, uses pprint.

        Do ip.set_hook("result_display", my_displayhook) for custom result
        display, e.g. when your own objects need special formatting.
        N(   t   IPythont   genericst   result_displayR   R   R   (   R5   R/   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   _display8  s    c         C   s  t  |  i d  |  i j o. |  i o$ t d |  i d  |  i   n d t i j oS |  i |  _	 |  i
 |  _ | |  _
 |  i i h |  i
 d 6|  i d 6|  i	 d 6 n h  } |  i o@ d |  i } | | | <|  i i |  | |  i d |  i <n d  S(   NR   s   Output cache limit (currently s    entries) hit.
Flushing cache and resetting history counter...
The only history variables available will be _,__,___ and _1
with the current result.R'   R   R   (   RN   RF   R   R   R   R   R   R   R   R   R'   R   Rs   (   R5   R/   t   to_maint
   new_result(    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR   F  s    '	2

c         C   s   |  i  p t d  n xA t d |  i d  D]) } d | } y |  i | =Wq. q. Xq. W|  i d i   d t i j o) |  i i h d  d 6d  d 6d  d 6 n d d  k
 } | i   d  S(   NsJ   You shouldn't have reached the cache flush if full caching is not enabled!i   R'   R   R   R   i(   R   t
   ValueErrort   rangeRs   RF   t   clearR   R   R   R   t   gct   collect(   R5   t   nt   keyR   (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR   `  s    
  )N(   Rd   Re   Rf   R   R{   RA   R   Rr   R   R   R   R   R   (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyR     s   	=			1		(    (I   Rf   R   R    t   authorst
   __author__t   licenset   __license__t   versiont   __version__R   RB   t   socketRK   RC   R   t   IPython.ItplR   t   IPython.ipstructR   t   IPython.macroR   t   IPython.genutilst   IPython.ipapiR   t   ColorSchemeTableR   t   InputTermColorst   InputColorst
   TermColorsRq   t
   add_schemet   ColorSchemeR   t   Greent
   LightGreent   Normalt   Redt   LightRedt   __PColLinuxt   copyt   __PColLightBGR   R   t   Bluet	   LightBlueR"   t   environt   getR#   R$   t   gethostnamet   HOSTNAMERV   t   HOSTNAME_SHORTt   namet   getuidt   ROOT_SYMBOLR<   R   RH   t   input_colorst   dirt   _colort   c_namet   getattrRE   R2   t   objectR3   Ri   R|   R}   R   (    (    (    sG   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/Prompts.pyt   <module>   s   			
																
	&


	 
	x !