
AHc        ,   @   s  d  Z  d d k l Z d e i 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 Z 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 k Z 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 k Z d d k Z e i d d  d d	 k  l! Z! d d
 k" l" Z" l# Z# d d k l$ Z$ l% Z% l& Z& l' Z' d d k( l) Z) l* Z* d d k+ l, Z, d d k- l. Z. d d k/ l0 Z0 l1 Z1 l2 Z2 l3 Z3 l4 Z4 d d k5 l6 Z6 d d k7 l8 Z8 d d k9 l: Z: d d k; l< Z< d d k= l> Z> d d k? l@ Z@ lA ZA d d kB Td d kC lD ZD d d kE Z d d kF Z d d kG iH ZH d d kI Z eJ ZK e iL d  ZM e iL d  ZN d   ZO d   ZP d e iQ f d     YZR d d* d     YZS d  d+ d!     YZT d" eU f d#     YZV d$ eW f d%     YZX d& e' iY f d'     YZZ d( eU e8 f d)     YZ[ d S(,   s   
IPython -- An enhanced Interactive Python

Requires Python 2.3 or newer.

This file contains all the classes and helper functions specific to IPython.

i(   t   Releases   %s <%s>
%s <%s>t   Jankot   FernandoNt   ignores   .*sets module*(   t   Set(   t   pprintt   pformat(   t   Debuggert   OInspectt
   PyColorizet   ultraTB(   t   ColorSchemet   ColorSchemeTable(   t   pickleshare(   t
   FakeModule(   t   Itplt   itplt   printplt   ItplNSt   itplns(   t   Logger(   t   Magic(   t   CachedOutput(   t   Struct(   t   BackgroundJobManager(   t   cmd_line_usaget   interactive_usage(   t   *(   t   StrDispatchs   ^\s+raise|^\s+return|^\s+passs   ^(\s+)c         C   s)   t  i |   } | o | i   Sd Sd S(   s/   Return the number of initial spaces in a stringi    N(   t   ini_spaces_ret   matcht   end(   t   strngt
   ini_spaces(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   num_ini_spaces`   s    c      	   C   sV   d } y |  i  } Wn t j
 o n Xy | |  _  Wn t t f j
 o n X| S(   s-   Copied from code.py, to remove the dependencyi    (   t	   softspacet   AttributeErrort	   TypeError(   t   filet   newvaluet   oldvalue(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR#   i   s    t   SpaceInInputc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR)   {   s    t   Bunchc           B   s   e  Z RS(    (   R*   R+   (    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR,      s    t	   Undefinedc           B   s   e  Z RS(    (   R*   R+   (    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR-      s    t   Quitterc           B   s/   e  Z d  Z d   Z d   Z e Z d   Z RS(   s   Simple class to handle exit, similar to Python 2.5's.

    It handles exiting in an ipython-safe manner, which the one in Python 2.5
    doesn't do (obviously, since it doesn't know about ipython).c         C   s   | |  _  | |  _ d  S(   N(   t   shellt   name(   t   selfR/   R0   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   __init__   s    	c         C   s   d |  i  S(   Ns   Type %s() to exit.(   R0   (   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   __repr__   s    c         C   s   |  i  i   d  S(   N(   R/   t   exit(   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   __call__   s    (   R*   R+   t   __doc__R2   R3   t   __str__R5   (    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR.      s
   		t	   InputListc           B   s   e  Z d  Z d   Z RS(   s   Class to store user input.

    It's basically a list, but slices return a string instead of a list, thus
    allowing things like (assuming 'In' is an instance):

    exec In[4:7]

    or

    exec In[5:9] + In[14] + In[21:25]c         C   s   d i  t i |  | |   S(   Nt    (   t   joint   listt   __getslice__(   R1   t   it   j(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR<      s    (   R*   R+   R6   R<   (    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR8      s   
t   SyntaxTBc           B   s,   e  Z d  Z d d  Z d   Z d   Z RS(   s:   Extension which holds some state: the last exception valuet   NoColorc         C   s    t  i i |  |  d  |  _ d  S(   N(   R
   t   ListTBR2   t   Nonet   last_syntax_error(   R1   t   color_scheme(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR2      s    c         C   s&   | |  _  t i i |  | | |  d  S(   N(   RC   R
   RA   R5   (   R1   t   etypet   valuet   elist(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR5      s    	c         C   s   |  i  } d |  _  | S(   s+   Return the current error state and clear itN(   RC   RB   (   R1   t   e(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   clear_err_state   s    		(   R*   R+   R6   R2   R5   RI   (    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR?      s   	t   InteractiveShellc           B   s/  e  Z d  Z e Z e e d e d e  e e d f  e f e d  Z d d  Z d   Z	 d   Z
 d	   Z d
   Z d e e d  Z d   Z d   Z d d  Z d   Z d   Z d   Z e e e e d  Z d   Z d   Z d   Z d   Z e d  Z d   Z d d  Z e d  Z e d  Z d d  Z d   Z  d    Z! d!   Z" d"   Z# d#   Z$ d$   Z% e& d%  Z' d&   Z( d'   Z) e d(  Z* e d)  Z+ e e e d*  Z, e d+  Z- d,   Z. d e e d d-  Z/ d.   Z0 d/   Z1 d0   Z2 e d1  Z3 d2   Z4 d3   Z5 d d4  Z6 d d5  Z7 d6   Z8 d7   Z9 d8   Z: d9 d: d;  Z; d<   Z< d=   Z= d>   Z> d?   Z? d e d@  Z@ dA   ZA dB   ZB dC   ZC eC ZD dD   ZE dE   ZF dF   ZG dG   ZH dH   ZI dI   ZJ dJ   ZK dK   ZL e dL  ZM dM   ZN dN   ZO dO   ZP dP   ZQ RS(Q   s   An enhanced console for Python.t   optst   argsR9   c	      !      s  t    d d d d   _ xD | | f D]6 }	 |	 d  j	 o# t |	  t i j o t d  q( q( Wt     _ |   _	 t
   _ |   _ | o t   _ n t i     _ g    _ d   _ t   d  t _ t   d  t _ t     _ t i i |  } t i i |  } |   _ |   _ h    _  h    _! h | d	 6| d
 6  i! d 6  i  d 6t i" d 6  _#     i | <| pJ y   i d }
 Wn t$ j
 o t$ d  qXt%   i  t& i' |
 <n g    _( t) d g    _* t) d g    _+ y t, i-   g   _. Wn t/ j
 o g    _. n Xh    _0 y t& i1 i2 p d   _3 Wn t4 j
 o d   _3 n Xh  } d d d d d d g } x t5 i6 | D] } d | | <qW| i7 t i"  |   _8   i*   i d <  i0   i d <  i.   i d <  i*   i d <  i0   i d <t i9   i d <d    _: d   _; d   _< d    _= d!   _> d"   _? d#   _@ d$   _A h   iB   iA 6  iB   i? 6  iB   i@ 6  iC   i> 6  iD   i= 6  iE   i; 6  iE   i< 6  _F tG iH      tI iJ   iK     f d%     _L t     _M h    _N t iM } x- | iO D]" }   iP | tQ | |  d&  q.Wt
   _R d'   _S | o |   _T n   iS   _T |   _U d(   _V g    _W t
   _X d)   _Y y tZ     _[ Wn t\ j
 o } t] |  n Xg    _^   f d*     __   f d+     _`   f d,     _a t, i-     _b d-   _c d. t& i"   _d |   _e tf d/ d0    _f tg ih d1 d2 d/ d0 d3 d    _i   ij o tg ik   } n  d4 d5 k ll } | im    }   in |    io |   t
   _p d6   _q t, i	 d7 j o4 dU } dV } dG t& ir j o
 dW } n | | } n! t, i	 dX j o
 dY } n dZ } g  } | D] } | | is d  d  q\~   _t t i iu      _v   iw   h    _x   iy   d  S([   Nt   logfnames   ipython_log.pyt   logmodet   rotates   namespace must be a dictionarys   <ipython console>R4   t   quitt   usert   user_globalt   aliast   internalt   builtinR*   s-   user_ns dictionary MUST have a "__name__" keys   
t   asciit   cdt   popdt   pushdt   dhistt   unaliasi   t   _iht   _oht   _dht   Int   Outt   _sht   !s   !!t   ?t   %t   ,t   ;t   /c            s    |  d    i  d  S(   t   strt   colors(   t   rc(   t   src(   R1   t   pyformat(    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   <lambda>  s    id   s          An enhanced console for Python.
        Some of its features are:
        - Readline support if the readline library is present.
        - Tab completion in the local namespace.
        - Logging of input, see command-line options.
        - System shell escape via ! , eg !ls.
        - Magic commands, starting with a % (like %ls, %pwd, %cd, etc.)
        - Keeps track of locally defined variables via %who, %whos.
        - Show object information with a ? eg ?x or x? (use ?? for more info).
        t   lesss  #log# Automatic Logger file. *** THIS MUST BE THE FIRST LINE ***
#log# DO NOT CHANGE THIS LINE OR THE TWO BELOW
#log# opts = %s
#log# args = %s
#log# It is safe to make manual edits below here.
#log#-----------------------------------------------------------------------
c            s     i  i   i |  d  d  S(   t   depthi   (   t   hookst
   shell_hookt
   var_expand(   t   cmd(   R1   (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRm     s    c            s1   t    i |  d  d d   i i d   i i S(   Ro   i   t   headert   verbose(   t	   getoutputRr   Rj   t   system_headert   system_verbose(   Rs   (   R1   (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRm     s    c            s1   t    i |  d  d d   i i d   i i S(   Ro   i   Rt   Ru   (   t   getoutputerrorRr   Rj   Rw   Rx   (   Rs   (   R1   (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRm     s    i  s#   Python %(version)s on %(platform)s
RD   R@   t   modet   Plaint	   tb_offseti(   t   CrashHandleri    t   posixs   mkdir mkdirs   rmdir rmdirs   mv mv -is   rm rm -is   cp cp -is   cat cats	   less lesss   clear clears   ls ls -Fs	   ll ls -lFs   lc ls -F -o --colors    lf ls -F -o --color %l | grep ^-s    lk ls -F -o --color %l | grep ^ls"   ldir ls -F -o --color %l | grep /$s#   lx ls -F -o --color %l | grep ^-..xt   bsds   lf ls -lF | grep ^-s   lk ls -lF | grep ^ls   ldir ls -lF | grep /$s   lx ls -lF | grep ^-..xt   ntt   doss
   ls dir /ons   ddir dir /ad /ons   ldir dir /ad /ons	   echo echos   ren rens   cls clss	   copy copy(
   s   mkdir mkdirs   rmdir rmdirs   mv mv -is   rm rm -is   cp cp -is   cat cats	   less lesss   clear clears   ls ls -Fs	   ll ls -lF(   s   lc ls -F -o --colors    lf ls -F -o --color %l | grep ^-s    lk ls -F -o --color %l | grep ^ls"   ldir ls -F -o --color %l | grep /$s#   lx ls -F -o --color %l | grep ^-..x(   s   lf ls -lF | grep ^-s   lk ls -lF | grep ^ls   ldir ls -lF | grep /$s   lx ls -lF | grep ^-..x(   s   nts   dos(	   s
   ls dir /ons   ddir dir /ad /ons   ldir dir /ad /ons   mkdir mkdirs   rmdir rmdirs	   echo echos   ren rens   cls clss	   copy copy(    (z   R   t   loggerRB   t   typet   typest   DictTypeR%   R   t   jobsR0   t   Falset   moret   embeddedt   Truet   embedded_activet   codeopt   CommandCompilert   compilet   buffert   filenameR.   t   __builtin__R4   RP   R   t   metat   IPythont   ipapit   make_user_nst   make_user_global_nst   user_nst   user_global_nst   internal_nst   alias_tablet   __dict__t   ns_tablet   KeyErrorR   t   syst   modulest   _user_main_modulesR8   t
   input_histt   input_hist_rawt   ost   getcwdt   dir_histt   OSErrort   output_histt   stdint   encodingt   stdin_encodingR$   t   keywordt   kwlistt   updatet   no_aliast   shadownst   code_to_runt	   ESC_SHELLt
   ESC_SH_CAPt   ESC_HELPt	   ESC_MAGICt	   ESC_QUOTEt
   ESC_QUOTE2t	   ESC_PARENt   handle_autot   handle_magict   handle_helpt   handle_shell_escapet   esc_handlersR   R2   R	   t   Parsert   formatt
   pycolorizeRp   t   strdispatcherst   __all__t   set_hookt   getattrt   exit_nowt	   usage_mint   usageRj   t   pagert	   tempfilest   has_readlinet   loghead_tplt   get_home_dirt   home_dirt   HomeDirErrort   fatalt	   dir_stackt   systemRv   Ry   t   starting_dirt   CACHELENGTHt   BANNERt   banner2R?   R
   t   AutoFormattedTBt   InteractiveTBt
   isthreadedt   FormattedTBR}   t   IPythonCrashHandlert   set_crash_handlert   set_custom_exct
   autoindentt   indent_current_nspt   platformt   splitt
   auto_aliast   IPApit   apit   init_auto_aliast   builtins_addedt   add_builtins(   R1   R0   R   Rj   R   R   R   t   custom_exceptionsR   t   nst	   main_nameR   t   no_alias_magicst   keyRp   t	   hook_namet   msgt   ipCrashHandlerR}   R   t   ls_extrat   _[1]t   s(    (   R1   Rl   sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR2      s$    #					%				


		 											
  		 								
		           
   
0
	i    c         C   s)   t  t | |  i t i | d  i   S(   s(  Expand python variables in a string.

        The depth argument indicates how many frames above the caller should
        be walked to look for the local namespace where to expand variables.

        The global namespace for expansion is always the user's interactive
        namespace.
        i   (   Rh   R   R   R   t	   _getframet   f_locals(   R1   Rs   Ro   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRr   i  s    
	c         C   s   |  i  } y t i | i d  |  _ Wn; t i j
 o, d GHd GHd GHd G| i GHt i   n Xt	 i
 i |  i  |  _ d S(   s   Pre-configuration init method

        This is called before the configuration files are processed to
        prepare the services the config files might need.
        
        self.rc already has reasonable default values at this point.
        s   /dbs,   Your ipythondir can't be decoded to unicode!s6   Please set HOME environment variable to something thats'   only has ASCII characters, e.g. c:\homes	   Now it isN(   Rj   R   t   PickleShareDBt
   ipythondirt   dbt
   exceptionst   UnicodeDecodeErrorR   R4   R   t   historyt
   ShadowHistt
   shadowhist(   R1   Rj   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   pre_config_initializationy  s    	c         C   sZ  |  i  } t i t i t i d | i  |  _ d |  _	 t
 |  _ | i o |  i   n |  i i |  _ t |  | i | i d | i d | i d | i d | i d | i d | i d | i |  _ y |  i i |  i i _ Wn t j
 o n Xt i  |  _! |  i t _  y t"   Wn t# j
 o t$ d	  n X|  i% | i&  | i' |  _( x | i) D] } |  i* |  qXW|  i i+   x$ |  i  i, D] } |  i- i. |  qWt
 } x g  } |  i  i/ D]- } | i0   i1 d
  o | t2 |  qq~ D]? } | i3   p d G| GHqn |  i- i. | i4    t5 } qW| o |  i  i6 o t5 |  _7 n d S(   s   Post configuration init method

        This is called after the configuration files have been processed to
        'finalize' the initialization.R@   t	   input_sept
   output_sept   output_sep2t   ps1t   ps2t   ps_outt   pad_lefts   doctest module does not exist.s   .ipys   No such batch file:N(8   Rj   R   t	   Inspectort   InspectColorsR	   t   ANSICodeColorst   object_info_string_levelt	   inspectorRB   t   rl_next_inputR   t   rl_do_indentt   readlinet   init_readlineR   t   logR   t
   cache_sizeR   t   separate_int   separate_outt   separate_out2t
   prompt_in1t
   prompt_in2t
   prompt_outt   prompts_pad_leftt   outputcacheRp   t   displayt	   __class__R$   R   t   displayhookt   sys_displayhookt   doctest_reloadt   ImportErrort   warnt   magic_colorsRi   t   pdbt   call_pdbRS   t   magic_aliast   late_startup_hookt   autoexecR   t   runlinesRL   t   lowert   endswitht   patht   isfilet   textR   t   interactR   (   R1   Rj   RS   Rs   t   batchrunR   t   argt	   batchfile(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   post_config_initialization  sd    			
							
  . 	
c         C   s   t  d |  d |  i d |  i d t |  i d  d t |  i  d t |  i d   } xb | i   D]T \ } } y t i	 | |  i
 | <Wn  t j
 o t |  i
 | <n X| t i	 | <qa Wt i	 i d	 d
  d S(   s   Store ipython references into the builtin namespace.

        Some parts of ipython operate via builtins injected here, which hold a
        reference to IPython itself.t   __IPYTHON__t   ip_set_hookR   t   ipmagics   _ip.magic()t   ipaliast   ipsystems   _ip.system()t   __IPYTHON__activei    N(   t   dictR   R   t   wrap_deprecatedR0  R1  R2  t   itemsR   R   R   R   R-   t
   setdefault(   R1   t   builtins_newt   binamet   bival(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR     s    		 c         C   sY   xE |  i  i   D]4 \ } } | t j o t i | =q | t i | <q W|  i  i   d S(   s~   Remove any builtins which might have been added by add_builtins, or
        restore overwritten ones to their previous values.N(   R   R6  R-   R   R   t   clear(   R1   R9  R:  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   clean_builtins  s     i2   c   	      C   sW  t  i | |  |  i  } | d j	 o= |  i i | t    } | i | | |  | |  i | <d S| d j	 oF |  i i | t    } | i t	 i
 |  | |  | |  i | <d St |  i | d  } | t i i j o d | t i i f GHn | p t i i   } n y | i | |  Wn t j
 o | } n Xt |  i | |  d S(   s
  set_hook(name,hook) -> sets an internal IPython hook.

        IPython exposes some of its internal API as user-modifiable hooks.  By
        adding your function to one of these hooks, you can modify IPython's 
        behavior to call at runtime your own routines.Ns#   Warning! Hook '%s' is not one of %s(   t   newt   instancemethodR  RB   R   t   getR   t   add_st   add_ret   reR   R   Rp   R   R   t   CommandChainDispatchert   addR$   t   setattr(	   R1   R0   t   hookt   priorityt   str_keyt   re_keyt   ft   sdpt   dp(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR     s*    c         C   s   | t  _ t  i |  _ d S(   s|   Set the IPython crash handler.

        This must be a callable with a signature suitable for use as
        sys.excepthook.N(   R   t
   excepthookt   sys_excepthook(   R1   t   crashHandler(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR   6  s    	c         C   sk   t  |  t  d  j p
 t d  d   } | d j o
 | } n t i | |  |  i  |  _ | |  _ d S(   s  set_custom_exc(exc_tuple,handler)

        Set a custom exception handler, which will be called if any of the
        exceptions in exc_tuple occur in the mainloop (specifically, in the
        runcode() method.

        Inputs:

          - exc_tuple: a *tuple* of valid exceptions to call the defined
          handler for.  It is very important that you use a tuple, and NOT A
          LIST here, because of the way Python's except statement works.  If
          you only want to trap a single exception, use a singleton tuple:

            exc_tuple == (MyCustomException,)

          - handler: this must be defined as a function with the following
          basic interface: def my_handler(self,etype,value,tb).

          This will be made into an instance method (via new.instancemethod)
          of IPython itself, and it will be called if any of the exceptions
          listed in the exc_tuple are caught.  If the handler is None, an
          internal basic one is used, which just prints basic info.

        WARNING: by putting in your own exception handler into IPython's main
        execution loop, you run a very good chance of nasty crashes.  This
        facility should only be used if you really know what you are doing.s/   The custom exceptions must be given AS A TUPLE.c         S   s9   d GHd G| GHd G| GHd G| GHd Gd i  |  i  GHd  S(   Ns'   *** Simple custom exception handler ***s   Exception type :s   Exception value:s   Traceback      :s   Source code    :s   
(   R:   R   (   R1   RE   RF   t   tb(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   dummy_handlere  s
    			N(    (   R   t   AssertionErrorRB   R=  R>  R  t   CustomTBR   (   R1   t	   exc_tuplet   handlerRQ  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR   F  s    	 
c         C   s8   t  i | |  i |  i i  } |  i i i | |  d S(   s   set_custom_completer(completer,pos=0)

        Adds a new custom completer function.

        The position argument (defaults to 0) is the index in the completers
        list where you want the completer to be inserted.N(   R=  R>  t	   CompleterR  t   matcherst   insert(   R1   t	   completert   post   newcomp(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   set_custom_completerq  s    c         C   s   |  i  i |  i i  d S(   s)   reset readline's completer to be our own.N(   R
  t   set_completerRV  t   complete(   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR]  }  s    c         C   s   |  i  S(   N(   t	   _call_pdb(   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   _get_call_pdb  s    c         C   sq   | d d t  t f j o t d  n | |  _ | |  i _ |  i o( y | |  i _ Wqm t d  qm Xn d  S(   Ni    i   s"   new call_pdb value must be booleans5   Failed to activate pdb for threaded exception handler(	   R   R   t
   ValueErrorR_  R   R  R   RN  R  (   R1   t   val(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   _set_call_pdb  s    	
s,   Control auto-activation of pdb at exceptionsc         C   s   | i  d d  } | d } | i |  i  } y | d } Wn t j
 o d } n Xt |  d | d  } | d j o t d |  n |  i | d  } | |  Sd S(   s  Call a magic function by name.

        Input: a string containing the name of the magic function to call and any
        additional arguments to be passed to the magic.

        ipmagic('name -opt foo bar') is equivalent to typing at the ipython
        prompt:

        In[1]: %name -opt foo bar

        To call a magic without arguments, simply use ipmagic('name').

        This provides a proper Python function to call IPython's magics in any
        valid Python code you can type at the interpreter, including loops and
        compound statements.  It is added by IPython to the Python builtin
        namespace upon initialization.t    i   i    R9   t   magic_s   Magic function `%s` not found.N(   R   t   lstripR   t
   IndexErrorR   RB   t   errorRr   (   R1   t   arg_sRL   t
   magic_namet
   magic_argst   fn(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR0    s    
c         C   s|   | i  d d  } | d } y | d } Wn t j
 o d } n X| |  i j o |  i | |  n t d |  d S(   sr  Call an alias by name.

        Input: a string containing the name of the alias to call and any
        additional arguments to be passed to the magic.

        ipalias('name -opt foo bar') is equivalent to typing at the ipython
        prompt:

        In[1]: name -opt foo bar

        To call an alias without arguments, simply use ipalias('name').

        This provides a proper Python function to call IPython's aliases in any
        valid Python code you can type at the interpreter, including loops and
        compound statements.  It is added by IPython to the Python builtin
        namespace upon initialization.Rd  i   i    R9   s   Alias `%s` not found.N(   R   Rg  R   t
   call_aliasRh  (   R1   Ri  RL   t
   alias_namet
   alias_args(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR1    s    
c         C   s   |  i  |  d S(   s"   Make a system call, using IPython.N(   R   (   R1   Ri  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR2    s    c         C   s|   |  i  i } d } h  } xG t o? | | | d | } | d j o Pn d | | <| d 7} q W| i   } | i   | S(   s)  Return a sorted list of all possible completions on text.

        Inputs:

          - text: a string of text to be completed on.

        This is a wrapper around the completion mechanism, similar to what
        readline does at the command line when the TAB key is hit.  By
        exposing it as a method, it can be used by other non-readline
        environments (such as GUIs) for text completion.

        Simple usage example:

        In [1]: x = 'hello'

        In [2]: __IP.complete('x.l')
        Out[2]: ['x.ljust', 'x.lower', 'x.lstrip']i    t   line_bufferi   N(   RV  R^  R   RB   t   keyst   sort(   R1   R(  R^  t   statet   compsR[  t   outcomps(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR^    s     

c         C   sK   | o" | i  |  i _ | i |  i _ n |  i |  i _ |  i |  i _ d  S(   N(   R   RV  t	   namespacet	   f_globalst   global_namespaceR   R   (   R1   t   frame(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   set_completer_frame  s
    c         C   s4   x- |  i  D]" \ } } |  i   i | |  q
 Wd S(   sP   Define some aliases automatically.

        These are ALL parameter-less aliasesN(   R   t   getapit   defalias(   R1   RS   Rs   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR     s    
 c         C   sV   |  i  } xF |  i i   D]5 } | | j o" |  i | =| o d | GHqN q q Wd S(   sr   Update information about the alias table.

        In particular, make sure no Python keywords/builtins are in it.s6   Deleting alias <%s>, it's a Python keyword or builtin.N(   R   R   Rq  (   R1   Ru   R   t   k(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   alias_table_validate  s    	 
c         C   sa   |  i  p, t i d j o t d  n d |  _ d S| d j o |  i |  _ n
 | |  _ d S(   sr   Set the autoindent flag, checking for readline support.

        If called with no arguments, it acts as a toggle.R~   s5   The auto-indent feature requires the readline libraryi    N(   R   R   R0   R  R   RB   (   R1   RF   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   set_autoindent%  s    
	c         C   sA   t  |  i |  } | d j o | } n t |  i | |  d S(   s   Set or toggle a field in IPython's rc config. structure.

        If called with no arguments, it acts as a toggle.

        If called with a non-existent field, the resulting AttributeError
        exception will propagate out.N(   R   Rj   RB   RE  (   R1   t   rc_fieldRF   t   rc_val(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   rc_set_toggle4  s    t   installc            s  d   } t  i   } t i } d d GH| d j o	 d GHn d GH| GHt  i i d d      f d	   } y2 t t  i i t | t i   d
 } d G| GHWn t	 j
 o d }	 t
 |	  |   t i d j o
 d }
 n d }
 h d d 6d |
 6} t  i | d d x8 | i   D]* \ } } t | d | d  i |  qWd SX| d j o yR t i | |  t  i |  | d  } x" | D] } t  i | | |  qWWqd t i   d }	 t
 |	  |   d SXn6| d j oy t  i |  Wn( d | t i   d f GH|   d SX| t  i i | d   } x | D] } t  i i |  } | i d  o | | } n t  i i |  o qKn t  i i |  oB | d } t  i i |  o t  i |  n t  i | |  n t i | |  qKWn t d |  y t  i |  Wn' d  | t i   d f GH|   nB Xx> | d  D]0 } y t | d! d
 Wq]t j
 o q]Xq]W| d j o	 d" GHn d# t   GH|   t  i |  d S($   s   Install the user configuration directory.

        Can be called when running for the first time or to upgrade the user's
        .ipython/ directory with the mode parameter. Valid modes are 'install'
        and 'upgrade'.c           S   s8   y t  d  Wn t j
 o t i Jn Xd d GHd  S(   Ns'   Please press <RETURN> to start IPython.R   iF   (   t	   raw_inputt   EOFErrort   Termt   cout(    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   waitH  s
    R   iF   R  s   Welcome to IPython. I will try to create a personal configuration directory
where you can customize many aspects of IPython's functionality in:
s,   I am going to upgrade your configuration in:R   t
   UserConfigc            s   t  i i |     S(    (   R   R&  R:   (   t   d(   t   rcdirend(    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRm   \  s    i    s   Initializing from configurationsj  
Installation error. IPython's directory was not found.

Check the following:

The ipython/IPython directory should be in a directory belonging to your
PYTHONPATH environment variable (that is, it should be in a directory
belonging to sys.path). You can copy it explicitly there or just link to it.

IPython will create a minimal default configuration for you.

t   win32s   ipythonrc.init	   ipythonrcs   import ipy_defaultss   ipy_user_conf.pys   # intentionally left blankRz   i  Rg   t   wNs
   ipythonrc*s   

There was a problem with the installation:
%s
Try to correct it or contact the developers if you think it's a bug.
IPython will proceed with builtin defaults.i   t   upgrades?   
Can not upgrade: changing to directory %s failed. Details:
%s
s	   [A-Za-z]*s   .olds   unrecognized mode for install:s   
Problem: changing to directory %s failed.
Details:
%s

Some configuration files may have incorrect line endings.  This should not
cause any problems during execution.  t   backups.  
Successful installation!

Please read the sections 'Initial Configuration' and 'Quick Tips' in the
IPython manual (there are both HTML and PDF versions supplied with the
distribution) to make sure that your system environment is properly configured
to take advantage of IPython's features.

Important note: the configuration system has changed! The old system is
still in place, but its setting may be partly overridden by the settings in 
"~/.ipython/ipy_user_conf.py" config file. Please take a look at the file 
if some of the new settings bother you. 

s  
Successful upgrade!

All files in your directory:
%(ipythondir)s
which would have been overwritten by the upgrade were backed up with a .old
extension.  If you had made particular customizations in those files you may
want to merge them back into the new files.(   R   R   t   globR&  R:   t   filtert   isdirt   mapR   Rg  R  R   t   makedirsR6  t   opent   writet   shutilt   copytreet   chdirt   renamet   exc_infot   basenamet
   startswitht   existst   removet   copyRa  t   native_line_endst   IOErrort   locals(   R1   R   t	   rc_suffixRz   R  t   cwdt   glbt   cfgt   rcdirt   warningt   inift   minimal_setupRJ  t   contt   rc_filest   rc_filet   sourcest   new_full_patht   new_filenamet   old_filet   fname(    (   R  sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt
   user_setupA  s    				%

 " 
	 
 			c         C   sV   |  i    x8 |  i D]- } y t i |  Wq t j
 o q Xq W|  i i   d S(   sh   This will be executed at the time of exit.

        Saving of persistent data should be performed here. N(   t   savehistR   R   t   unlinkR   Rp   t   shutdown_hook(   R1   t   tfile(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   atexit_operations  s    

 	c         C   sA   |  i  p d Sy |  i i |  i  Wn d |  i GHn Xd S(   s4   Save input history to a file (via readline library).Ns0   Unable to save IPython command history to file: (   R   R
  t   write_history_filet   histfile(   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR    s    
c         C   sO   |  i  oA y' |  i i   |  i i |  i i  WqK t j
 o qK Xn d S(   s(   Reload the input history from disk file.N(   R   R
  t   clear_historyt   read_history_fileR/   R  R$   (   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt
   reloadhist  s    
c            s%     i  p  S   f d   } | S(   s    Wrap func for readline history saving
        
        Convert func into callable that saves & restores
        history around the call c              s-     i    z    Wd  t i   i  Xd  S(   N(   R  R
  R  R  (    (   R1   t   func(    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   wrapper  s    
(   R   (   R1   R  R  (    (   R1   R  sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   history_saving_wrapper  s    
c         C   sX   |  i  o |  i i |  i    n |  i d j	 o  |  i i |  i  d |  _ n d S(   sc   readline hook to be used at the start of each line.

        Currently it handles auto-indent only.N(   R	  R
  t   insert_textt   indent_current_strR  RB   (   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   pre_readline  s
    
c   	      C   s  d d k  i } | i p  d |  _ d |  _ t d  n8| t i d <d d k	 } d d k
 l } | |  |  i |  i |  i i |  i  |  _ |  i i d t    } | |  i d <| |  i _ t i d j o | i |  _ n | i |  _ t i i d	  } | d j oM t   } | d j	 o3 d
 } | i o
 d } n t i i | |  } qUn t i i  |  o- y | i! |  Wqt d |  qXn d |  _ | |  _ |  i i" t _# |  i$   | i p( x% |  i i% D] } | i& |  qWn | i'   } | i( t) i* |  i i+  } | i, |  | i- d  y | i. |  i/  Wn t0 j
 o n X| i1 |  i2  ~ |  i3 |  i i4  d S(   s,   Command history completion/saving/reloading.iNi    s1   Readline services not available on this platform.R
  (   t   IPCompletert   complete_commandR   t   INPUTRCs   .inputrcs   .editrcs2   Problems reading readline initialization file <%s>i   i  (5   t   IPython.rlineimplt	   rlineimplt   have_readlineR   RB   R
  R  R   R   t   atexitt   IPython.completerR  R   R   Rj   t   readline_omit__namesR   RV  R   R?  R   t   custom_completersR   R0   t   set_pre_input_hookt   readline_startup_hookt   set_startup_hookt   environR   t   uses_libeditR&  R:   R'  t   read_init_fileR^  t   ipcompleterR]  t   readline_parse_and_bindt   parse_and_bindt   get_completer_delimst	   translatet   stringt   _idmapt   readline_remove_delimst   set_completer_delimst   set_history_lengthR  R  R  t   registerR  R  R   (	   R1   R
  R  R  t   sdispt   inputrc_nameR   t	   rlcommandt   delims(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR  "  sj    
				

		

 c         C   s   |  i  i o t St | |  S(   N(   Rj   t   quietR   t
   ask_yes_no(   R1   t   promptt   default(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR  q  s    c         C   s   | i  d
 j o t Sy* |  i i o |  i d d  o t SWn t j
 o t SXd   } |  i i | i  | | i	  | | i
  | i  t S(   s%   Utility routine for edit_syntax_errors   <ipython console>s   <input>s   <string>s	   <console>s   <BackgroundJob compilation>s0   Return to editor to correct syntax error? [Y/n] t   yc         S   s)   y t  |   SWn t j
 o d SXd  S(   Ni    (   t   intR%   (   t   x(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   int0  s    N(   s   <ipython console>s   <input>s   <string>s	   <console>s   <BackgroundJob compilation>N(   R   RB   R   Rj   t   autoedit_syntaxR  R  Rp   t   fix_error_editort   linenot   offsetR   R   (   R1   RH   R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   _should_recompilev  s     
			"c         C   s   x |  i  i o |  i  i   } |  i |  p d Sy |  i | i |  i  Wn |  i   q Xy8 t | i  } z t	 i
 | i    Wd | i   XWq |  i   q Xq Wd S(   s   The bottom half of the syntax error handler called in the main loop.

        Loop until syntax error is fixed or user cancels.
        N(   R?   RC   RI   R  t   safe_execfileR   R   t   showtracebackR&   R   R  t   readt   close(   R1   t   errRJ  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   edit_syntax_error  s      c   
      C   s   t  i   \ } } } | t  _ | t  _ | t  _ | ox | t j ok y | \ } \ } } } }	 Wn q Xy t | | | | |	 f  } Wq | | | | |	 f f } q Xn |  i | | g   d S(   s8  Display the syntax error that just occurred.

        This doesn't display a stack trace because there isn't one.

        If a filename is given, it is stuffed in the exception instead
        of what was there before (because Python's parser always uses
        "<string>" when reading from a string).
        N(   R   R  t	   last_typet
   last_valuet   last_tracebackt   SyntaxErrorR?   (
   R1   R   RE   RF   R  R   t   dummy_filenameR  R  t   line(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   showsyntaxerror  s    				 c            sv   | p   i  p d St t d  p t d  d St i o d d k l } n   f d   }   i |    d S(   s9  Call the pydb/pdb debugger.

        Keywords:

          - force(False): by default, this routine checks the instance call_pdb
          flag and does not actually invoke the debugger if the flag is false.
          The 'force' option forces the debugger to activate even if the flag
          is false.
        NR  s1   No traceback has been produced, nothing to debug.i(   t   pmc              s     i  i d  t  S(   t   force(   R   t   debuggerR   (    (   R1   (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRm     s    (	   R  t   hasattrR   Rh  R   t   has_pydbt   pydbR  R  (   R1   R   R  (    (   R1   sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR    s    

c      	   C   s  y | d j o t i   \ } } } n | \ } } } | t j o |  i |  n | t i i j o d G| GHn | t _ | t _	 | t _
 | |  i j o |  i | | |  n? |  i | | | d | |  i i o |  i o |  i   n Wn  t j
 o |  i d  n Xd S(   s  Display the exception that just occurred.

        If nothing is known about the exception, this is the method which
        should be used throughout the code for presenting user tracebacks,
        rather than directly invoking the InteractiveTB object.

        A specific showsyntaxerror() also exists, but this method can take
        care of calling it if needed, so unless you are explicitly catching a
        SyntaxError exception, don't try to analyze the stack manually and
        simply call this method.s   UsageError:R|   s   
KeyboardInterrupt
N(   RB   R   R  R  R  R   R   t
   UsageErrorR  R  R  R   RS  R   R  R   R]  t   KeyboardInterruptR  (   R1   RT  R   R|   RE   RF   RP  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR    s$    			c         C   s   |  i  i o |  i   n | d j oQ |  i  i p
 d } qy t |  i  i t  o |  i  i } qy |  i |  i } n x8 y |  i	 |  PWq| t
 j
 o |  i d  q| Xq| d S(   s   Creates the local namespace and starts the mainloop.

        If an optional banner argument is given, it will override the
        internally created default banner.R9   s!   
KeyboardInterrupt in interact()
N(   Rj   t   ct   exec_init_cmdRB   t   bannert
   isinstancet
   basestringR   R   R)  R  R  (   R1   R	  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   mainloop  s    
c         C   s=   |  i  |  i |  i i t   |  i i p t |  _ n d S(   sW   Execute a command given at the command line.

        This emulates Python's -c option.N(   t   pusht	   prefilterRj   R  R   R)  R   R   (   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR  1  s    c   	      C   s  | d j p | d j oJ t i |  i } | d j o | i } n | d j o | i } qd n | |  _ | i   } |  i i	 |  | d j o$ | d j o |  i i	 t
 i  n |  i   |  i   |  i |  |  i i } x | D] } | | d  q W|  i   d S(   s&  Embeds IPython into a running python program.

        Input:

          - header: An optional header message can be specified.

          - local_ns, global_ns: working namespaces. If given as None, the
          IPython-initialized one is updated with __main__.__dict__, so that
          program variables become visible but user-specific configuration
          remains possible.

          - stack_depth: specifies how many levels in the stack to go to
          looking for namespaces (when local_ns and global_ns are None).  This
          allows an intermediate caller to make sure that this function gets
          the namespace from the intended level in the stack.  By default (0)
          it will get its locals and globals from the immediate caller.

        Warning: it's possible to use this in a program which is being run by
        IPython itself (via %run), but some funny things will happen (a few
        globals get overwritten). In the future this will be cleaned up, as
        there is no fundamental reason why it can't work perfectly.N(   RB   R   R   t   f_backR   Rw  R   Rq  R   R   t   __main__R   Rz  R   R)  t   popR<  (	   R1   Rt   t   local_nst	   global_nst   stack_deptht
   call_framet   local_varnamest   delvart   var(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   embed_mainloop;  s&    	

 c         C   s   |  i  oE y |  i i t  } Wn |  i   n X|  i o t |  _ qy n+ y |  i i t  } Wn |  i   n X|  i |  d S(   s    Print the prompt (in read-eval-print loop) 

        Provided for those who want to implement their own read-eval-print loop (e.g. GUIs), not 
        used in standard IPython flow.
        N(	   R   Rp   t   generate_promptR   R  R   R	  R   R  (   R1   R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   interact_prompt  s    

c         C   s   | i    | j o |  i i | i    n |  i | |  i  } | i   o= |  i o |  i d c d | 7<q |  i i d |  n |  i |  |  _ |  i	 i
 o |  i i o |  i   n d S(   s    Handle the input line (in read-eval-print loop)
        
        Provided for those who want to implement their own read-eval-print loop (e.g. GUIs), not 
        used in standard IPython flow.        
        is   %s
N(   Rf  R   RD  t   stripR  R   R   t   appendR  R?   RC   Rj   R  R  (   R1   R  t   lineout(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   interact_handle_input  s    
c         C   sr   |  i  |  i  x[ |  i pP |  i   |  i o t |  _ n
 t |  _ t   i	 |  i
  } |  i |  q Wd S(   s    Demo of using interact_handle_input, interact_prompt
        
        This is the main read-eval-print loop. If you need to implement your own (e.g. for GUI),
        it should work like this.
        N(   R  R  R   R  R   R   R	  R   t   raw_input_originalt   decodeR   R  (   R1   R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   interact_with_readline  s     


	c      	   C   s  |  i  o d Sd } | d j o- |  i d t i t i | |  i i f  n |  i |  d } t i	 d c d 7<|  i
 o |  i |  i  n x|  i  p|  i i   | oE y |  i i t  } Wn |  i   n X|  i o t |  _ q#n+ y |  i i t  } Wn |  i   n Xy< |  i | |  } |  i  o Pn |  i o t |  _ n Wn t j
 og yJ |  i d  |  i   |  i i d 8_ |  i o d |  _ n d } Wqt j
 o qXq t j
 oB |  i o t |  _ |  i d  n |  i d  |  i   q t i j
 o t d	  q |  i   q X|  i  |  } |  i! i" o |  i# i$ o |  i%   q q Wt i	 d c d 8<d S(
   s  Closely emulate the interactive Python console.

        The optional banner argument specify the banner to print
        before the first interaction; by default it prints a banner
        similar to the one printed by the real Python interpreter,
        followed by the current class name in parentheses (so as not
        to confuse this with the real interpreter -- since it's so
        close!).

        Ns>   Type "copyright", "credits" or "license" for more information.s   Python %s on %s
%s
(%s)
i    R3  i   s   
KeyboardInterrupt
s   
s   The Python debugger has exited with a BdbQuit exception.
Because of how pdb handles the stack, it is impossible
for IPython to properly format this particular exception.
IPython will resume normal operation.(&   R   RB   R  R   t   versionR   R  R*   R   R   R   R  R  Rp   t   pre_prompt_hookR  R   R  R   R	  R   R  R  t   resetbufferR  t   prompt_countR   R  R4   t   bdbt   BdbQuitR  R  R?   RC   Rj   R  R  (   R1   R	  t   cprtR   R  R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR)    sr    
	
 






	
	c         C   s    |  i  | | | f d d d S(   s2  One more defense for GUI apps that call sys.excepthook.

      GUI frameworks like wxPython trap exceptions and call
      sys.excepthook themselves.  I guess this is a feature that
      enables them to keep running after exceptions that would
      otherwise kill their mainloop. This is a bother for IPython
      which excepts to catch all of the program exceptions with a try:
      except: statement.

      Normally, IPython sets sys.excepthook to a CrashHandler instance, so if
      any app directly invokes sys.excepthook, it will look to the user like
      IPython crashed.  In order to work around this, we can disable the
      CrashHandler and replace it with this excepthook instead, which prints a
      regular traceback using our InteractiveTB.  In this fashion, apps which
      call sys.excepthook will generate a regular-looking exception from
      IPython, and the CrashHandler will only be triggered by real IPython
      crashes.

      This hook should be used sparingly, only in places which are not likely
      to be true IPython errors.
      R|   i    N(   R  (   R1   RE   RF   RP  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRM    s    c         C   s   | d | } t    } x t i | t i  \ } } } | |  i j o | | j o t d |  d S| i |  |  i | |  } | | j o Pn | i d d  d | i d d  d j o | } Pn | } q Pq | S(   s    Expand multiple levels of aliases:
        
        if:
        
        alias foo bar /tmp
        alias baz foo
        
        then:
        
        baz huhhahhei -> bar /tmp huhhahhei
        
        Rd  s&   Cyclic alias definition, repeated '%s'R9   i   i    N(
   R   R  t   splitUserInputt   shell_line_splitR   R  RD  t   transform_aliasR   RB   (   R1   Rl  t   restR  t   donet   pret   l2(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   expand_aliases1  s&    		-
c         C   s  |  i  | } | \ } } d | j o! t i i |  o d | } n | i d  d j o | i d |  } d } n | d j o d | | f } ns | i d |  } t |  | j  o" t	 d | | t |  f  d Sd | t
 | |   d i | |  f } | S(	   s3    Transform alias to system command string.
        Rd  s   "%s"s   %li    R9   s   %s %ss+   Alias <%s> requires %s arguments, %s given.N(   R   R   R&  R'  t   findt   replaceR   RB   t   lenRh  t   tupleR:   (   R1   RS   R-  t   trgt   nargsRs   RL   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR,  ]  s      
+c         C   s;   |  i  | |  } y |  i |  Wn |  i   n Xd S(   s   Call an alias given its name and the rest of the line.

        This is only used to provide backwards compatibility for users of
        ipalias(), use of which is not recommended for anymore.N(   R,  R   R  (   R1   RS   R-  Rs   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRm  z  s
    c         C   s   |  i  d S(   s3   return the current level of indentation as a stringRd  (   R   (   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR    s    c         C   s   |  i  o | ot t |  } | |  i j  o | |  _ n | d d j o |  i d 7_ q t i |  o |  i d 8_ q q d |  _ n d S(   s   Keep track of the indent level.it   :i   i    N(   R   R"   R   t	   dedent_reR   (   R1   R  t   inisp(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   autoindent_update  s    
c         C   s   |  i    | i d  } d } xu | D]m } | p | oI |  i i d | d  |  i |  i | |   } | d j o Pq q& |  i i d  q& W| o |  i d  n d S(   sU  Run a string of one or more lines of source.

        This method is capable of running a string containing multiple source
        lines, as if they had been entered at the IPython prompt.  Since it
        exposes IPython's processing machinery, the given strings can contain
        magic calls (%magic), special shell access (!cmd), etc.s   
i    s   # N(   R%  R   R   R  R  R  RB   (   R1   t   linesR   R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR#    s    

 	s   <input>t   singlec      	   C   s   | i  |  i  } | d  d j o d | } n y |  i | | |  } Wn- t t t t f j
 o |  i |  d SX| d j o t	 S| |  _
 |  i |  d j o t Sd Sd S(   s  Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is:

          - True in case 2

          - False in the other cases, unless an exception is raised, where
          None is returned instead.  This can be used by external callers to
          know whether to continue feeding input or not.

        The return value can be used to decide whether to use sys.ps1 or
        sys.ps2 to prompt the next line.i   Rd  s   	s   if 1:
%si    N(   Rd  s   	(   t   encodeR   R   t   OverflowErrorR  Ra  R%   R  RB   R   R   t   runcodeR   (   R1   t   sourceR   t   symbolt   code(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt	   runsource  s    !	c      	   B   s"  e  i |  i } e  _ | |  _ d } yK z: |  i i   |  i o | |  i |  i Un | |  i UWd | e  _ XWn e j
 o+ |  i	   |  i
   e d d d nm |  i j
 o/ e  i   \ } } } |  i | | |  n0 |  i
   n Xd } e e  i d  o Hn d |  _ | S(   s-  Execute a code object.

        When an exception occurs, self.showtraceback() is called to display a
        traceback.

        Return value: a flag indicating whether the code to be run completed
        successfully:

          - 0: successful execution.
          - 1: an error occurred.
        i   NsK   Type %exit or %quit to exit IPython (%Exit or %Quit do so unconditionally).t   leveli    (   R   RM  RN  Rp   t   pre_runcode_hookR   R   R   t
   SystemExitR%  R  R  R   R  RS  R#   t   stdoutRB   R   (   R1   t   code_objt   old_excepthookt   outflagRE   RF   RP  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR@    s2    	


		c         C   sn   x! | i    D] } |  i |  q W|  i i |  |  i d i |  i  |  i  } | p |  i   n | S(   s~  Push a line to the interpreter.

        The line should not have a trailing newline; it may have
        internal newlines.  The line is appended to a buffer and the
        interpreter's runsource() method is called with the
        concatenated contents of the buffer as source.  If this
        indicates that the command was executed or invalid, the buffer
        is reset; otherwise, the command is incomplete, and the buffer
        is left as it was after the line was appended.  The return
        value is 1 if more input is required, 0 if the line was dealt
        with in some way (this is the same as runsource()).
        s   
(   t
   splitlinesR;  R   R  RD  R:   R   R%  (   R1   R  t   sublineR   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR  4  s     !c         C   s   t  i |  S(   N(   R  R*  (   R1   R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   split_user_inputP  s    c         C   s   g  |  i  (d S(   s   Reset the input buffer.N(   R   (   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR%  T  s    c         C   s  |  i  o |  i   n y t |  i |  i  } Wn' t j
 o t d  t |  _ d SX|  i	 o4 t
 |  |  i j o | |  i } d |  _ q n | i   o | o |  i d c d | 7<|  i  o yn |  i i   } | d j oN |  i d i   } |  i i | d  |  i i | d | i |  i   n WqYt j
 o qYXqqn |  i i d |  | i   | j o |  i i | i    qn | p |  i i d  n y |  i | |  } Wn |  i   d SX| Sd	 S(
   s  Write a prompt and read a line.

        The returned line does not include the trailing newline.
        When the user enters the EOF key sequence, EOFError is raised.

        Optional inputs:

          - prompt(''): a string to be printed to prompt the user.

          - continue_prompt(False): whether this line is the first one or a
          continuation in a sequence of inputs.
        sb   
********
You or a %run:ed script called sys.stdin.close() or sys.stdout.close()!
Exiting IPython!R9   i    is   %s
i   i   s   
N(   R   R]  R   R!  R   Ra  R  R   R   R   R"   R   R  R   R
  t   get_current_history_lengtht   rstript   remove_history_itemt   replace_history_itemR>  R$   R  Rf  R   RD  R  R  (   R1   R  t   continue_promptR  t   histlent   newhistR  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR  X  sH    

	


c         C   s  | |  _  | p, d i |  i  i   o g  |  i (n d St i | |  } | i   } | p+ | p |  i i d 8_ n |  i	 |  S| o |  i
 i o |  i	 |  S|  i i |  } | | j o' | i | } |  i	 t i | |   St i | |   S(   s=   Calls different preprocessors, depending on the form of line.R9   i   (   t   _last_input_lineR:   R   t   isspaceR  t   LineInfoR  R  R&  t   handle_normalRj   t   multi_line_specialsRp   t   input_prefilterR/  (   R1   R  RS  t	   line_infot   strippedt	   rewritten(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt
   _prefilter  s&    	c         C   s   |  i  | |  S(   s(   simple prefilter function, for debugging(   RY  (   R1   R  RS  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   _prefilter_dumb  s    c         C   sO   g  } x9 | i  d  i d  D] } | i |  i | |   q Wd i |  S(   s    Run _prefilter for each line of input
        
        Covers cases where there are multiple lines in the user entry,
        which is the case when the user goes back to a multiline history
        entry and presses enter.
        
        s   
(   RP  R   R  R_  R:   (   R1   R  RS  t   outt   l(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   multiline_prefilter  s
     c         C   s   | i  } | i } | of |  i o\ | i   oO d t t |  |  i  j  o
 d j n p |  i d i   o
 d } n |  i | | |  | S(   s:   Handle normal input lines. Use as a template for handlers.i    i   iR9   (	   R  RS  R   RW  t   absR4  R   R   R  (   R1   R\  R  RS  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRY    s    		1
c         C   s   |  i  | i } t |  oJ d | i j o
 d } n d } d | | i | i t | i  f } n2 |  i | i | i  } d | i t |  f } |  i | i | | i	  | S(   s   Handle alias input lines. t   $s   (_ip, _ip.itpl(%s))s   (_ip,%s)s   %s_sh.%ss   %s_ip.system(%s)(
   R   t   iFunt   callableR  t   preWhitespacet   make_quoted_exprR1  t   theRestR  RS  (   R1   R\  t   tgtt	   call_metht   line_outt   transformed(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   handle_alias 	  s    
	c         C   s   | i  } | i   i d  oF | i   d } d |  i | f | _  d | _ | | _ |  i |  S| i   i d  } d | i t |  f } |  i	 | | | i
  | S(   s/   Execute the line in a shell, empty return values   !!i   s   %ssx %st   sxRb   s   %s_ip.system(%s)(   R  Rf  R  R   Rf  Rj  R   Rh  Ri  R  RS  (   R1   R\  R  t   new_restRs   Rm  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR   	  s    				c         C   sP   | i  } | i } d | i t | d |  f } |  i | i | | i  | S(   s   Execute magic functions.s   %s_ip.magic(%s)Rd  (   Rf  Rj  Rh  Ri  R  R  RS  (   R1   R\  Rf  Rj  Rs   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR   /	  s    			c         C   sU  | i  } | i } | i } | i } | i } | i |   d } | o |  i | | |  | St | t i	 i
  } t }	 | |  i j o# d | d i | i    f }
 n5| |  i j o d | | f }
 n| |  i j o# d | d i | i    f }
 n | o5 |  i i d j  o" | o d | | f }
 t }	 n | oT | i d  oD t | d	  o d | | f }
 t }	 qd | i   | f }
 nE | i d
  o d | i   | d  f }
 n d | i   | f }
 |	 oV |  i i i   |
 } y t |  } t i | IJWq>t j
 o d |
 GHq>Xn |  i | |
 |  |
 S(   s=   Hande lines which can be auto-executed, quoting if requested.t   objs   %s("%s")s   ", "s   %s(%s)Re   i   s   %s %st   [t   __getitem__Rf   s   %s(%s);is   -------------->(   R  Rf  Rj  R/  RS  t   ofindR  R
  R   R   t   IPyAutocallR   R   R:   R   R   R   Rj   t   autocallR   R  R  RP  R%  R  t   prompt1t   auto_rewriteRh   R  R  t   UnicodeEncodeError(   R1   R\  R  Rf  Rj  R/  RS  Rr  t
   force_autoRy  t   newcmdt   rw(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR   9	  sJ    					###

c         C   s   | i  } y t i |  Wn t j
 o | d |  i j o | d } n# | d |  i j o | d  } n |  i | d | | i  | o |  i |  n t |  i	 d |  i
 i d S|  i |  SX|  i |  Sd S(   s   Try to get some help for the object.

        obj? or ?obj   -> basic information.
        obj?? or ??obj -> more details.
        i    i   is   #?t   screen_linesR9   N(   R  R   t   compile_commandR  R   R  RS  t   magic_pinfot   pageR   Rj   t   screen_lengthRY  (   R1   R\  R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR   |	  s     	c         C   s   |  i  S(   si   Get an IPApi object for this shell instance
        
        Getting an IPApi object is always preferable to accessing the shell
        directly, but this holds true especially for extensions.
        
        It should always be possible to implement an extension with IPApi
        alone. If not, contact maintainer to request an addition.
        
        (   R   (   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR{  	  s    
c         C   s   | i  S(   s)   Handle input lines marked by python-mode.(   R  (   R1   R\  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   handle_emacs	  s    c         C   sW   t  i d d  } |  i i |  | o* t | d  } | i |  | i   n | S(   sY  Make a new tempfile and return its filename.

        This makes a call to tempfile.mktemp, but it registers the created
        filename internally so ipython cleans it up at exit time.

        Optional inputs:

          - data(None): if data is given, it gets written out to the temp file
          immediately, and the file is closed again.s   .pyt   ipython_edit_R  (   t   tempfilet   mktempR   R  R  R  R  (   R1   t   dataR   t   tmp_file(    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt
   mktempfile	  s    c         C   s   t  i i |  d S(   s$   Write a string to the default outputN(   R  R  R  (   R1   R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR  	  s    c         C   s   t  i i |  d S(   s*   Write a string to the default error outputN(   R  t   cerrR  (   R1   R  (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt	   write_err	  s    c         C   s>   |  i  i o$ |  i d d  o t |  _ q: n
 t |  _ d S(   sJ   Handle interactive exit.

        This method sets the exit_now attribute.s#   Do you really want to exit ([y]/n)?R  N(   Rj   t   confirm_exitR  R   R   (   R1   (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR4   	  s    c            s     f d   } e  i i |  } e  i i e  i i |    e    e i j o e i i d   e   n y e	 |  } Wn  e
 i d | IJ|   d SX| i d d  | i d d  | i d d  | i   } e |  i  i d d  d i   } | i   | i |  p | d o!d	 | GH| d o e i } e i   e _ n y | d d
 !\ }	 }
 Wn0 y | d }	 }
 Wqe   }	 }
 qXn Xg  } e i d  } e	 |  } | i   } | i   e |  } d } x | | j  o | | } | d 7} | i d  o qq| } y | | } Wn d } n XxN | oF | i |  o6 | | 7} | d 7} y | | } WqSd } qSXqSWy | |	 |
 UWqe j
 o q| i | i    qXqW| d o e i i   | e _ n d | GH| o3 e i  d | IJx | D] } e i  | IJq0Wqnwy e i! d j on e i" d j  o^ y | d d
 !\ }	 }
 Wn0 y | d }	 }
 Wqe   }	 }
 qXn Xe# |  |	 |
 Un e$ | |  Wn e% j
 o |  i&   e' d |  n e j
 o } e } e i" d
  d j o* | i( d j o | d o
 e } qn! | i) o | d o
 e } n | o |  i*   e' d |  qn  |  i*   e' d |  n X|   d S(   s&  A safe version of the builtin execfile().

        This version will never throw an exception, and knows how to handle
        ipython logs as well.

        :Parameters:
          fname : string
            Name of the file to be executed.
            
          where : tuple
            One or two namespaces, passed to execfile() as (globals,locals).
            If only one is given, it is passed as both.

        :Keywords:
          islog : boolean (False)

          quiet : boolean (True)

          exit_ignore : boolean (False)
          c              s9     o. y t  i i   Wq5 t j
 o q5 Xn d S(   s&   Internal cleanup routine for sys.path.N(   R   R&  R  Ra  (    (   t	   add_dnamet   dname(    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   syspath_cleanup	  s
    i    s,   Could not open file <%s> for safe execution.t   islogR  i   t   exit_ignores   
s+   Loading log file <%s> one line at a time...i   s   \s+\Ss   #log#s    Finished replaying log file <%s>s9   
The following lines/blocks in file <%s> reported errors:R  i   s   Failure executing file: <%s>N(   i   i   i   (   i   i   (+   R   R&  t
   expandusert   dirnamet   abspathR   R   RX  R   R  R  R  RB   R7  R
  Rh   R   R   R  R  R  RH  t   StringIOt   globalsRB  R   t	   readlinesR4  R   RG  R  RP  t   stderrR   t   version_infoR&   t   execfileR  R  R  t   messageRC  R  (   R1   R  t   wheret   kwR  t   xfilet   firstt   logheadt   stdout_savet   globst   locst	   badblockst	   indent_ret	   filelinest   nlinest   lnumR  t   blockt   nextt   badlinet   statust   show(    (   R  R  sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyR  	  s    	

%
		
 


 

	
  



(R   R*   R+   R6   R   R   RB   R   R2   Rr   R   R-  R   R<  R   R   R   R\  R]  R`  Rc  t   propertyR  R0  R1  R2  R^  Rz  R   R~  R  R  R  R  R  R  R  R  R  R   R  R  R  R  R  R  R  R  R  R  R  R"  R)  RM  R1  R,  Rm  R  R;  R#  RD  R@  R  RN  R%  R  R_  R`  Rc  R  RY  Ro  R   R   R   R   R{  R  R  R  R  R4   R  (    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyRJ      s   	 		V		
*		+					!			#								O		!/	
F			\		,			$<	7			E	;						
	C	 		
			(    (    (\   R6   R   R    t   authorst
   __author__t   licenset   __license__R#  t   __version__R  R   R  R'  t   cPicklet   pickleR   R   R  t   inspectR   R=  R   t   pydocRB  R  R  R   R  t	   tracebackR   t   warningst   filterwarningst   setsR   R   R   R   R   R	   R
   t   IPython.ColorANSIR   R   t   IPython.ExtensionsR   t   IPython.FakeModuleR   t   IPython.ItplR   R   R   R   R   t   IPython.LoggerR   t   IPython.MagicR   t   IPython.PromptsR   t   IPython.ipstructR   t   IPython.background_jobsR   t   IPython.usageR   R   t   IPython.genutilst   IPython.strdispatchR   t   IPython.ipapit   IPython.historyt   IPython.prefilterR  t   IPython.shadownsR  R   R   R9  R   R"   R#   t	   ExceptionR)   R,   R-   t   objectR.   R;   R8   RA   R?   RJ   (    (    (    sE   /u/d/b/dbachman/web/work/lib/python2.3/site-packages/IPython/iplib.pyt   <module>	   st   		"(
			&