mirror of
https://github.com/wrabit/django-cotton.git
synced 2025-08-04 07:08:21 +00:00
18 lines
429 B
Python
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}"'
|