if sys.maxunicode >= 65536:
    _illegal_unichrs.extend([(131070, 131071), (196606, 196607), (262142, 
        262143), (327678, 327679), (393214, 393215), (458750, 458751), (
        524286, 524287), (589822, 589823), (655358, 655359), (720894, 
        720895), (786430, 786431), (851966, 851967), (917502, 917503), (
        983038, 983039), (1048574, 1048575), (1114110, 1114111)])
_illegal_ranges = [('%s-%s' % (chr(low), chr(high))) for low, high in
    _illegal_unichrs]
_illegal_xml_chars_RE = re.compile('[%s]' % ''.join(_illegal_ranges))
Fast way to filter illegal xml unicode chars in python?