misc.py 612 B

1234567891011121314151617181920
  1. import yaml
  2. from django.conf import settings
  3. def yaml_coerce(value):
  4. """
  5. Pass in a string dictionary and convert it into proper python dictionary
  6. """
  7. if isinstance(value, str):
  8. # create a tiny snippet of YAML, with key=dummy, and val=value, then load the YAML into
  9. # a pure Pythonic dictionary. Then, we read off the dummy key from the coversion to get our
  10. # final result
  11. return yaml.load(f'dummy: {value}', Loader=yaml.SafeLoader)['dummy']
  12. return value
  13. def print_(*args, **kwargs):
  14. if settings.ENABLE_PRINT_STATEMENTS:
  15. print(*args, **kwargs)