def METHOD_NAME(self, ns):
    """Process a string that needs to undergo entity substitution.
    This may be a string encountered in an attribute value or as
    text.
    :param ns: A string.
    :return: A string with certain characters replaced by named
       or numeric entities.
    """
    if not self.entity_substitution:
        return ns
    from .element import NavigableString
    if (isinstance(ns, NavigableString)
        and ns.parent is not None
        and ns.parent.name in self.cdata_containing_tags):
        # Do nothing.
        return ns
    # Substitute.
    return self.entity_substitution(ns)