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