diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-05-10 03:05:20 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-10 03:05:20 (GMT) |
commit | 305ccbe27ea5ba82fd2d8c32ec739f980e524330 (patch) | |
tree | b2a5769d41b5de66dff278d57b2caa57b18d4f63 /Lib/sre_parse.py | |
parent | 211a392cc15f9a7b1b8ce65d8f6c9f8237d1b77f (diff) | |
download | cpython-305ccbe27ea5ba82fd2d8c32ec739f980e524330.zip cpython-305ccbe27ea5ba82fd2d8c32ec739f980e524330.tar.gz cpython-305ccbe27ea5ba82fd2d8c32ec739f980e524330.tar.bz2 |
bpo-30298: Weaken the condition of deprecation warnings for inline modifiers. (#1490)
Now allowed several subsequential inline modifiers at the start of the
pattern (e.g. '(?i)(?s)...'). In verbose mode whitespaces and comments
now are allowed before and between inline modifiers (e.g.
'(?x) (?i) (?s)...').
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r-- | Lib/sre_parse.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py index ab37fd3..d8d1bd5 100644 --- a/Lib/sre_parse.py +++ b/Lib/sre_parse.py @@ -412,7 +412,7 @@ def _parse_sub(source, state, verbose, nested=True): sourcematch = source.match start = source.tell() while True: - itemsappend(_parse(source, state, verbose)) + itemsappend(_parse(source, state, verbose, not nested and not items)) if not sourcematch("|"): break @@ -466,7 +466,7 @@ def _parse_sub_cond(source, state, condgroup, verbose): subpattern.append((GROUPREF_EXISTS, (condgroup, item_yes, item_no))) return subpattern -def _parse(source, state, verbose): +def _parse(source, state, verbose, first=False): # parse a simple pattern subpattern = SubPattern(state) @@ -730,10 +730,9 @@ def _parse(source, state, verbose): state.checklookbehindgroup(condgroup, source) elif char in FLAGS or char == "-": # flags - pos = source.pos flags = _parse_flags(source, state, char) if flags is None: # global flags - if pos != 3: # "(?x" + if not first or subpattern: import warnings warnings.warn( 'Flags not at the start of the expression %s%s' % ( @@ -742,6 +741,8 @@ def _parse(source, state, verbose): ), DeprecationWarning, stacklevel=7 ) + if (state.flags & SRE_FLAG_VERBOSE) and not verbose: + raise Verbose continue add_flags, del_flags = flags group = None @@ -795,9 +796,6 @@ def _parse_flags(source, state, char): msg = "unknown flag" if char.isalpha() else "missing -, : or )" raise source.error(msg, len(char)) if char == ")": - if ((add_flags & SRE_FLAG_VERBOSE) and - not (state.flags & SRE_FLAG_VERBOSE)): - raise Verbose state.flags |= add_flags return None if add_flags & GLOBAL_FLAGS: |