Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

safely convert ini parameters to bool, int, list and dict #104

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
9 changes: 9 additions & 0 deletions pyramid_celery/loaders.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import datetime
import json
import pyjson5 as json5
from pyjson5 import Json5DecoderException as JSONDecodeError
import celery.loaders.base
import celery.schedules
import configparser
Expand Down Expand Up @@ -93,6 +95,13 @@ def get_route_config(parser, section):

def safe_conversion(value):
"""convert a string to a more specific type"""
try:
newval= json5.loads(value)
#print("JSON DECODED", type(newval), newval)
return newval
except JSONDecodeError:
pass

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably try using json.load as fallback if pyjson5 is not installed.
The imports should also handle missing pyjson5 from installed packages.
I don't think it is necessary for pyramid_celery to inject this new dependency.


if value.lower() in ("true", "false"):
return bool(value)
try:
Expand Down