ó
Pñ`cc           @   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   sG   e  Z d  Z e e d d „ Z d „  Z d e d „ Z	 d e 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(    (    s/   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   (    (    s/   lib/python2.7/site-packages/pexpect/replwrap.pyR   <   s    iÿÿÿÿc         C   s(   |  j  j |  j |  j g d | d | ƒS(   Nt   timeoutt   async_(   R   t   expect_exactR   R   (   R   R   R   (    (    s/   lib/python2.7/site-packages/pexpect/replwrap.pyR   @   s    c         C   s0  | j  ƒ  } | j d ƒ r+ | j d ƒ n  | s@ t d ƒ ‚ n  | rf d d l m } | |  | | ƒ Sg  } |  j j | d ƒ xE | d D]9 } |  j d | ƒ | j |  j j	 ƒ |  j j | ƒ q‹ W|  j d | ƒ d k r|  j j
 t j ƒ |  j d d ƒ t d | ƒ ‚ n  d	 j | |  j j	 g ƒ S(
   s0  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.
        s   
t    s   No command was giveni   (   t   repl_run_command_asynci    R   s2   Continuation prompt found - input was incomplete:
u    (   t
   splitlinest   endswitht   appendt
   ValueErrort   _asyncR   R   R   R   t   beforet   killt   signalt   SIGINTt   join(   R   t   commandR   R   t   cmdlinesR   t   rest   line(    (    s/   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   R   (    (    (    s/   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*   (    (    s/   lib/python2.7/site-packages/pexpect/replwrap.pyR3   o   s    t   bashc         C   s™   t  j j t  j j t ƒ d ƒ } t j |  d | g d t d d ƒ} t d  d t d } t	 d  d t	 d } d j
 | | ƒ } t | d	 | d
 d ƒS(   s<   Start a bash shell and return a :class:`REPLWrapper` object.s	   bashrc.shs   --rcfileR   R   s   utf-8i   u   \[\]u%   PS1='{0}' PS2='{1}' PROMPT_COMMAND=''u   \$R   s   export PAGER=cat(   t   ost   pathR)   t   dirnamet   __file__R   R   R   R1   R2   R   R    (   R*   t   bashrcR   t   ps1t   ps2R   (    (    s/   lib/python2.7/site-packages/pexpect/replwrap.pyR4   s   s    !	(   R0   t   os.pathR5   R'   t   sysR   t   version_infot   PY3t   strR   R1   R2   t   objectR    R3   R4   (    (    (    s/   lib/python2.7/site-packages/pexpect/replwrap.pyt   <module>   s   	^