eaiovnaovbqoebvqoeavibavo 3 .]2@sjdZddlZddlZddlZddlZejddkZer:eZ dZ dZ Gddde Z d d dZd d d ZdS)zEGeneric wrapper for read-eval-print-loops, a.k.a. interactive shells Nz[PEXPECT_PROMPT>z[PEXPECT_PROMPT+c@s<eZdZdZeedfddZddZd dd Zdd d Z dS) REPLWrapperaWrapper 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. NcCst|trtj|ddd|_n||_|jjrB|jjd|jj|dkrR||_n|j ||j ||||_||_ |j |dk r|j |dS)NFzutf-8)echoencoding) isinstance basestringpexpectspawnchildrZsetechoZ waitnoechoprompt set_promptformatcontinuation_prompt_expect_prompt run_command)selfZ cmd_or_spawn orig_prompt prompt_changeZ new_promptrextra_init_cmdr/usr/lib/python3.6/replwrap.py__init__!s   zREPLWrapper.__init__cCs|jj||jj|dS)N)r expectsendline)rrrrrrr <s zREPLWrapper.set_promptcCs|jj|j|jg|dS)N)timeout)r Z expect_exactr r)rrrrrr@szREPLWrapper._expect_promptcCs|j}|jdr|jd|s(tdg}|jj|dx:|ddD]*}|j|d|j|jj|jj|qJW|j|ddkr|jjt j |jddtd|dj ||jjgS) aSend 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.  zNo command was givenrrN)rz2Continuation prompt found - input was incomplete: ) splitlinesendswithappend ValueErrorr rrZbeforekillsignalSIGINTjoin)rcommandrZcmdlinesreslinerrrrDs"     zREPLWrapper.run_command)r)r))r)) __name__ __module__ __qualname____doc__PEXPECT_PROMPTPEXPECT_CONTINUATION_PROMPTrr rrrrrrrs  rpythoncCs t|ddS)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&rrrr0gsbashcCstjjtjjtd}tj|d|gddd}tdddtdd}tdddtdd}d j ||}t |d |d d S) zsV