@@ -264,22 +264,18 @@ def _vformat(self, format_string, args, kwargs, used_args, recursion_depth,
264
264
265
265
return '' .join (result ), auto_arg_index
266
266
267
-
268
267
def get_value (self , key , args , kwargs ):
269
268
if isinstance (key , int ):
270
269
return args [key ]
271
270
else :
272
271
return kwargs [key ]
273
272
274
-
275
273
def check_unused_args (self , used_args , args , kwargs ):
276
274
pass
277
275
278
-
279
276
def format_field (self , value , format_spec ):
280
277
return format (value , format_spec )
281
278
282
-
283
279
def convert_field (self , value , conversion ):
284
280
# do any conversion on the resulting object
285
281
if conversion is None :
@@ -292,34 +288,32 @@ def convert_field(self, value, conversion):
292
288
return ascii (value )
293
289
raise ValueError ("Unknown conversion specifier {0!s}" .format (conversion ))
294
290
295
-
296
- # returns an iterable that contains tuples of the form:
297
- # (literal_text, field_name, format_spec, conversion)
298
- # literal_text can be zero length
299
- # field_name can be None, in which case there's no
300
- # object to format and output
301
- # if field_name is not None, it is looked up, formatted
302
- # with format_spec and conversion and then used
303
291
def parse (self , format_string ):
304
- return _string .formatter_parser (format_string )
292
+ """
293
+ Return an iterable that contains tuples of the form
294
+ (literal_text, field_name, format_spec, conversion).
305
295
306
296
307
- # given a field_name, find the object it references.
308
- # field_name: the field being looked up, e.g. "0.name"
309
- # or "lookup[3]"
310
- # used_args: a set of which args have been used
311
- # args, kwargs: as passed in to vformat
297
+ *field_name* can be None, in which case there's no object
298
+ to format and output; otherwise, it is looked up and
299
+ formatted with *format_spec* and *conversion*.
300
+ """
301
+ return _string .formatter_parser (format_string )
302
+
312
303
def get_field (self , field_name , args , kwargs ):
313
- first , rest = _string . formatter_field_name_split ( field_name )
304
+ """Find the object referenced by a given field name.
314
305
306
+ The field name *field_name* can be for instance "0.name"
307
+ or "lookup[3]". The *args* and *kwargs* arguments are
308
+ passed to get_value().
309
+ """
310
+ first , rest = _string .formatter_field_name_split (field_name )
315
311
obj = self .get_value (first , args , kwargs )
316
-
317
312
# loop through the rest of the field_name, doing
318
313
# getattr or getitem as needed
319
314
for is_attr , i in rest :
320
315
if is_attr :
321
316
obj = getattr (obj , i )
322
317
else :
323
318
obj = obj [i ]
324
-
325
319
return obj , first
0 commit comments