本文整理匯總了Python中code.InteractiveInterpreter方法的典型用法代碼示例。如果您正苦於以下問題:Python code.InteractiveInterpreter方法的具體用法?Python code.InteractiveInterpreter怎麽用?Python code.InteractiveInterpreter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code
的用法示例。
在下文中一共展示了code.InteractiveInterpreter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: push
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def push(self, line):
"""Push a line to the interpreter."""
self._buffer.append(line)
source = '\n'.join(self._buffer)
self.write(line + '\n')
# We do two special things with the context managers here:
# - We replace stdout/stderr to capture output. Even if we could
# override InteractiveInterpreter's write method, most things are
# printed elsewhere (e.g. by exec). Other Python GUI shells do the
# same.
# - We disable our exception hook, so exceptions from the console get
# printed and don't open a crashdialog.
with utils.fake_io(self.write), utils.disabled_excepthook():
self._more = self._interpreter.runsource(source, '<console>')
self.write(self._curprompt())
if not self._more:
self._buffer = []
示例2: runsource
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def runsource(self, source):
source = source.rstrip() + "\n"
ThreadedStream.push()
prompt = "... " if self.more else ">>> "
try:
source_to_eval = "".join(self.buffer + [source])
if code.InteractiveInterpreter.runsource(
self, source_to_eval, "<debugger>", "single"
):
self.more = True
self.buffer.append(source)
else:
self.more = False
del self.buffer[:]
finally:
output = ThreadedStream.fetch()
return prompt + escape(source) + output
示例3: runsource
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def runsource(self, source):
source = source.rstrip() + '\n'
ThreadedStream.push()
prompt = self.more and '... ' or '>>> '
try:
source_to_eval = ''.join(self.buffer + [source])
if code.InteractiveInterpreter.runsource(self,
source_to_eval, '<debugger>', 'single'):
self.more = True
self.buffer.append(source)
else:
self.more = False
del self.buffer[:]
finally:
output = ThreadedStream.fetch()
return prompt + source + output
示例4: runsource
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def runsource(self, source):
source = source.rstrip() + '\n'
ThreadedStream.push()
prompt = self.more and '... ' or '>>> '
try:
source_to_eval = ''.join(self.buffer + [source])
if code.InteractiveInterpreter.runsource(self,
source_to_eval, '<debugger>', 'single'):
self.more = True
self.buffer.append(source)
else:
self.more = False
del self.buffer[:]
finally:
output = ThreadedStream.fetch()
return prompt + escape(source) + output
示例5: push
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def push(self, line):
"""
Push a line to the interpreter.
The line should not have a trailing newline; it may have
internal newlines. The line is appended to a buffer and the
interpreter's runsource() method is called with the
concatenated contents of the buffer as source. If this
indicates that the command was executed or invalid, the buffer
is reset; otherwise, the command is incomplete, and the buffer
is left as it was after the line was appended. The return
value is 1 if more input is required, 0 if the line was dealt
with in some way (this is the same as runsource()).
@param line: line of text
@type line: L{bytes}
@return: L{bool} from L{code.InteractiveInterpreter.runsource}
"""
self.buffer.append(line)
source = b"\n".join(self.buffer)
source = source.decode("utf-8")
more = self.runsource(source, self.filename)
if not more:
self.resetBuffer()
return more
示例6: __init__
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def __init__(self, host=None, port=None, encoding='utf-8'):
"""
"""
if host:
self.host = host
if port:
self.port = port
self.encoding = encoding
self.lock = threading.RLock()
self.stdio_hook = OutputHookContext()
import __main__ as main
self.user_defined_executor = getattr(
main, '_user_defined_executor', None)
self.in_user_defined_executor = False
self.user_defined_executor_local = {}
self._interpreter = code.InteractiveInterpreter(locals=locals())
self.runsource('import sys')
self.runsource('import __main__ as main')
self.sock = SockClient(self.host, self.port, encoding)
super(RemoteShellThread, self).__init__()
示例7: runsource
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def runsource(self, source):
source = source.rstrip() + '\n'
ThreadedStream.push()
prompt = self.more and '... ' or '>>> '
try:
source_to_eval = ''.join(self.buffer + [source])
if code.InteractiveInterpreter.runsource(self,
source_to_eval, '<debugger>', 'single'):
self.more = True
self.buffer.append(source)
else:
self.more = False
del self.buffer[:]
finally:
output = ThreadedStream.fetch()
return prompt + source + output
示例8: _core_loadlib
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def _core_loadlib(self, request, response):
data_tlv = packet_get_tlv(request, TLV_TYPE_DATA)
if (data_tlv['type'] & TLV_META_TYPE_COMPRESSED) == TLV_META_TYPE_COMPRESSED:
return ERROR_FAILURE
self.last_registered_extension = None
symbols_for_extensions = {'meterpreter': self}
symbols_for_extensions.update(EXPORTED_SYMBOLS)
i = code.InteractiveInterpreter(symbols_for_extensions)
i.runcode(compile(data_tlv['value'], '', 'exec'))
extension_name = self.last_registered_extension
if extension_name:
check_extension = lambda x: x.startswith(extension_name)
lib_methods = list(filter(check_extension, list(self.extension_functions.keys())))
for method in lib_methods:
response += tlv_pack(TLV_TYPE_METHOD, method)
return ERROR_SUCCESS, response
示例9: __init__
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [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)
示例10: __init__
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def __init__(self, globals, locals):
code.InteractiveInterpreter.__init__(self, locals)
self.globals = dict(globals)
self.globals["dump"] = dump
self.globals["help"] = helper
self.globals["__loader__"] = self.loader = _ConsoleLoader()
self.more = False
self.buffer = []
_wrap_compiler(self)
示例11: __init__
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def __init__(self, globals, locals):
code.InteractiveInterpreter.__init__(self, locals)
self.globals = dict(globals)
self.globals['dump'] = dump
self.globals['help'] = helper
self.globals['__loader__'] = self.loader = _ConsoleLoader()
self.more = False
self.buffer = []
_wrap_compiler(self)
示例12: __init__
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def __init__(self, locals = None, globals = None):
if locals is None: locals = __main__.__dict__
if globals is None: globals = locals
self.globals = globals
code.InteractiveInterpreter.__init__(self, locals)
示例13: showsyntaxerror
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def showsyntaxerror(self, filename=None):
sys.stderr.write(tracebackHeader) # So the color syntaxer recognises it.
code.InteractiveInterpreter.showsyntaxerror(self, filename)
示例14: __init__
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def __init__(self, *args, **kargs):
code.InteractiveInterpreter.__init__(self, *args, **kargs)
self.error = 0
示例15: showsyntaxerror
# 需要導入模塊: import code [as 別名]
# 或者: from code import InteractiveInterpreter [as 別名]
def showsyntaxerror(self, *args, **kargs):
self.error = 1
return code.InteractiveInterpreter.showsyntaxerror(self, *args, **kargs)