ó
’›V]c           @@  s   d  Z  d d l m Z d d l Z d d l m 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 e Z e d „ Z d „  Z d S(   s   
Utilities for end-users.
i    (   t   absolute_importN(   t
   namedtuple(   t   Interpreterc         @  sÞ   t  r( t j d d d d d t j ƒ n  d t f ‡  f d †  ƒ  Y} y d d	 l } d d	 l } Wn t k
 rx d
 GHnb X| j | ƒ  j	 ƒ | j
 d ƒ | j
 d ƒ | j
 d ƒ | j
 d ƒ | j
 d ƒ | j d ƒ d	 S(   sk  
    Install Jedi completer to :mod:`readline`.

    This function setups :mod:`readline` to use Jedi in Python interactive
    shell.  If you want to use a custom ``PYTHONSTARTUP`` file (typically
    ``$HOME/.pythonrc.py``), you can add this piece of code::

        try:
            from jedi.utils import setup_readline
            setup_readline()
        except ImportError:
            # Fallback to the stdlib readline completer if it is installed.
            # Taken from http://docs.python.org/2/library/rlcompleter.html
            print("Jedi is not installed, falling back to readline")
            try:
                import readline
                import rlcompleter
                readline.parse_and_bind("tab: complete")
            except ImportError:
                print("Readline is not installed either. No tab completion is enabled.")

    This will fallback to the readline completer if Jedi is not installed.
    The readline completer will only complete names in the global namespace,
    so for example::

        ran<TAB>

    will complete to ``range``

    with both Jedi and readline, but::

        range(10).cou<TAB>

    will show complete to ``range(10).count`` only with Jedi.

    You'll also need to add ``export PYTHONSTARTUP=$HOME/.pythonrc.py`` to
    your shell profile (usually ``.bash_profile`` or ``.profile`` if you use
    bash).

    t   filenames   /tmp/jedi.logt   filemodet   at   levelt   JediRLc           @  s   e  Z ‡  f d  †  Z RS(   c         @  s  | d k rä t  j j d t j ƒ  ƒ z¨ y€ t j d t | ƒ ƒ t | ˆ  j	 g ƒ } | j
 ƒ  } t j d | ƒ g  | D]$ } | t | ƒ | j  | j ^ qz |  _ Wn! t j d t j ƒ  ƒ ‚  n XWd t  j j d ƒ Xn  y |  j | SWn t k
 rd SXd S(   s  
            This complete stuff is pretty weird, a generator would make
            a lot more sense, but probably due to backwards compatibility
            this is still the way how it works.

            The only important part is stuff in the ``state == 0`` flow,
            everything else has been copied from the ``rlcompleter`` std.
            library module.
            i    s   Start REPL completion: s   REPL completions: %ss   REPL Completion error:
N(   t   syst   patht   insertt   ost   getcwdt   loggingt   debugt   reprR   t   __dict__t   completionst   lent   _like_name_lengtht   name_with_symbolst   matchest   errort	   tracebackt
   format_exct   popt
   IndexErrort   None(   t   selft   textt   statet   interpreterR   t   c(   t   namespace_module(    s)   lib/python2.7/site-packages/jedi/utils.pyt   completeE   s$    
 5(   t   __name__t
   __module__R"   (    (   R!   (    s)   lib/python2.7/site-packages/jedi/utils.pyR   D   s   i    Ns$   Jedi: Module readline not available.s   tab: completes   set completion-ignore-case ons   set show-all-if-unmodifieds   set show-all-if-ambiguous ons&   set completion-prefix-display-length 2t    (   t   READLINE_DEBUGR   t   basicConfigt   DEBUGt   objectt   rlcompletert   readlinet   ImportErrort   set_completerR"   t   parse_and_bindt   set_completer_delims(   R!   R   R*   R+   (    (   R!   s)   lib/python2.7/site-packages/jedi/utils.pyt   setup_readline   s$    )	#	c          C@  sr   t  d d ƒ }  d d l m } t j d | ƒ } |  g  t | ƒ D]* \ } } | d k r_ | n	 t | ƒ ^ qA Œ  S(   s_   
    Returns a namedtuple of Jedi's version, similar to Python's
    ``sys.version_info``.
    t   Versions   major, minor, microi    (   t   __version__s
   [a-z]+|\d+i   (   R   t   jediR2   t   ret   findallt	   enumeratet   int(   R1   R2   t   tuplt   it   x(    (    s)   lib/python2.7/site-packages/jedi/utils.pyt   version_info~   s    (   t   __doc__t
   __future__R    t   __main__t   collectionsR   R   R   R4   R   R   R3   R   t   FalseR&   R0   R;   (    (    (    s)   lib/python2.7/site-packages/jedi/utils.pyt   <module>   s   j