Beispiel #1
0

def w_getlower(space, char_ord, flags):
    return space.wrap(getlower(char_ord, flags))


w_getlower.unwrap_spec = [ObjSpace, int, int]


def w_getcodesize(space):
    return space.wrap(CODESIZE)


# use the same version of unicodedb as the standard objspace
from pypy.objspace.std.unicodeobject import unicodedb
rsre.set_unicode_db(unicodedb)

#### State classes


def make_state(space, w_string, start, end, flags):
    # XXX maybe turn this into a __new__ method of W_State
    if space.is_true(space.isinstance(w_string, space.w_str)):
        cls = W_StringState
    elif space.is_true(space.isinstance(w_string, space.w_unicode)):
        cls = W_UnicodeState
    else:
        cls = W_GenericState
    return space.wrap(cls(space, w_string, start, end, flags))

Beispiel #2
0
"""Interp-level rsre tests."""
import sys
from py.test import raises
from pypy.rlib.rsre.rsre import SimpleStringState, set_unicode_db
from pypy.rlib.rsre import rsre_char
isre = SimpleStringState.rsre_core

from pypy.module.unicodedata import unicodedb_3_2_0
set_unicode_db(unicodedb_3_2_0)

EM_SPACE = u"\u2001"
INDIAN_DIGIT = u"\u0966"


def create_context(string, string_position, end):
    state = SimpleStringState(string, 0, end)
    state.string_position = string_position
    return state._MatchContext(state, [])


def test_is_uni_linebreak():
    for char in ["\n", "\r"]:
        assert rsre_char.is_uni_linebreak(ord(char))
    for char in [" ", "b"]:
        assert not rsre_char.is_uni_linebreak(ord(char))
    assert rsre_char.is_uni_linebreak(8232)


def test_is_uni_word():
    for char in ["a", "_", "\xe4"]:
        assert rsre_char.is_uni_word(ord(char))
Beispiel #3
0
#### Constants and exposed functions

from pypy.rlib.rsre import rsre
from pypy.rlib.rsre.rsre_char import MAGIC, CODESIZE, getlower
copyright = "_sre.py 2.4 Copyright 2005 by Nik Haldimann"

def w_getlower(space, char_ord, flags):
    return space.wrap(getlower(char_ord, flags))
w_getlower.unwrap_spec = [ObjSpace, int, int]

def w_getcodesize(space):
    return space.wrap(CODESIZE)

# use the same version of unicodedb as the standard objspace
from pypy.objspace.std.unicodeobject import unicodedb
rsre.set_unicode_db(unicodedb)

#### State classes

def make_state(space, w_string, start, end, flags):
    # XXX maybe turn this into a __new__ method of W_State
    if space.is_true(space.isinstance(w_string, space.w_str)):
        cls = W_StringState
    elif space.is_true(space.isinstance(w_string, space.w_unicode)):
        cls = W_UnicodeState
    else:
        cls = W_GenericState
    return space.wrap(cls(space, w_string, start, end, flags))
make_state.unwrap_spec = [ObjSpace, W_Root, int, int, int]

"""Interp-level rsre tests."""
import sys
from py.test import raises
from pypy.rlib.rsre.rsre import SimpleStringState, set_unicode_db
from pypy.rlib.rsre import rsre_char

isre = SimpleStringState.rsre_core

from pypy.module.unicodedata import unicodedb_3_2_0

set_unicode_db(unicodedb_3_2_0)

EM_SPACE = u"\u2001"
INDIAN_DIGIT = u"\u0966"


def create_context(string, string_position, end):
    state = SimpleStringState(string, 0, end)
    state.string_position = string_position
    return state._MatchContext(state, [])


def test_is_uni_linebreak():
    for char in ["\n", "\r"]:
        assert rsre_char.is_uni_linebreak(ord(char))
    for char in [" ", "b"]:
        assert not rsre_char.is_uni_linebreak(ord(char))
    assert rsre_char.is_uni_linebreak(8232)


def test_is_uni_word():