diff --git a/plexpy/helpers.py b/plexpy/helpers.py index 9e844aa9..e546597b 100644 --- a/plexpy/helpers.py +++ b/plexpy/helpers.py @@ -530,6 +530,20 @@ def cast_to_float(s): return 0 +def helper_divmod(a, b): + try: + return divmod(a, b) + except (ValueError, TypeError): + return 0 + + +def helper_round(n, ndigits): + try: + return round(n, ndigits) + except (ValueError, TypeError): + return 0 + + def convert_xml_to_json(xml): o = xmltodict.parse(xml) return json.dumps(o) diff --git a/plexpy/notification_handler.py b/plexpy/notification_handler.py index da02aa43..97c57993 100644 --- a/plexpy/notification_handler.py +++ b/plexpy/notification_handler.py @@ -1818,10 +1818,10 @@ def str_eval(field_name, kwargs): field_name = field_name.strip('`') allowed_names = { 'bool': bool, - 'divmod': divmod, - 'float': float, - 'int': int, - 'round': round, + 'divmod': helpers.helper_divmod, + 'float': helpers.cast_to_float, + 'int': helpers.cast_to_int, + 'round': helpers.helper_round, 'str': str } allowed_names.update(kwargs)