MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _compile

Function _compile

tools/python-3.11.9-amd64/Lib/re/__init__.py:272–303  ·  view source on GitHub ↗
(pattern, flags)

Source from the content-addressed store, hash-verified

270
271_MAXCACHE = 512
272def _compile(pattern, flags):
273 # internal: compile pattern
274 if isinstance(flags, RegexFlag):
275 flags = flags.value
276 try:
277 return _cache[type(pattern), pattern, flags]
278 except KeyError:
279 pass
280 if isinstance(pattern, Pattern):
281 if flags:
282 raise ValueError(
283 "cannot process flags argument with a compiled pattern")
284 return pattern
285 if not _compiler.isstring(pattern):
286 raise TypeError("first argument must be string or compiled pattern")
287 if flags & T:
288 import warnings
289 warnings.warn("The re.TEMPLATE/re.T flag is deprecated "
290 "as it is an undocumented flag "
291 "without an obvious purpose. "
292 "Don't use it.",
293 DeprecationWarning)
294 p = _compiler.compile(pattern, flags)
295 if not (flags & DEBUG):
296 if len(_cache) >= _MAXCACHE:
297 # Drop the oldest item
298 try:
299 del _cache[next(iter(_cache))]
300 except (StopIteration, RuntimeError, KeyError):
301 pass
302 _cache[type(pattern), pattern, flags] = p
303 return p
304
305@functools.lru_cache(_MAXCACHE)
306def _compile_repl(repl, pattern):

Callers 10

matchFunction · 0.70
fullmatchFunction · 0.70
searchFunction · 0.70
subFunction · 0.70
subnFunction · 0.70
splitFunction · 0.70
findallFunction · 0.70
finditerFunction · 0.70
compileFunction · 0.70
templateFunction · 0.70

Calls 3

typeClass · 0.50
warnMethod · 0.45
compileMethod · 0.45

Tested by

no test coverage detected