;ò
ÎÑAHc           @   sû   d  Z  d Z d Z d Z d Z d k Z d k Z d k Z d k Z d k	 Z	 d k
 Z
 d k Z d k Z d k l Z d k l Z y d k Z Wn% e j
 o Z d e e ƒ ‚ n Xd	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   sM  
Provides IPython remote instance.

@author: Laurent Dufrechou
laurent.dufrechou _at_ gmail.com
@license: BSD

All rights reserved. This program and the accompanying materials are made
available under the terms of the BSD which accompanies this distribution, and
is available at U{http://www.opensource.org/licenses/bsd-license.php}
f0.90000000000000002s   Laurent Dufrechous    laurent.dufrechou _at_ gmail.coms   BSDN(   s   ThreadEx(   s   StringIOs   Error importing IPython (%s)s   _Helperc           B   s)   t  Z d  Z d „  Z d „  Z d „  Z RS(   sZ   Redefine the built-in 'help'.
    This is a wrapper around pydoc.help (with a twist).
    c         C   s   | |  _ d  S(   N(   s   pagers   selfs   _pager(   s   selfs   pager(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   __init__(   s    c         C   s   d Sd  S(   NsH   Type help() for interactive help, or help(object) for help about object.(    (   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   __repr__+   s    c         O   sW   d t  f d „  ƒ  Y} d  k } | |  i ƒ | i _ d „  | i _ | i | | Ž  Sd  S(   Ns   DummyWriterc           B   s   t  Z d „  Z d „  Z RS(   Nc         C   s   | |  _ d  S(   N(   s   pagers   selfs   _pager(   s   selfs   pager(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   __init__1   s    c         C   s   |  i | ƒ d  S(   N(   s   selfs   _pagers   data(   s   selfs   data(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   write4   s    (   s   __name__s
   __module__s   __init__s   write(    (    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   DummyWriter0   s   	c           C   s   d S(   Ni   (    (    (    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   <lambda>9   s    (
   s   objects   DummyWriters   pydocs   selfs   _pagers   helps   outputs   interacts   argss   kwds(   s   selfs   argss   kwdss   pydocs   DummyWriter(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   __call__/   s
    	(   s   __name__s
   __module__s   __doc__s   __init__s   __repr__s   __call__(    (    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _Helper#   s    		s   _CodeExecutorc           B   s   t  Z d „  Z d „  Z RS(   Nc         C   s#   t  i |  ƒ | |  _ | |  _ d  S(   N(   s   ThreadExs   __init__s   selfs   instances   afters   _afterExecute(   s   selfs   instances   after(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   __init__A   s    	c         C   sM   y3 t  |  i _ t  |  i _ |  i i ƒ  |  i ƒ  Wn t j
 o n Xd  S(   N(   s   Nones   selfs   instances	   _doc_texts
   _help_texts   _executes   _afterExecutes   KeyboardInterrupt(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   runF   s    (   s   __name__s
   __module__s   __init__s   run(    (    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _CodeExecutor?   s   	s   NonBlockingIPShellc           B   s  t  Z d  Z g  h  e e e e e d „ Z g  h  e e e e e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d d „ Z d „  Z d „  Z RS(   s÷   
    Create an IPython instance, running the commands in a separate,
    non-blocking thread. 
    This allows embedding in any GUI without blockage.

    Note: The ThreadEx class supports asynchroneous function call
          via raise_exc()
    c         C   s‰   |  i | | | | | | | ƒ d |  _	 d |  _
 t i d ƒ |  _ t |  i i i ƒ i ƒ  |  _ d |  _ t |  _ t |  _ t |  _ d S(   s¨  
        @param argv: Command line options for IPython
        @type argv: list
        @param user_ns: User namespace.
        @type user_ns: dictionary
        @param user_global_ns: User global namespace.
        @type user_global_ns: dictionary.
        @param cin: Console standard input.
        @type cin: IO stream
        @param cout: Console standard output.
        @type cout: IO stream
        @param cerr: Console standard error.
        @type cerr: IO stream
        @param exit_handler: Replacement for builtin exit() function
        @type exit_handler: function
        @param time_loop: Define the sleep time between two thread's loop
        @type int
        i    s   [\s\{\}\[\]\(\)\=]s    N(   s   selfs   initIpython0s   argvs   user_nss   user_global_nss   cins   couts   cerrs   ask_exit_handlers
   _iter_mores   _history_levels   res   compiles   _complete_seps   strs   _IPs   outputcaches   prompt1s   strips   _prompts   _line_to_executes   Nones	   _doc_texts
   _help_texts   _add_button(   s   selfs   argvs   user_nss   user_global_nss   cins   couts   cerrs   ask_exit_handler(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   __init__]   s     						c      
   C   su  | o | t i i _  n | o | t i i _ n | o | t i i _ n d „  t i _ t i i	 d | d | d | ƒ |  _ t i }
 t i i | d | d | d t d t i i ƒ|  _ t i ƒ  } | o | |  i _ n |  i i d	 |  i ƒ |  i i d
 |  i ƒ |  i t i _ | |  i _ t  |  i! ƒ |  i i d <t i" i# ƒ  }	 d „  } |	 i& d | ƒ |
 t _ d  S(   Nc         C   s   t  S(   N(   s   None(   s   x(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   <lambda>“   s    s   cins   couts   cerrs   user_nss   user_global_nss   embeddeds   shell_classs   show_in_pagers
   shell_hooks   helpc         C   s	   d GHd  S(   Ns"   %this magic is currently disabled.(    (   s   selfs   arg(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   bypassMagic³   s    s   cpaste('   s   cins   IPythons   Shells   Terms   couts   cerrs   iplibs	   raw_inputs   genutilss   IOTerms   selfs   _terms   syss
   excepthooks   make_IPythons   argvs   user_nss   user_global_nss   Trues   InteractiveShells   _IPs   locales   getpreferredencodings   locs   stdin_encodings   set_hooks   _pagers   _shells
   _raw_inputs   raw_input_originals   ask_exit_handlers   exits   _Helpers   _pager_helps   ipapis   gets   ips   bypassMagics   expose_magic(   s   selfs   argvs   user_nss   user_global_nss   cins   couts   cerrs   ask_exit_handlers   locs   ips
   excepthooks   bypassMagic(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   initIpython0†   s2    $		c         C   s/   | |  _ t |  |  i ƒ |  _ |  i i ƒ  d S(   s?   
        Tell the thread to process the 'line' command
        N(   s   lines   selfs   _line_to_executes   _CodeExecutors   _afterExecutes   ces   start(   s   selfs   line(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys	   doExecuteº   s     	c         C   s   |  i Sd S(   s•   
        Returns the output of the processing that need to be paged (if any)

        @return: The std output string.
        @rtype: string
        N(   s   selfs	   _doc_text(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys
   getDocTextÅ   s     c         C   s   |  i Sd S(   s£   
        Returns the output of the processing that need to be paged via help pager(if any)

        @return: The std output string.
        @rtype: string
        N(   s   selfs
   _help_text(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   getHelpTextÎ   s     c         C   s   |  i i Sd S(   sŒ   
        Returns the IPython banner for useful info on IPython instance

        @return: The banner string.
        @rtype: string
        N(   s   selfs   _IPs   BANNER(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys	   getBanner×   s     c         C   s   |  i i i Sd S(   s¿   
        Returns the prompt number.
        Each time a user execute a line in the IPython shell the prompt count is increased

        @return: The prompt number
        @rtype: int
        N(   s   selfs   _IPs   outputcaches   prompt_count(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   getPromptCountà   s     c         C   s   |  i Sd S(   s    
        Returns current prompt inside IPython instance
        (Can be In [...]: ot ...:)

        @return: The current prompt.
        @rtype: string
        N(   s   selfs   _prompt(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys	   getPromptê   s     c         C   s   |  i i Sd S(   sÒ   
        Returns the current indentation level
        Usefull to put the caret at the good start position if we want to do autoindentation.

        @return: The indentation level.
        @rtype: int
        N(   s   selfs   _IPs   indent_current_nsp(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   getIndentationô   s     c         C   s   |  i i i | ƒ d S(   sž   
        Add the current dictionary to the shell namespace.

        @param ns_dict: A dictionary of symbol-values.
        @type ns_dict: dictionary
        N(   s   selfs   _IPs   user_nss   updates   ns_dict(   s   selfs   ns_dict(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   updateNamespaceþ   s     c         C   sx   |  i i | ƒ } |  i i | d ƒ } | o5 d „  } t	 | | ƒ } | t | d ƒ  | } n | } | | f Sd S(   s  
        Returns an auto completed line and/or posibilities for completion.

        @param line: Given line so far.
        @type line: string

        @return: Line completed as for as possible,
        and possible further completions.
        @rtype: tuple
        iÿÿÿÿc         C   sJ   x? t  t |  ƒ ƒ D]+ } | i |  | d  ƒ o |  |  Sq q W|  Sd S(   sV  
                Reduction function. returns common prefix of two given strings.

                @param str1: First string.
                @type str1: string
                @param str2: Second string
                @type str2: string

                @return: Common prefix to both strings.
                @rtype: string
                i   N(   s   ranges   lens   str1s   is   str2s
   startswith(   s   str1s   str2s   i(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _commonPrefix  s      N(   s   selfs   _complete_seps   splits   lines
   split_lines   _IPs   completes   possibilitiess   _commonPrefixs   reduces   common_prefixs   lens	   completed(   s   selfs   lines   _commonPrefixs   possibilitiess
   split_lines	   completeds   common_prefix(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   complete  s    
 	c         C   so   d } x^ | d j p
 | d j o |  i d j o3 |  i d j o |  i d 8_ n |  i ƒ  } q	 W| Sd S(   sq   
        Provides one history command back.

        @return: The command string.
        @rtype: string
        s    s   
i    i   N(   s   historys   selfs   _history_levels   _getHistory(   s   selfs   history(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   historyBack,  s      *c         C   s¶   d } x¥ | d j p
 | d j o |  i |  i ƒ  j ot |  i |  i ƒ  j  o |  i d 7_ |  i ƒ  } q	 |  i |  i ƒ  j o |  i ƒ  } |  i d 7_ q	 d } q	 W| Sd S(   st   
        Provides one history command forward.

        @return: The command string.
        @rtype: string
        s    s   
i   N(   s   historys   selfs   _history_levels   _getHistoryMaxIndexs   _getHistory(   s   selfs   history(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   historyForward;  s      0c         C   s   |  i ƒ  d |  _ d S(   s5   
        set history to last command entered
        i   N(   s   selfs   _getHistoryMaxIndexs   _history_level(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   initHistoryIndexP  s     c         C   s   d S(   sP   
        Can be redefined to generate post event after excution is done
        N(    (   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _afterExecuteW  s     c         C   s   t  |  i i ƒ d Sd S(   ss   
        returns the max length of the history buffer

        @return: history length
        @rtype: int
        i   N(   s   lens   selfs   _IPs   input_hist_raw(   s   self(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _getHistoryMaxIndexc  s     c         C   s$   |  i i |  i i d ƒ } | Sd S(   s‡   
        Get's the command string of the current history level.

        @return: Historic command stri
        @rtype: string
        s   
N(   s   selfs   _IPs   input_hist_raws   _history_levels   strips   rv(   s   selfs   rv(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _getHistoryl  s     c         C   s0   |  i t j o | |  _ n |  i | 7_ d S(   sÚ   
        This function is used as a callback replacment to IPython help pager function

        It puts the 'text' value inside the self._help_text string that can be retrived via getHelpText
        function.
        N(   s   selfs
   _help_texts   Nones   text(   s   selfs   text(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _pager_helpv  s     c         C   s   | |  _ d S(   sÓ   
        This function is used as a callback replacment to IPython pager function

        It puts the 'text' value inside the self._doc_text string that can be retrived via getDocText
        function.
        N(   s   texts   selfs	   _doc_text(   s   selfs   IPs   text(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _pager‚  s     s    c         C   s   |  i Sd S(   s  
        Custom raw_input() replacement. Get's current line from console buffer.

        @param prompt: Prompt to print. Here for compatability as replacement.
        @type prompt: string

        @return: The current command line text.
        @rtype: string
        N(   s   selfs   _line_to_execute(   s   selfs   prompt(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys
   _raw_input‹  s    	 c         C   s©  t  i } t i i i t  _ y= |  i i	 t
 |  i ƒ } |  i i o |  i i t
 ƒ n Wn~ t j
 o_ |  i i d ƒ |  i i ƒ  |  i i i d 8_ |  i i o d |  i _ n d |  _ n[ |  i i ƒ  nG X|  i i | ƒ |  _ |  i i i o |  i i i o |  i i ƒ  n |  i oI t |  i i i ƒ i ƒ  |  _ |  i i o |  i i |  i i  ƒ qœn+ t |  i i i! ƒ i ƒ  |  _ d |  i _ | t  _ d S(   sI   
        Executes the current line provided by the shell object.
        s   
KeyboardInterrupt
i   i    N("   s   syss   stdouts   orig_stdouts   IPythons   Shells   Terms   couts   selfs   _IPs	   raw_inputs   Nones
   _iter_mores   lines
   autoindents   readline_startup_hooks   KeyboardInterrupts   writes   resetbuffers   outputcaches   prompt_counts   indent_current_nsps   showtracebacks   pushs   SyntaxTBs   last_syntax_errors   rcs   autoedit_syntaxs   edit_syntax_errors   strs   prompt2s   strips   _prompts   pre_readlines   prompt1(   s   selfs   orig_stdouts   line(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _execute—  s4     	 
c         C   sZ   t  i | ƒ \ } } | i ƒ  i d ƒ i t i	 ƒ  ƒ } d | GH| i ƒ  | i ƒ  d S(   sö   
        Replacement method to allow shell commands without them blocking.

        @param ip: Ipython instance, same as self._IP
        @type cmd: Ipython instance
        @param cmd: Shell command to execute.
        @type cmd: string
        s   cp437s	   [1;36mN(   s   oss   popen4s   cmds   stdins   stdouts   reads   decodes   encodes   locales   getpreferredencodings   results   close(   s   selfs   ips   cmds   stdins   stdouts   result(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   _shell¼  s     $	
(   s   __name__s
   __module__s   __doc__s   Nones   __init__s   initIpython0s	   doExecutes
   getDocTexts   getHelpTexts	   getBanners   getPromptCounts	   getPrompts   getIndentations   updateNamespaces   completes   historyBacks   historyForwards   initHistoryIndexs   _afterExecutes   _getHistoryMaxIndexs   _getHistorys   _pager_helps   _pagers
   _raw_inputs   _executes   _shell(    (    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   NonBlockingIPShellS   s.    )4								
	
	
			%							
				%(   s   __doc__s   __version__s
   __author__s	   __email__s   __license__s   res   syss   oss   locales   times   pydocs   __builtin__s   sites	   thread_exs   ThreadExs   StringIOs   IPythons	   Exceptions   es   strs   objects   _Helpers   _CodeExecutors   NonBlockingIPShell(   s   locales   sites   __builtin__s	   __email__s   _CodeExecutors   IPythons   res   __version__s   ThreadExs   _Helpers   __license__s
   __author__s   syss   NonBlockingIPShells   es   StringIOs   pydocs   times   os(    (    sS   /u/d/b/dbachman/=/lib/python2.3/site-packages/IPython/gui/wx/ipshell_nonblocking.pys   ?   s&   					