MCPcopy Index your code
hub / github.com/RustPython/RustPython / _vformat

Method _vformat

Lib/string/__init__.py:213–265  ·  view source on GitHub ↗
(self, format_string, args, kwargs, used_args, recursion_depth,
                 auto_arg_index=0)

Source from the content-addressed store, hash-verified

211 return result
212
213 def _vformat(self, format_string, args, kwargs, used_args, recursion_depth,
214 auto_arg_index=0):
215 if recursion_depth < 0:
216 raise ValueError('Max string recursion exceeded')
217 result = []
218 for literal_text, field_name, format_spec, conversion in \
219 self.parse(format_string):
220
221 # output the literal text
222 if literal_text:
223 result.append(literal_text)
224
225 # if there's a field, output it
226 if field_name is not None:
227 # this is some markup, find the object and do
228 # the formatting
229
230 # handle arg indexing when empty field first parts are given.
231 field_first, _ = _string.formatter_field_name_split(field_name)
232 if field_first == '':
233 if auto_arg_index is False:
234 raise ValueError('cannot switch from manual field '
235 'specification to automatic field '
236 'numbering')
237 field_name = str(auto_arg_index) + field_name
238 auto_arg_index += 1
239 elif isinstance(field_first, int):
240 if auto_arg_index:
241 raise ValueError('cannot switch from automatic field '
242 'numbering to manual field '
243 'specification')
244 # disable auto arg incrementing, if it gets
245 # used later on, then an exception will be raised
246 auto_arg_index = False
247
248 # given the field_name, find the object it references
249 # and the argument it came from
250 obj, arg_used = self.get_field(field_name, args, kwargs)
251 used_args.add(arg_used)
252
253 # do any conversion on the resulting object
254 obj = self.convert_field(obj, conversion)
255
256 # expand the format spec, if needed
257 format_spec, auto_arg_index = self._vformat(
258 format_spec, args, kwargs,
259 used_args, recursion_depth-1,
260 auto_arg_index=auto_arg_index)
261
262 # format the object and append to the result
263 result.append(self.format_field(obj, format_spec))
264
265 return ''.join(result), auto_arg_index
266
267
268 def get_value(self, key, args, kwargs):

Callers 2

vformatMethod · 0.95

Calls 9

parseMethod · 0.95
get_fieldMethod · 0.95
convert_fieldMethod · 0.95
format_fieldMethod · 0.95
strFunction · 0.85
isinstanceFunction · 0.85
appendMethod · 0.45
addMethod · 0.45
joinMethod · 0.45

Tested by 1