| 119 | (lineno, colno)) |
| 120 | |
| 121 | def substitute(self, mapping=_sentinel_dict, /, **kws): |
| 122 | if mapping is _sentinel_dict: |
| 123 | mapping = kws |
| 124 | elif kws: |
| 125 | from collections import ChainMap |
| 126 | mapping = ChainMap(kws, mapping) |
| 127 | # Helper function for .sub() |
| 128 | def convert(mo): |
| 129 | # Check the most common path first. |
| 130 | named = mo.group('named') or mo.group('braced') |
| 131 | if named is not None: |
| 132 | return str(mapping[named]) |
| 133 | if mo.group('escaped') is not None: |
| 134 | return self.delimiter |
| 135 | if mo.group('invalid') is not None: |
| 136 | self._invalid(mo) |
| 137 | raise ValueError('Unrecognized named group in pattern', |
| 138 | self.pattern) |
| 139 | return self.pattern.sub(convert, self.template) |
| 140 | |
| 141 | def safe_substitute(self, mapping=_sentinel_dict, /, **kws): |
| 142 | if mapping is _sentinel_dict: |