import re


def _SageEscape(s):
  """Encode a string so it's safe to include in a SageTV config file."""
  return re.sub(re.compile(r"[^\w'\- !@#$%^*_+,.&]", re.UNICODE), '_',
                s.strip()).encode('unicode-escape')