Exemple #1
0
    def from_cache(
        path: str = FALLBACK_CACHE_PATH
    ) -> Dict[str, 'stem.directory.Fallback']:
        conf = stem.util.conf.Config()
        conf.load(path)
        headers = collections.OrderedDict([(k.split('.', 1)[1], conf.get(k))
                                           for k in conf.keys()
                                           if k.startswith('header.')])

        results = {}

        for fingerprint in set([key.split('.')[0] for key in conf.keys()]):
            if fingerprint in ('tor_commit', 'stem_commit', 'header'):
                continue

            attr = {}

            for attr_name in ('address', 'or_port', 'dir_port', 'nickname',
                              'has_extrainfo', 'orport6_address',
                              'orport6_port'):
                key = '%s.%s' % (fingerprint, attr_name)
                attr[attr_name] = conf.get(key)

                if not attr[attr_name] and attr_name not in ('nickname',
                                                             'has_extrainfo',
                                                             'orport6_address',
                                                             'orport6_port'):
                    raise IOError("'%s' is missing from %s" %
                                  (key, FALLBACK_CACHE_PATH))

            if attr['orport6_address'] and attr['orport6_port']:
                orport_v6 = (attr['orport6_address'],
                             int(attr['orport6_port']))
            else:
                orport_v6 = None

            results[fingerprint] = Fallback(
                address=attr['address'],
                or_port=int(attr['or_port']),
                dir_port=int(attr['dir_port']),
                fingerprint=fingerprint,
                nickname=attr['nickname'],
                has_extrainfo=attr['has_extrainfo'] == 'true',
                orport_v6=orport_v6,
                header=headers,
            )

        return results
Exemple #2
0
  def _from_config_cache(path):
    conf = stem.util.conf.Config()
    conf.load(path, commenting = False)

    config_options = OrderedDict()

    for key in conf.keys():
      if key.startswith('config_options.'):
        key = key.split('.')[1]

        if key not in config_options:
          config_options[key] = ConfigOption(
            conf.get('config_options.%s.name' % key, ''),
            conf.get('config_options.%s.category' % key, ''),
            conf.get('config_options.%s.usage' % key, ''),
            conf.get('config_options.%s.summary' % key, ''),
            conf.get('config_options.%s.description' % key, '')
          )

    manual = Manual(
      conf.get('name', ''),
      conf.get('synopsis', ''),
      conf.get('description', ''),
      conf.get('commandline_options', OrderedDict()),
      conf.get('signals', OrderedDict()),
      conf.get('files', OrderedDict()),
      config_options,
    )

    manual.man_commit = conf.get('man_commit', None)
    manual.stem_commit = conf.get('stem_commit', None)

    return manual
Exemple #3
0
  def from_cache(path = None):
    """
    Provides manual information cached with Stem. Unlike
    :func:`~stem.manual.Manual.from_man` and
    :func:`~stem.manual.Manual.from_remote` this doesn't have any system
    requirements, and is faster too. Only drawback is that this manual
    content is only as up to date as the Stem release we're using.

    :param str path: cached manual content to read, if not provided this uses
      the bundled manual information

    :returns: :class:`~stem.manual.Manual` with our bundled manual information

    :raises: **IOError** if a **path** was provided and we were unable to read it
    """

    conf = stem.util.conf.Config()
    conf.load(path if path else CACHE_PATH, commenting = False)

    config_options = OrderedDict()

    for key in conf.keys():
      if key.startswith('config_options.'):
        key = key.split('.')[1]

        if key not in config_options:
          config_options[key] = ConfigOption(
            conf.get('config_options.%s.name' % key, ''),
            conf.get('config_options.%s.category' % key, ''),
            conf.get('config_options.%s.usage' % key, ''),
            conf.get('config_options.%s.summary' % key, ''),
            conf.get('config_options.%s.description' % key, '')
          )

    manual = Manual(
      conf.get('name', ''),
      conf.get('synopsis', ''),
      conf.get('description', ''),
      conf.get('commandline_options', {}),
      conf.get('signals', {}),
      conf.get('files', {}),
      config_options,
    )

    manual.man_commit = conf.get('man_commit', None)
    manual.stem_commit = conf.get('stem_commit', None)

    return manual
Exemple #4
0
  def from_cache(path = None):
    """
    Provides manual information cached with Stem. Unlike
    :func:`~stem.manual.Manual.from_man` and
    :func:`~stem.manual.Manual.from_remote` this doesn't have any system
    requirements, and is faster too. Only drawback is that this manual
    content is only as up to date as the Stem release we're using.

    :param str path: cached manual content to read, if not provided this uses
      the bundled manual information

    :returns: :class:`~stem.manual.Manual` with our bundled manual information

    :raises: **IOError** if a **path** was provided and we were unable to read it
    """

    conf = stem.util.conf.Config()
    conf.load(path if path else CACHE_PATH, commenting = False)

    config_options = OrderedDict()

    for key in conf.keys():
      if key.startswith('config_options.'):
        key = key.split('.')[1]

        if key not in config_options:
          config_options[key] = ConfigOption(
            conf.get('config_options.%s.name' % key, ''),
            conf.get('config_options.%s.category' % key, ''),
            conf.get('config_options.%s.usage' % key, ''),
            conf.get('config_options.%s.summary' % key, ''),
            conf.get('config_options.%s.description' % key, '')
          )

    manual = Manual(
      conf.get('name', ''),
      conf.get('synopsis', ''),
      conf.get('description', ''),
      conf.get('commandline_options', {}),
      conf.get('signals', {}),
      conf.get('files', {}),
      config_options,
    )

    manual.man_commit = conf.get('man_commit', None)
    manual.stem_commit = conf.get('stem_commit', None)

    return manual