Пример #1
0
def compile(pattern, flags=None, alphabet=None, engine=None):
    require_engine(engine)
    if isinstance(pattern, RegexObject):
        if flags is not None and flags != pattern.flags:
            raise ValueError('Changed flags')
        if alphabet is not None and alphabet != pattern.alphabet:
            raise ValueError('Changed alphabet')
    else:
        if flags is None:
            flags = 0
        if isinstance(pattern, str):
            hint_alphabet = Ascii()
        elif isinstance(pattern, unicode):
            hint_alphabet = Unicode()
        else:
            hint_alphabet = None
        pattern = RegexObject(parse_pattern(pattern, engine, flags=flags, 
                                            alphabet=alphabet, 
                                            hint_alphabet=hint_alphabet),
                              pattern, engine=engine)
    return pattern
Пример #2
0
def compile(pattern, flags=None, alphabet=None, engine=None):
    require_engine(engine)
    if isinstance(pattern, RegexObject):
        if flags is not None and flags != pattern.flags:
            raise ValueError('Changed flags')
        if alphabet is not None and alphabet != pattern.alphabet:
            raise ValueError('Changed alphabet')
    else:
        if flags is None:
            flags = 0
        if isinstance(pattern, str):
            hint_alphabet = Ascii()
        elif isinstance(pattern, unicode):
            hint_alphabet = Unicode()
        else:
            hint_alphabet = None
        pattern = RegexObject(parse_pattern(pattern,
                                            engine,
                                            flags=flags,
                                            alphabet=alphabet,
                                            hint_alphabet=hint_alphabet),
                              pattern,
                              engine=engine)
    return pattern
Пример #3
0
 def parse(self, regexp, flags=0, alphabet=None):
     return parse_pattern(regexp,
                          self.default_engine(),
                          alphabet=alphabet if alphabet else self._alphabet,
                          flags=flags)
Пример #4
0
def parse(pattern, replacement):
    (state, _graph) = parse_pattern(pattern, BaseEngine)
    return parse_replace(replacement, state)
Пример #5
0
def parse(pattern, flags=0):
    return parse_pattern(pattern, BaseEngine, flags=flags)
Пример #6
0
def parse(pattern, engine=BaseEngine, flags=0):
    return parse_pattern(pattern, engine, flags=flags)
Пример #7
0
 def parse(self, regexp, flags=0, alphabet=None):
     return parse_pattern(regexp, self.default_engine(),
                          alphabet=alphabet if alphabet else self._alphabet, 
                          flags=flags)