def dictfetchall(cursor, classname=None):
    """Returns all rows from a cursor as a dict
     optionally replaces all __ with the specified classname
     ex: TPA__ becomes TPA_Douglas-Fir_14_18"""
    desc = cursor.description
    if not classname:
        res = [
            dict(zip([col[0] for col in desc], row))
            for row in cursor.fetchall()
        ]
    else:
        cname = "_%s" % classname
        res = [
            dict(zip([col[0].replace("__", cname) for col in desc], row))
            for row in cursor.fetchall()
        ]
    return res