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


Python InteractiveShellEmbed.set_hook方法代码示例

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


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

示例1: interact_ipython

# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import set_hook [as 别名]
    def interact_ipython(header='', *args, **kwargs):
        global interact_ipython_

        def pre_prompt_hook(_):
            R.gInterpreter.EndOfLineAction()

        # Interact is a callable which starts an ipython shell
        if not interact_ipython_:
            interact_ipython_ = InteractiveShellEmbed(banner1=UP_LINE)
        # needed for graphics to work correctly
        interact_ipython_.set_hook('pre_prompt_hook', pre_prompt_hook)
        stack_depth = kwargs.pop("stack_depth", 0) + 2
        kwargs["stack_depth"] = stack_depth
        interact_ipython_(header, *args, **kwargs)
开发者ID:S-Bahrasemani,项目名称:rootpy,代码行数:16,代码来源:console.py

示例2: RunModeConsole

# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import set_hook [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()
开发者ID:iwm911,项目名称:plaso,代码行数:104,代码来源:preg.py

示例3: RunModeConsole

# 需要导入模块: from IPython.terminal.embed import InteractiveShellEmbed [as 别名]
# 或者: from IPython.terminal.embed.InteractiveShellEmbed import set_hook [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()
开发者ID:cnbird1999,项目名称:plaso,代码行数:104,代码来源:preg.py


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