| 1 |
from rpython.rlib.rsre import rsre_char, rsre_core, rsre_constants |
| 2 |
from rpython.rlib.rarithmetic import intmask |
| 3 |
from rpython.rlib.objectmodel import we_are_translated |
| 4 |
|
| 5 |
VERSION = "2.7.6" |
| 6 |
MAGIC = 20031017 |
| 7 |
MAXREPEAT = rsre_char.MAXREPEAT |
| 8 |
CODESIZE = rsre_char.CODESIZE |
| 9 |
getlower = rsre_char.getlower |
| 10 |
|
| 11 |
|
| 12 |
class GotIt(Exception): |
| 13 |
pass |
| 14 |
|
| 15 |
def compile(pattern, flags, code, *args): |
| 16 |
if not we_are_translated() and isinstance(pattern, unicode): |
| 17 |
flags |= rsre_constants.SRE_FLAG_UNICODE |
| 18 |
raise GotIt(rsre_core.CompiledPattern([intmask(i) for i in code], flags), flags, args) |
| 19 |
|
| 20 |
|
| 21 |
def get_code(regexp, flags=0, allargs=False): |
| 22 |
"""NOT_RPYTHON: you can't compile new regexps in an RPython program, |
| 23 |
you can only use precompiled ones""" |
| 24 |
from . import sre_compile |
| 25 |
if rsre_constants.V37: |
| 26 |
import pytest |
| 27 |
pytest.skip("This test cannot run in a 3.7 branch of pypy") |
| 28 |
try: |
| 29 |
sre_compile.compile(regexp, flags) |
| 30 |
except GotIt as e: |
| 31 |
pass |
| 32 |
else: |
| 33 |
raise ValueError("did not reach _sre.compile()!") |
| 34 |
if allargs: |
| 35 |
return e.args |
| 36 |
else: |
| 37 |
return e.args[0] |