;ò
ÎÑAHc           @   s  d  Z  d k Z d k Z y e Wn% e j
 o d k Z e i Z n Xd e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d f  d „  ƒ  YZ
 d f  d	 „  ƒ  YZ e a e e d
 „ Z d f  d „  ƒ  YZ d f  d „  ƒ  YZ e e d „ Z e d „ Z e d „ Z e e d „ Z d S(   s   IPython customization API

Your one-stop module for configuring & extending ipython

The API will probably break when ipython 1.0 is released, but so 
will the other configuration method (rc files).

All names prefixed by underscores are for internal use, not part 
of the public api.

Below is an example that you can just put to a module and import from ipython. 

A good practice is to install the config script below as e.g. 

~/.ipython/my_private_conf.py

And do 

import_mod my_private_conf 

in ~/.ipython/ipythonrc

That way the module is imported at startup and you can have all your
personal configuration (as opposed to boilerplate ipythonrc-PROFILENAME 
stuff) in there. 

-----------------------------------------------
import IPython.ipapi
ip = IPython.ipapi.get()

def ankka_f(self, arg):
    print "Ankka",self,"says uppercase:",arg.upper()

ip.expose_magic("ankka",ankka_f)

ip.magic('alias sayhi echo "Testing, hi ok"')
ip.magic('alias helloworld echo "Hello world"')
ip.system('pwd')

ip.ex('import re')
ip.ex("""
def funcci(a,b):
    print a+b
print funcci(3,4)
""")
ip.ex("funcci(348,9)")

def jed_editor(self,filename, linenum=None):
    print "Calling my own editor, jed ... via hook!"
    import os
    if linenum is None: linenum = 0
    os.system('jed +%d %s' % (linenum, filename))
    print "exiting jed"

ip.set_hook('editor',jed_editor)

o = ip.options
o.autocall = 2  # FULL autocall mode

print "done!"
Ns   TryNextc           B   s   t  Z d  Z d „  Z RS(   s  Try next hook exception.
     
    Raise this in your hook function to indicate that the next hook handler
    should be used to handle the operation.  If you pass arguments to the
    constructor those arguments will be used by the next hook instead of the
    original ones.
    c         O   s   | |  _  | |  _ d  S(   N(   s   argss   selfs   kwargs(   s   selfs   argss   kwargs(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   __init__U   s    	(   s   __name__s
   __module__s   __doc__s   __init__(    (    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   TryNextL   s    s
   UsageErrorc           B   s   t  Z d  Z RS(   s­    Error in magic function arguments, etc.
    
    Something that probably won't warrant a full traceback, but should
    nevertheless interrupt a macro / batch file.   
    (   s   __name__s
   __module__s   __doc__(    (    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys
   UsageErrorY   s   s   IPyAutocallc           B   s   t  Z d  Z d „  Z RS(   s¡    Instances of this class are always autocalled
    
    This happens regardless of 'autocall' variable state. Use this to
    develop macro-like mechanisms.
    c         C   s   | |  _ d S(   s    Will be used to set _ip point to current ipython instance b/f call
        
        Override this method if you don't want this to happen.
        
        N(   s   ips   selfs   _ip(   s   selfs   ip(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   set_ipg   s     (   s   __name__s
   __module__s   __doc__s   set_ip(    (    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   IPyAutocall`   s    s   IPythonNotRunningc           B   sD   t  Z d  Z e d „ Z d „  Z e Z d „  Z d „  Z d „  Z	 RS(   sÎ  Dummy do-nothing class.

    Instances of this class return a dummy attribute on all accesses, which
    can be called and warns.  This makes it easier to write scripts which use
    the ipapi.get() object for informational purposes to operate both with and
    without ipython.  Obviously code which uses the ipython object for
    computations will not work, but this allows a wider range of code to
    transparently work whether ipython is being used or not.c         C   s'   | o |  i |  _ n |  i |  _ d  S(   N(   s   warns   selfs   _dummy_warns   dummys   _dummy_silent(   s   selfs   warn(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   __init__|   s    c         C   s   d Sd  S(   Ns   <IPythonNotRunning>(    (   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   __str__‚   s    c         C   s   |  i Sd  S(   N(   s   selfs   dummy(   s   selfs   name(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   __getattr__‡   s    c         O   s	   d GHd S(   s3   Dummy function, which doesn't do anything but warn.s6   IPython is not running, this is a dummy no-op functionN(    (   s   selfs   argss   kw(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   _dummy_warnŠ   s     c         O   s   d S(   s@   Dummy function, which doesn't do anything and emits no warnings.N(    (   s   selfs   argss   kw(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   _dummy_silent   s     (
   s   __name__s
   __module__s   __doc__s   Trues   __init__s   __str__s   __repr__s   __getattr__s   _dummy_warns   _dummy_silent(    (    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   IPythonNotRunningr   s    			c         C   s'   |  o t o t | ƒ a n t Sd S(   sª  Get an IPApi object.

    If allow_dummy is true, returns an instance of IPythonNotRunning 
    instead of None if not running under IPython.

    If dummy_warn is false, the dummy instance will be completely silent.

    Running this should be the first thing you do when writing extensions that
    can be imported as normal modules. You can then direct all the
    configuration operations against the returned object.
    N(   s   allow_dummys   _recents   IPythonNotRunnings
   dummy_warn(   s   allow_dummys
   dummy_warn(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   get–   s
      s   IPApic           B   sÂ   t  Z d  Z d „  Z d „  Z e e e e e i ƒ Z d „  Z e e e e e i ƒ Z	 d „  Z
 d „  Z d „  Z d „  Z e d „ Z d	 „  Z d
 d „ Z d „  Z d „  Z d „  Z d „  Z RS(   sß    The actual API class for configuring IPython 
    
    You should do all of the IPython configuration by getting an IPApi object
    with IPython.ipapi.get() and using the attributes and methods of the
    returned object.c         C   sŒ   | i |  _ | i |  _ | i |  _ | i |  _ | i |  _ |  |  i d <| i |  _ | i	 |  _	 | |  _
 h  |  _ t |  ƒ |  _ |  a d  S(   Ns   _ip(   s   ips   ipmagics   selfs   magics   systems   set_hooks   set_custom_excs   user_nss   set_crash_handlers   metas   IPs
   extensionss
   DebugToolss   dbgs   _recent(   s   selfs   ip(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   __init__®   s    		 c         C   s   |  i i Sd S(   sB   A handle to persistent dict-like database (a PickleShareDB object)N(   s   selfs   IPs   db(   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   get_dbÓ   s     c         C   s!   |  i i i t ƒ |  i i Sd S(   s   All configurable variables.N(   s   selfs   IPs   rcs   allow_new_attrs   False(   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   get_optionsÙ   s     c         C   s€   d k  } | i | |  i |  i i ƒ } t |  i d | t	 ƒ } | o |  i i d | | f ƒ n t |  i d | | ƒ d S(   sl   Expose own function as magic function for ipython 
    
        def foo_impl(self,parameter_s=''):
            """My very own magic!. (Use docstrings, IPython reads them)."""
            print 'Magic function. Passed parameter is between < >: <'+parameter_s+'>'
            print 'The self object is:',self
    
        ipapi.expose_magic("foo",foo_impl)
        Ns   magic_s   Magic redefinition '%s', old %s(   s   news   instancemethods   funcs   selfs   IPs	   __class__s   ims   getattrs	   magicnames   Nones   olds   dbgs   debug_stacks   setattr(   s   selfs	   magicnames   funcs   olds   ims   new(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   expose_magicå   s    	 	c         B   s   | |  i Ud S(   s5    Execute a normal python statement in user namespace N(   s   cmds   selfs   user_ns(   s   selfs   cmd(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   exù   s     c         C   s   t  | |  i ƒ Sd S(   se    Evaluate python expression expr in user namespace 
        
        Returns the result of evaluationN(   s   evals   exprs   selfs   user_ns(   s   selfs   expr(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   evý   s     c         C   sR   d „  } t | t ƒ o
 | } n d i | ƒ } | | ƒ } |  i i	 | ƒ d S(   s×    Run the specified lines in interpreter, honoring ipython directives.
        
        This allows %magic and !shell escape notations.
        
        Takes either all lines in one string or list of lines.
        c   	      C   sÐ   g  } |  i ƒ  } d } x  | D]˜ } | i ƒ  } | i ƒ  } | o q n t
 | ƒ t
 | ƒ } d „  } | d j o | d j o | | ƒ o | i d ƒ n | i | ƒ | } q Wd i | ƒ d Sd S(   sË    Make a script safe for _ip.runlines() 
            
            - Removes empty lines
            - Suffixes all indented blocks that end with unindented lines with empty lines
            
            i    c         C   se   |  i d ƒ o t Sn |  i d ƒ p- |  i d ƒ p |  i d ƒ p |  i d ƒ o t Sn d  S(   Ns   :s   elifs   elses   excepts   finally(   s   ss   endswiths   Falses
   startswiths   True(   s   s(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   is_secondary_block_start  s    @s    s   
N(   s   ress   scripts
   splitliness   liness   levels   ls   lstrips	   lstrippeds   strips   strippeds   lens   newlevels   is_secondary_block_starts   appends   join(	   s   scripts   levels   ress   liness   ls   newlevels   strippeds   is_secondary_block_starts	   lstripped(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   cleanup_ipy_script  s"      		(
s   
N(
   s   cleanup_ipy_scripts
   isinstances   liness
   basestrings   scripts   joins   cleans   selfs   IPs   runlines(   s   selfs   liness   scripts   cleanup_ipy_scripts   clean(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   runlines  s     	"
c         C   s$  t  | t ƒ o
 | } nŒ t  | t ƒ oo t i d ƒ } h  } xc | i ƒ  D]E } y  t
 | | i | i ƒ | | <WqL d | | i i f GHqL XqL Wn t d ƒ ‚ |  i i | ƒ |  i i } | o1 xU | i ƒ  D] \ } } | i | t ƒ qÕ Wn( x$ | i ƒ  D] \ } } | | | <qWd S(   sK  Inject a group of variables into the IPython user namespace.

        Inputs:

         - vars: string with variable names separated by whitespace, or a
         dict with name/value pairs.

         - interactive: if True (default), the var will be listed with
        %whos et. al.
         
        This utility routine is meant to ease interactive debugging work,
        where you want to easily propagate some internal variable in your code
        up to the interactive namespace for further exploration.

        When you run code via %run, globals in your script become visible at
        the interactive prompt, but this doesn't happen for locals inside your
        own functions and methods.  Yet when debugging, it is common to want
        to explore some internal variables further at the interactive propmt.

        Examples:

        To use this, you first must obtain a handle on the ipython object as
        indicated above, via:

        import IPython.ipapi
        ip = IPython.ipapi.get()

        Once this is done, inside a routine foo() where you want to expose
        variables x and y, you do the following:

        def foo():
            ...
            x = your_computation()
            y = something_else()
            
            # This pushes x and y to the interactive prompt immediately, even
            # if this routine crashes on the next line after:
            ip.to_user_ns('x y')
            ...
            
            # To expose *ALL* the local variables from the function, use:
            ip.to_user_ns(locals())

            ...
            # return           
        

        If you need to rename variables, the dict input makes it easy.  For
        example, this call exposes variables 'foo' as 'x' and 'bar' as 'y'
        in IPython user namespace:

        ip.to_user_ns(dict(x=foo,y=bar))    
        i   s   could not get var. %s from %ss   vars must be a string or a dictN(   s
   isinstances   varss   dicts   vdicts
   basestrings   syss	   _getframes   cfs   splits   names   evals	   f_globalss   f_localss   f_codes   co_names
   ValueErrors   selfs   user_nss   updates   IPs   user_config_nss	   config_nss   interactives	   iteritemss   vals   pops   None(   s   selfs   varss   interactives   names   vdicts   cfs	   config_nss   val(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys
   to_user_ns4  s,    5 
  !  c         C   s<   |  i i | ƒ \ } } } | |  i i | | ƒ } | Sd S(   s?   Expand an alias in the command line 
        
        Returns the provided command line, possibly with the first word 
        (command) translated according to alias expansion rules.
        
        [ipython]|16> _ip.expand_aliases("np myfile.txt")
                 <16> 'q:/opt/np/notepad++.exe myfile.txt'
        N(	   s   selfs   IPs   split_user_inputs   lines   pres   fns   rests   expand_aliasess   res(   s   selfs   lines   pres   ress   rests   fn(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   expand_aliasŒ  s     i   c         C   s   |  i i | | ƒ Sd S(   sµ    Expand Itpl format string s.
        
        Only callable from command line (i.e. prefilter results);
        If you use in your scripts, you need to use a bigger depth!
        N(   s   selfs   IPs
   var_expands   ss   depth(   s   selfs   ss   depth(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   itplš  s     c         C   s  |  i i | ƒ | |  i i j o+ |  i i d | | |  i i | f ƒ n t | ƒ o4 | |  i i | <d k	 } t | i | | ƒ d Sn t | t ƒ o` | i d ƒ } | d j o | i d ƒ d j o t d ƒ ‚ n | | f |  i i | <d Sn | |  i i | <d S(   s    Define a new alias
        
        _ip.defalias('bb','bldmake bldfiles')
        
        Creates a new alias named 'bb' in ipython user namespace
        s+   Alias redefinition: '%s' => '%s' (old '%s')Ns   %si    s   %lsE   The %s and %l specifiers are mutually exclusive in alias definitions.(   s   selfs   dbgs   check_hotnames   names   IPs   alias_tables   debug_stacks   cmds   callables   IPython.shadownss   IPythons   setattrs   shadownss
   isinstances
   basestrings   counts   nargss   finds	   Exception(   s   selfs   names   cmds   nargss   IPython(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   defalias¢  s      +	#c         G   sz   d k  } t | ƒ d j o | i i | d ƒ SnC t | ƒ d j o% | i i | d ƒ |  i | d <n t d ƒ Sd S(   sX   Define a new macro
    
        2 forms of calling:
        
        mac = _ip.defmacro('print "hello"
print "world"')
        
        (doesn't put the created macro on user namespace)
        
        _ip.defmacro('build', 'bldmake bldfiles
abld build winscw udeb')
        
        (creates a macro named 'build' in user namespace)
        Ni   i    i   s1   _ip.defmacro must be called with 1 or 2 arguments(	   s   IPython.macros   IPythons   lens   argss   macros   Macros   selfs   user_nss	   Exception(   s   selfs   argss   IPython(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   defmacroÄ  s     	%c         C   s   | |  i _ d S(   s   Sets the 'default' input string for the next command line.
        
        Requires readline.
        
        Example:
        
        [D:\ipython]|1> _ip.set_next_input("Hello Word")
        [D:\ipython]|2> Hello Word_  # cursor is here        
        N(   s   ss   selfs   IPs   rl_next_input(   s   selfs   s(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   set_next_inputÛ  s    	 c         C   sÐ   | |  i j o |  i | Sn t | ƒ t i | } t | d ƒ o | i |  ƒ n t | d ƒ oT |  i	 i
 d t ƒ  ƒ } | | j o+ | i |  ƒ | i | ƒ | |  i	 d <q» n | |  i | <| Sd S(   sì    Load an extension.
        
        Some modules should (or must) be 'load()':ed, rather than just imported.
        
        Loading will do:
        
        - run init_ipython(ip)
        - run ipython_firstrun(ip)
        
        s   init_ipythons   ipython_firstruns   firstrun_doneN(   s   mods   selfs
   extensionss
   __import__s   syss   moduless   ms   hasattrs   init_ipythons   dbs   gets   sets   already_loadeds   ipython_firstruns   add(   s   selfs   mods   ms   already_loaded(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   loadè  s    
 
(   s   __name__s
   __module__s   __doc__s   __init__s   get_dbs   propertys   Nones   dbs   get_optionss   optionss   expose_magics   exs   evs   runliness   Trues
   to_user_nss   expand_aliass   itpls   defaliass   defmacros   set_next_inputs   load(    (    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   IPApi§   s"    	%		
				1X		"		s
   DebugToolsc           B   s5   t  Z d  Z d „  Z d „  Z e d „ Z d „  Z RS(   sb    Used for debugging mishaps in api usage
    
    So far, tracing redefinitions is supported.
    c         C   s"   | |  _  t |  _ t ƒ  |  _ d  S(   N(   s   ips   selfs   Falses	   debugmodes   sets   hotnames(   s   selfs   ip(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   __init__  s    		c         C   s   |  i i | ƒ d  S(   N(   s   selfs   hotnamess   adds   name_to_catch(   s   selfs   name_to_catch(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   hotname  s    c         C   sD   |  i o d  Sn d  k } | t j	 o d | GHn | i ƒ  d  S(   Ns   ====== %s  ========(   s   selfs	   debugmodes	   tracebacks   msgs   Nones   print_stack(   s   selfs   msgs	   traceback(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   debug_stack  s    	c         C   s)   | |  i j o |  i d | ƒ n d  S(   Ns   HotName '%s' caught(   s   names   selfs   hotnamess   debug_stack(   s   selfs   name(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   check_hotname   s    (   s   __name__s
   __module__s   __doc__s   __init__s   hotnames   Nones   debug_stacks   check_hotname(    (    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys
   DebugTools	  s
    			c         C   s   t  |  | ƒ } | i ƒ  d S(   sâ    Make and start a new ipython instance.
    
    This can be called even without having an already initialized 
    ipython session running.
    
    This is also used as the egg entry point for the 'ipython' script.
    
    N(   s   make_sessions   user_nss
   shellclasss   sess   mainloop(   s   user_nss
   shellclasss   ses(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   launch_new_instance$  s     c         C   sQ   |  t j o h  d d <d t <}  n! |  i d d ƒ |  i d t ƒ |  Sd S(   sá   Return a valid user interactive namespace.

    This builds a dict with the minimal information needed to operate as a
    valid IPython user namespace, which you can pass to the various embedding
    classes in ipython.
    s   __name__s   __main__s   __builtins__N(   s   user_nss   Nones   __builtin__s
   setdefault(   s   user_ns(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   make_user_ns1  s     c         C   s   |  t j o
 h  }  n |  Sd S(   s  Return a valid user global namespace.

    Similar to make_user_ns(), but global namespaces are really only needed in
    embedded applications, where there is a distinction between the user's
    interactive namespace and the global one where ipython is running.N(   s   nss   None(   s   ns(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   make_user_global_nsF  s      
c         C   s;   d k  } | t j o | i i |  ƒ Sn | d |  ƒ Sd S(   s&  Makes, but does not launch an IPython session.
    
    Later on you can call obj.mainloop() on the returned object.

    Inputs:

      - user_ns(None): a dict to be used as the user's namespace with initial
      data.
    
    WARNING: This should *not* be run when a session exists already.Ns   user_ns(   s   IPython.Shells   IPythons
   shellclasss   Nones   Shells   starts   user_ns(   s   user_nss
   shellclasss   IPython(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   make_sessionQ  s
    
 	(   s   __doc__s   __builtin__s   syss   sets	   NameErrors   setss   Sets	   Exceptions   TryNexts
   UsageErrors   IPyAutocalls   IPythonNotRunnings   Nones   _recents   Falses   Trues   gets   IPApis
   DebugToolss   launch_new_instances   make_user_nss   make_user_global_nss   make_session(   s   make_sessions   sets
   UsageErrors
   DebugToolss   IPApis   make_user_nss   gets   __builtin__s   launch_new_instances   syss   make_user_global_nss   setss   IPythonNotRunnings   TryNexts   IPyAutocall(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/ipapi.pys   ?=   s(   			!ÿ c