summaryrefslogtreecommitdiff
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-21 22:47:30 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-21 22:47:30 +0300
commitc0799e3a26f5da0613e7b7506e1d717750b84530 (patch)
tree22a7d227764c933ea023b238f76283c6d32370ba /Lib/sre_parse.py
parent91943460b54c20fda330d78a6b8d7643ef838b4e (diff)
downloadcpython-git-c0799e3a26f5da0613e7b7506e1d717750b84530.tar.gz
Issue #22423: Fixed debugging output of the GROUPREF_EXISTS opcode in the re
module.
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r--Lib/sre_parse.py45
1 files changed, 27 insertions, 18 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 0a361abc70..b85ce88c34 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -94,33 +94,42 @@ class SubPattern:
self.data = data
self.width = None
def dump(self, level=0):
- nl = 1
- seqtypes = type(()), type([])
+ seqtypes = (tuple, list)
for op, av in self.data:
- print level*" " + op,; nl = 0
- if op == "in":
+ print level*" " + op,
+ if op == IN:
# member sublanguage
- print; nl = 1
+ print
for op, a in av:
print (level+1)*" " + op, a
- elif op == "branch":
- print; nl = 1
- i = 0
- for a in av[1]:
- if i > 0:
+ elif op == BRANCH:
+ print
+ for i, a in enumerate(av[1]):
+ if i:
print level*" " + "or"
- a.dump(level+1); nl = 1
- i = i + 1
- elif type(av) in seqtypes:
+ a.dump(level+1)
+ elif op == GROUPREF_EXISTS:
+ condgroup, item_yes, item_no = av
+ print condgroup
+ item_yes.dump(level+1)
+ if item_no:
+ print level*" " + "else"
+ item_no.dump(level+1)
+ elif isinstance(av, seqtypes):
+ nl = 0
for a in av:
if isinstance(a, SubPattern):
- if not nl: print
- a.dump(level+1); nl = 1
+ if not nl:
+ print
+ a.dump(level+1)
+ nl = 1
else:
- print a, ; nl = 0
+ print a,
+ nl = 0
+ if not nl:
+ print
else:
- print av, ; nl = 0
- if not nl: print
+ print av
def __repr__(self):
return repr(self.data)
def __len__(self):