Browse Source

Definitely fix the `DateAwareJSONDecoder`

Restore `arrow` instead of `dateutil` but assert that the decoded
datetimes indeed serialized to the correct ISO-8601 string.
Phyks (Lucas Verney) 2 years ago
parent
commit
ce422dc998
No known key found for this signature in database
2 changed files with 4 additions and 4 deletions
  1. 4
    3
      infotuyo/helpers/json_helpers.py
  2. 0
    1
      requirements.txt

+ 4
- 3
infotuyo/helpers/json_helpers.py View File

@@ -10,7 +10,7 @@ import datetime
10 10
 import json
11 11
 
12 12
 # pip imports
13
-import dateutil
13
+import arrow
14 14
 
15 15
 
16 16
 class DateAwareJSONDecoder(json.JSONDecoder):
@@ -31,8 +31,9 @@ def date_hook(json_dict):
31 31
         if not isinstance(value, str):
32 32
             continue
33 33
         try:
34
-            json_dict[key] = dateutil.parser.parse(value)
35
-        except ValueError:
34
+            json_dict[key] = arrow.parser.DateTimeParser().parse_iso(value)
35
+            assert json_dict[key].isoformat() == value
36
+        except (arrow.parser.ParserError, AssertionError, ValueError):
36 37
             pass
37 38
     return json_dict
38 39
 

+ 0
- 1
requirements.txt View File

@@ -5,4 +5,3 @@ future==0.16.0
5 5
 graphviz==0.5.2
6 6
 Jinja2==2.8
7 7
 python-crontab==2.1.1
8
-python-dateutil==2.6.0