def collect_string_fields(format_string):
 formatter = string.Formatter()
 try:
  parseiterator = formatter.parse(format_string)
  for result in parseiterator:
   if all(((item is None) for item in result[1:])):
    continue
   name = result[1]
   nested = result[2]
   (yield name)
   if nested:
    for field in collect_string_fields(nested):
     (yield field)
 except ValueError:
  raise utils.IncompleteFormatString(format_string)

def collect_string_fields ( format_string ) : formatter = string . Formatter ( ) try : parseiterator = formatter . parse ( format_string ) for result in parseiterator : if all ( ( ( item is None ) for item in result [ 1 : ] ) ) : continue name = result [ 1 ] nested = result [ 2 ] ( yield name ) if nested : for field in collect_string_fields ( nested ) : ( yield field ) except ValueError : raise utils . IncompleteFormatString ( format_string )
given a format string .