Apply a mapping of name-value-pairs to a template.

def apply(self, mapping):
        """Apply a mapping of name-value-pairs to a template."""
        mapping = {name: self.str(value, tolerant=self.tolerant)
                   for name, value in mapping.items()
                   if value is not None or self.tolerant}

        if self.tolerant:
            return self.template.safe_substitute(mapping)

        return self.template.substitute(mapping)