diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2016-11-14 11:39:05 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2016-11-14 11:39:05 (GMT) |
commit | d62ecf51ef1ce05c8c1c397a7a19fee5629c42a2 (patch) | |
tree | 371e0ea05a6cf0fa4d6d3d67e3634940e2871221 | |
parent | 2294f83c7c50ec1d574835231ca7993da1c419e8 (diff) | |
parent | 8bf43e6d0b3dc5d76e9d99656528ccdcd5dd6e6a (diff) | |
download | cpython-d62ecf51ef1ce05c8c1c397a7a19fee5629c42a2.zip cpython-d62ecf51ef1ce05c8c1c397a7a19fee5629c42a2.tar.gz cpython-d62ecf51ef1ce05c8c1c397a7a19fee5629c42a2.tar.bz2 |
Merge 3.6
-rw-r--r-- | Lib/re.py | 33 | ||||
-rw-r--r-- | Lib/test/test_re.py | 6 |
2 files changed, 27 insertions, 12 deletions
@@ -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 diff --git a/Lib/test/test_re.py b/Lib/test/test_re.py index 3bd6d7b..aac3a2c 100644 --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1771,6 +1771,12 @@ SUBPATTERN None 0 0 self.checkPatternError(r'(?<>)', 'unknown extension ?<>', 1) self.checkPatternError(r'(?', 'unexpected end of pattern', 2) + def test_enum(self): + # Issue #28082: Check that str(flag) returns a human readable string + # instead of an integer + self.assertIn('ASCII', str(re.A)) + self.assertIn('DOTALL', str(re.S)) + class PatternReprTests(unittest.TestCase): def check(self, pattern, expected): |