Skip to content

Commit 0889bd1

Browse files
committed
Cleanup workaround.
1 parent 57bb167 commit 0889bd1

File tree

1 file changed

+12
-18
lines changed

1 file changed

+12
-18
lines changed

graalpython/lib-graalpython/_sre.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ def default(value, default):
4545
def maxsize():
4646
import sys
4747
return sys.maxsize
48-
49-
TREGEX_ENGINE = _interop.eval(string="", language="regex")()
48+
try:
49+
TREGEX_ENGINE = _interop.eval(string="", language="regex")()
50+
except BaseException:
51+
TREGEX_ENGINE = None
5052

5153
CODESIZE = 4
5254

@@ -150,7 +152,9 @@ def __init__(self, pattern, flags, code, groups=0, groupindex=None, indexgroup=N
150152

151153

152154
def __tregex_compile(self, pattern):
153-
return TREGEX_ENGINE(pattern, self.jsflags)
155+
if TREGEX_ENGINE is not None:
156+
return TREGEX_ENGINE(pattern, self.jsflags)
157+
raise RuntimeError("TREGEX engine not available")
154158

155159

156160
def __compile_cpython_sre(self):
@@ -219,9 +223,7 @@ def search(self, string, pos=0, endpos=None):
219223
try:
220224
return self._search(self.pattern, string, pos, default(endpos, -1))
221225
except RuntimeError:
222-
# TODO this is a workaround since exceptions are currently not correctly stacked
223-
pass
224-
return self.__compile_cpython_sre().search(string, pos, default(endpos, maxsize()))
226+
return self.__compile_cpython_sre().search(string, pos, default(endpos, maxsize()))
225227

226228
def match(self, string, pos=0, endpos=None):
227229
try:
@@ -230,9 +232,7 @@ def match(self, string, pos=0, endpos=None):
230232
else:
231233
return self._search(self.pattern, string, pos, default(endpos, -1))
232234
except RuntimeError:
233-
# TODO this is a workaround since exceptions are currently not correctly stacked
234-
pass
235-
return self.__compile_cpython_sre().match(string, pos, default(endpos, maxsize()))
235+
return self.__compile_cpython_sre().match(string, pos, default(endpos, maxsize()))
236236

237237
def fullmatch(self, string, pos=0, endpos=None):
238238
try:
@@ -243,9 +243,7 @@ def fullmatch(self, string, pos=0, endpos=None):
243243
pattern = pattern + "$"
244244
return self._search(pattern, string, pos, default(endpos, -1))
245245
except RuntimeError:
246-
# TODO this is a workaround since exceptions are currently not correctly stacked
247-
pass
248-
return self.__compile_cpython_sre().fullmatch(string, pos, default(endpos, maxsize()))
246+
return self.__compile_cpython_sre().fullmatch(string, pos, default(endpos, maxsize()))
249247

250248
def findall(self, string, pos=0, endpos=-1):
251249
try:
@@ -270,9 +268,7 @@ def findall(self, string, pos=0, endpos=-1):
270268
pos = result.end[0] + no_progress
271269
return matchlist
272270
except RuntimeError:
273-
# TODO this is a workaround since exceptions are currently not correctly stacked
274-
pass
275-
return self.__compile_cpython_sre().findall(string, pos, maxsize() if endpos == -1 else endpos)
271+
return self.__compile_cpython_sre().findall(string, pos, maxsize() if endpos == -1 else endpos)
276272

277273

278274
def __replace_groups(self, repl, string, match_result, pattern):
@@ -360,9 +356,7 @@ def sub(self, repl, string, count=0):
360356
result.append(self._emit(string[pos:]))
361357
return self._emit("").join(result)
362358
except BaseException:
363-
# TODO this is a workaround since exceptions are currently not correctly stacked
364-
pass
365-
return self.__compile_cpython_sre().sub(repl, string, count)
359+
return self.__compile_cpython_sre().sub(repl, string, count)
366360

367361
def _emit(self, str_like_obj):
368362
assert isinstance(str_like_obj, str) or isinstance(str_like_obj, bytes)

0 commit comments

Comments
 (0)