old_contents: import csv
  
  
  def csv_to_dict(value, delimiter=","):
      """
      >>> csv_to_dict("\\n".join(['"UUID","Name","State"',\
  '"af6a3419","","power off"', \
  '"c11b095b","foo","power on"']))
      [{'State': 'power off', 'UUID': 'af6a3419', 'Name': ''}, \
  {'State': 'power on', 'UUID': 'c11b095b', 'Name': 'foo'}]
      >>> csv_to_dict('"UUID","Name","State"\\n')
      []
      >>> csv_to_dict('')
      []
      >>> csv_to_dict('"UUID","Name","State"')
      []
      """
      if not value:
          return []
      fieldnames = [i.strip('"') for i in value.splitlines()[0].split(delimiter)]
      return [i for i in csv.DictReader(value.splitlines()[1:],
                                        fieldnames=fieldnames)]
  
  
  class FilterModule(object):
  
      def filters(self):
          return {
              'from_csv': csv_to_dict
          }
  
new_contents: import csv
  try:
      from io import StringIO
  except ImportError:
      from StringIO import StringIO
  
  
  def csv_to_dict(string, delimiter=','):
      """ Creates a list of dicts from a string in the format:
                              [
          "a, b, c\n"\            {'a': '1', 'b': '2', 'c': '3'},
          "1, 2, 3\n"\  -->       {'a': '4', 'b': '5', 'c': '6'},
          "4, 5, 6\n"\            {'a': '7', 'b': '8', 'c': '9'}
          "7, 8, 9\n"         ]
      >>> csv_to_dict("\n".join(['"UUID","Name","State"',\
      '"af6a3419","","power off"', \
      '"c11b095b","foo","power on"']))
      [{'State': 'power off', 'UUID': 'af6a3419', 'Name': ''}, \
      {'State': 'power on', 'UUID': 'c11b095b', 'Name': 'foo'}]
      >>> csv_to_dict('"UUID","Name","State"\n')
      []
      >>> csv_to_dict('')
      []
      >>> csv_to_dict('"UUID","Name","State"')
      []
      """
      if not string:
          return []
      reader = csv.reader(StringIO(string), delimiter=delimiter)
      column_index_to_name_map = [column_name for index, column_name in enumerate(next(reader))]
      return [dict(zip(column_index_to_name_map, rows)) for rows in reader]
  
  
  class FilterModule(object):
      def filters(self):
          return {
              'from_csv': csv_to_dict
          }
  
subject: Refactor from_csv jinja filter