<s> import os <EOL> import json <EOL> import datetime <EOL> import time <EOL> import dateutil . parser <EOL> import dateutil . tz <EOL> class DatetimeEncoder ( json . JSONEncoder ) : <EOL> def default ( self , obj ) : <EOL> if isinstance ( obj , datetime . datetime ) : <EOL> return obj . isoformat ( ) <EOL> return json . JSONEncoder . default ( self , obj ) <EOL> def serialize_json ( obj , protection = True ) : <EOL> str = json . dumps ( obj , cls = DatetimeEncoder ) <EOL> if protection : <EOL> return "<STR_LIT>" + str <EOL> else : <EOL> return str <EOL> def deserialize_json ( string ) : <EOL> return json . loads ( string , object_hook = deserialize_datetime ) <EOL> def deserialize_datetime ( obj ) : <EOL> try : <EOL> obj [ '<STR_LIT:date>' ] = dateutil . parser . parse ( obj [ '<STR_LIT:date>' ] ) <EOL> except KeyError : <EOL> pass <EOL> return obj </s>
