code: def parse_pattern(format_string, env, wrapper=lambda x, y: y):
      formatter = Formatter()
      fields = [x[1] for x in formatter.parse(format_string) if x[1] is not None]
      prepared_env = {}
      for field in fields:
          for field_alt in (x.strip() for x in field.split('|')):
              if field_alt[0] in '\'"' and field_alt[-1] in '\'"':
                  field_values = field_alt[1:-1]
              else:
                  field_values = env.get(field_alt)
              if field_values is not None:
                  break
          else:
              field_values = []
          if not isinstance(field_values, list):
              field_values = [field_values]
          prepared_env[field] = wrapper(field_alt, field_values)
      return prepared_env