def css_escape(s):
    """from http://mathiasbynens.be/notes/css-escapes"""
    s = re.sub(r'(^-$|[ !"#\$%&\'()*+,./:;<=>?@\[\\\]^`{|}~])', r'\\\1', s)
    s = re.sub(r'^(-?)(\d)', lambda m: '%s\%x ' % (m.group(1), ord(m.group(2))), s)
    s = re.sub(r'([\t\n\v\f\r])', lambda m: '\%x ' % ord(m.group(1)), s)
    return s
from http://mathiasbynens.be/notes/css-escapes
slybot/slybot/plugins/scrapely_annotations/migration.py