django-cotton/django_cotton/utils.py
Will Abbott 07017418dc wip
2024-07-05 23:19:19 +01:00

18 lines
429 B
Python

import ast
def eval_string(value):
"""
Evaluate a string representation of a constant, list, or dictionary to the actual Python object.
"""
try:
return ast.literal_eval(value)
except (ValueError, SyntaxError):
return value
def ensure_quoted(value):
if isinstance(value, str) and value.startswith('"') and value.endswith('"'):
return value
else:
return f'"{value}"'