Forráskód Böngészése

Allow parsing of regular dicts
This allows the deserialization of serialized payloads, for example: events stored in a database JSON column.

Stan Janssen 4 éve
szülő
commit
0b4b4e10d6
1 módosított fájl, 4 hozzáadás és 7 törlés
  1. 4 7
      openleadr/utils.py

+ 4 - 7
openleadr/utils.py

@@ -80,19 +80,19 @@ def normalize_dict(ordered_dict):
             continue
         key = normalize_key(key)
 
-        if isinstance(value, OrderedDict):
+        if isinstance(value, (OrderedDict, dict)):
             d[key] = normalize_dict(value)
         elif isinstance(value, list):
             d[key] = []
             for item in value:
-                if isinstance(item, OrderedDict):
+                if isinstance(item, (OrderedDict, dict)):
                     dict_item = normalize_dict(item)
                     d[key].append(normalize_dict(dict_item))
                 else:
                     d[key].append(item)
         elif key in ("duration", "startafter", "max_period", "min_period"):
             d[key] = parse_duration(value)
-        elif "date_time" in key and isinstance(value, str):
+        elif ("date_time" in key or key == "dtstart") and isinstance(value, str):
             d[key] = parse_datetime(value)
         elif value in ('true', 'false'):
             d[key] = parse_boolean(value)
@@ -183,10 +183,7 @@ def normalize_dict(ordered_dict):
 
         # Durations are encapsulated in their own object, remove this nesting
         elif isinstance(d[key], dict) and "duration" in d[key] and len(d[key]) == 1:
-            try:
-                d[key] = d[key]["duration"]
-            except:
-                breakpoint()
+            d[key] = d[key]["duration"]
 
         # In general, remove all double nesting
         elif isinstance(d[key], dict) and key in d[key] and len(d[key]) == 1: