ó
æNXc        	   @   sð   d  Z  d d l Z d d l Z d d l Z d d l m Z d d d d d d	 d
 d d g	 Z i d d 6d d 6d d 6Z d e	 d „ Z
 d d l Z d „  Z d „  Z d d d „  ƒ  YZ 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 can make an :doc:`extension
</config/extensions/index>` or a :ref:`startup script <startup_files>`. For
example, you could use a startup file like this::

    import os

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

    def load_ipython_extension(ip):
        ip.set_hook('editor', calljed)

iÿÿÿÿN(   t   TryNextt   editort   fix_error_editort   synchronize_with_editort   shutdown_hookt   late_startup_hookt   show_in_pagert   pre_prompt_hookt   pre_run_code_hookt   clipboard_gets8   a callback for the 'pre_execute' or 'pre_run_cell' events,   a callback for the 'shell_initialized' events   the atexit modulec         C   s¿   |  j  } | d
 k s! | d k r* d } n d t | ƒ } d | k ru t j j | ƒ ru | d d k ru d | } n  t j d | | | f d	 t ƒ} | r» | j	 ƒ  d k r» t
 ƒ  ‚ n  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).t   notepadt    s   +%dt    i    t   "s   "%s"s   %s %s %st   shellN(   R   t   Nonet   intt   ost   patht   isfilet
   subprocesst   Popent   Truet   waitR    (   t   selft   filenamet   linenumR   R   t   linemarkt   proc(    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR   9   s    			.	c            s‹   ‡  ‡ ‡ ‡ f d †  } t  j j |  j ƒ d k rJ |  j j ˆ ˆ ƒ d S| ƒ  } z& t  j d | j ƒ rx t ƒ  ‚ n  Wd | j ƒ  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             s7   t  j ƒ  }  |  j d ˆ ˆ ˆ  ˆ f ƒ |  j ƒ  |  S(   Ns   %s:%d:%d:%s
(   t   tempfilet   NamedTemporaryFilet   writet   flush(   t   t(   t   columnR   R   t   msg(    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyt   vim_quickfix_file]   s    
t   vimNs+   vim --cmd "set errorformat=%f:%l:%c:%m" -q (	   R   R   t   basenameR   t   hookst   systemt   nameR    t   close(   R   R   R   R"   R#   R$   R!   (    (   R"   R   R   R#   sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR   U   s    	c         C   s   d  S(   N(    (   R   R   R   R"   (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR   m   s    t   CommandChainDispatcherc           B   sA   e  Z d  Z d 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%   | d  k r g  |  _ n	 | |  _ d  S(   N(   R   t   chain(   R   t   commands(    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyt   __init__x   s    c         O   sZ   t  ƒ  } xD |  j D]9 \ } } y | | | Ž  SWq t  k
 rK } | } q Xq W| ‚ 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
        TryNextN(   R    R,   (   R   t   argst   kwt   last_exct   priot   cmdt   exc(    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyt   __call__   s    	c         C   s   t  |  j ƒ S(   N(   t   strR,   (   R   (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyt   __str__   s    i    c         C   s0   |  j  j | | f ƒ |  j  j d d „  ƒ d S(   s1    Add a func to the cmd chain with given priority t   keyc         S   s   |  d S(   Ni    (    (   t   x(    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyt   <lambda>•   s    N(   R,   t   appendt   sort(   R   t   funct   priority(    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyt   add’   s    c         C   s   t  |  j ƒ S(   sV    Return all objects in chain.

        Handy if the objects are not callable.
        (   t   iterR,   (   R   (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyt   __iter__—   s    N(	   t   __name__t
   __module__t   __doc__R   R.   R5   R7   R?   RA   (    (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR+   q   s   		c         C   s   d S(   sl    default shutdown hook

    Typically, shotdown hooks should raise TryNext so all shutdown ops are done
    N(    (   R   (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR   Ÿ   s    c         C   s   d S(   sA    Executed after ipython has been constructed and configured

    N(    (   R   (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR   ©   s    c         C   s
   t  ‚ d S(   s    Run a string through pager N(   R    (   R   t   datat   startt   screen_lines(    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR   °   s    c         C   s   d 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(   R   (   R   (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR   ¶   s    c         C   s   d S(   s;    Executed before running the (prefiltered) code in IPython N(   R   (   R   (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR   À   s    c         C   s•   d d l  m } m } m } t j d k r: | | g } n' t j d k rX | | g } n	 | g } t ƒ  } x | D] } | j | ƒ qq W| ƒ  } | S(   s"    Get text from the clipboard.
    iÿÿÿÿ(   t   osx_clipboard_gett   tkinter_clipboard_gett   win32_clipboard_gett   win32t   darwin(   t   IPython.lib.clipboardRH   RI   RJ   t   syst   platformR+   R?   (   R   RH   RI   RJ   R,   t
   dispatcherR=   t   text(    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyR	   Å   s    			(    (   RD   R   R   RN   t   IPython.core.errorR    t   __all__t
   deprecatedR   R   R   R   R   R   R+   R   R   R   R   R   R	   (    (    (    sJ   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/hooks.pyt   <module>   s,   		

		.	
			
	