root/scripts/util/simplify_xpath @ 64
1 | 33 | aaronmk | #!/usr/bin/env python
|
---|---|---|---|
2 | # Removes duplication from XPath expressions
|
||
3 | 59 | aaronmk | # Filters one XPath per line from stdin to stdout
|
4 | 33 | aaronmk | |
5 | import re |
||
6 | import sys |
||
7 | |||
8 | def main(): |
||
9 | while True: |
||
10 | line = sys.stdin.readline() |
||
11 | if line == '': break |
||
12 | # Forward * abbrs
|
||
13 | 60 | aaronmk | line = re.sub(r'(?i)(/)(\w+)(?=\w*(?:->/[^/]*)?/\2\b)', r'\1*', line) |
14 | 33 | aaronmk | # Backward * abbrs
|
15 | 60 | aaronmk | line = re.sub(r'(?i)(/(\w+)->/[^/]*/[^/]*\[)\2', r'\1*', line) |
16 | 33 | aaronmk | sys.stdout.write(line) |
17 | |||
18 | main() |