MCPcopy Index your code
hub / github.com/python/cpython / substitute

Method substitute

Lib/string/__init__.py:121–139  ·  view source on GitHub ↗
(self, mapping=_sentinel_dict, /, **kws)

Source from the content-addressed store, hash-verified

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:

Callers 15

test_escapesMethod · 0.95
test_percentsMethod · 0.95
test_stringificationMethod · 0.95
test_tupleargsMethod · 0.95
test_unicode_valuesMethod · 0.95
_formatMethod · 0.80

Calls 2

ChainMapClass · 0.90
subMethod · 0.45