Python sys.ps2() Examples

The following are code examples for showing how to use sys.ps2(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don't like. You can also save this page to your account.

Example 1
Project: pythonVSCode   Author: DonJayamanne   File: visualstudio_py_repl.py    (license) View Source Project 6 votes vote down vote up
def execution_loop(self):
        """loop on the main thread which is responsible for executing code"""

        if sys.platform == 'cli' and sys.version_info[:3] < (2, 7, 1):
            # IronPython doesn't support thread.interrupt_main until 2.7.1
            import System
            self.main_thread = System.Threading.Thread.CurrentThread

        # save ourselves so global lookups continue to work (required pre-2.6)...
        cur_modules = set()
        try:
            cur_ps1 = sys.ps1
            cur_ps2 = sys.ps2
        except:
            # CPython/IronPython don't set sys.ps1 for non-interactive sessions, Jython and PyPy do
            sys.ps1 = cur_ps1 = '>>> '
            sys.ps2 = cur_ps2 = '... '

        self.send_prompt(cur_ps1, cur_ps2, allow_multiple_statements=False)

        while True:
            exit, cur_modules, cur_ps1, cur_ps2 = self.run_one_command(cur_modules, cur_ps1, cur_ps2)
            if exit:
                return 
Example 2
Project: pythonVSCode   Author: DonJayamanne   File: visualstudio_py_repl.py    (license) View Source Project 6 votes vote down vote up
def execution_loop(self):
        """loop on the main thread which is responsible for executing code"""

        if sys.platform == 'cli' and sys.version_info[:3] < (2, 7, 1):
            # IronPython doesn't support thread.interrupt_main until 2.7.1
            import System
            self.main_thread = System.Threading.Thread.CurrentThread

        # save ourselves so global lookups continue to work (required pre-2.6)...
        cur_modules = set()
        try:
            cur_ps1 = sys.ps1
            cur_ps2 = sys.ps2
        except:
            # CPython/IronPython don't set sys.ps1 for non-interactive sessions, Jython and PyPy do
            sys.ps1 = cur_ps1 = '>>> '
            sys.ps2 = cur_ps2 = '... '

        self.send_prompt(cur_ps1, cur_ps2, allow_multiple_statements=False)

        while True:
            exit, cur_modules, cur_ps1, cur_ps2 = self.run_one_command(cur_modules, cur_ps1, cur_ps2)
            if exit:
                return 
Example 3
Project: watchmen   Author: lycclsltt   File: replwrap.py    (license) View Source Project 6 votes vote down vote up
def bash(command="bash"):
    """Start a bash shell and return a :class:`REPLWrapper` object."""
    bashrc = os.path.join(os.path.dirname(__file__), 'bashrc.sh')
    child = pexpect.spawn(command, ['--rcfile', bashrc], echo=False,
                          encoding='utf-8')

    # If the user runs 'env', the value of PS1 will be in the output. To avoid
    # replwrap seeing that as the next prompt, we'll embed the marker characters
    # for invisible characters in the prompt; these show up when inspecting the
    # environment variable, but not when bash displays the prompt.
    ps1 = PEXPECT_PROMPT[:5] + u'\[\]' + PEXPECT_PROMPT[5:]
    ps2 = PEXPECT_CONTINUATION_PROMPT[:5] + u'\[\]' + PEXPECT_CONTINUATION_PROMPT[5:]
    prompt_change = u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''".format(ps1, ps2)

    return REPLWrapper(child, u'\$', prompt_change,
                       extra_init_cmd="export PAGER=cat") 
Example 4
Project: roborepl   Author: typesupply   File: roboREPL.py    (license) View Source Project 6 votes vote down vote up
def executeLine_(self, line):
        if line == "help":
            self.writeStdout_(documentation)
            self.writeCode_("\n")
            return
        self._history.append(line)
        self._historyIndex = len(self._history)
        save = (sys.stdout, sys.stderr, self.rawText())
        sys.stdout = self._stdout
        sys.stderr = self._stderr
        more = False
        try:
            more = self._console.push(line)
            if more:
                self._prompt = sys.ps2
            else:
                self._prompt = sys.ps1
        except:
            self._prompt = sys.ps1
        finally:
            sys.stdout, sys.stderr, previousRawText = save
            self.previousOutput = self.rawText()[len(previousRawText):-1]

    # Selection, Insertion Point 
Example 5
Project: leetcode   Author: thomasyimgit   File: replwrap.py    (license) View Source Project 6 votes vote down vote up
def bash(command="bash"):
    """Start a bash shell and return a :class:`REPLWrapper` object."""
    bashrc = os.path.join(os.path.dirname(__file__), 'bashrc.sh')
    child = pexpect.spawn(command, ['--rcfile', bashrc], echo=False,
                          encoding='utf-8')

    # If the user runs 'env', the value of PS1 will be in the output. To avoid
    # replwrap seeing that as the next prompt, we'll embed the marker characters
    # for invisible characters in the prompt; these show up when inspecting the
    # environment variable, but not when bash displays the prompt.
    ps1 = PEXPECT_PROMPT[:5] + u'\[\]' + PEXPECT_PROMPT[5:]
    ps2 = PEXPECT_CONTINUATION_PROMPT[:5] + u'\[\]' + PEXPECT_CONTINUATION_PROMPT[5:]
    prompt_change = u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''".format(ps1, ps2)

    return REPLWrapper(child, u'\$', prompt_change,
                       extra_init_cmd="export PAGER=cat") 
Example 6
Project: leetcode   Author: thomasyimgit   File: interactiveshell.py    (license) View Source Project 6 votes vote down vote up
def init_prompts(self):
        # Set system prompts, so that scripts can decide if they are running
        # interactively.
        sys.ps1 = 'In : '
        sys.ps2 = '...: '
        sys.ps3 = 'Out: ' 
Example 7
Project: ml-utils   Author: LinxiFan   File: repl.py    (license) View Source Project 6 votes vote down vote up
def _bash_repl(command="bash", remove_ansi=True):
    """Start a bash shell and return a :class:`REPLWrapper` object."""
    # `repl_bashrc.sh` suppresses user-defined PS1
    bashrc = os.path.join(os.path.dirname(__file__), 'repl_bashrc.sh')
    child = pexpect.spawn(command, ['--rcfile', bashrc], echo=False,
                          encoding='utf-8')

    # If the user runs 'env', the value of PS1 will be in the output. To avoid
    # replwrap seeing that as the next prompt, we'll embed the marker characters
    # for invisible characters in the prompt; these show up when inspecting the
    # environment variable, but not when bash displays the prompt.
    ps1 = PEXPECT_PROMPT[:5] + u'\[\]' + PEXPECT_PROMPT[5:]
    ps2 = PEXPECT_CONTINUATION_PROMPT[:5] + u'\[\]' + PEXPECT_CONTINUATION_PROMPT[5:]
    prompt_change = u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''".format(ps1, ps2)

    return REPLWrapper(child, u'\$', prompt_change,
                       remove_ansi=remove_ansi,
                       extra_init_cmd="export PAGER=cat") 
Example 8
Project: remoteControlPPT   Author: htwenning   File: interact.py    (license) View Source Project 6 votes vote down vote up
def AppendToPrompt(self,bufLines, oldPrompt = None):
		" Take a command and stick it at the end of the buffer (with python prompts inserted if required)."
		self.flush()
		lastLineNo = self.GetLineCount()-1
		line = self.DoGetLine(lastLineNo)
		if oldPrompt and line==oldPrompt:
			self.SetSel(self.GetTextLength()-len(oldPrompt), self.GetTextLength())
			self.ReplaceSel(sys.ps1)
		elif (line!=str(sys.ps1)):
			if len(line)!=0: self.write('\n')
			self.write(sys.ps1)
		self.flush()
		self.idle.text.mark_set("iomark", "end-1c")
		if not bufLines:
			return
		terms = (["\n" + sys.ps2] * (len(bufLines)-1)) + ['']
		for bufLine, term in zip(bufLines, terms):
			if bufLine.strip():
				self.write( bufLine + term )
		self.flush() 
Example 9
Project: remoteControlPPT   Author: htwenning   File: interact.py    (license) View Source Project 6 votes vote down vote up
def HookHandlers(self):
		# Hook menu command (executed when a menu item with that ID is selected from a menu/toolbar
		self.HookCommand(self.OnSelectBlock, win32ui.ID_EDIT_SELECT_BLOCK)
		self.HookCommand(self.OnEditCopyCode, ID_EDIT_COPY_CODE)
		self.HookCommand(self.OnEditExecClipboard, ID_EDIT_EXEC_CLIPBOARD)
		mod = pywin.scintilla.IDLEenvironment.GetIDLEModule("IdleHistory")
		if mod is not None:
			self.history = mod.History(self.idle.text, "\n" + sys.ps2)
		else:
			self.history = None
		# hack for now for event handling.

	# GetBlockBoundary takes a line number, and will return the
	# start and and line numbers of the block, and a flag indicating if the
	# block is a Python code block.
	# If the line specified has a Python prompt, then the lines are parsed
	# backwards and forwards, and the flag is true.
	# If the line does not start with a prompt, the block is searched forward
	# and backward until a prompt _is_ found, and all lines in between without
	# prompts are returned, and the flag is false. 
Example 10
Project: CodeReader   Author: jasonrbr   File: interact.py    (license) View Source Project 6 votes vote down vote up
def AppendToPrompt(self,bufLines, oldPrompt = None):
		" Take a command and stick it at the end of the buffer (with python prompts inserted if required)."
		self.flush()
		lastLineNo = self.GetLineCount()-1
		line = self.DoGetLine(lastLineNo)
		if oldPrompt and line==oldPrompt:
			self.SetSel(self.GetTextLength()-len(oldPrompt), self.GetTextLength())
			self.ReplaceSel(sys.ps1)
		elif (line!=str(sys.ps1)):
			if len(line)!=0: self.write('\n')
			self.write(sys.ps1)
		self.flush()
		self.idle.text.mark_set("iomark", "end-1c")
		if not bufLines:
			return
		terms = (["\n" + sys.ps2] * (len(bufLines)-1)) + ['']
		for bufLine, term in zip(bufLines, terms):
			if bufLine.strip():
				self.write( bufLine + term )
		self.flush() 
Example 11
Project: CodeReader   Author: jasonrbr   File: interact.py    (license) View Source Project 6 votes vote down vote up
def HookHandlers(self):
		# Hook menu command (executed when a menu item with that ID is selected from a menu/toolbar
		self.HookCommand(self.OnSelectBlock, win32ui.ID_EDIT_SELECT_BLOCK)
		self.HookCommand(self.OnEditCopyCode, ID_EDIT_COPY_CODE)
		self.HookCommand(self.OnEditExecClipboard, ID_EDIT_EXEC_CLIPBOARD)
		mod = pywin.scintilla.IDLEenvironment.GetIDLEModule("IdleHistory")
		if mod is not None:
			self.history = mod.History(self.idle.text, "\n" + sys.ps2)
		else:
			self.history = None
		# hack for now for event handling.

	# GetBlockBoundary takes a line number, and will return the
	# start and and line numbers of the block, and a flag indicating if the
	# block is a Python code block.
	# If the line specified has a Python prompt, then the lines are parsed
	# backwards and forwards, and the flag is true.
	# If the line does not start with a prompt, the block is searched forward
	# and backward until a prompt _is_ found, and all lines in between without
	# prompts are returned, and the flag is false. 
Example 12
Project: Repobot   Author: Desgard   File: replwrap.py    (license) View Source Project 6 votes vote down vote up
def bash(command="bash"):
    """Start a bash shell and return a :class:`REPLWrapper` object."""
    bashrc = os.path.join(os.path.dirname(__file__), 'bashrc.sh')
    child = pexpect.spawn(command, ['--rcfile', bashrc], echo=False,
                          encoding='utf-8')

    # If the user runs 'env', the value of PS1 will be in the output. To avoid
    # replwrap seeing that as the next prompt, we'll embed the marker characters
    # for invisible characters in the prompt; these show up when inspecting the
    # environment variable, but not when bash displays the prompt.
    ps1 = PEXPECT_PROMPT[:5] + u'\[\]' + PEXPECT_PROMPT[5:]
    ps2 = PEXPECT_CONTINUATION_PROMPT[:5] + u'\[\]' + PEXPECT_CONTINUATION_PROMPT[5:]
    prompt_change = u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''".format(ps1, ps2)

    return REPLWrapper(child, u'\$', prompt_change,
                       extra_init_cmd="export PAGER=cat") 
Example 13
Project: pipenv   Author: pypa   File: replwrap.py    (license) View Source Project 6 votes vote down vote up
def bash(command="bash"):
    """Start a bash shell and return a :class:`REPLWrapper` object."""
    bashrc = os.path.join(os.path.dirname(__file__), 'bashrc.sh')
    child = pexpect.spawn(command, ['--rcfile', bashrc], echo=False,
                          encoding='utf-8')

    # If the user runs 'env', the value of PS1 will be in the output. To avoid
    # replwrap seeing that as the next prompt, we'll embed the marker characters
    # for invisible characters in the prompt; these show up when inspecting the
    # environment variable, but not when bash displays the prompt.
    ps1 = PEXPECT_PROMPT[:5] + u'\\[\\]' + PEXPECT_PROMPT[5:]
    ps2 = PEXPECT_CONTINUATION_PROMPT[:5] + u'\\[\\]' + PEXPECT_CONTINUATION_PROMPT[5:]
    prompt_change = u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''".format(ps1, ps2)

    return REPLWrapper(child, u'\\$', prompt_change,
                       extra_init_cmd="export PAGER=cat") 
Example 14
Project: yatta_reader   Author: sound88   File: replwrap.py    (license) View Source Project 6 votes vote down vote up
def bash(command="bash"):
    """Start a bash shell and return a :class:`REPLWrapper` object."""
    bashrc = os.path.join(os.path.dirname(__file__), 'bashrc.sh')
    child = pexpect.spawn(command, ['--rcfile', bashrc], echo=False,
                          encoding='utf-8')

    # If the user runs 'env', the value of PS1 will be in the output. To avoid
    # replwrap seeing that as the next prompt, we'll embed the marker characters
    # for invisible characters in the prompt; these show up when inspecting the
    # environment variable, but not when bash displays the prompt.
    ps1 = PEXPECT_PROMPT[:5] + u'\[\]' + PEXPECT_PROMPT[5:]
    ps2 = PEXPECT_CONTINUATION_PROMPT[:5] + u'\[\]' + PEXPECT_CONTINUATION_PROMPT[5:]
    prompt_change = u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''".format(ps1, ps2)

    return REPLWrapper(child, u'\$', prompt_change,
                       extra_init_cmd="export PAGER=cat") 
Example 15
Project: kinect-2-libras   Author: inessadl   File: code.py    (Apache License 2.0) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 16
Project: hostapd-mana   Author: adde88   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 17
Project: pythonVSCode   Author: DonJayamanne   File: visualstudio_py_repl.py    (license) View Source Project 5 votes vote down vote up
def send_prompt(self, ps1, ps2, allow_multiple_statements):
        """sends the current prompt to the interactive window"""
        with self.send_lock:
            write_bytes(self.conn, ReplBackend._PRPC)
            write_string(self.conn, ps1)
            write_string(self.conn, ps2)
            write_int(self.conn, 1 if allow_multiple_statements else 0) 
Example 18
Project: pythonVSCode   Author: DonJayamanne   File: visualstudio_py_repl.py    (license) View Source Project 5 votes vote down vote up
def send_prompt(self, ps1, ps2, allow_multiple_statements):
        """sends the current prompt to the interactive window"""
        with self.send_lock:
            write_bytes(self.conn, ReplBackend._PRPC)
            write_string(self.conn, ps1)
            write_string(self.conn, ps2)
            write_int(self.conn, 1 if allow_multiple_statements else 0) 
Example 19
Project: watchmen   Author: lycclsltt   File: replwrap.py    (license) View Source Project 5 votes vote down vote up
def python(command="python"):
    """Start a Python shell and return a :class:`REPLWrapper` object."""
    return REPLWrapper(command, u">>> ", u"import sys; sys.ps1={0!r}; sys.ps2={1!r}") 
Example 20
Project: pythonrc   Author: lonetwin   File: test_pythonrc.py    (license) View Source Project 5 votes vote down vote up
def test_init_prompt(self):
        self.assertRegexpMatches(
            sys.ps1, '\001\033\[1;3[23]m\002>>> \001\033\[0m\002'
        )
        self.assertEqual(sys.ps2, '\001\033[1;31m\002... \001\033[0m\002')

        with patch.dict(os.environ,
                        {'SSH_CONNECTION': '1.1.1.1 10240 127.0.0.1 22'}):
            self.pymp.init_prompt()
            self.assertIn('[127.0.0.1]>>> ', sys.ps1)
            self.assertIn('[127.0.0.1]... ', sys.ps2) 
Example 21
Project: pythonrc   Author: lonetwin   File: pythonrc.py    (license) View Source Project 5 votes vote down vote up
def init_prompt(self):
        """Activates color on the prompt based on python version.

        Also adds the hosts IP if running on a remote host over a
        ssh connection.
        """
        prompt_color = green if sys.version_info.major == 2 else yellow
        sys.ps1 = prompt_color('>>> ', readline_workaround=True)
        sys.ps2 = red('... ', readline_workaround=True)
        # - if we are over a remote connection, modify the ps1
        if os.getenv('SSH_CONNECTION'):
            _, _, this_host, _ = os.getenv('SSH_CONNECTION').split()
            sys.ps1 = prompt_color('[{}]>>> '.format(this_host), readline_workaround=True)
            sys.ps2 = red('[{}]... '.format(this_host), readline_workaround=True) 
Example 22
Project: Intranet-Penetration   Author: yuxiaokui   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 23
Project: MKFQ   Author: maojingios   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 24
Project: saas-api-boilerplate   Author: rgant   File: console.py    (license) View Source Project 5 votes vote down vote up
def _set_prompt():
    """ Color code the Python prompt based on environment. """
    env = os.environ.get('ENV', 'dev')
    color = {'dev': '32',  # Green
             'stage': '33',  # Yellow
             'prod': '31'}.get(env)  # Red
    sys.ps1 = '\001\033[1;%sm\002>>> \001\033[0m\002' % color
    sys.ps2 = '\001\033[1;%sm\002... \001\033[0m\002' % color 
Example 25
Project: leetcode   Author: thomasyimgit   File: replwrap.py    (license) View Source Project 5 votes vote down vote up
def python(command="python"):
    """Start a Python shell and return a :class:`REPLWrapper` object."""
    return REPLWrapper(command, u">>> ", u"import sys; sys.ps1={0!r}; sys.ps2={1!r}") 
Example 26
Project: zippy   Author: securesystemslab   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 27
Project: oil   Author: oilshell   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 28
Project: python2-tracer   Author: extremecoders-re   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 29
Project: ml-utils   Author: LinxiFan   File: repl.py    (license) View Source Project 5 votes vote down vote up
def _python_repl(command="python"):
    """Start a Python shell and return a :class:`REPLWrapper` object."""
    return REPLWrapper(command, u">>> ", u"import sys; sys.ps1={0!r}; sys.ps2={1!r}") 
Example 30
Project: bonobo-docker   Author: python-bonobo   File: pythonrc.py    (license) View Source Project 5 votes vote down vote up
def _enable_shell_colors():
    import sys
    from colorama import Fore
    sys.ps1 = Fore.LIGHTWHITE_EX + '?? >' + Fore.RESET + ' '
    sys.ps2 = Fore.BLACK + '..' + Fore.LIGHTBLACK_EX + '.' + Fore.RESET + ' ' 
Example 31
Project: sslstrip-hsts-openwrt   Author: adde88   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 32
Project: specto   Author: mrknow   File: pydevconsole_code_for_ironpython.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 33
Project: web_ctp   Author: molebot   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 34
Project: remoteControlPPT   Author: htwenning   File: interact.py    (license) View Source Project 5 votes vote down vote up
def GetPromptPrefix(line):
	ps1=sys.ps1
	if line[:len(ps1)]==ps1: return ps1
	ps2=sys.ps2
	if line[:len(ps2)]==ps2: return ps2

#############################################################
#
# Colorizer related code.
#
############################################################# 
Example 35
Project: remoteControlPPT   Author: htwenning   File: interact.py    (license) View Source Project 5 votes vote down vote up
def SetContext(self, globals, locals, name = "Dbg"):
		oldPrompt = sys.ps1
		if globals is None:
			# Reset
			sys.ps1 = ">>> "
			sys.ps2 = "... "
			locals = globals = __main__.__dict__
		else:
			sys.ps1 = "[%s]>>> " % name
			sys.ps2 = "[%s]... " % name
		self.interp.locals = locals
		self.interp.globals = globals
		self.AppendToPrompt([], oldPrompt) 
Example 36
Project: remoteControlPPT   Author: htwenning   File: interact.py    (license) View Source Project 5 votes vote down vote up
def EnsureNoPrompt(self):
		# Get ready to write some text NOT at a Python prompt.
		self.flush()
		lastLineNo = self.GetLineCount()-1
		line = self.DoGetLine(lastLineNo)
		if not line or line in [sys.ps1, sys.ps2]:
			self.SetSel(self.GetTextLength()-len(line), self.GetTextLength())
			self.ReplaceSel('')
		else:
			# Just add a new line.
			self.write('\n') 
Example 37
Project: xxNet   Author: drzorm   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 38
Project: obsoleted-vpduserv   Author: InfraSIM   File: replwrap.py    (license) View Source Project 5 votes vote down vote up
def python(command="python"):
    """Start a Python shell and return a :class:`REPLWrapper` object."""
    return REPLWrapper(command, u(">>> "), u("import sys; sys.ps1={0!r}; sys.ps2={1!r}")) 
Example 39
Project: CodeReader   Author: jasonrbr   File: interact.py    (license) View Source Project 5 votes vote down vote up
def GetPromptPrefix(line):
	ps1=sys.ps1
	if line[:len(ps1)]==ps1: return ps1
	ps2=sys.ps2
	if line[:len(ps2)]==ps2: return ps2

#############################################################
#
# Colorizer related code.
#
############################################################# 
Example 40
Project: CodeReader   Author: jasonrbr   File: interact.py    (license) View Source Project 5 votes vote down vote up
def SetContext(self, globals, locals, name = "Dbg"):
		oldPrompt = sys.ps1
		if globals is None:
			# Reset
			sys.ps1 = ">>> "
			sys.ps2 = "... "
			locals = globals = __main__.__dict__
		else:
			sys.ps1 = "[%s]>>> " % name
			sys.ps2 = "[%s]... " % name
		self.interp.locals = locals
		self.interp.globals = globals
		self.AppendToPrompt([], oldPrompt) 
Example 41
Project: CodeReader   Author: jasonrbr   File: interact.py    (license) View Source Project 5 votes vote down vote up
def EnsureNoPrompt(self):
		# Get ready to write some text NOT at a Python prompt.
		self.flush()
		lastLineNo = self.GetLineCount()-1
		line = self.DoGetLine(lastLineNo)
		if not line or line in [sys.ps1, sys.ps2]:
			self.SetSel(self.GetTextLength()-len(line), self.GetTextLength())
			self.ReplaceSel('')
		else:
			# Just add a new line.
			self.write('\n') 
Example 42
Project: Repobot   Author: Desgard   File: replwrap.py    (license) View Source Project 5 votes vote down vote up
def python(command="python"):
    """Start a Python shell and return a :class:`REPLWrapper` object."""
    return REPLWrapper(command, u">>> ", u"import sys; sys.ps1={0!r}; sys.ps2={1!r}") 
Example 43
Project: Repobot   Author: Desgard   File: interactiveshell.py    (license) View Source Project 5 votes vote down vote up
def init_prompts(self):
        # Set system prompts, so that scripts can decide if they are running
        # interactively.
        sys.ps1 = 'In : '
        sys.ps2 = '...: '
        sys.ps3 = 'Out: ' 
Example 44
Project: pefile.pypy   Author: cloudtracer   File: _pypy_interact.py    (license) View Source Project 5 votes vote down vote up
def interactive_console(mainmodule=None, quiet=False):
    # set sys.{ps1,ps2} just before invoking the interactive interpreter. This
    # mimics what CPython does in pythonrun.c
    if not hasattr(sys, 'ps1'):
        sys.ps1 = '>>>> '
    if not hasattr(sys, 'ps2'):
        sys.ps2 = '.... '
    #
    if not quiet:
        try:
            from _pypy_irc_topic import some_topic
            text = "%s: ``%s''" % ( irc_header, some_topic())
            while len(text) >= 80:
                i = text[:80].rfind(' ')
                print(text[:i])
                text = text[i+1:]
            print(text)
        except ImportError:
            pass
    #
    try:
        if not os.isatty(sys.stdin.fileno()):
            # Bail out if stdin is not tty-like, as pyrepl wouldn't be happy
            # For example, with:
            # subprocess.Popen(['pypy', '-i'], stdin=subprocess.PIPE)
            raise ImportError
        from pyrepl.simple_interact import check
        if not check():
            raise ImportError
        from pyrepl.simple_interact import run_multiline_interactive_console
    except ImportError:
        run_simple_interactive_console(mainmodule)
    else:
        run_multiline_interactive_console(mainmodule) 
Example 45
Project: pefile.pypy   Author: cloudtracer   File: _pypy_interact.py    (license) View Source Project 5 votes vote down vote up
def run_simple_interactive_console(mainmodule):
    import code
    if mainmodule is None:
        import __main__ as mainmodule
    console = code.InteractiveConsole(mainmodule.__dict__, filename='<stdin>')
    # some parts of code.py are copied here because it seems to be impossible
    # to start an interactive console without printing at least one line
    # of banner
    more = 0
    while 1:
        try:
            if more:
                prompt = getattr(sys, 'ps2', '... ')
            else:
                prompt = getattr(sys, 'ps1', '>>> ')
            try:
                line = raw_input(prompt)
                # Can be None if sys.stdin was redefined
                encoding = getattr(sys.stdin, 'encoding', None)
                if encoding and not isinstance(line, unicode):
                    line = line.decode(encoding)
            except EOFError:
                console.write("\n")
                break
            else:
                more = console.push(line)
        except KeyboardInterrupt:
            console.write("\nKeyboardInterrupt\n")
            console.resetbuffer()
            more = 0

# ____________________________________________________________ 
Example 46
Project: HomeAutomation   Author: gs2671   File: visualstudio_py_repl.py    (license) View Source Project 5 votes vote down vote up
def send_prompt(self, ps1, ps2, update_all = True):
        """sends the current prompt to the interactive window"""
        with self.send_lock:
            write_bytes(self.conn, ReplBackend._PRPC)
            write_string(self.conn, ps1)
            write_string(self.conn, ps2)
            write_int(self.conn, update_all) 
Example 47
Project: HomeAutomation   Author: gs2671   File: visualstudio_py_repl.py    (license) View Source Project 5 votes vote down vote up
def execution_loop(self):
        """loop on the main thread which is responsible for executing code"""
        
        if sys.platform == 'cli' and sys.version_info[:3] < (2, 7, 1):
            # IronPython doesn't support thread.interrupt_main until 2.7.1
            import System
            self.main_thread = System.Threading.Thread.CurrentThread

        # save our selves so global lookups continue to work (required pre-2.6)...
        cur_modules = set()
        try:
            cur_ps1 = sys.ps1
            cur_ps2 = sys.ps2
        except:
            # CPython/IronPython don't set sys.ps1 for non-interactive sessions, Jython and PyPy do
            sys.ps1 = cur_ps1 = '>>> '
            sys.ps2 = cur_ps2 = '... '

        self.send_prompt(cur_ps1, cur_ps2)

        # launch the startup script if one has been specified
        if self.launch_file:
            try:
                self.run_file_as_main(self.launch_file, '')
            except:
                print('error in launching startup script:')
                traceback.print_exc()

        while True:
            exit, cur_modules, cur_ps1, cur_ps2 = self.run_one_command(cur_modules, cur_ps1, cur_ps2)
            if exit:
                return 
Example 48
Project: pipenv   Author: pypa   File: replwrap.py    (license) View Source Project 5 votes vote down vote up
def python(command="python"):
    """Start a Python shell and return a :class:`REPLWrapper` object."""
    return REPLWrapper(command, u">>> ", u"import sys; sys.ps1={0!r}; sys.ps2={1!r}") 
Example 49
Project: ouroboros   Author: pybee   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False 
Example 50
Project: ndk-python   Author: gittor   File: code.py    (license) View Source Project 5 votes vote down vote up
def runsource(self, source, filename="<input>", symbol="single"):
        """Compile and run some source in the interpreter.

        Arguments are as for compile_command().

        One several things can happen:

        1) The input is incorrect; compile_command() raised an
        exception (SyntaxError or OverflowError).  A syntax traceback
        will be printed by calling the showsyntaxerror() method.

        2) The input is incomplete, and more input is required;
        compile_command() returned None.  Nothing happens.

        3) The input is complete; compile_command() returned a code
        object.  The code is executed by calling self.runcode() (which
        also handles run-time exceptions, except for SystemExit).

        The return value is True in case 2, False in the other cases (unless
        an exception is raised).  The return value can be used to
        decide whether to use sys.ps1 or sys.ps2 to prompt the next
        line.

        """
        try:
            code = self.compile(source, filename, symbol)
        except (OverflowError, SyntaxError, ValueError):
            # Case 1
            self.showsyntaxerror(filename)
            return False

        if code is None:
            # Case 2
            return True

        # Case 3
        self.runcode(code)
        return False