Пример #1
0
    def _AddFromConfigHelper(self, document, context):
        """Helper method that reads a single yaml document and adds all subfields found.

    Also adds any findings to the subfield.

    Args:
      document: yaml document
      context: config file context
    """
        for category in SubfieldCategory:
            category_name = _SUBFIELD_CATEGORY_NAMES[category]
            if category_name not in document:
                continue
            # TODO(berkoben): Add warnings for unrecognized fields

            subfield_map = document[category_name]
            if not subfield_map:
                self.AddFinding(
                    findings_lib.EmptyBlockWarning(document, context))
                continue

            for subfield_name in subfield_map:
                # TODO(berkoben): Add handling for tagged measurement types
                description = subfield_map[subfield_name]
                self.AddSubfield(
                    Subfield(subfield_name, category, description, context))
Пример #2
0
    def _AddFromConfigHelper(self, document, context):
        """Helper method that reads a single yaml document and adds all fields found.

    Also adds any findings to the field.

    Args:
      document: yaml document
      context: config file context
    """
        if 'literals' not in document:
            self.AddFinding(
                findings_lib.UnrecognizedFormatError(document, context))
            return
        field_list = document['literals']
        if field_list is None:
            self.AddFinding(findings_lib.EmptyBlockWarning(document, context))
            return
        for field_spec in field_list:
            field_name = ''
            states = None
            if isinstance(field_spec, dict):
                # If the field has a list of states, field_spec must be a dict with
                # a single entry.
                try:
                    [(field_name, states)] = field_spec.items()
                except ValueError:
                    self.AddFinding(
                        findings_lib.InvalidFieldFormatError(
                            document, context))
                    continue
            else:
                field_name = field_spec
            field = Field(field_name, states, context)
            self.AddField(field)
Пример #3
0
  def _AddFromConfigHelper(self, document, context):
    """Helper method that reads a single yaml document and adds all fields found.

    Also adds any findings to the field.

    Args:
      document: yaml document
      context: config file context
    """
    if 'literals' not in document:
      self.AddFinding(findings_lib.UnrecognizedKeyError(document, context))
      return
    field_list = document['literals']
    if field_list is None:
      self.AddFinding(findings_lib.EmptyBlockWarning('literals', context))
      return
    for field_spec in field_list:
      field_name = ''
      states = None
      if isinstance(field_spec, dict):
        # If the field has a list of states, field_spec must be a dict with
        # a single entry.
        if len(field_spec) == 1:
          # TODO(b/188242279) handle namespacing for states correctly.
          field_name, states = next(iter(field_spec.items()))
        else:
          field_name = next(iter(field_spec), '(Blank)')
          self.AddFinding(
              findings_lib.InvalidFieldFormatError(field_name, context))
          continue
      else:
        field_name = field_spec
      field = Field(field_name, states, context)
      self.AddField(field)