
NXc           @   s8  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 d d l m Z d d l m Z d d l m Z d d l m Z m Z d d l m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z d d l m Z m Z m  Z  d d l! m" Z" m# Z# d d g Z$ e j% d k rjd Z& n d Z& d   Z' d   Z( d   Z) d   Z* d   Z+ e d e, f d     Y Z- d Z. d Z/ d e, f d     YZ0 d e f d     YZ1 d   Z2 d    Z3 d!   Z4 d"   Z5 d#   Z6 d e1 f d$     YZ7 d S(%   s  Word completion for IPython.

This module is a fork of the rlcompleter module in the Python standard
library.  The original enhancements made to rlcompleter have been sent
upstream and were accepted as of Python 2.3, but we need a lot more
functionality specific to IPython, so this module will continue to live as an
IPython-specific utility.

Original rlcompleter documentation:

This requires the latest extension to the readline module (the
completes keywords, built-ins and globals in __main__; when completing
NAME.NAME..., it evaluates (!) the expression up to the last dot and
completes its attributes.

It's very cool to do "import string" type "string.", hit the
completion key (twice), and see the list of names defined by the
string module!

Tip: to use the tab key as the completion key, call

    readline.parse_and_bind("tab: complete")

Notes:

- Exceptions raised by the completer function are *ignored* (and
  generally cause the completion to fail).  This is a feature -- since
  readline sets the tty device in raw (or cbreak) mode, printing a
  traceback wouldn't work well without some complicated hoopla to save,
  reset and restore the tty state.

- The evaluation of the NAME.NAME... form may cause arbitrary
  application defined code to be executed if an object with a
  ``__getattr__`` hook is found.  Since it is the responsibility of the
  application (or the user) to enable this feature, I consider this an
  acceptable risk.  More complicated expressions (e.g. function calls or
  indexing operations) are *not* evaluated.

- GNU readline is also used by the built-in functions input() and
  raw_input(), and thus these also benefit/suffer from the completer
  features.  Clearly an interactive application can benefit by
  specifying its own completer function and using raw_input() for all
  its input.

- When the original stdin is not a tty device, GNU readline is never
  used, and this module (and the readline module) are silently inactive.
iN(   t   Configurable(   t   TryNext(   t	   ESC_MAGIC(   t   latex_symbolst   reverse_latex_symbol(   t   generics(   t   io(   t   undoc(   t   dir2(   t	   arg_split(   t   builtin_modt   string_typest   PY3(   t   CBoolt   Enumt	   Completert   IPCompletert   win32t    s    ()[]{}?=\|;:'#*"^&c         C   s6   |  j  d  d r d S|  j  d  d r. d St Sd S(   s  Return whether a string has open quotes.

    This simply counts whether the number of quote characters of either type in
    the string is odd.

    Returns
    -------
    If there is an open quote, the quote character is returned.  Else, return
    False.
    t   "i   t   'N(   t   countt   False(   t   s(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   has_open_quotes`   s
    c         C   s6   d j  g  |  D]" } | t k r) d | p, | ^ q  S(   s.   Escape a string to protect certain characters.t    s   \(   t   joint   PROTECTABLES(   R   t   ch(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   protect_filenameu   s    	c         C   ss   t  } d } |  } |  j d  rf t } t |   d } t j j |   } | r] | |  } qf | } n  | | | f S(   s  Expand '~'-style usernames in strings.

    This is similar to :func:`os.path.expanduser`, but it computes and returns
    extra information that will be useful if the input was being used in
    computing completions, and you wish to return the completions with the
    original '~' instead of its expanded value.

    Parameters
    ----------
    path : str
      String to be expanded.  If no ~ is present, the output is the same as the
      input.

    Returns
    -------
    newpath : str
      Result of ~ expansion in the input path.
    tilde_expand : bool
      Whether any expansion was performed or not.
    tilde_val : str
      The value that ~ was replaced with.
    R   t   ~i   (   R   t
   startswitht   Truet   lent   ost   patht
   expanduser(   R#   t   tilde_expandt	   tilde_valt   newpatht   rest(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   expand_user{   s    	c         C   s   | r |  j  | d  S|  Sd S(   s8   Does the opposite of expand_user, with its outputs.
    R   N(   t   replace(   R#   R%   R&   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   compress_user   s    c         C   sb   |  d  d k r/ d |  d k r/ |  d d Sn  |  d  d k r^ d |  d k r^ |  d d Sn  |  S(   s  key for sorting that penalizes magic commands in the ordering

    Normal words are left alone.

    Magic commands have the initial % moved to the end, e.g.
    %matplotlib is transformed as follows:

    %matplotlib -> matplotlib%

    [The choice of the final % is arbitrary.]

    Since "matplotlib" < "matplotlib%" as strings, 
    "timeit" will appear before the magic "%timeit" in the ordering

    For consistency, move "%%" to the end, so cell magics appear *after*
    line magics with the same name.

    A check is performed that there are no other "%" in the string; 
    if there are, then the string is not a magic command and is left unchanged.

    i   s   %%t   %i   (    (   t   word(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   penalize_magics_key   s    t   Bunchc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR/      s   s    	
`!@#$^&*()=+[{]}\|;:'",<>?s    =
t   CompletionSplitterc           B   sY   e  Z d  Z e Z d Z d Z d d  Z e	 d    Z
 e
 j d    Z
 d d  Z RS(   sU  An object to split an input line in a manner similar to readline.

    By having our own implementation, we can expose readline-like completion in
    a uniform manner to all frontends.  This object only needs to be given the
    line of text to be split and the cursor position on said line, and it
    returns the 'word' to be completed on at the cursor after splitting the
    entire line.

    What characters are used as splitting delimiters can be controlled by
    setting the `delims` attribute (this is a property that internally
    automatically builds the necessary regular expression)c         C   s(   | d  k r t j n | } | |  _ d  S(   N(   t   NoneR2   t   _delimst   delims(   t   selfR5   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   __init__   s    c         C   s   |  j  S(   s*   Return the string of delimiter characters.(   R4   (   R6   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR5      s    c         C   sI   d d j  d   | D  d } t j |  |  _ | |  _ | |  _ d S(   s&   Set the delimiters for line splitting.t   [R   c         s   s   |  ] } d  | Vq d S(   s   \N(    (   t   .0t   c(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pys	   <genexpr>  s    t   ]N(   R   t   ret   compilet	   _delim_reR4   t   _delim_expr(   R6   R5   t   expr(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR5      s    !	c         C   s0   | d k r | n | |  } |  j j |  d S(   sB   Split a line of text with a cursor at the given position.
        iN(   R3   R>   t   split(   R6   t   linet
   cursor_post   l(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt
   split_line  s    N(   R0   R1   t   __doc__t   DELIMSR4   R3   R?   R>   R7   t   propertyR5   t   setterRE   (    (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR2      s   c           B   sJ   e  Z e e d  e d d Z d d d  Z d   Z d   Z	 d   Z
 RS(   t   configt   helps   Activate greedy completion

        This will enable completion on elements of lists, results of function calls, etc.,
        but can be unsafe because the code is actually evaluated on TAB.
        c         K   se   | d k r d |  _ n d |  _ | |  _ | d k rB i  |  _ n	 | |  _ t t |   j |   d S(   s  Create a new completer for the command line.

        Completer(namespace=ns,global_namespace=ns2) -> completer instance.

        If unspecified, the default namespace where completions are performed
        is __main__ (technically, __main__.__dict__). Namespaces should be
        given as dictionaries.

        An optional second namespace can be given.  This allows the completer
        to handle cases where both the local and global scopes need to be
        distinguished.

        Completer instances should be used as the completion mechanism of
        readline via the set_completer() call:

        readline.set_completer(Completer(my_namespace).complete)
        i   i    N(   R3   t   use_main_nst	   namespacet   global_namespacet   superR   R7   (   R6   RM   RN   t   kwargs(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR7     s    			c         C   s   |  j  r t j |  _ n  | d k rZ d | k rE |  j |  |  _ qZ |  j |  |  _ n  y |  j | SWn t k
 r} d SXd S(   s   Return the next possible completion for 'text'.

        This is called successively with state == 0, 1, 2, ... until it
        returns None.  The completion should begin with 'text'.

        i    t   .N(	   RL   t   __main__t   __dict__RM   t   attr_matchest   matchest   global_matchest
   IndexErrorR3   (   R6   t   textt   state(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   complete<  s    	c         C   s   g  } | j  } t |  } xr t j t j j   |  j j   |  j j   g D]@ } x7 | D]/ } | |  | k rY | d k rY | |  qY qY WqL W| S(   s   Compute matches when text is a simple name.

        Return a list of all keywords, built-in functions and names currently
        defined in self.namespace or self.global_namespace that match.

        t   __builtins__(	   t   appendR!   t   keywordt   kwlistR
   RS   t   keysRM   RN   (   R6   RX   RU   t   match_appendt   nt   lstR-   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyRV   P  s    		c         C   sk  t  j d |  } | r3 | j d d  \ } } nG |  j rv t  j d |  j  } | s[ g  S| j d d  \ } } n g  Sy t | |  j  } Wn( y t | |  j  } Wq g  SXn X|  j r t	 | d  r t
 |  } n t |  } y t j | |  } Wn! t k
 rn t k
 r'n Xt |  } g  | D]& }	 |	 |  | k r;d | |	 f ^ q;}
 |
 S(   s  Compute matches when text contains a dot.

        Assuming the text is of the form NAME.NAME....[NAME], and is
        evaluatable in self.namespace or self.global_namespace, it will be
        evaluated and its attributes (as revealed by dir()) are used as
        possible completions.  (For class instances, class members are are
        also considered.)

        WARNING: this can still invoke arbitrary C code, if an object
        with a __getattr__ hook is evaluated.

        s   (\S+(\.\w+)*)\.(\w*)$i   i   s   (.+)\.(\w*)$i   t   __all__s   %s.%s(   R<   t   matcht   groupt   greedyt   line_buffert   evalRM   RN   t   limit_to__all__t   hasattrt   get__all__entriesR   R   t   complete_objectR   t	   ExceptionR!   (   R6   RX   t   mR@   t   attrt   m2t   objt   wordsRa   t   wt   res(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyRT   d  s8    		3N(   R0   R1   R   R   R    Rf   R3   R7   RZ   RV   RT   (    (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     s   	$		c         C   sD   y t  |  d  } Wn g  SXg  | D] } t | t  r% | ^ q% S(   s,   returns the strings in the __all__ attributeRc   (   t   getattrt
   isinstanceR   (   Rq   Rr   Rs   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyRk     s
    c         C   s
  | sA d d g  |  D]' } t | t t f  r t |  ^ q f St j d |  } | j   } y t | | i   } Wn t	 k
 r d d g  f SXd d j
 d   | D  d } t j | | t j  } | j   }	 | j   }
 g  } x|  D]} y | j |  sw n  Wn t t t f k
 r0q n X| t |  } t | d  } | j d  r| d d	 k ry t | j d
  d  } Wqt k
 rq qXn  | d | j d  d !} | d k r| j d d  } n  | j d |
 | f  q W| |	 | f S(   s?   Used by dict_key_matches, matching the prefix to a list of keysi    s   ["']s   [^R   c         s   s   |  ] } d  | Vq d S(   s   \N(    (   R9   R:   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pys	   <genexpr>  s    s   ]*$R   t   ut   uUt   asciii   R   is   \"s   %s%sN(   R3   Rv   R   t   bytest   reprR<   t   searchRe   Rh   Rm   R   t   UNICODEt   startR   t   AttributeErrort	   TypeErrort   UnicodeErrorR!   t   encodet   UnicodeEncodeErrort   indexR*   R\   (   R_   t   prefixR5   t   kt   quote_matcht   quotet
   prefix_strt   patternt   token_matcht   token_startt   token_prefixt   matchedt   keyt   remt   rem_repr(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   match_dict_keys  s@    (!

c         C   s+   | t  j k o* t |  t t |  |   S(   s@   Checks if obj is an instance of module.class_name if loaded
    (   t   syst   modulesRv   Ru   t
   __import__(   Rq   t   modulet
   class_name(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   _safe_isinstance  s    c         C   s   t  |   d k  r d d f S|  d } | d k r< d d	 f S|  d } | t j k sa | d
 k rk d d f Sy( t j |  } d | d | g f SWn t k
 r } n Xd d f S(   uu  Match unicode characters back to unicode name
    
    This does  ☃ -> \snowman

    Note that snowman is not a valid python3 combining character but will be expanded.
    Though it will not recombine back to the snowman character by the completion machinery.

    This will not either back-complete standard sequences like \n, \b ...
    
    Used on Python 3 only.
    i   u    is   \iR   R   (    (    (   R   R   (    (    (   R!   t   stringt   ascii_letterst   unicodedatat   namet   KeyError(   RX   t   maybe_slasht   chart   unict   e(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   back_unicode_name_matches  s    




c         C   s   t  |   d k  r d d f S|  d } | d k r< d d	 f S|  d } | t j k sa | d
 k rk d d f Sy t | } d | | g f SWn t k
 r } n Xd d f S(   uh   Match latex characters back to unicode name
    
    This does  ->\sqrt

    Used on Python 3 only.
    i   u    is   \iR   R   (    (    (   R   R   (    (    (   R!   R   R   R   R   (   RX   R   R   t   latexR   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   back_latex_name_matches  s    





c           B   s  e  Z d  Z d   Z e e d e d d Z e d d d d e d d	 Z e d e	 d e d d
  Z
 d d d e d 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 d d  Z d   Z RS(   s?   Extension of the completer class with IPython-specific featuresc         C   sG   | r t  |  j _ n t |  j _ |  j rC |  j j |  j j  n  d S(   s>   update the splitter and readline delims when greedy is changedN(   t   GREEDY_DELIMSt   splitterR5   RG   t   readlinet   set_completer_delims(   R6   R   t   oldt   new(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   _greedy_changed  s
    	RJ   RK   s   Whether to merge completion results into a single list
        
        If False, only the completion results from the first non-empty
        completer will be returned.
        i    i   i   t   default_valuesQ  Instruct the completer to omit private method names
        
        Specifically, when completing on ``object.<tab>``.
        
        When 2 [default]: all names that start with '_' will be excluded.
        
        When 1: all 'magic' names (``__foo__``) will be excluded.
        
        When 0: nothing will be excluded.
        s  Instruct the completer to use __all__ for the completion
        
        Specifically, when completing on ``object.<tab>``.
        
        When True: only those names in obj.__all__ will be included.
        
        When False [default]: the __all__ attribute is ignored 
        c   	   	   K   s1  t  |  _ t   |  _ | r9 d d l j j } | |  _ n	 d |  _ t	 j
 |  d | d | d | | g  |  _ | |  _ t j d  |  _ t j |  _ t j j d d  } | d k |  _ t j d k r |  j |  _ n |  j |  _ t j d  |  _ t j d  |  _ |  j |  j |  j |  j |  j  g |  _! d S(   sm  IPCompleter() -> completer

        Return a completer object suitable for use by the readline library
        via readline.set_completer().

        Inputs:

        - shell: a pointer to the ipython shell itself.  This is needed
          because this completer knows about magic functions, and those can
          only be accessed via the ipython instance.

        - namespace: an optional dict where completions are performed.

        - global_namespace: secondary optional dict for completions, to
          handle cases (such as IPython embedded inside functions) where
          both Python scopes are visible.

        use_readline : bool, optional
          If true, use the readline library.  This completer can still function
          without readline, though in that case callers must provide some extra
          information on each call about the current line.iNRM   RN   RJ   s   ([^\\] )t   TERMt   xtermt   dumbt   emacsR   s   ^[\w|\s.]+\(([^)]*)\).*s   [\s|\[]*(\w+)(?:\s*=\s*.*)(   R   R   ("   R   t   magic_escapeR2   R   t   IPython.utils.rlineimplt   utilst	   rlineimplR   R3   R   R7   RU   t   shellR<   R=   t   space_name_ret   globR"   t   environt   gett   dumb_terminalR   t   platformt   _clean_glob_win32t
   clean_globt   _clean_globt   docstring_sig_ret   docstring_kwd_ret   python_matchest   file_matchest   magic_matchest   python_func_kw_matchest   dict_key_matchest   matchers(	   R6   R   RM   RN   t   use_readlineRJ   RP   R   t   term(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR7   E  s0    		
		c         C   s   |  j  |  d S(   s_   
        Wrapper around the complete method for the benefit of emacs
        and pydb.
        i   (   RZ   (   R6   RX   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   all_completions  s    c         C   s   |  j  d |  S(   Ns   %s*(   R   (   R6   RX   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     s    c         C   s0   g  |  j  d |  D] } | j d d  ^ q S(   Ns   %s*s   \t   /(   R   R*   (   R6   RX   t   f(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     s    c         C   s  | j  d  r" | d } d } n d } |  j } t |  } d | k sU d | k r^ | } n^ y t |  d } WnG t k
 r | r | j |  d } q g  Sn t k
 r d } n X| r | t |  k r t } | | } } n t	 } t
 j j |  } | d k r9g  |  j d  D] } | t |  ^ qS|  j | j d d   }	 | rt |  }
 g  |	 D] } | | t | |
  ^ qm} n2 | r|	 } n# g  |	 D] } | t |  ^ q} g  | D]( } t
 j j |  r| d	 n | ^ q} | S(
   s  Match filenames, expanding ~USER type strings.

        Most of the seemingly convoluted logic in this completer is an
        attempt to handle filenames with spaces in them.  And yet it's not
        quite perfect, because Python's readline doesn't expose all of the
        GNU readline details needed for this to be done correctly.

        For a filename with a space in it, the printed completions will be
        only the parts after what's already been typed (instead of the
        full completions, as is normally done).  I don't think with the
        current (as of Python 2.3) Python readline it's possible to do
        better.t   !i   R   t   (R8   it   *s   \R   (   R   t   text_until_cursorR   R	   t
   ValueErrorRA   RW   R   R    R   R"   R#   R$   R   R   R*   R!   t   isdir(   R6   RX   t   text_prefixR   t   open_quotest   lsplitt   has_protectablest   text0R   t   m0t
   len_lsplitRU   t   x(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     sD    
			
*+	 5c   
      C   s   |  j  j j   } | d } | d } |  j } | | } | j |  } g  | D] } | j |  rO | | ^ qO }	 | j |  s |	 g  | D] } | j |  r | | ^ q 7}	 n  |	 S(   s   Match magicsRB   t   cell(   R   t   magics_managert   lsmagicR   t   lstripR   (
   R6   RX   t   lsmt   line_magicst   cell_magicst   pret   pre2t	   bare_textRn   t   comp(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     s    

	
,3c         C   s   d | k r ya |  j  |  } | j d  rl |  j rl |  j d k rQ d   } n	 d   } t | |  } n  Wq t k
 r g  } q Xn |  j |  } | S(   s'   Match attributes or global python namesRQ   i   c         S   s   t  j d |   d  k S(   Ns   .*\.__.*?__(   R<   Rd   R3   (   t   txt(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   <lambda>  s    c         S   s#   t  j d |  |  j d   d  k S(   Ns   \._.*?RQ   (   R<   Rd   t   rindexR3   (   R   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     s    (   RT   t   endswitht   omit__namest   filtert	   NameErrorRV   (   R6   RX   RU   t   no__name(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     s    	c         C   s   | d k r g  S| j   j   d } |  j j |  } | d k rH g  S| j   d j d  } g  } x$ | D] } | |  j j |  7} qn W| S(   s  Parse the first line of docstring for call signature.

        Docstring should be of the form 'min(iterable[, key=func])
'.
        It can also parse cython docstring of the form
        'Minuit.migrad(self, int ncall=10000, resume=True, int nsplit=1)'.
        i    t   ,N(	   R3   R   t
   splitlinesR   R|   t   groupsRA   R   t   findall(   R6   t   docRB   t   sigt   retR   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt!   _default_arguments_from_docstring  s    c         C   s/  | } g  } t  j |  r n t  j |  p9 t  j |  s t  j |  r | |  j t | d d   7} t | d d  p t | d d  } q t | d  r | j	 } q n  | |  j t | d d   7} y= t  j
 |  \ } } } } | r
| | t |  7} n  Wn t k
 rn Xt t |   S(   s_   Return the list of default arguments of obj if it is callable,
        or empty list otherwise.RF   R   R7   t   __new__t   __call__N(   t   inspectt	   isbuiltint
   isfunctiont   ismethodt   isclassR   Ru   R3   Rj   R   t
   getargspecR!   R   t   listt   set(   R6   Rq   t   call_objR   t   argst   _t   _1t   defaults(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   _default_arguments7  s*    		c         C   s&  d | k r g  Sy |  j  } Wn4 t k
 rS t j d t j t j B } |  _  n X| j |  j  } | j   t	 |  } d } xT | D]H } | d k r | d 8} q | d k r | d 7} | d k r Pq q q Wg  Sg  } t j d  j
 } xj t r]yK | j t |   | | d  s.| j   Pn  t |  d k sDPn  Wq t k
 rYPq Xq Wt |  d k r|  j | d  }	 n% |  j d j | d	 d	 d    }	 g  }
 xn |	 D]f } y |  j t | |  j   } Wn
 qn Xx1 | D]) } | j |  r|
 j d
 |  qqWqW|
 S(   s9   Match named parameters (kwargs) of the last open functionRQ   s   
                '.*?(?<!\\)' |    # single quoted strings or
                ".*?(?<!\\)" |    # double quoted strings or
                \w+          |    # identifier
                \S                # other characters
                i    t   )i   R   s   \w+$iNs   %s=(   t   _IPCompleter__funcParamsRegexR   R<   R=   t   VERBOSEt   DOTALLR   R   t   reverset   iterRd   R    R\   t   nextt   popt   StopIterationR!   RV   RT   R   R  Rh   RM   R   (   R6   RX   t   regexpt   tokenst
   iterTokenst   openPart   tokent   idst   isIdt   callableMatchest
   argMatchest   callableMatcht	   namedArgst   namedArg(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR   W  sZ     !
 
	
 	%c         C   sY  d   } y |  j  } WnL t k
 rd d } i t j | d  t 6t j | d  t 6} |  _  n X| |  j j |  j  } | d	 k r g  S| j
   \ } } y t | |  j  } Wn< t k
 r y t | |  j  } Wq t k
 r g  SXn X| |  }	 |	 s|	 St |	 | |  j j  \ }
 } } | s6| St |  j  t |  } | rq| j d  } | | } n | j   } } | | k rd } n | | | !} | j d  } d } |  j t |  j  } | | k r|
 r| j |
  r| t |
  } q| |
 7} n  | | k r:| j d  s:| d 7} q:n  g  | D] } | | | ^ qAS(
   s5   Match string keys in a dictionary, after e.g. 'foo[' c         S   s   t  |  t  s! t |  d d  rM y t |  j    SWq t k
 rI g  SXn4 t |  d d  sq t |  d d  r |  j j p g  Sg  S(   Nt   pandast	   DataFramet   numpyt   ndarrayt   void(   Rv   t   dictR   R   R_   Rm   t   dtypet   names(   Rq   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   get_keys  s    s  (?x)
            (  # match dict-referring expression wrt greedy setting
                %s
            )
            \[   # open bracket
            \s*  # and optional whitespace
            ([uUbB]?  # string prefix (r not handled)
                (?:   # unclosed string
                    '(?:[^']|(?<!\\)\\')*
                |
                    "(?:[^"]|(?<!\\)\\")*
                )
            )?
            $
            s   
                                  # identifiers separated by .
                                  (?!\d)\w+
                                  (?:\.(?!\d)\w+)*
                                  sF   
                                 .+
                                 i   R   i   R;   N(   t   _IPCompleter__dict_key_regexpsR   R<   R=   R   R    Rf   R|   R   R3   R   Rh   RM   Rm   RN   R   R   R5   R!   R~   t   endRg   R   (   R6   RX   R"  t   regexpst   dict_key_re_fmtRd   R@   R   Rq   R_   t   closing_quotet   token_offsetRU   t
   text_startt	   key_startt   completion_startt   leadingt   bracket_idxt   suft   continuationR   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     s\    				!	c         C   s   | j  d  } | d k rv | | d } y4 t j |  } d | j   r\ d | | g f SWqv t k
 rr } qv Xn  d g  f S(   uI  Match Latex-like syntax for unicode characters base 
        on the name of the character.
        
        This does  \GREEK SMALL LETTER ETA -> η

        Works only on valid python 3 identifier, or on combining characters that 
        will combine to form a valid identifier.
        
        Used on Python 3 only.
        s   \ii   t   au    (   t   rfindR   t   lookupt   isidentifierR   (   R6   RX   t   slashposR   R   R   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   unicode_name_matches  s    c         C   s   | j  d  } | d k rw | | } | t k rB | t | g f Sg  t D] } | j |  rI | ^ qI } | | f Sn  d g  f S(   u   Match Latex syntax for unicode characters.
        
        This does both \alp -> \alpha and \alpha -> α
        
        Used on Python 3 only.
        s   \iu    (   R1  R   R   (   R6   RX   R4  R   R   RU   (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   latex_matches  s    
(c         C   sf  |  j  } | j   s d  St   } | | _ | | _ | j d  d  d } | | _ |  j | _ | j	 |  j
  s |  j j |  j
 |  } n g  } x t j |  j j |  | |  j j |  j   D] } y | |  } | rIg  | D] } | j	 |  r | ^ q }	 |	 r|	 S| j   }
 g  | D]! } | j   j	 |
  r$| ^ q$SWq t k
 r]q Xq Wd  S(   Ni   i    (   Rg   t   stripR3   R/   RB   t   symbolRA   t   commandR   R   R   t   custom_completerst	   s_matchest	   itertoolst   chaint   flat_matchest   lowerR   (   R6   RX   RB   t   eventt   cmdt	   try_magicR:   Rt   t   rt   withcaset   text_low(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   dispatch_custom_completer*  s6    						(0c         C   s  | d k r3 | d k r$ t |  n	 t |  } n  t r | sE | n | |  } |  j |  \ } } | rt | | f Sd } g  } x? |  j t t f D]( }	 |	 |  \ } } | r | | f Sq Wn  | s |  j j | |  } n  | d k r | } n  | |  _	 |  j	 |  |  _
 g  |  j (|  j |  }
 |
 d k	 r?|
 |  _ n |  j rg  |  _ x{ |  j D]= } y |  j j | |   Wq[t j t j     q[Xq[Wn0 x- |  j D]" } | |  |  _ |  j rPqqWt t |  j  d t |  _ | |  j f S(   s6  Find completions for the given text and line context.

        Note that both the text and the line_buffer are optional, but at least
        one of them must be given.

        Parameters
        ----------
          text : string, optional
            Text to perform the completion on.  If not given, the line buffer
            is split using the instance's CompletionSplitter object.

          line_buffer : string, optional
            If not given, the completer attempts to obtain the current line
            buffer via readline.  This keyword allows clients which are
            requesting for text completions in non-readline contexts to inform
            the completer of the entire text.

          cursor_pos : int, optional
            Index of the cursor in the full line buffer.  Should be provided by
            remote frontends where kernel has no access to frontend state.

        Returns
        -------
        text : str
          Text that was actually used in the completion.

        matches : list
          A list of completion matches.
        R   R   N(   R3   R!   R   R6  R5  R   R   R   RE   Rg   R   RU   RF  t   merge_completionsR   t   extendR   t
   excepthookt   exc_infot   sortedR   R.   (   R6   RX   Rg   RC   t	   base_textt
   latex_textR6  t	   name_textt   name_matchest   metht
   custom_rest   matcher(    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyRZ   U  sH    "'
		
			c         C   s   | d k r |  j  j   |  _ } |  j  j   } |  j pC | j   sg |  j  j d  t j j	   d St } | r y |  j | | |  Wq d d l } | j   q Xq |  j | | |  n  y |  j | SWn t k
 r d SXd S(   sp  Return the state-th possible completion for 'text'.

        This is called successively with state == 0, 1, 2, ... until it
        returns None.  The completion should begin with 'text'.

        Parameters
        ----------
          text : string
            Text to perform the completion on.

          state : int
            Counter used by readline.
        i    s   	iN(   R   t   get_line_bufferRg   t
   get_endidxR   R7  t   insert_textR   t   stdoutt   flushR3   R   RZ   t	   tracebackt	   print_excRU   RW   (   R6   RX   RY   Rg   RC   t   DEBUGRX  (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt
   rlcomplete  s&     (   i    i   i   N(   R0   R1   RF   R   R   R    RG  R   R   R   Ri   R3   R7   R   R   R   R   R   R   R   R  R   R   R5  R6  RF  RZ   R[  (    (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyR     s2   	
	
			G				S				 	>	f			+a(8   RF   RR   R   R   R<  R]   R"   R<   R   R   R   t   traitlets.config.configurableR    t   IPython.core.errorR   t   IPython.core.inputsplitterR   t   IPython.core.latex_symbolsR   R   t   IPython.utilsR   R   t   IPython.utils.decoratorsR   t   IPython.utils.dir2R   t   IPython.utils.processR	   t   IPython.utils.py3compatR
   R   R   t	   traitletsR   R   Rc   R   R   R   R   R)   R+   R.   t   objectR/   RG   R   R2   R   Rk   R   R   R   R   R   (    (    (    sN   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/IPython/core/completer.pyt   <module>0   sT   				(	
	%3	
	3			