_pattern_type = type(sre_compile.compile("", 0))
@functools.lru_cache(maxsize=500, typed=True)
def _compile(pattern, flags):
# internal: compile pattern
if isinstance(pattern, _pattern_type):
if flags:
raise ValueError(
"Cannot process flags argument with a compiled pattern")
return pattern
if not sre_compile.isstring(pattern):
raise TypeError("first argument must be string or compiled pattern")
return sre_compile.compile(pattern, flags)
Cl9wYXR0ZXJuX3R5cGUgPSB0eXBlKHNyZV9jb21waWxlLmNvbXBpbGUoIiIsIDApKQoKQGZ1bmN0b29scy5scnVfY2FjaGUobWF4c2l6ZT01MDAsIHR5cGVkPVRydWUpCmRlZiBfY29tcGlsZShwYXR0ZXJuLCBmbGFncyk6CiAgICAjIGludGVybmFsOiBjb21waWxlIHBhdHRlcm4KICAgIGlmIGlzaW5zdGFuY2UocGF0dGVybiwgX3BhdHRlcm5fdHlwZSk6CiAgICAgICAgaWYgZmxhZ3M6CiAgICAgICAgICAgIHJhaXNlIFZhbHVlRXJyb3IoCiAgICAgICAgICAgICAgICAiQ2Fubm90IHByb2Nlc3MgZmxhZ3MgYXJndW1lbnQgd2l0aCBhIGNvbXBpbGVkIHBhdHRlcm4iKQogICAgICAgIHJldHVybiBwYXR0ZXJuCiAgICBpZiBub3Qgc3JlX2NvbXBpbGUuaXNzdHJpbmcocGF0dGVybik6CiAgICAgICAgcmFpc2UgVHlwZUVycm9yKCJmaXJzdCBhcmd1bWVudCBtdXN0IGJlIHN0cmluZyBvciBjb21waWxlZCBwYXR0ZXJuIikKICAgIHJldHVybiBzcmVfY29tcGlsZS5jb21waWxlKHBhdHRlcm4sIGZsYWdzKQ==