equal
deleted
inserted
replaced
501 finally: |
501 finally: |
502 os.remove(name) |
502 os.remove(name) |
503 |
503 |
504 def rematch(el, l): |
504 def rematch(el, l): |
505 try: |
505 try: |
506 # hack to deal with graphlog, which looks like bogus regexes |
506 # ensure that the regex matches to the end of the string |
507 if el.startswith('|'): |
507 return re.match(el + r'\Z', l) |
508 el = '\\' + el |
|
509 return re.match(el, l) |
|
510 except re.error: |
508 except re.error: |
511 # el is an invalid regex |
509 # el is an invalid regex |
512 return False |
510 return False |
|
511 |
|
512 def globmatch(el, l): |
|
513 # The only supported special characters are * and ?. Escaping is |
|
514 # supported. |
|
515 i, n = 0, len(el) |
|
516 res = '' |
|
517 while i < n: |
|
518 c = el[i] |
|
519 i += 1 |
|
520 if c == '\\' and el[i] in '*?\\': |
|
521 res += el[i - 1:i + 1] |
|
522 i += 1 |
|
523 elif c == '*': |
|
524 res += '.*' |
|
525 elif c == '?': |
|
526 res += '.' |
|
527 else: |
|
528 res += re.escape(c) |
|
529 return rematch(res, l) |
513 |
530 |
514 pos = -1 |
531 pos = -1 |
515 postout = [] |
532 postout = [] |
516 ret = 0 |
533 ret = 0 |
517 for n, l in enumerate(output): |
534 for n, l in enumerate(output): |
528 if pos in expected and expected[pos]: |
545 if pos in expected and expected[pos]: |
529 el = expected[pos].pop(0) |
546 el = expected[pos].pop(0) |
530 |
547 |
531 if el == l: # perfect match (fast) |
548 if el == l: # perfect match (fast) |
532 postout.append(" " + l) |
549 postout.append(" " + l) |
533 elif el and rematch(el, l): # fallback regex match |
550 elif (el and |
534 postout.append(" " + el) |
551 (el.endswith(" (re)\n") and rematch(el[:-6] + '\n', l) or |
535 else: # mismatch - let diff deal with it |
552 el.endswith(" (glob)\n") and globmatch(el[:-8] + '\n', l))): |
536 postout.append(" " + l) |
553 postout.append(" " + el) # fallback regex/glob match |
|
554 else: |
|
555 postout.append(" " + l) # let diff deal with it |
537 |
556 |
538 if pos in after: |
557 if pos in after: |
539 postout += after.pop(pos) |
558 postout += after.pop(pos) |
540 |
559 |
541 return exitcode, postout |
560 return exitcode, postout |