Пример #1
0
def match(pattern, string, start=0, end=sys.maxint, fullmatch=False):
    start, end = _adjust(start, end, len(string))
    start = Position(start)
    end = Position(end)
    ctx = MatchContextForTests(string, start, end)
    ctx.fullmatch_only = fullmatch
    if match_context(ctx, pattern):
        return ctx
    else:
        return None
Пример #2
0
def utf8match(pattern, utf8string, bytestart=0, byteend=sys.maxint, flags=0,
              fullmatch=False):
    # bytestart and byteend must be valid byte positions inside the
    # utf8string.
    from rpython.rlib.rsre.rsre_core import match_context

    ctx = make_utf8_ctx(utf8string, bytestart, byteend, flags)
    ctx.fullmatch_only = fullmatch
    if match_context(ctx, pattern):
        return ctx
    else:
        return None
Пример #3
0
    def matches(self, s, pos):
        if not we_are_translated():
            m = self.re.match(s, pos)
            return Match(*m.span(0)) if m is not None else None
        else:
            assert pos >= 0
            ctx = rsre_core.StrMatchContext(s, pos, len(s))

            matched = rsre_core.match_context(ctx, self._pattern)
            if matched:
                return Match(ctx.match_start, ctx.match_end)
            else:
                return None
Пример #4
0
def utf8match(pattern,
              utf8string,
              bytestart=0,
              byteend=sys.maxint,
              fullmatch=False):
    # bytestart and byteend must be valid byte positions inside the
    # utf8string.
    from rpython.rlib.rsre.rsre_core import match_context, MODE_FULL

    ctx = make_utf8_ctx(utf8string, bytestart, byteend)
    if fullmatch:
        ctx.match_mode = MODE_FULL
    if match_context(ctx, pattern):
        return ctx
    else:
        return None
Пример #5
0
def matchcontext(space, ctx, pattern):
    try:
        return rsre_core.match_context(ctx, pattern)
    except rsre_core.Error as e:
        raise OperationError(space.w_RuntimeError, space.newtext(e.msg))
Пример #6
0
def matchcontext(space, ctx):
    try:
        return rsre_core.match_context(ctx)
    except rsre_core.Error as e:
        raise OperationError(space.w_RuntimeError, space.wrap(e.msg))
Пример #7
0
def matchcontext(space, ctx):
    try:
        return rsre_core.match_context(ctx)
    except rsre_core.Error, e:
        raise OperationError(space.w_RuntimeError, space.wrap(e.msg))