tools/json_schema_compiler/feature_compiler.py
def _FindParent(self, feature_name, feature_value):
    """Checks to see if a feature has a parent. If it does, returns the
    parent."""
    no_parent = False
    if type(feature_value) is list:
      no_parent_values = ['noparent' in v for v in feature_value]
      no_parent = all(no_parent_values)
      assert no_parent or not any(no_parent_values), (
              '"%s:" All child features must contain the same noparent value' %
                  feature_name)
    else:
      no_parent = 'noparent' in feature_value
    sep = feature_name.rfind('.')
    if sep == -1 or no_parent:
      return None

    parent_name = feature_name[:sep]
    while sep != -1 and parent_name not in self._features:
      # This recursion allows for a feature to have a parent that isn't a direct
      # ancestor. For instance, we could have feature 'alpha', and feature
      # 'alpha.child.child', where 'alpha.child.child' inherits from 'alpha'.
      # TODO(devlin): Is this useful? Or logical?
      sep = feature_name.rfind('.', 0, sep)
      parent_name = feature_name[:sep]

    if sep == -1:
      # TODO(devlin): It'd be kind of nice to be able to assert that the
      # deduced parent name is in our features, but some dotted features don't
      # have parents and also don't have noparent, e.g. system.cpu. We should
      # probably just noparent them so that we can assert this.
      #   raise KeyError('Could not find parent "%s" for feature "%s".' %
      #                      (parent_name, feature_name))
      return None
    return self._features[parent_name].AsParent()
Checks to see if a feature has a parent. If it does, returns the
    parent.
Checks to see if a feature has a parent. If it does, returns the
parent.
Checks to see if a feature has a parent . If it does returns the parent .
def _FindParent(self, feature_name, feature_value):
    no_parent = False
    if type(feature_value) is list:
      no_parent_values = ['noparent' in v for v in feature_value]
      no_parent = all(no_parent_values)
      assert no_parent or not any(no_parent_values), (
              '"%s:" All child features must contain the same noparent value' %
                  feature_name)
    else:
      no_parent = 'noparent' in feature_value
    sep = feature_name.rfind('.')
    if sep == -1 or no_parent:
      return None
    parent_name = feature_name[:sep]
    while sep != -1 and parent_name not in self._features:
      sep = feature_name.rfind('.', 0, sep)
      parent_name = feature_name[:sep]
    if sep == -1:
      return None
    return self._features[parent_name].AsParent()
def _FindParent ( self , feature_name , feature_value ) : no_parent = False if type ( feature_value ) is list : no_parent_values = [ 'noparent' in v for v in feature_value ] no_parent = all ( no_parent_values ) assert no_parent or not any ( no_parent_values ) , ( '"%s:" All child features must contain the same noparent value' % feature_name ) else : no_parent = 'noparent' in feature_value sep = feature_name . rfind ( '.' ) if sep == - 1 or no_parent : return None parent_name = feature_name [ : sep ] while sep != - 1 and parent_name not in self . _features : sep = feature_name . rfind ( '.' , 0 , sep ) parent_name = feature_name [ : sep ] if sep == - 1 : return None return self . _features [ parent_name ] . AsParent ( )
Checks to see if a feature has a parent.
Checks to see if a feature has a parent .
"""Checks to see if a feature has a parent. If it does, returns the
    parent.""" # This recursion allows for a feature to have a parent that isn't a direct # ancestor. For instance, we could have feature 'alpha', and feature # 'alpha.child.child', where 'alpha.child.child' inherits from 'alpha'. # TODO(devlin): Is this useful? Or logical? # TODO(devlin): It'd be kind of nice to be able to assert that the # deduced parent name is in our features, but some dotted features don't # have parents and also don't have noparent, e.g. system.cpu. We should # probably just noparent them so that we can assert this. #   raise KeyError('Could not find parent "%s" for feature "%s".' % #                      (parent_name, feature_name))
self
feature_name
feature_value