;
AHc           @   s:  d  Z  d k l Z d k l Z d e i d Z e i Z e i Z	 d k
 Z
 d k Z d k l Z l Z d k l Z d d	 d
 d d d d d d d d d g Z e   i Z e d  Z d k Z d   Z d f  d     YZ d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d    Z  d!   Z! d S("   s}  hooks for IPython.

In Python, it is possible to overwrite any method of any object if you really
want to.  But IPython exposes a few 'hooks', methods which are _designed_ to
be overwritten by users for customization purposes.  This module defines the
default versions of all such hooks, which get used by IPython if not
overridden by the user.

hooks are simple functions, but they should be declared with 'self' as their
first argument, because when activated they are registered into IPython as
instance methods.  The self argument will be the IPython running instance
itself, so hooks have full access to the entire IPython object.

If you wish to define a new hook and activate it, you need to put the
necessary code into a python file which can be either imported or execfile()'d
from within your ipythonrc configuration.

For example, suppose that you have a module called 'myiphooks' in your
PYTHONPATH, which contains the following definition:

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

def calljed(self,filename, linenum):
    "My editor hook calls the jed editor directly."
    print "Calling my own editor, jed ..."
    os.system('jed +%d %s' % (linenum,filename))

ip.set_hook('editor', calljed)

You can then enable the functionality by doing 'import myiphooks'
somewhere in your configuration files or ipython command line.

$Id: hooks.py 2998 2008-01-31 10:06:04Z vivainio $(   s   Release(   s   ipapis   %s <%s>s   FernandoN(   s   Terms   shell(   s   PrettyPrinters   editors   fix_error_editors   result_displays   input_prefilters   shutdown_hooks   late_startup_hooks   generate_prompts   generate_output_prompts
   shell_hooks   show_in_pagers   pre_prompt_hooks   pre_runcode_hookc         C   s   |  i i } | t j p
 | d j o
 d } n d t |  } d | j o! t i i	 |  o | d d j o d | } n t i
 d | | | f  d	 S(
   s  Open the default editor at the given filename and linenumber.

    This is IPython's default editor hook, you can use it as an example to
    write your own modified one.  To set your own editor function as the
    new editor hook, call ip.set_hook('editor',yourfunc).s   notepads    s   +%ds    i    s   "s   "%s"s   %s %s %sN(   s   selfs   rcs   editors   linenums   Nones   linemarks   ints   oss   paths   isfiles   systems   filename(   s   selfs   filenames   linenums   editors   linemark(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   editor?   s     
1c            s        d   } t i i |  i i  d j o |  i i     d Sn |   } z t i d | i  Wd | i   Xd S(   s]  Open the editor at the given filename, linenumber, column and 
    show an error message. This is used for correcting syntax errors.
    The current implementation only has special support for the VIM editor,
    and falls back on the 'editor' hook if VIM is not used.

    Call ip.set_hook('fix_error_editor',youfunc) to use your own function,
    c             s;   t  i   }  |  i d      f  |  i   |  Sd  S(   Ns   %s:%d:%d:%s
(	   s   tempfiles   NamedTemporaryFiles   ts   writes   filenames   linenums   columns   msgs   flush(   s   t(   s   columns   filenames   linenums   msg(    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   vim_quickfix_file`   s    
s   vimNs+   vim --cmd "set errorformat=%f:%l:%c:%m" -q (   s   vim_quickfix_files   oss   paths   basenames   selfs   rcs   editors   hookss   filenames   linenums   ts   systems   names   close(   s   selfs   filenames   linenums   columns   msgs   vim_quickfix_files   t(    (   s   filenames   linenums   columns   msgs=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   fix_error_editorX   s     	 s   CommandChainDispatcherc           B   sA   t  Z d  Z e d  Z d   Z d   Z d d  Z d   Z RS(   s    Dispatch calls to a chain of commands until some func can handle it
    
    Usage: instantiate, execute "add" to add commands (with optional
    priority), execute normally via f() calling mechanism.
    
    c         C   s'   | t j o g  |  _ n
 | |  _ d  S(   N(   s   commandss   Nones   selfs   chain(   s   selfs   commands(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   __init__v   s    c         O   s   xs |  i D]h \ } } y | | |   } | SWq
 t i j
 o3 } | i p | i
 o | i } | i
 } qr q
 Xq
 Wt i  d S(   s    Command chain is called just like normal func. 
        
        This will call all funcs in chain with the same args as were given to this
        function, and return the result of first func that didn't raise
        TryNext N(   s   selfs   chains   prios   cmds   argss   kws   rets   ipapis   TryNexts   excs   kwargs(   s   selfs   argss   kws   excs   prios   cmds   ret(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   __call__}   s     
 	c         C   s   t  |  i  Sd  S(   N(   s   strs   selfs   chain(   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   __str__   s    i    c         C   s   t  i |  i | | f  d S(   s1    Add a func to the cmd chain with given priority N(   s   bisects   insorts   selfs   chains   prioritys   func(   s   selfs   funcs   priority(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   add   s     c         C   s   t  |  i  Sd S(   s^    Return all objects in chain.
        
        Handy if the objects are not callable.
        N(   s   iters   selfs   chain(   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   __iter__   s     (	   s   __name__s
   __module__s   __doc__s   Nones   __init__s   __call__s   __str__s   adds   __iter__(    (    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   CommandChainDispatchero   s    		c         C   sf   |  i i o> t |  } d | j o t i i d  n t i | IJn t i t	 |  IJt
 Sd S(   sR    Default display hook.
    
    Called for displaying the result to the user.
    s   
N(   s   selfs   rcs   pprints   pformats   args   outs   Terms   couts   writes   reprs   None(   s   selfs   args   out(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   result_display   s     c         C   s   | Sd S(   s?   Default input prefilter
    
    This returns the line as unchanged, so that the interpreter
    knows that nothing was done and proceeds with "classic" prefiltering
    (%magics, !shell commands etc.). 
    
    Note that leading whitespace is not passed to this hook. Prefilter
    can't alter indentation.
    
    N(   s   line(   s   selfs   line(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   input_prefilter   s    
 c         C   s   d Sd S(   sp    default shutdown hook
    
    Typically, shotdown hooks should raise TryNext so all shutdown ops are done
    N(    (   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   shutdown_hook   s     c         C   s   d S(   sF    Executed after ipython has been constructed and configured 
    
    N(    (   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   late_startup_hook   s    c         C   s>   |  i } | o t | i i i  Sn t | i i i  Sd S(   s:    calculate and return a string with the prompt to display N(	   s   selfs   apis   ips   is_continuations   strs   IPs   outputcaches   prompt2s   prompt1(   s   selfs   is_continuations   ip(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   generate_prompt   s
     	c         C   s    |  i } t | i i i  Sd  S(   N(   s   selfs   apis   ips   strs   IPs   outputcaches
   prompt_out(   s   selfs   ip(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   generate_output_prompt   s    	c         C   s&   t  | d |  i i d |  i i d S(   s+    Run system/shell command a'la os.system() s   headers   verboseN(   s   shells   cmds   selfs   rcs   system_headers   system_verbose(   s   selfs   cmd(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys
   shell_hook   s     c         C   s   t  i  d S(   s    Run a string through pager N(   s   ipapis   TryNext(   s   selfs   s(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   show_in_pager   s     c         C   s   t  Sd S(   s    Run before displaying the next prompt
    
    Use this e.g. to display output from asynchronous operations (in order 
    to not mess up text entry)   
    N(   s   None(   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   pre_prompt_hook   s     c         C   s   t  Sd S(   s;    Executed before running the (prefiltered) code in IPython N(   s   None(   s   self(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   pre_runcode_hook   s     ("   s   __doc__s   IPythons   Releases   ipapis   authorss
   __author__s   licenses   __license__s   versions   __version__s   oss   bisects   genutilss   Terms   shells   pprints   PrettyPrinters   __all__s   pformats   Nones   editors   tempfiles   fix_error_editors   CommandChainDispatchers   result_displays   input_prefilters   shutdown_hooks   late_startup_hooks   generate_prompts   generate_output_prompts
   shell_hooks   show_in_pagers   pre_prompt_hooks   pre_runcode_hook(   s   shutdown_hooks   fix_error_editors
   shell_hooks   input_prefilters   generate_output_prompts   show_in_pagers   late_startup_hooks   __all__s   tempfiles   editors   __version__s   ipapis   Terms   shells   __license__s
   __author__s   Releases   PrettyPrinters   bisects   oss   generate_prompts   pformats   CommandChainDispatchers   pre_runcode_hooks   pre_prompt_hooks   result_display(    (    s=   /nyx/web/d/b/dbachman/work/src/ipython-0.8.4/IPython/hooks.pys   ?#   s0   			*		/											