summaryrefslogtreecommitdiff
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2016-09-11 12:50:02 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2016-09-11 12:50:02 +0300
commitbd48d27944453ad83d3ce37b2c867fa0d59a1c15 (patch)
treef5585b5ce3995541ed6cce7bb4daef97f936be89 /Lib/sre_parse.py
parent352601ca00376aaf07d4399096f985d3d8ecb96f (diff)
downloadcpython-git-bd48d27944453ad83d3ce37b2c867fa0d59a1c15.tar.gz
Issue #22493: Inline flags now should be used only at the start of the
regular expression. Deprecation warning is emitted if uses them in the middle of the regular expression.
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r--Lib/sre_parse.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index d74e93ff5c..4a77f0c9a7 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -279,6 +279,9 @@ class Tokenizer:
break
result += c
return result
+ @property
+ def pos(self):
+ return self.index - len(self.next or '')
def tell(self):
return self.index - len(self.next or '')
def seek(self, index):
@@ -727,8 +730,13 @@ 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"
+ import warnings
+ warnings.warn('Flags not at the start of the expression',
+ DeprecationWarning, stacklevel=7)
continue
add_flags, del_flags = flags
group = None