@@ -45,8 +45,10 @@ def default(value, default):
45
45
def maxsize ():
46
46
import sys
47
47
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
50
52
51
53
CODESIZE = 4
52
54
@@ -150,7 +152,9 @@ def __init__(self, pattern, flags, code, groups=0, groupindex=None, indexgroup=N
150
152
151
153
152
154
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" )
154
158
155
159
156
160
def __compile_cpython_sre (self ):
@@ -219,9 +223,7 @@ def search(self, string, pos=0, endpos=None):
219
223
try :
220
224
return self ._search (self .pattern , string , pos , default (endpos , - 1 ))
221
225
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 ()))
225
227
226
228
def match (self , string , pos = 0 , endpos = None ):
227
229
try :
@@ -230,9 +232,7 @@ def match(self, string, pos=0, endpos=None):
230
232
else :
231
233
return self ._search (self .pattern , string , pos , default (endpos , - 1 ))
232
234
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 ()))
236
236
237
237
def fullmatch (self , string , pos = 0 , endpos = None ):
238
238
try :
@@ -243,9 +243,7 @@ def fullmatch(self, string, pos=0, endpos=None):
243
243
pattern = pattern + "$"
244
244
return self ._search (pattern , string , pos , default (endpos , - 1 ))
245
245
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 ()))
249
247
250
248
def findall (self , string , pos = 0 , endpos = - 1 ):
251
249
try :
@@ -270,9 +268,7 @@ def findall(self, string, pos=0, endpos=-1):
270
268
pos = result .end [0 ] + no_progress
271
269
return matchlist
272
270
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 )
276
272
277
273
278
274
def __replace_groups (self , repl , string , match_result , pattern ):
@@ -360,9 +356,7 @@ def sub(self, repl, string, count=0):
360
356
result .append (self ._emit (string [pos :]))
361
357
return self ._emit ("" ).join (result )
362
358
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 )
366
360
367
361
def _emit (self , str_like_obj ):
368
362
assert isinstance (str_like_obj , str ) or isinstance (str_like_obj , bytes )
0 commit comments