def ApplyFormat(self, variable, name, policy):
    expansions = dict(name=name)
    # The variable should always be present in normal execution. We allow
    # it to be None solely for testing.
    # TODO(user): Figure out a way to fail hard if not present during
    # execution, even though django catches the error and siliently ignores it.
    # OR... maybe just fix the tests to always pass in the complete kind of
    # object we need.
    parent_name = 'global'
    if variable:
      if hasattr(variable, 'module'):
        expansions['module'] = variable.module.name
      if hasattr(variable, 'api'):
        api = variable.api
        if api:
          api_name = api.GetTemplateValue('wireName') or parent_name
        expansions['api_name'] = self.ApplyCaseTransform(api_name, policy)
      if hasattr(variable, 'parent'):
        parent = variable.parent
        if parent:
          parent_name = parent.GetTemplateValue('wireName') or parent_name
      if hasattr(variable, 'schema'):
        # This lets the format string access all template values on schema,
        # which is powerful but potentially flaky if the schema changes.
        expansions['schema'] = variable.schema
      expansions['variable_name'] = self.ApplyCaseTransform(
          variable.GetTemplateValue('wireName') or '', policy)
    expansions['parent_name'] = self.ApplyCaseTransform(parent_name,
                                                        policy)
    # TODO(user): Expand the range of things available.
    return policy.format_string.format(**expansions)
The render function is used to transform a BBCodeTag and its context (value, option) to
dataset/ETHPy150Open google/apis-client-generator/src/googleapis/codegen/language_model.py/LanguageModel.ApplyFormat--crossover with--dataset/ETHPy150Open ellmetha/django-precise-bbcode/precise_bbcode/bbcode/tag.py/BBCodeTag.render