Splits the line into (line[:i], line[i:]), where i is the index of first occurrence of one of the characters not within quotes, or len(line) if no such index exists
(line, characters)
| 666 | ## |
| 667 | |
| 668 | def split_by_unquoted(line, characters): |
| 669 | """ |
| 670 | Splits the line into (line[:i], line[i:]), |
| 671 | where i is the index of first occurrence of one of the characters |
| 672 | not within quotes, or len(line) if no such index exists |
| 673 | """ |
| 674 | assert not (set('"\'') & set(characters)), "cannot split by unquoted quotes" |
| 675 | r = re.compile( |
| 676 | r"\A(?P<before>({single_quoted}|{double_quoted}|{not_quoted})*)" |
| 677 | r"(?P<after>{char}.*)\Z".format( |
| 678 | not_quoted="[^\"'{}]".format(re.escape(characters)), |
| 679 | char="[{}]".format(re.escape(characters)), |
| 680 | single_quoted=r"('([^'\\]|(\\.))*')", |
| 681 | double_quoted=r'("([^"\\]|(\\.))*")')) |
| 682 | m = r.match(line) |
| 683 | if m: |
| 684 | d = m.groupdict() |
| 685 | return (d["before"], d["after"]) |
| 686 | return (line, "") |
| 687 | |
| 688 | def _simplifyargs(argsline): |
| 689 | a = [] |
no test coverage detected