本文整理汇总了Python中IPython.terminal.embed.InteractiveShellEmbed.register_magics方法的典型用法代码示例。如果您正苦于以下问题:Python InteractiveShellEmbed.register_magics方法的具体用法?Python InteractiveShellEmbed.register_magics怎么用?Python InteractiveShellEmbed.register_magics使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPython.terminal.embed.InteractiveShellEmbed
的用法示例。
在下文中一共展示了InteractiveShellEmbed.register_magics方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ishell
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import register_magics [as 别名]
def ishell(local_ns):
"""Embed an IPython shell handing it the local namespace from
:var:`local_ns`.
"""
banner = (
"Welcome to the pystuck interactive shell.\nUse the 'modules' dictionary "
"to access remote modules (like 'os', or '__main__')\nUse the `%show "
"threads` magic to display all thread stack traces.\n"
)
try:
from IPython.terminal.embed import InteractiveShellEmbed
ipshell = InteractiveShellEmbed(banner1=banner)
ipshell.register_magics(IntrospectMagics)
ipshell(local_ns=local_ns)
except ImportError:
# IPython < 0.11
# Explicitly pass an empty list as arguments, because otherwise
# IPython would use sys.argv from this script.
try:
from IPython.Shell import IPShellEmbed
ipshell = IPShellEmbed(argv=[], user_ns=local_ns, banner1=banner)
ipshell.register_magics(IntrospectMagics)
ipshell()
except ImportError:
# IPython not found at all, raise ImportError
raise
示例2: RunModeConsole
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import register_magics [as 别名]
#.........这里部分代码省略.........
'pwd', 'Print the working "directory" or the path of the current key.',
function_name_length))
banners.append(frontend_utils.FormatOutputString(
'plugin [-h] plugin_name', (
'Run a particular key-based plugin on the loaded hive. The correct '
'Registry key will be loaded, opened and then parsed.'),
function_name_length))
banners.append('')
if len(hives) == 1:
hive = hives[0]
hives = []
else:
hive = None
if len(hive_collectors) == 1:
hive_collector = hive_collectors[0][1]
hive_collectors = []
else:
hive_collector = None
if hive and not hive_collectors:
OpenHive(hive, hive_collector)
if RegCache.hive and RegCache.GetHiveName() != 'N/A':
banners.append(
u'Registry hive: {0:s} is available and loaded.'.format(
RegCache.GetHiveName()))
elif hives:
banners.append('More than one Registry file ready for use.')
banners.append('')
banners.append('Registry files discovered:')
for number, hive in enumerate(hives):
banners.append(' - {0:d} {1:s}'.format(number, hive.location))
banners.append('')
banners.append('To load a hive use:')
text = 'OpenHive(hives[NR], collector)'
if hive_collectors:
banners.append('')
banners.append((
'There is more than one collector available. To use any of them '
'instead of the attribute "collector" in the OpenHive '
'function use the collectors attribute.\nThe available collectors '
'are:'))
counter = 0
for name, _ in hive_collectors:
if not name:
name = 'Current Value'
banners.append(' {0:d} = {1:s}'.format(counter, name))
counter += 1
banners.append(
'To use the collector use:\ncollector = collectors[NR][1]\nwhere '
'NR is the number as listed above.')
else:
banners.append(frontend_utils.FormatOutputString(text, (
'Collector is an available attribute and NR is a number ranging'
' from 0 to {0:d} (see above which files these numbers belong to).'
' To get the name of the loaded hive use RegCache.GetHiveName()'
' and RegCache.hive_type to get the '
'type.').format(len(hives) + 1), len(text)))
else:
# We have a single hive but many collectors.
banners.append(
'There is more than one collector available for the hive that was '
'discovered. To open up a hive use:\nOpenHive(hive, collectors[NR][1])'
'\nWhere NR is one of the following values:')
counter = 0
for name, _ in hive_collectors:
if not name:
name = 'Current Value'
banners.append(' {0:d} = {1:s}'.format(counter, name))
counter += 1
banners.append('')
banners.append('Happy command line console fu-ing.')
# Adding variables in scope.
namespace.update(globals())
namespace.update({
'hives': hives,
'hive': hive,
'collector': hive_collector,
'collectors': hive_collectors})
# Starting the shell.
ipshell = InteractiveShellEmbed(
user_ns=namespace, banner1=u'\n'.join(banners), exit_msg='')
ipshell.confirm_exit = False
# Adding "magic" functions.
ipshell.register_magics(MyMagics)
# Registering command completion for the magic commands.
ipshell.set_hook('complete_command', CdCompleter, str_key='%cd')
ipshell.set_hook('complete_command', VerboseCompleter, str_key='%ls')
ipshell.set_hook('complete_command', VerboseCompleter, str_key='%parse')
ipshell.set_hook('complete_command', PluginCompleter, str_key='%plugin')
ipshell()
示例3: Device
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import register_magics [as 别名]
You can script the device's SCSI interface too:
sc c ac # Backdoor signature
sc 8 ff 00 ff # Undocumented firmware version
ALSO: reset, eject, sc_sense, sc_read, scsi_in, scsi_out
Happy hacking! -- Type 'thing?' for help on 'thing' or
~MeS`14 '?' for IPython, '%h' for this again.
"""
from IPython.terminal.embed import InteractiveShellEmbed
from shell_magics import ShellMagics
from remote import Device
import shell_namespace
# Make a global device, but only give it to the user namespace.
# Make it default by assigning it to 'd', our current device.
shell_namespace.d = shell_namespace.d_remote = Device()
# Make a shell that feels like a debugger
ipy = InteractiveShellEmbed(user_ns = shell_namespace.__dict__)
shell_namespace.ipy = ipy
ipy.register_magics(ShellMagics)
ipy.register_magic_function(lambda _: ipy.write(__doc__), magic_name='h')
ipy.alias_manager.define_alias('git', 'git')
ipy.alias_manager.define_alias('make', 'make')
# Hello, tiny world
ipy.mainloop(display_banner = __doc__)
示例4: RunModeConsole
# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import register_magics [as 别名]
#.........这里部分代码省略.........
u'pwd', u'Print the working "directory" or the path of the current key.',
function_name_length))
banners.append(frontend_utils.FormatOutputString(
u'plugin [-h] plugin_name', (
u'Run a particular key-based plugin on the loaded hive. The correct '
u'Registry key will be loaded, opened and then parsed.'),
function_name_length))
banners.append(frontend_utils.FormatOutputString(
u'get_value value_name', (
u'Get a value from the currently loaded Registry key.')))
banners.append(frontend_utils.FormatOutputString(
u'get_value_data value_name', (
u'Get a value data from a value stored in the currently loaded '
u'Registry key.')))
banners.append(frontend_utils.FormatOutputString(
u'get_key', u'Return the currently loaded Registry key.'))
banners.append(u'')
# Build the global cache and prepare the tool.
hive_storage = preg.PregStorage()
shell_helper = preg.PregHelper(options, front_end, hive_storage)
parser_mediator = shell_helper.BuildParserMediator()
preg.PregCache.parser_mediator = parser_mediator
preg.PregCache.shell_helper = shell_helper
preg.PregCache.hive_storage = hive_storage
registry_types = getattr(options, 'regfile', None)
if isinstance(registry_types, basestring):
registry_types = registry_types.split(u',')
if not registry_types:
registry_types = [
'NTUSER', 'USRCLASS', 'SOFTWARE', 'SYSTEM', 'SAM', 'SECURITY']
preg.PregCache.shell_helper.Scan(registry_types)
if len(preg.PregCache.hive_storage) == 1:
preg.PregCache.hive_storage.SetOpenHive(0)
hive_helper = preg.PregCache.hive_storage.loaded_hive
banners.append(
u'Opening hive: {0:s} [{1:s}]'.format(
hive_helper.path, hive_helper.collector_name))
ConsoleConfig.SetPrompt(hive_path=hive_helper.path)
loaded_hive = preg.PregCache.hive_storage.loaded_hive
if loaded_hive and loaded_hive.name != u'N/A':
banners.append(
u'Registry hive: {0:s} is available and loaded.'.format(
loaded_hive.name))
else:
banners.append(u'More than one Registry file ready for use.')
banners.append(u'')
banners.append(preg.PregCache.hive_storage.ListHives())
banners.append(u'')
banners.append((
u'Use "hive open INDEX" to load a hive and "hive list" to see a '
u'list of available hives.'))
banners.append(u'')
banners.append(u'Happy command line console fu-ing.')
# Adding variables in scope.
namespace.update(globals())
namespace.update({
'get_current_key': GetCurrentKey,
'get_key': GetCurrentKey,
'get_value': GetValue,
'get_value_data': GetValueData,
'number_of_hives': GetTotalNumberOfLoadedHives,
'range_of_hives': GetRangeForAllLoadedHives,
'options': options})
ipshell_config = ConsoleConfig.GetConfig()
if loaded_hive:
ConsoleConfig.SetPrompt(
hive_path=loaded_hive.name, config=ipshell_config)
else:
ConsoleConfig.SetPrompt(hive_path=u'NO HIVE LOADED', config=ipshell_config)
# Starting the shell.
ipshell = InteractiveShellEmbed(
user_ns=namespace, config=ipshell_config, banner1=u'\n'.join(banners),
exit_msg='')
ipshell.confirm_exit = False
# Adding "magic" functions.
ipshell.register_magics(MyMagics)
# Set autocall to two, making parenthesis not necessary when calling
# function names (although they can be used and are necessary sometimes,
# like in variable assignments, etc).
ipshell.autocall = 2
# Registering command completion for the magic commands.
ipshell.set_hook('complete_command', CdCompleter, str_key='%cd')
ipshell.set_hook('complete_command', VerboseCompleter, str_key='%ls')
ipshell.set_hook('complete_command', VerboseCompleter, str_key='%parse')
ipshell.set_hook('complete_command', PluginCompleter, str_key='%plugin')
ipshell()