ó
æNXc           @   s–   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 rX e Z	 n  d Z
 d Z d e f d „  ƒ  YZ d	 d
 „ Z d d „ Z d S(   sE   Generic wrapper for read-eval-print-loops, a.k.a. interactive shells
iÿÿÿÿNi    i   u   [PEXPECT_PROMPT>u   [PEXPECT_PROMPT+t   REPLWrapperc           B   sA   e  Z d  Z e e d d „ Z d „  Z d d „ Z d d „ Z	 RS(   sÿ  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.
    c         C   sÕ   t  | t ƒ r0 t j | d t d d ƒ|  _ n	 | |  _ |  j j re |  j j t ƒ |  j j ƒ  n  | d  k r} | |  _
 n% |  j | | j | | ƒ ƒ | |  _
 | |  _ |  j ƒ  | d  k	 rÑ |  j | ƒ n  d  S(   Nt   echot   encodings   utf-8(   t
   isinstancet
   basestringt   pexpectt   spawnt   Falset   childR   t   setechot
   waitnoechot   Nonet   promptt
   set_promptt   formatt   continuation_promptt   _expect_promptt   run_command(   t   selft   cmd_or_spawnt   orig_promptt   prompt_changet
   new_promptR   t   extra_init_cmd(    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/pexpect/replwrap.pyt   __init__!   s    !				
c         C   s$   |  j  j | ƒ |  j  j | ƒ d  S(   N(   R   t   expectt   sendline(   R   R   R   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/pexpect/replwrap.pyR   <   s    iÿÿÿÿc         C   s"   |  j  j |  j |  j g d | ƒS(   Nt   timeout(   R   t   expect_exactR   R   (   R   R   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/pexpect/replwrap.pyR   @   s    c         C   s
  | j  ƒ  } | j d ƒ r+ | j d ƒ n  | s@ t d ƒ ‚ n  g  } |  j j | d ƒ xE | d D]9 } |  j d | ƒ | j |  j j ƒ |  j j | ƒ qe W|  j d | ƒ d k rð |  j j t	 j
 ƒ |  j d d ƒ t d | ƒ ‚ n  d j | |  j j g ƒ S(	   s  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.
        s   
t    s   No command was giveni    i   R   s2   Continuation prompt found - input was incomplete:
u    (   t
   splitlinest   endswitht   appendt
   ValueErrorR   R   R   t   beforet   killt   signalt   SIGINTt   join(   R   t   commandR   t   cmdlinest   rest   line(    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/pexpect/replwrap.pyR   D   s"    N(
   t   __name__t
   __module__t   __doc__t   PEXPECT_PROMPTt   PEXPECT_CONTINUATION_PROMPTR   R   R   R   R   (    (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/pexpect/replwrap.pyR       s   	t   pythonc         C   s   t  |  d d ƒ S(   s>   Start a Python shell and return a :class:`REPLWrapper` object.u   >>> u(   import sys; sys.ps1={0!r}; sys.ps2={1!r}(   R    (   R'   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/pexpect/replwrap.pyR0   g   s    t   bashc         C   s[   t  j j t  j j t ƒ d ƒ } t j |  d | g d t d d ƒ} t | d d d d	 ƒS(
   s<   Start a bash shell and return a :class:`REPLWrapper` object.s	   bashrc.shs   --rcfileR   R   s   utf-8u   \$u%   PS1='{0}' PS2='{1}' PROMPT_COMMAND=''R   s   export PAGER=cat(	   t   ost   pathR&   t   dirnamet   __file__R   R   R   R    (   R'   t   bashrcR   (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/pexpect/replwrap.pyR1   k   s
    !	(   R-   t   os.pathR2   R$   t   sysR   t   version_infot   PY3t   strR   R.   R/   t   objectR    R0   R1   (    (    (    sH   /data/av2000/mvv/env_mvv/lib/python2.7/site-packages/pexpect/replwrap.pyt   <module>   s   	V