def re_escape(pattern, chars=frozenset("<STR_LIT>")):
escape = '<STR_LIT>'.format<EOL>return '<STR_LIT>'.join(<EOL>escape(c) if c in chars or c.isspace() else<EOL>'<STR_LIT>' if c == '<STR_LIT:\x00>' else c<EOL>for c in pattern<EOL>)<EOL>
Escape all special regex characters in pattern.
Logic taken from regex module.

:param pattern: regex pattern to escape
:type patterm: str
:returns: escaped pattern
:rtype: str