code: def escape(string, escape_pattern):
      
      try:
          return string.translate(escape_pattern)
      except AttributeError:
          warnings.warn("Non-string-like data passed. "
                        "Attempting to convert to 'str'.")
          return str(string).translate(tag_escape)
docs: Assistant function for string escaping