本文整理汇总了Python中code.InteractiveConsole方法的典型用法代码示例。如果您正苦于以下问题:Python code.InteractiveConsole方法的具体用法?Python code.InteractiveConsole怎么用?Python code.InteractiveConsole使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code
的用法示例。
在下文中一共展示了code.InteractiveConsole方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run_console
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def run_console(glob):
import readline
import rlcompleter
import atexit
import code
history_path = os.path.expanduser("~/.python_history")
def save_history(history_path=history_path):
readline.write_history_file(history_path)
if os.path.exists(history_path):
readline.read_history_file(history_path)
atexit.register(save_history)
readline.set_completer(rlcompleter.Completer(glob).complete)
readline.parse_and_bind("tab: complete")
code.InteractiveConsole(locals=glob).interact()
示例2: __init__
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def __init__(self, ch):
super(Link_Convolution2D, self).__init__(L.Convolution2D(None, None))
# code.InteractiveConsole({'ch': ch}).interact()
self.ksize = size2d(ch.ksize)
self.stride = size2d(ch.stride)
ps = size2d(ch.pad)
self.pads = ps + ps
if not (ch.b is None):
# nobias = True の場合
self.M = ch.b.shape[0]
self.b = helper.make_tensor_value_info(
'/b', TensorProto.FLOAT, [self.M])
else:
self.M = "TODO"
self.b = None
self.W = helper.make_tensor_value_info(
'/W', TensorProto.FLOAT,
[self.M, 'channel_size'] + list(self.ksize))
示例3: __init__
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def __init__(self, classtype):
# classtypeのmethod は持ってるが init は呼ばれてない、というobjectが必要になる。
# ので、あえて parent のinit を呼ばない継承をする
class Tmp(classtype):
def __init__(_):
pass
# dprint('user defined class of',classtype)
ch = Tmp()
ch.__module__ = classtype.__module__
# code.InteractiveConsole({'Tmp': Tmp,'v': ch}).interact()
def f(args, kwargs, env):
if not isinstance(classtype.__init__, type(str.__init__)): # slot wrapper というものらしい
User_Defined_Func_In_Link(
ch, classtype.__init__).call(args, kwargs, env)
return ch
self.init_wrapper = Func(f)
示例4: _create_interactive_locals
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def _create_interactive_locals(self):
# Create and return a *new* locals dictionary based on self.locals,
# and set any new entries in it. (InteractiveConsole does not
# copy its locals value)
_locals = self.locals.copy()
# __builtins__ may either be the __builtin__ module or
# __builtin__.__dict__; in the latter case typing
# locals() at the backdoor prompt spews out lots of
# useless stuff
try:
import __builtin__
_locals["__builtins__"] = __builtin__
except ImportError:
import builtins
_locals["builtins"] = builtins
_locals['__builtins__'] = builtins
return _locals
示例5: handle
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def handle(self, conn, address):
"""
Interact with one remote user.
.. versionchanged:: 1.1b2 Each connection gets its own
``locals`` dictionary. Previously they were shared in a
potentially unsafe manner.
"""
fobj = conn.makefile(mode="rw")
fobj = _fileobject(conn, fobj, self.stderr)
getcurrent()._fileobj = fobj
getcurrent().switch_in()
try:
console = InteractiveConsole(self._create_interactive_locals())
console.interact(banner=self.banner)
except SystemExit: # raised by quit()
if hasattr(sys, 'exc_clear'): # py2
sys.exc_clear()
finally:
conn.close()
fobj.close()
示例6: python
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [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.
示例7: python
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [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()
示例8: main
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def main():
parser = argparse.ArgumentParser(description='win_syscall: Windows native system call utility', conflict_handler='resolve')
parser.add_argument('-f', '--file', dest='syscall_file', action='store', type=argparse.FileType('r'), help='json file to load syscall data from')
parser.add_argument('-o', '--os', dest='os_name', action='store', help='the windows version to load syscall data for')
arguments = parser.parse_args()
if platform.system() != 'Windows':
print("[-] Incompatible platform '{0}'".format(platform.system()))
return
syscall_map = None
if arguments.syscall_file and arguments.os_name:
syscall_map = json.load(arguments.syscall_file)
if not arguments.os_name in syscall_map:
print("[-] Invalid os name '{0}'".format(arguments.os_name))
return
syscall_map = [arguments.os_name]
print("[+] Loaded {0} syscall symbols".format(len(syscall_map)))
syscall = windows.WindowsX86Syscall(syscall_map)
print("[+] Allocated syscall stub at 0x{0:08x}".format(syscall.address))
console = code.InteractiveConsole(dict(syscall=syscall))
console.interact()
示例9: cmd_console
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def cmd_console(args):
import code
import platform
d = u2.connect(args.serial)
model = d.shell("getprop ro.product.model").output.strip()
serial = d.serial
try:
import IPython
from traitlets.config import get_config
c = get_config()
c.InteractiveShellEmbed.colors = "neutral"
IPython.embed(config=c, header="IPython -- d.info is ready")
except ImportError:
_vars = globals().copy()
_vars.update(locals())
shell = code.InteractiveConsole(_vars)
shell.interact(banner="Python: %s\nDevice: %s(%s)" %
(platform.python_version(), model, serial))
示例10: main
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def main(argv):
if 'createdb' in argv:
models.db.create_all()
elif 'createdata' in argv:
from scoreboard.tests import data
models.db.create_all()
data.create_all()
elif 'shell' in argv:
try:
import IPython
run_shell = IPython.embed
except ImportError:
import readline # noqa: F401
import code
run_shell = code.InteractiveConsole().interact
run_shell()
else:
wsgi.app.run(
host='0.0.0.0', debug=True,
port=wsgi.app.config.get('PORT', 9999))
示例11: _debug
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def _debug(_sig, frame):
"""Starts an interactive prompt in the main thread."""
d = {'_frame': frame}
d.update(frame.f_globals)
d.update(frame.f_locals)
try:
# Enables arrows to work normally.
# pylint: disable=unused-variable
import readline
except ImportError:
pass
msg = 'Signal received : entering python shell.\nTraceback:\n%s' % (''.join(
traceback.format_stack(frame)))
symbols = set(frame.f_locals.keys() + frame.f_globals.keys())
msg += 'Symbols:\n%s' % '\n'.join(' ' + x for x in sorted(symbols))
code.InteractiveConsole(d).interact(msg)
示例12: runCode
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def runCode(self):
'''Use :py:func:`code.interact` to acess python terminal'''
# separe in thread to avoid conflict with running Qt Application
if self.Vradar.value is None:
common.ShowWarning("No Radar linked, aborting!")
return
import threading
env = LocalEnvoriment(self.Vradar)
env["np"] = np
env["pyart"] = pyart
banner = ("\n\n"
"## Interactive field manipulation console\n"
"##\n"
"## Work with fields are if they were numpy arrays.\n"
"##\n"
"## Call help() for more\n"
)
self.console = code.InteractiveConsole(env)
self.thread = threading.Thread(
target=self.console.interact,
kwargs={'banner': banner},
)
self.thread.daemon=True
self.thread.start()
#self.isRunning = True
示例13: _create_interactive_locals
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def _create_interactive_locals(self):
# Create and return a *new* locals dictionary based on self.locals,
# and set any new entries in it. (InteractiveConsole does not
# copy its locals value)
_locals = self.locals.copy()
# __builtins__ may either be the __builtin__ module or
# __builtin__.__dict__; in the latter case typing
# locals() at the backdoor prompt spews out lots of
# useless stuff
try:
import __builtin__
_locals["__builtins__"] = __builtin__
except ImportError:
import builtins # pylint:disable=import-error
_locals["builtins"] = builtins
_locals['__builtins__'] = builtins
return _locals
示例14: launch_debugger
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def launch_debugger(frame, stream=None):
"""
Interrupt running process, and provide a python prompt for
interactive debugging.
"""
d = {'_frame': frame} # Allow access to frame object.
d.update(frame.f_globals) # Unless shadowed by global
d.update(frame.f_locals)
import code, traceback
i = code.InteractiveConsole(d)
message = "Signal received : entering python shell.\nTraceback:\n"
message += ''.join(traceback.format_stack(frame))
i.interact(message)
示例15: interact
# 需要导入模块: import code [as 别名]
# 或者: from code import InteractiveConsole [as 别名]
def interact(self, locals=None):
class LambdaConsole(code.InteractiveConsole):
def runsource(code_console, source, filename=None, symbol=None):
try:
self.runner.run(source)
except SystemExit:
raise
except:
code_console.showtraceback()
return False
try:
import readline; readline
except ImportError:
pass
ps1, ps2 = getattr(sys, 'ps1', None), getattr(sys, 'ps2', None)
try:
sys.ps1, sys.ps2 = self.ps1, self.ps2
LambdaConsole(locals=locals, filename="<demo>").interact(banner='')
finally:
sys.ps1, sys.ps2 = ps1, ps2