Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(95286)

Side by Side Diff: Lib/sre_parse.py

Issue 12759: "(?P=)" input for Tools/scripts/redemo.py raises unnhandled exception
Patch Set: Created 7 years ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/test/test_re.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # 1 #
2 # Secret Labs' Regular Expression Engine 2 # Secret Labs' Regular Expression Engine
3 # 3 #
4 # convert re-style regular expression to sre pattern 4 # convert re-style regular expression to sre pattern
5 # 5 #
6 # Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved. 6 # Copyright (c) 1998-2001 by Secret Labs AB. All rights reserved.
7 # 7 #
8 # See the sre.py file for information on usage and redistribution. 8 # See the sre.py file for information on usage and redistribution.
9 # 9 #
10 10
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 # named group: skip forward to end of name 573 # named group: skip forward to end of name
574 name = "" 574 name = ""
575 while 1: 575 while 1:
576 char = sourceget() 576 char = sourceget()
577 if char is None: 577 if char is None:
578 raise error("unterminated name") 578 raise error("unterminated name")
579 if char == ">": 579 if char == ">":
580 break 580 break
581 name = name + char 581 name = name + char
582 group = 1 582 group = 1
583 if not name:
584 raise error("bad group name")
583 if not isname(name): 585 if not isname(name):
584 raise error("bad character in group name") 586 raise error("bad character in group name")
585 elif sourcematch("="): 587 elif sourcematch("="):
586 # named backreference 588 # named backreference
587 name = "" 589 name = ""
588 while 1: 590 while 1:
589 char = sourceget() 591 char = sourceget()
590 if char is None: 592 if char is None:
591 raise error("unterminated name") 593 raise error("unterminated name")
592 if char == ")": 594 if char == ")":
593 break 595 break
594 name = name + char 596 name = name + char
597 if not name:
598 raise error("bad group name")
595 if not isname(name): 599 if not isname(name):
596 raise error("bad character in group name") 600 raise error("bad character in group name")
597 gid = state.groupdict.get(name) 601 gid = state.groupdict.get(name)
598 if gid is None: 602 if gid is None:
599 raise error("unknown group name") 603 raise error("unknown group name")
600 subpatternappend((GROUPREF, gid)) 604 subpatternappend((GROUPREF, gid))
601 continue 605 continue
602 else: 606 else:
603 char = sourceget() 607 char = sourceget()
604 if char is None: 608 if char is None:
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 # conditional backreference group 641 # conditional backreference group
638 condname = "" 642 condname = ""
639 while 1: 643 while 1:
640 char = sourceget() 644 char = sourceget()
641 if char is None: 645 if char is None:
642 raise error("unterminated name") 646 raise error("unterminated name")
643 if char == ")": 647 if char == ")":
644 break 648 break
645 condname = condname + char 649 condname = condname + char
646 group = 2 650 group = 2
651 if not condname:
652 raise error("bad group name")
647 if isname(condname): 653 if isname(condname):
648 condgroup = state.groupdict.get(condname) 654 condgroup = state.groupdict.get(condname)
649 if condgroup is None: 655 if condgroup is None:
650 raise error("unknown group name") 656 raise error("unknown group name")
651 else: 657 else:
652 try: 658 try:
653 condgroup = int(condname) 659 condgroup = int(condname)
654 except ValueError: 660 except ValueError:
655 raise error("bad character in group name") 661 raise error("bad character in group name")
656 else: 662 else:
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 groups, literals = template 845 groups, literals = template
840 literals = literals[:] 846 literals = literals[:]
841 try: 847 try:
842 for index, group in groups: 848 for index, group in groups:
843 literals[index] = s = g(group) 849 literals[index] = s = g(group)
844 if s is None: 850 if s is None:
845 raise error("unmatched group") 851 raise error("unmatched group")
846 except IndexError: 852 except IndexError:
847 raise error("invalid group reference") 853 raise error("invalid group reference")
848 return sep.join(literals) 854 return sep.join(literals)
OLDNEW
« no previous file with comments | « no previous file | Lib/test/test_re.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+