def test_is_word(): assert rsre_char.is_word(ord('A')) assert rsre_char.is_word(ord('_')) assert not rsre_char.is_word(UPPER_PI) assert not rsre_char.is_word(LOWER_PI) assert not rsre_char.is_word(ord(',')) # assert rsre_char.is_uni_word(ord('A')) assert rsre_char.is_uni_word(ord('_')) assert rsre_char.is_uni_word(UPPER_PI) assert rsre_char.is_uni_word(LOWER_PI) assert not rsre_char.is_uni_word(ord(','))
def _parse_escape(source, info, in_set): saved_ignore = source.ignore_space source.ignore_space = False ch = source.get() source.ignore_space = saved_ignore if not ch: return Character(0) if ch == u"g" and not in_set: here = source.pos try: return _parse_group_ref(source, info) except RegexpError: source.pos = here return make_character(info, ord(ch[0]), in_set) elif ch == u"G" and not in_set: return AtPosition(AT_BEGINNING) elif ch in u"pP": return _parse_property(source, info, ch == u"p", in_set) elif is_word(ord(ch[0])): if not in_set: if ch in POSITION_ESCAPES: return POSITION_ESCAPES[ch] if ch in CHARSET_ESCAPES: return CHARSET_ESCAPES[ch] elif ch in CHARACTER_ESCAPES: return Character(ord(CHARACTER_ESCAPES[ch])) return make_character(info, ord(ch[0]), in_set) if is_digit(ord(ch[0])): return _parse_numeric_escape(source, info, ch, in_set) else: return make_character(info, ord(ch[0]), in_set)
def _parse_escape(source, info, in_set): saved_ignore = source.ignore_space source.ignore_space = False ch = source.get() source.ignore_space = saved_ignore if not ch: raise RegexpError("bad escape") if ch == u"g" and not in_set: here = source.pos try: return _parse_group_ref(source, info) except RegexpError: source.pos = here return make_character(info, ord(ch[0]), in_set) elif ch == u"G" and not in_set: return AtPosition(AT_BEGINNING) elif ch in u"pP": return _parse_property(source, info, ch == u"p", in_set) elif is_word(ord(ch[0])): if not in_set: if ch in POSITION_ESCAPES: return POSITION_ESCAPES[ch] if ch in CHARSET_ESCAPES: return CHARSET_ESCAPES[ch] elif ch in CHARACTER_ESCAPES: return Character(ord(CHARACTER_ESCAPES[ch])) return make_character(info, ord(ch[0]), in_set) if is_digit(ord(ch[0])): return _parse_numeric_escape(source, info, ch, in_set) else: return make_character(info, ord(ch[0]), in_set)