mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Merge 3.6
This commit is contained in:
commit
d62ecf51ef
2 changed files with 27 additions and 12 deletions
33
Lib/re.py
33
Lib/re.py
|
@ -119,6 +119,7 @@ This module also defines an exception 'error'.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import enum
|
||||||
import sre_compile
|
import sre_compile
|
||||||
import sre_parse
|
import sre_parse
|
||||||
import functools
|
import functools
|
||||||
|
@ -138,18 +139,26 @@ __all__ = [
|
||||||
|
|
||||||
__version__ = "2.2.1"
|
__version__ = "2.2.1"
|
||||||
|
|
||||||
# flags
|
class RegexFlag(enum.IntFlag):
|
||||||
A = ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
|
ASCII = sre_compile.SRE_FLAG_ASCII # assume ascii "locale"
|
||||||
I = IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
|
IGNORECASE = sre_compile.SRE_FLAG_IGNORECASE # ignore case
|
||||||
L = LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
|
LOCALE = sre_compile.SRE_FLAG_LOCALE # assume current 8-bit locale
|
||||||
U = UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
|
UNICODE = sre_compile.SRE_FLAG_UNICODE # assume unicode "locale"
|
||||||
M = MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
|
MULTILINE = sre_compile.SRE_FLAG_MULTILINE # make anchors look for newline
|
||||||
S = DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
|
DOTALL = sre_compile.SRE_FLAG_DOTALL # make dot match newline
|
||||||
X = VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
|
VERBOSE = sre_compile.SRE_FLAG_VERBOSE # ignore whitespace and comments
|
||||||
|
A = ASCII
|
||||||
# sre extensions (experimental, don't rely on these)
|
I = IGNORECASE
|
||||||
T = TEMPLATE = sre_compile.SRE_FLAG_TEMPLATE # disable backtracking
|
L = LOCALE
|
||||||
DEBUG = sre_compile.SRE_FLAG_DEBUG # dump pattern after compilation
|
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
|
# sre exception
|
||||||
error = sre_compile.error
|
error = sre_compile.error
|
||||||
|
|
|
@ -1771,6 +1771,12 @@ SUBPATTERN None 0 0
|
||||||
self.checkPatternError(r'(?<>)', 'unknown extension ?<>', 1)
|
self.checkPatternError(r'(?<>)', 'unknown extension ?<>', 1)
|
||||||
self.checkPatternError(r'(?', 'unexpected end of pattern', 2)
|
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):
|
class PatternReprTests(unittest.TestCase):
|
||||||
def check(self, pattern, expected):
|
def check(self, pattern, expected):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue