5454import math # for log
5555import os
5656import re
57- import sre_compile
5857import string
5958import sys
6059import sysconfig
6665
6766__VERSION__ = '1.6.1'
6867
68+ # sre_compile will be/has been removed in Python 3.13
69+ # use re._compiler instead
70+ # Refs: https://github.com/python/cpython/issues/105456
71+ # Refs: https://github.com/python/cpython/issues/91308
72+ try :
73+ srecompile = re ._compiler .compile
74+ except AttributeError :
75+ import sre_compile
76+ srecompile = sre_compile .compile
77+
6978try :
7079 # -- pylint: disable=used-before-assignment
7180 xrange # Python 2
@@ -1077,7 +1086,7 @@ def Match(pattern, s):
10771086 # performance reasons; factoring it out into a separate function turns out
10781087 # to be noticeably expensive.
10791088 if pattern not in _regexp_compile_cache :
1080- _regexp_compile_cache [pattern ] = sre_compile . compile (pattern )
1089+ _regexp_compile_cache [pattern ] = srecompile (pattern )
10811090 return _regexp_compile_cache [pattern ].match (s )
10821091
10831092
@@ -1095,14 +1104,14 @@ def ReplaceAll(pattern, rep, s):
10951104 string with replacements made (or original string if no replacements)
10961105 """
10971106 if pattern not in _regexp_compile_cache :
1098- _regexp_compile_cache [pattern ] = sre_compile . compile (pattern )
1107+ _regexp_compile_cache [pattern ] = srecompile (pattern )
10991108 return _regexp_compile_cache [pattern ].sub (rep , s )
11001109
11011110
11021111def Search (pattern , s ):
11031112 """Searches the string for the pattern, caching the compiled regexp."""
11041113 if pattern not in _regexp_compile_cache :
1105- _regexp_compile_cache [pattern ] = sre_compile . compile (pattern )
1114+ _regexp_compile_cache [pattern ] = srecompile (pattern )
11061115 return _regexp_compile_cache [pattern ].search (s )
11071116
11081117
0 commit comments