summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2016-11-14 11:35:55 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2016-11-14 11:35:55 (GMT)
commitfb6a6596b53e7ecf89e36073661eaf556ca4822e (patch)
treec3eb6cdaa0e3339eb4b03ec681b1289746a5066e /Lib
parent996fc1fcfc165a8d7f56b6d31933b594a5f48d73 (diff)
downloadcpython-fb6a6596b53e7ecf89e36073661eaf556ca4822e.zip
cpython-fb6a6596b53e7ecf89e36073661eaf556ca4822e.tar.gz
cpython-fb6a6596b53e7ecf89e36073661eaf556ca4822e.tar.bz2
Issue #28637: Reapply changeset 223731925d06
"issue28082: use IntFlag for re constants" by Ethan Furman. The re module is not more used in the site module and so adding "import enum" to re.py doesn't impact python_startup benchmark anymore.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/re.py33
1 files changed, 21 insertions, 12 deletions
diff --git a/Lib/re.py b/Lib/re.py
index 3fd600c..d321cff 100644
--- a/Lib/re.py
+++ b/Lib/re.py
@@ -119,6 +119,7 @@ This module also defines an exception 'error'.
"""
+import enum
import sre_compile
import sre_parse
import functools
@@ -138,18 +139,26 @@ __all__ = [
__version__ = "2.2.1"
-# flags
-A = ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
-I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
-L = LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
-U = UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
-M = MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
-S = DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
-X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
-
-# sre extensions (experimental, don't rely on these)
-T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
-DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
+class RegexFlag(enum.IntFlag):
+ ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
+ IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
+ LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
+ UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
+ MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
+ DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
+ VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
+ A = ASCII
+ I = IGNORECASE
+ L = LOCALE
+ U = UNICODE
+ M = MULTILINE
+ S = DOTALL
+ X = VERBOSE
+ # sre extensions (experimental, don't rely on these)
+ TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
+ T = TEMPLATE
+ DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
+globals().update(RegexFlag.__members__)
# sre exception
error = sre_compile.error