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


Python descriptor._value函数代码示例

本文整理汇总了Python中stem.descriptor._value函数的典型用法代码示例。如果您正苦于以下问题:Python _value函数的具体用法?Python _value怎么用?Python _value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _parse_version_line

def _parse_version_line(descriptor, entries):
  value = _value('version', entries)

  if value.isdigit():
    descriptor.version = int(value)
  else:
    raise ValueError('version line must have a positive integer value: %s' % value)
开发者ID:sammyshj,项目名称:stem,代码行数:7,代码来源:hidden_service_descriptor.py

示例2: _parse_geoip_to_count_line

def _parse_geoip_to_count_line(keyword, attribute, descriptor, entries):
  # "<keyword>" CC=N,CC=N,...
  #
  # The maxmind geoip (https://www.maxmind.com/app/iso3166) has numeric
  # locale codes for some special values, for instance...
  #   A1,"Anonymous Proxy"
  #   A2,"Satellite Provider"
  #   ??,"Unknown"

  value, locale_usage = _value(keyword, entries), {}
  error_msg = 'Entries in %s line should only be CC=N entries: %s %s' % (keyword, keyword, value)

  if value:
    for entry in value.split(','):
      if '=' not in entry:
        raise ValueError(error_msg)

      locale, count = entry.split('=', 1)

      if _locale_re.match(locale) and count.isdigit():
        locale_usage[locale] = int(count)
      else:
        raise ValueError(error_msg)

  setattr(descriptor, attribute, locale_usage)
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:25,代码来源:extrainfo_descriptor.py

示例3: _parse_hs_stats

def _parse_hs_stats(keyword, stat_attribute, extra_attribute, descriptor, entries):
  # "<keyword>" num key=val key=val...

  value, stat, extra = _value(keyword, entries), None, {}

  if value is not None:
    value_comp = value.split()

    if not value_comp:
      raise ValueError("'%s' line was blank" % keyword)

    try:
      stat = int(value_comp[0])
    except ValueError:
      raise ValueError("'%s' stat was non-numeric (%s): %s %s" % (keyword, value_comp[0], keyword, value))

    for entry in value_comp[1:]:
      if '=' not in entry:
        raise ValueError('Entries after the stat in %s lines should only be key=val entries: %s %s' % (keyword, keyword, value))

      key, val = entry.split('=', 1)
      extra[key] = val

  setattr(descriptor, stat_attribute, stat)
  setattr(descriptor, extra_attribute, extra)
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:25,代码来源:extrainfo_descriptor.py

示例4: _parse_w_line

def _parse_w_line(descriptor, entries):
  # "w" "Bandwidth=" INT ["Measured=" INT] ["Unmeasured=1"]
  # example: w Bandwidth=7980

  value = _value('w', entries)
  w_comp = value.split(' ')

  if len(w_comp) < 1:
    raise ValueError("%s 'w' line is blank: w %s" % (descriptor._name(), value))
  elif not w_comp[0].startswith('Bandwidth='):
    raise ValueError("%s 'w' line needs to start with a 'Bandwidth=' entry: w %s" % (descriptor._name(), value))

  for w_entry in w_comp:
    if '=' in w_entry:
      w_key, w_value = w_entry.split('=', 1)
    else:
      w_key, w_value = w_entry, None

    if w_key == 'Bandwidth':
      if not (w_value and w_value.isdigit()):
        raise ValueError("%s 'Bandwidth=' entry needs to have a numeric value: w %s" % (descriptor._name(), value))

      descriptor.bandwidth = int(w_value)
    elif w_key == 'Measured':
      if not (w_value and w_value.isdigit()):
        raise ValueError("%s 'Measured=' entry needs to have a numeric value: w %s" % (descriptor._name(), value))

      descriptor.measured = int(w_value)
    elif w_key == 'Unmeasured':
      if w_value != '1':
        raise ValueError("%s 'Unmeasured=' should only have the value of '1': w %s" % (descriptor._name(), value))

      descriptor.is_unmeasured = True
    else:
      descriptor.unrecognized_bandwidth_entries.append(w_entry)
开发者ID:FedericoCeratto,项目名称:stem,代码行数:35,代码来源:router_status_entry.py

示例5: _parse_hidden_service_dir_line

def _parse_hidden_service_dir_line(descriptor, entries):
  value = _value('hidden-service-dir', entries)

  if value:
    descriptor.hidden_service_dir = value.split(' ')
  else:
    descriptor.hidden_service_dir = ['2']
开发者ID:sammyshj,项目名称:stem,代码行数:7,代码来源:server_descriptor.py

示例6: _parse_dirreq_line

def _parse_dirreq_line(keyword, recognized_counts_attr, unrecognized_counts_attr, descriptor, entries):
  value = _value(keyword, entries)

  recognized_counts = {}
  unrecognized_counts = {}

  is_response_stats = keyword in ('dirreq-v2-resp', 'dirreq-v3-resp')
  key_set = DirResponse if is_response_stats else DirStat

  key_type = 'STATUS' if is_response_stats else 'STAT'
  error_msg = '%s lines should contain %s=COUNT mappings: %s %s' % (keyword, key_type, keyword, value)

  if value:
    for entry in value.split(','):
      if '=' not in entry:
        raise ValueError(error_msg)

      status, count = entry.split('=', 1)

      if count.isdigit():
        if status in key_set:
          recognized_counts[status] = int(count)
        else:
          unrecognized_counts[status] = int(count)
      else:
        raise ValueError(error_msg)

  setattr(descriptor, recognized_counts_attr, recognized_counts)
  setattr(descriptor, unrecognized_counts_attr, unrecognized_counts)
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:29,代码来源:extrainfo_descriptor.py

