当前位置: 首页>>代码示例>>Python>>正文


Python sys.ps1方法代码示例

本文整理汇总了Python中sys.ps1方法的典型用法代码示例。如果您正苦于以下问题:Python sys.ps1方法的具体用法?Python sys.ps1怎么用?Python sys.ps1使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sys的用法示例。


在下文中一共展示了sys.ps1方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: bash

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
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") 
开发者ID:pypa,项目名称:pipenv,代码行数:18,代码来源:replwrap.py

示例2: main

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def main(url):
    # set default timeout 10s
    socket.setdefaulttimeout(10)

    f = Fetch(url.strip())
    print ':) URL: {0}'.format(f.fullurl)
    try:
        msg = f.injection('id')
    except InjectionFailed:
        print '*_* Injection Code Failed.'
        return 1
    except InjectionNetError:
        print '*_* Check the target server connection'
        return 1
    idinfo = msg.split(' ')[0].split('=')
    if len(idinfo) == 2:
        f.user = idinfo[1]
    else:
        f.user = idinfo[0]
    csc = CgiShellConsole()
    csc.set_fetch(f)
    sys.ps1 = '{0}@{1} >>'.format(f.host, f.user)
    csc.interact(':) Injection Code Success! Shell it.')
    return 0 
开发者ID:cj1324,项目名称:CGIShell,代码行数:26,代码来源:cgishell.py

示例3: runCommand

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def runCommand(self, command, commandNumber=1, nCommands=1):
        pipeline = self.pipeline

        if self._handleSpecial(command):
            return

        try:
            incomplete, doPrint = pipeline.run(command, commandNumber,
                                               nCommands)
        except KeyboardInterrupt:
            print('^C', file=sys.stderr)
            self.reset()
            return False
        except Exception:
            print(traceback.format_exc(), file=sys.stderr)
            self.reset()
            return False
        else:
            self.prompt = sys.ps2 if incomplete else sys.ps1
            if doPrint:
                pipeline.print_()

        return True 
开发者ID:terrycojones,项目名称:daudin,代码行数:25,代码来源:interaction.py

示例4: AppendToPrompt

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
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() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:interact.py

示例5: OnEditCopyCode

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def OnEditCopyCode(self, command, code):
		""" Sanitizes code from interactive window, removing prompts and output,
			and inserts it in the clipboard."""
		code=self.GetSelText()
		lines=code.splitlines()
		out_lines=[]
		for line in lines:
			if line.startswith(sys.ps1):
				line=line[len(sys.ps1):]
				out_lines.append(line)
			elif line.startswith(sys.ps2):
				line=line[len(sys.ps2):]
				out_lines.append(line)
		out_code=os.linesep.join(out_lines)
		win32clipboard.OpenClipboard()
		try:
			win32clipboard.SetClipboardData(win32clipboard.CF_UNICODETEXT, unicode(out_code))
		finally:
			win32clipboard.CloseClipboard() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:interact.py

