Show More
@@ -521,6 +521,33 b' def escapef(m):' | |||||
521 | def stringescape(s): |
|
521 | def stringescape(s): | |
522 | return escapesub(escapef, s) |
|
522 | return escapesub(escapef, s) | |
523 |
|
523 | |||
|
524 | def rematch(el, l): | |||
|
525 | try: | |||
|
526 | # ensure that the regex matches to the end of the string | |||
|
527 | return re.match(el + r'\Z', l) | |||
|
528 | except re.error: | |||
|
529 | # el is an invalid regex | |||
|
530 | return False | |||
|
531 | ||||
|
532 | def globmatch(el, l): | |||
|
533 | # The only supported special characters are * and ?. Escaping is | |||
|
534 | # supported. | |||
|
535 | i, n = 0, len(el) | |||
|
536 | res = '' | |||
|
537 | while i < n: | |||
|
538 | c = el[i] | |||
|
539 | i += 1 | |||
|
540 | if c == '\\' and el[i] in '*?\\': | |||
|
541 | res += el[i - 1:i + 1] | |||
|
542 | i += 1 | |||
|
543 | elif c == '*': | |||
|
544 | res += '.*' | |||
|
545 | elif c == '?': | |||
|
546 | res += '.' | |||
|
547 | else: | |||
|
548 | res += re.escape(c) | |||
|
549 | return rematch(res, l) | |||
|
550 | ||||
524 | def tsttest(test, wd, options, replacements): |
|
551 | def tsttest(test, wd, options, replacements): | |
525 | t = open(test) |
|
552 | t = open(test) | |
526 | out = [] |
|
553 | out = [] | |
@@ -608,33 +635,6 b' def tsttest(test, wd, options, replaceme' | |||||
608 | finally: |
|
635 | finally: | |
609 | os.remove(name) |
|
636 | os.remove(name) | |
610 |
|
637 | |||
611 | def rematch(el, l): |
|
|||
612 | try: |
|
|||
613 | # ensure that the regex matches to the end of the string |
|
|||
614 | return re.match(el + r'\Z', l) |
|
|||
615 | except re.error: |
|
|||
616 | # el is an invalid regex |
|
|||
617 | return False |
|
|||
618 |
|
||||
619 | def globmatch(el, l): |
|
|||
620 | # The only supported special characters are * and ?. Escaping is |
|
|||
621 | # supported. |
|
|||
622 | i, n = 0, len(el) |
|
|||
623 | res = '' |
|
|||
624 | while i < n: |
|
|||
625 | c = el[i] |
|
|||
626 | i += 1 |
|
|||
627 | if c == '\\' and el[i] in '*?\\': |
|
|||
628 | res += el[i - 1:i + 1] |
|
|||
629 | i += 1 |
|
|||
630 | elif c == '*': |
|
|||
631 | res += '.*' |
|
|||
632 | elif c == '?': |
|
|||
633 | res += '.' |
|
|||
634 | else: |
|
|||
635 | res += re.escape(c) |
|
|||
636 | return rematch(res, l) |
|
|||
637 |
|
||||
638 | # Merge the script output back into a unified test |
|
638 | # Merge the script output back into a unified test | |
639 |
|
639 | |||
640 | pos = -1 |
|
640 | pos = -1 |
General Comments 0
You need to be logged in to leave comments.
Login now