Replaces a conditional match in a transformation.
(match, string)
| 50 | |
| 51 | |
| 52 | def _replace_conditional(match, string): |
| 53 | """Replaces a conditional match in a transformation.""" |
| 54 | conditional_match = _CONDITIONAL.search(string) |
| 55 | while conditional_match: |
| 56 | start = conditional_match.start() |
| 57 | end = _find_closing_brace(string, start + 4) |
| 58 | args = _split_conditional(string[start + 4 : end - 1]) |
| 59 | rv = "" |
| 60 | if match.group(int(conditional_match.group(1))): |
| 61 | rv = unescape(_replace_conditional(match, args[0])) |
| 62 | elif len(args) > 1: |
| 63 | rv = unescape(_replace_conditional(match, args[1])) |
| 64 | string = string[:start] + rv + string[end:] |
| 65 | conditional_match = _CONDITIONAL.search(string) |
| 66 | return string |
| 67 | |
| 68 | |
| 69 | _ONE_CHAR_CASE_SWITCH = re.compile(r"\\([ul].)", re.DOTALL) |
no test coverage detected