Skip to content

Commit

Permalink
tools: remove deprecated python api
Browse files Browse the repository at this point in the history
PR-URL: #49731
Fixes: #49729
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
himself65 authored and targos committed Feb 15, 2024
1 parent 36e42aa commit 83b3aa8
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions tools/cpplint.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import math # for log
import os
import re
import sre_compile
import string
import sys
import sysconfig
Expand All @@ -66,6 +65,16 @@

__VERSION__ = '1.6.1'

# sre_compile will be/has been removed in Python 3.13
# use re._compiler instead
# Refs: https://github.com/python/cpython/issues/105456
# Refs: https://github.com/python/cpython/issues/91308
try:
srecompile = re._compiler.compile
except AttributeError:
import sre_compile
srecompile = sre_compile.compile

try:
# -- pylint: disable=used-before-assignment
xrange # Python 2
Expand Down Expand Up @@ -1077,7 +1086,7 @@ def Match(pattern, s):
# performance reasons; factoring it out into a separate function turns out
# to be noticeably expensive.
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
_regexp_compile_cache[pattern] = srecompile(pattern)
return _regexp_compile_cache[pattern].match(s)


Expand All @@ -1095,14 +1104,14 @@ def ReplaceAll(pattern, rep, s):
string with replacements made (or original string if no replacements)
"""
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
_regexp_compile_cache[pattern] = srecompile(pattern)
return _regexp_compile_cache[pattern].sub(rep, s)


def Search(pattern, s):
"""Searches the string for the pattern, caching the compiled regexp."""
if pattern not in _regexp_compile_cache:
_regexp_compile_cache[pattern] = sre_compile.compile(pattern)
_regexp_compile_cache[pattern] = srecompile(pattern)
return _regexp_compile_cache[pattern].search(s)


Expand Down

0 comments on commit 83b3aa8

Please sign in to comment.