
    e?                         S r SSKrSSKrSSKrSSKr\R                  S   S:  r\(       a  \r	Sr
Sr " S S\5      r\R                  4S jrS	 rSS
 jrSS jrg)zEGeneric wrapper for read-eval-print-loops, a.k.a. interactive shells
    N   z[PEXPECT_PROMPT>z[PEXPECT_PROMPT+c                   B    \ rS rSrSr\\S4S jrS rS	S jr	S	S jr
Srg)
REPLWrapper   a  Wrapper for a REPL.

:param cmd_or_spawn: This can either be an instance of :class:`pexpect.spawn`
  in which a REPL has already been started, or a str command to start a new
  REPL process.
:param str orig_prompt: The prompt to expect at first.
:param str prompt_change: A command to change the prompt to something more
  unique. If this is ``None``, the prompt will not be changed. This will
  be formatted with the new and continuation prompts as positional
  parameters, so you can use ``{}`` style formatting to insert them into
  the command.
:param str new_prompt: The more unique prompt to expect after the change.
:param str extra_init_cmd: Commands to do extra initialisation, such as
  disabling pagers.
Nc                    [        U[        5      (       a  [        R                  " USSS9U l        OXl        U R                  R
                  (       a5  U R                  R                  S5        U R                  R                  5         Uc  X l        O'U R                  UUR                  XE5      5        X@l        XPl        U R                  5         Ub  U R                  U5        g g )NFutf-8echoencoding)
isinstance
basestringpexpectspawnchildr
   setecho
waitnoechoprompt
set_promptformatcontinuation_prompt_expect_promptrun_command)selfcmd_or_spawnorig_promptprompt_change
new_promptr   extra_init_cmds          2/usr/lib/python3/dist-packages/pexpect/replwrap.py__init__REPLWrapper.__init__!   s     lJ// |%'RDJ%J::?? JJu%JJ!!# %KOOK%,,ZMO$K#6 %^, &    c                 p    U R                   R                  U5        U R                   R                  U5        g )N)r   expectsendline)r   r   r   s      r   r   REPLWrapper.set_prompt<   s&    

+&

M*r"   c                 b    U R                   R                  U R                  U R                  /XS9$ )N)timeoutasync_)r   expect_exactr   r   )r   r(   r)   s      r   r   REPLWrapper._expect_prompt@   s4    zz&&T5M5M'N/6 ' G 	Gr"   c                    UR                  5       nUR                  S5      (       a  UR                  S5        U(       d  [        S5      eU(       a  SSKJn  U" XU5      $ / nU R                  R                  US   5        USS  HR  nU R                  US9  UR                  U R                  R                  5        U R                  R                  U5        MT     U R                  US9S:X  aF  U R                  R                  [        R                  5        U R                  SS9  [        S	U-   5      eSR                  X`R                  R                  /-   5      $ )
a  Send a command to the REPL, wait for and return output.

:param str command: The command to send. Trailing newlines are not needed.
  This should be a complete block of input that will trigger execution;
  if a continuation prompt is found after sending input, :exc:`ValueError`
  will be raised.
:param int timeout: How long to wait for the next prompt. -1 means the
  default from the :class:`pexpect.spawn` object (default 30 seconds).
  None means to wait indefinitely.
:param bool async_: On Python 3.4, or Python 3.3 with asyncio
  installed, passing ``async_=True`` will make this return an
  :mod:`asyncio` Future, which you can yield from to get the same
  result that this method would normally give directly.

 zNo command was given   )repl_run_command_asyncr   N)r(   z2Continuation prompt found - input was incomplete:
)
splitlinesendswithappend
ValueError_asyncr0   r   r%   r   beforekillsignalSIGINTjoin)r   commandr(   r)   cmdlinesr0   reslines           r   r   REPLWrapper.run_commandD   s)     %%'D!!OOB3446)$'BB

HQK(QRLD0JJtzz(()JJ% ! w/14JJOOFMM**R&' ( (xxzz001122r"   )r   r   r   )F)__name__
__module____qualname____firstlineno____doc__PEXPECT_PROMPTPEXPECT_CONTINUATION_PROMPTr    r   r   r   __static_attributes__ r"   r   r   r      s'      +%@ $-6+G)3r"   r   c                     [        U SS5      $ )z>Start a Python shell and return a :class:`REPLWrapper` object.z>>> z(import sys; sys.ps1={0!r}; sys.ps2={1!r})r   )r;   s    r   pythonrK   o   s    w)TUUr"   c                     [         R                  " XSSS9n[        S S U-   [        SS  -   n[        S S U-   [        SS  -   nSR	                  XE5      n[        USUSS9$ )	NFr   r	      z%PS1='{0}' PS2='{1}' PROMPT_COMMAND=''z\$zexport PAGER=cat)r   )r   r   rF   rG   r   r   )r;   argsnon_printable_insertr   ps1ps2r   s          r   _repl_shrR   s   s{    MM'egFE !
3
3nQR6H
HC
%bq
),@
@C^_`_aCb
bC<CCCMMufm&8: :r"   c                     [         R                  R                  [         R                  R                  [        5      S5      n[        U SU/SS9$ )z<Start a bash shell and return a :class:`REPLWrapper` object.z	bashrc.shz--rcfilez\[\]rO   )ospathr:   dirname__file__rR   )r;   bashrcs     r   bashrZ      s7    WW\\"''//(3[AFGj&1QQr"   c                 *    [        U [        U5      SS9$ )z;Start a zsh shell and return a :class:`REPLWrapper` object.z%(!..)rT   )rR   list)r;   rN   s     r   zshr]      s    GT$ZhGGr"   )rZ   )r]   )z--no-rcsz-Vz+Z)rE   os.pathrU   r8   sysr   version_infoPY3strr   rF   rG   objectr   
executablerK   rR   rZ   r]   rI   r"   r   <module>re      sm      
 
aJ$1 \3& \3| >> V:R
Hr"   