示例6: test_cp4299

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def test_cp4299(self):
        superConsole.SendKeys('outputRedirectStart{(}{)}{ENTER}')
        superConsole.SendKeys('import sys{ENTER}')
        superConsole.SendKeys('print sys.ps1{ENTER}')
        superConsole.SendKeys('print sys.ps2{ENTER}')
        
        superConsole.SendKeys('sys.ps1 = "abc "{ENTER}')
        superConsole.SendKeys('sys.ps2 = "xyz "{ENTER}')
        superConsole.SendKeys('def f{(}{)}:{ENTER}    pass{ENTER}{ENTER}')
        superConsole.SendKeys('outputRedirectStop{(}{)}{ENTER}')
        lines = getTestOutput()[0]
        expected_lines = ['>>> import sys\n', 
                        '>>> print sys.ps1\n', '>>> \n', 
                        '>>> print sys.ps2\n', '... \n', 
                        '>>> sys.ps1 = "abc "\n', 'abc sys.ps2 = "xyz "\n', 
                        'abc def f():\n', 'xyz         pass\n', 'xyz         \n', 
                        'abc outputRedirectStop()\n']
        
        for i in xrange(len(lines)):
            AreEqual(lines[i], expected_lines[i])
        AreEqual(len(lines), len(expected_lines)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_superconsole.py

示例7: _do_PYREPL

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def _do_PYREPL(self, params):
        # SOURCE: https://github.com/python/cpython/blob/e42b705188271da108de42b55d9344642170aa2b/Lib/code.py
        cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
        self.push("=== PYREPL START ===\nPython %s on %s\n%s\n" % (sys.version, sys.platform, cprt))

        try:
            sys.ps1
        except AttributeError:
            sys.ps1 = ">>> "

        try:
            sys.ps2
        except AttributeError:
            sys.ps2 = "... "

        self.push(sys.ps1)

        # Redirect STDOUT & STDERR
        self._stdout = sys.stdout
        sys.stdout = IOProxy(self, prefix="STDOUT")
        self._stderr = sys.stderr
        sys.stderr = IOProxy(self, prefix="STDERR")

        self._in_repl = True 
开发者ID:SafeBreach-Labs,项目名称:backdoros,代码行数:26,代码来源:backdoros.py

示例8: python

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def python(self, argv):
        import code
        ns = self._get_ns()
        console = code.InteractiveConsole(ns)
        console.raw_input = self._ui.user_input
        try:
            saveps1, saveps2 = sys.ps1, sys.ps2
        except AttributeError:
            saveps1, saveps2 = ">>> ", "... "
        sys.ps1, sys.ps2 = "%%GPython%%N:%s> " % (self._obj.__class__.__name__,), "more> "
        if readline:
            oc = readline.get_completer()
            readline.set_completer(Completer(ns).complete)
        console.interact("You are now in Python. ^D exits.")
        if readline:
            readline.set_completer(oc)
        sys.ps1, sys.ps2 = saveps1, saveps2
        self._reset_scopes()


# This is needed to reset PagedIO so background events don't cause the pager to activate. 
开发者ID:kdart,项目名称:pycopia,代码行数:23,代码来源:CLI.py

示例9: python

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def python(self, argv):
        import code
        ns = self._get_ns()
        console = code.InteractiveConsole(ns)
        console.raw_input = self._ui.user_input
        try:
            saveps1, saveps2 = sys.ps1, sys.ps2
        except AttributeError:
            saveps1, saveps2 = ">>> ", "... "
        sys.ps1, sys.ps2 = "%%GPython%%N:%s> " % (self._obj.__class__.__name__,), "more> "
        if readline:
            oc = readline.get_completer()
            readline.set_completer(Completer(ns).complete)
        console.interact("You are now in Python. ^D exits.")
        if readline:
            readline.set_completer(oc)
        sys.ps1, sys.ps2 = saveps1, saveps2
        self._reset_scopes() 
开发者ID:kdart,项目名称:pycopia,代码行数:20,代码来源:CLI.py

示例10: __init__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def __init__(self, parent=None):
        super().__init__(parent)
        if not hasattr(sys, 'ps1'):
            sys.ps1 = '>>> '
        if not hasattr(sys, 'ps2'):
            sys.ps2 = '... '
        namespace = {
            '__name__': '__console__',
            '__doc__': None,
            'q_app': QApplication.instance(),
            # We use parent as self here because the user "feels" the whole
            # console, not just the line edit.
            'self': parent,
            'objreg': objreg,
        }
        self._more = False
        self._buffer = []  # type: typing.MutableSequence[str]
        self._lineedit = ConsoleLineEdit(namespace, self)
        self._lineedit.execute.connect(self.push)
        self._output = ConsoleTextEdit()
        self.write(self._curprompt())
        self._vbox = QVBoxLayout()
        self._vbox.setSpacing(0)
        self._vbox.addWidget(self._output)
        self._vbox.addWidget(self._lineedit)
        stylesheet.set_register(self)
        self.setLayout(self._vbox)
        self._lineedit.setFocus()
        self._interpreter = code.InteractiveInterpreter(namespace) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:31,代码来源:consolewidget.py

示例11: __init__

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def __init__(self, pipeline=None, ps1=DEFAULT_PS1, ps2=DEFAULT_PS2):
        super().__init__(pipeline)

        try:
            sys.ps1
        except AttributeError:
            sys.ps1 = ps1

        try:
            sys.ps2
        except AttributeError:
            sys.ps2 = ps2

        self.prompt = sys.ps1 
开发者ID:terrycojones,项目名称:daudin,代码行数:16,代码来源:interaction.py

示例12: setup_method

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def setup_method(self, method):
        try:
            del sys.ps1
        except AttributeError:
            pass
        try:
            del sys.ps2
        except AttributeError:
            pass 
开发者ID:terrycojones,项目名称:daudin,代码行数:11,代码来源:test_interaction.py

示例13: testSetPrompts

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def testSetPrompts(self):
        """
        Setting the prompts via __init__ must work.
        """
        pl = Pipeline(loadInitFile=False)
        repl = REPL(pipeline=pl, ps1='x', ps2='y')
        self.assertEqual('x', repl.prompt)
        self.assertEqual('x', sys.ps1)
        self.assertEqual('y', sys.ps2) 
开发者ID:terrycojones,项目名称:daudin,代码行数:11,代码来源:test_interaction.py

示例14: remote_api_shell

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
def remote_api_shell(servername, appid, path, secure, rpc_server_factory):
  """Actually run the remote_api_shell."""


  remote_api_stub.ConfigureRemoteApi(appid, path, auth_func,
                                     servername=servername,
                                     save_cookies=True, secure=secure,
                                     rpc_server_factory=rpc_server_factory)
  remote_api_stub.MaybeInvokeAuthentication()


  os.environ['SERVER_SOFTWARE'] = 'Development (remote_api_shell)/1.0'

  if not appid:

    appid = os.environ['APPLICATION_ID']
  sys.ps1 = '%s> ' % appid
  if readline is not None:

    readline.parse_and_bind('tab: complete')
    atexit.register(lambda: readline.write_history_file(HISTORY_PATH))
    if os.path.exists(HISTORY_PATH):
      readline.read_history_file(HISTORY_PATH)


  if '' not in sys.path:
    sys.path.insert(0, '')

  preimported_locals = {
      'memcache': memcache,
      'urlfetch': urlfetch,
      'users': users,
      'db': db,
      'ndb': ndb,
      }


  code.interact(banner=BANNER, local=preimported_locals) 
开发者ID:elsigh,项目名称:browserscope,代码行数:40,代码来源:remote_api_shell.py

示例15: runsource

# 需要导入模块: import sys [as 别名]
# 或者: from sys import ps1 [as 别名]
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 
开发者ID:glmcdona,项目名称:meddle,代码行数:40,代码来源:code.py


注:本文中的sys.ps1方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。