示例7: _parse_extrainfo_digest_line

def _parse_extrainfo_digest_line(descriptor, entries):
  value = _value('extra-info-digest', entries)
  value = value.split(' ')[0]  # lines have additional content from propsal 228, waiting for it to be documented: #16227

  if not stem.util.tor_tools.is_hex_digits(value, 40):
    raise ValueError('extra-info-digest should be 40 hex characters: %s' % value)

  descriptor.extra_info_digest = value
开发者ID:sammyshj,项目名称:stem,代码行数:8,代码来源:server_descriptor.py

示例8: _parse_hibernating_line

def _parse_hibernating_line(descriptor, entries):
  # "hibernating" 0|1 (in practice only set if one)

  value = _value('hibernating', entries)

  if value not in ('0', '1'):
    raise ValueError('Hibernating line had an invalid value, must be zero or one: %s' % value)

  descriptor.hibernating = value == '1'
开发者ID:sammyshj,项目名称:stem,代码行数:9,代码来源:server_descriptor.py

示例9: _parse_id_line

def _parse_id_line(descriptor, entries):
  value = _value('id', entries)
  value_comp = value.split()

  if len(value_comp) >= 2:
    descriptor.identifier_type = value_comp[0]
    descriptor.identifier = value_comp[1]
  else:
    raise ValueError("'id' lines should contain both the key type and digest: id %s" % value)
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:9,代码来源:microdescriptor.py

示例10: _parse_extrainfo_digest_line

def _parse_extrainfo_digest_line(descriptor, entries):
  value = _value('extra-info-digest', entries)
  digest_comp = value.split(' ')

  if not stem.util.tor_tools.is_hex_digits(digest_comp[0], 40):
    raise ValueError('extra-info-digest should be 40 hex characters: %s' % digest_comp[0])

  descriptor.extra_info_digest = digest_comp[0]
  descriptor.extra_info_sha256_digest = digest_comp[1] if len(digest_comp) >= 2 else None
开发者ID:patrickod,项目名称:stem,代码行数:9,代码来源:server_descriptor.py

示例11: _parse_protocols_line

def _parse_protocols_line(descriptor, entries):
  value = _value('protocols', entries)
  protocols_match = re.match('^Link (.*) Circuit (.*)$', value)

  if not protocols_match:
    raise ValueError('Protocols line did not match the expected pattern: protocols %s' % value)

  link_versions, circuit_versions = protocols_match.groups()
  descriptor.link_protocols = link_versions.split(' ')
  descriptor.circuit_protocols = circuit_versions.split(' ')
开发者ID:sammyshj,项目名称:stem,代码行数:10,代码来源:server_descriptor.py

示例12: _parse_p_line

def _parse_p_line(descriptor, entries):
  # "p" ("accept" / "reject") PortList
  # p reject 1-65535
  # example: p accept 80,110,143,443,993,995,6660-6669,6697,7000-7001

  value = _value('p', entries)

  try:
    descriptor.exit_policy = stem.exit_policy.MicroExitPolicy(value)
  except ValueError as exc:
    raise ValueError('%s exit policy is malformed (%s): p %s' % (descriptor._name(), exc, value))
开发者ID:FedericoCeratto,项目名称:stem,代码行数:11,代码来源:router_status_entry.py

示例13: _parse_dirreq_share_line

def _parse_dirreq_share_line(keyword, attribute, descriptor, entries):
  value = _value(keyword, entries)

  if not value.endswith('%'):
    raise ValueError('%s lines should be a percentage: %s %s' % (keyword, keyword, value))
  elif float(value[:-1]) < 0:
    raise ValueError('Negative percentage value: %s %s' % (keyword, value))

  # bug means it might be above 100%: https://lists.torproject.org/pipermail/tor-dev/2012-June/003679.html

  setattr(descriptor, attribute, float(value[:-1]) / 100)
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:11,代码来源:extrainfo_descriptor.py

示例14: _parse_cell_circuits_per_decline_line

def _parse_cell_circuits_per_decline_line(descriptor, entries):
  # "cell-circuits-per-decile" num

  value = _value('cell-circuits-per-decile', entries)

  if not value.isdigit():
    raise ValueError('Non-numeric cell-circuits-per-decile value: %s' % value)
  elif int(value) < 0:
    raise ValueError('Negative cell-circuits-per-decile value: %s' % value)

  descriptor.cell_circuits_per_decile = int(value)
开发者ID:Fuzew,项目名称:sharp-stem,代码行数:11,代码来源:extrainfo_descriptor.py

示例15: _parse_protocol_versions_line

def _parse_protocol_versions_line(descriptor, entries):
  value = _value('protocol-versions', entries)

  try:
    versions = [int(entry) for entry in value.split(',')]
  except ValueError:
    raise ValueError('protocol-versions line has non-numeric versoins: protocol-versions %s' % value)

  for v in versions:
    if v <= 0:
      raise ValueError('protocol-versions must be positive integers: %s' % value)

  descriptor.protocol_versions = versions
开发者ID:sammyshj,项目名称:stem,代码行数:13,代码来源:hidden_service_descriptor.py


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