def MergeData(self, merge_data, raw_data=None):
    """Merges data read from a config file into the current config."""
    self.FlushCache()
    if raw_data is None:
      raw_data = self.raw_data

    for k, v in iteritems(merge_data):
      # A context clause.
      if isinstance(v, dict) and k not in self.type_infos:
        if k not in self.valid_contexts:
          raise InvalidContextError("Invalid context specified: %s" % k)
        context_data = raw_data.setdefault(k, collections.OrderedDict())
        self.MergeData(v, context_data)

      else:
        # Find the descriptor for this field.
        descriptor = self.type_infos.get(k)
        if descriptor is None:
          msg = ("Missing config definition for %s. This option is likely "
                 "deprecated or renamed. Check the release notes." % k)
          if flags.FLAGS.disallow_missing_config_definitions:
            raise MissingConfigDefinitionError(msg)

        if isinstance(v, string_types):
          v = v.strip()

        # If we are already initialized and someone tries to modify a constant
        # value (e.g. via Set()), break loudly.
        if self.initialized and k in self.constants:
          raise ConstModificationError(
              "Attempting to modify constant value %s" % k)

        raw_data[k] = v
def MergeData ( self , merge_data , raw_data = None ) : self . FlushCache ( ) if raw_data is None : raw_data = self . raw_data for k , v in iteritems ( merge_data ) : if isinstance ( v , dict ) and k not in self . type_infos : if k not in self . valid_contexts : raise InvalidContextError ( "Invalid context specified: %s" % k ) context_data = raw_data . setdefault ( k , collections . OrderedDict ( ) ) self . MergeData ( v , context_data ) else : descriptor = self . type_infos . get ( k ) if descriptor is None : msg = ( "Missing config definition for %s. This option is likely " "deprecated or renamed. Check the release notes." % k ) if flags . FLAGS . disallow_missing_config_definitions : raise MissingConfigDefinitionError ( msg ) if isinstance ( v , string_types ) : v = v . strip ( ) if self . initialized and k in self . constants : raise ConstModificationError ( "Attempting to modify constant value %s" % k ) raw_data [ k ] = v
Merges data read from a config file into the current config.