2 from .variables import SsiVariable, SsiExpect
6 if isinstance(o, SsiVariable):
7 return {'__var__': o.name}
8 if isinstance(o, SsiExpect):
9 return {'__expect__': o.name}
10 raise TypeError(o, 'not JSON serializable')
13 def _json_obj_hook(obj):
14 if obj.keys() == ['__var__']:
15 return SsiVariable(name=obj['__var__'])
16 if obj.keys() == ['__expect__']:
17 return SsiExpect(obj['__expect__'])
21 def json_encode(obj, **kwargs):
22 return json.JSONEncoder(
23 default=_json_default,
24 separators=(',', ':'),
28 def json_decode(data, **kwargs):
29 return json.loads(data, object_hook=_json_obj_hook, **kwargs)