forked from facebook/buck
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_encoder.py
More file actions
23 lines (19 loc) · 778 Bytes
/
Copy pathjson_encoder.py
File metadata and controls
23 lines (19 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import with_statement
import collections
from json import JSONEncoder
# A JSONEncoder subclass which handles map-like and list-like objects.
class BuckJSONEncoder(JSONEncoder):
def __init__(self):
super(BuckJSONEncoder, self).__init__(self, sort_keys=True)
def default(self, obj):
if (isinstance(obj, collections.Mapping) and
isinstance(obj, collections.Sized)): # nopep8
return dict(obj)
elif (isinstance(obj, collections.Iterable) and
isinstance(obj, collections.Sized)):
return list(obj)
else:
return super(BuckJSONEncoder, self).default(obj)