
    MhH                     h    d 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
 dZedfdZd ZdS )z
Utilities for end-users.
    N)
namedtuple)InterpreterFc                     t           r!t          j        ddt          j                    G  fdd          }	 ddl}ddl}|                     |            j                   |                    d           |                    d	           |                    d
           |                    d           |                    d           |	                    d           dS # t          $ r t          d           Y dS w xY w)a  
    This function sets up :mod:`readline` to use Jedi in a 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
        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.")
        else:
            setup_readline()

    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 Jedi the following code::

        range(10).cou<TAB>

    will complete to ``range(10).count``, this does not work with the default
    cPython :mod:`readline` completer.

    You will also need to add ``export PYTHONSTARTUP=$HOME/.pythonrc.py`` to
    your shell profile (usually ``.bash_profile`` or ``.profile`` if you use
    bash).
    z/tmp/jedi.loga)filenamefilemodelevelc                       e Zd Z fdZdS )setup_readline.<locals>.JediRLc                    |dk    rt           j                            dt          j                               	 t          j        dt                    z              t          j	        g          }|
                              }t          j        d|           fd|D             | _        n.#  t          j        dt          j                    z               xY w	 t           j                            d           n$# t           j                            d           w xY w	 | j        |         S # t           $ r Y dS w xY w)a  
            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.
            r   zStart REPL completion: )fuzzyzREPL completions: %sc                 ^    g | ])}d t                    |j        z
           |j        z   *S )N)len_like_name_lengthname_with_symbols).0ctexts     J/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jedi/utils.py
<listcomp>z;setup_readline.<locals>.JediRL.complete.<locals>.<listcomp>Y   sJ     $ $ $ =c$ii!*===>ATT$ $ $    zREPL Completion error:
N)syspathinsertosgetcwdloggingdebugreprr   __dict__completematcheserror	traceback
format_excpop
IndexError)selfr   stateinterpretercompletionsr   namespace_modules    `   r   r!   z'setup_readline.<locals>.JediRL.completeE   sF    zz29;;///$M";d4jj"HIII"-d5E5N4O"P"PK"-"6"6U"6"C"CKM"8+FFF$ $ $ $!,$ $ $DLLM"<y?S?U?U"UVVV ! HLLOOOOCHLLOOOO|E**   tts0   A8B5 4D 5+C  D !D%)D6 6
EEN)__name__
__module____qualname__r!   )r   r,   s   r   JediRLr   D   s3         	  	  	  	  	  	  	  	r   r0   r   Nztab: completezset completion-ignore-case onzset show-all-if-unmodifiedzset show-all-if-ambiguous onz&set completion-prefix-display-length 2 z$Jedi: Module readline not available.)READLINE_DEBUGr   basicConfigDEBUGrlcompleterreadlineset_completerr!   parse_and_bindset_completer_delimsImportErrorprint)r,   r   r0   r5   r6   s   ``   r   setup_readliner<      s^   T  
$-	
 	
 	
 	
! ! ! ! ! ! ! ! ! ! !F*
 	 	vvxx0111000 ?@@@ <=== >??? HIII%%b)))))  6 6 645555556s   C& &DDc                      t          dd          } ddlm} t          j        d|          } | d t          |          D              S )z_
    Returns a namedtuple of Jedi's version, similar to Python's
    ``sys.version_info``.
    Versionzmajor, minor, micror   )__version__z
[a-z]+|\d+c                 B    g | ]\  }}|d k    r|nt          |          S )   )int)r   ixs      r   r   z version_info.<locals>.<listcomp>   s.    IIIA!q&&QQc!ffIIIr   )r   jedir?   refindall	enumerate)r>   r?   tupls      r   version_inforJ   ~   sY    
 $9::G      :m[11D7II4IIIJJr   )__doc____main__collectionsr   r   r$   rF   r   r   rE   r   r2   r<   rJ    r   r   <module>rO      s      " " " " " "      				 				 



        %-E h* h* h* h*VK K K K Kr   