
    e?                         d Z ddlZddlZddlZddlZej                  d   dk\  ZereZ	dZ
dZ G d de      Zej                  fdZd	 Zdd
ZddZy)zEGeneric wrapper for read-eval-print-loops, a.k.a. interactive shells
    N   z[PEXPECT_PROMPT>z[PEXPECT_PROMPT+c                   4    e Zd ZdZeedfdZd ZddZddZ	y)REPLWrappera  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                    t        |t              rt        j                  |dd      | _        n|| _        | j                  j
                  r5| j                  j                  d       | j                  j                          ||| _        n)| j                  ||j                  ||             || _        || _        | j                          || j                  |       y y )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__zREPLWrapper.__init__!   s     lJ/ |%'RDJ%DJ::?? JJu%JJ!!# %DKOOK%,,Z9LMO$DK#6 %^, &    c                 p    | j                   j                  |       | j                   j                  |       y )N)r   expectsendline)r   r   r   s      r   r   zREPLWrapper.set_prompt<   s&    

+&

M*r    c                 j    | j                   j                  | j                  | j                  g||      S )N)timeoutasync_)r   expect_exactr   r   )r   r%   r&   s      r   r   zREPLWrapper._expect_prompt@   s6    zz&&T5M5M'N/6v ' G 	Gr    c                    |j                         }|j                  d      r|j                  d       |st        d      |rddlm}  || ||      S g }| j                  j                  |d          |dd D ]T  }| j                  |       |j                  | j                  j                         | j                  j                  |       V | j                  |      dk(  rI| j                  j                  t        j                         | j                  d       t        d	|z         dj                  || j                  j                  gz         S )
a0  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_asyncr,   r   r#   r   beforekillsignalSIGINTjoin)r   commandr%   r&   cmdlinesr,   reslines           r   r   zREPLWrapper.run_commandD   s/     %%'D!OOB3446)$'BB

HQK(QRL 	&D0JJtzz(()JJ%	& w/14JJOOFMM**R&' ( (xxtzz001122r    )F)
__name__
__module____qualname____doc__PEXPECT_PROMPTPEXPECT_CONTINUATION_PROMPTr   r   r   r    r    r   r   r      s'      +%@ $-6+G)3r    r   c                     t        | dd      S )z>Start a Python shell and return a :class:`REPLWrapper` object.z>>> z(import sys; sys.ps1={0!r}; sys.ps2={1!r})r   )r7   s    r   pythonrD   o   s    w)TUUr    c                     t        j                  | |dd      }t        d d |z   t        dd  z   }t        d d |z   t        dd  z   }dj	                  ||      }t        |d|d      S )	NFr   r      z%PS1='{0}' PS2='{1}' PROMPT_COMMAND=''z\$zexport PAGER=cat)r   )r   r   r@   rA   r   r   )r7   argsnon_printable_insertr   ps1ps2r   s          r   _repl_shrK   s   s    MM'4egFE !
3
3nQR6H
HC
%bq
),@
@C^_`_aCb
bC<CCCMMufm&8: :r    c                     t         j                  j                  t         j                  j                  t              d      }t        | d|gd      S )z<Start a bash shell and return a :class:`REPLWrapper` object.z	bashrc.shz--rcfilez\[\]rH   )ospathr6   dirname__file__rK   )r7   bashrcs     r   bashrS      s7    WW\\"''//(3[AFGj&1QQr    c                 0    t        | t        |      d      S )z;Start a zsh shell and return a :class:`REPLWrapper` object.z%(!..)rM   )rK   list)r7   rG   s     r   zshrV      s    GT$ZhGGr    )rS   )rV   )z--no-rcsz-Vz+Z)r?   os.pathrN   r4   sysr   version_infoPY3strr   r@   rA   objectr   
executablerD   rK   rS   rV   rB   r    r   <module>r^      sm      
 
aJ$1 \3& \3| >> V:R
Hr    