def default(self, obj):
        if isinstance(obj, Mapping):
            try:
                return dict(obj)
            except:
                pass
        if isinstance(obj, Sized) and isinstance(obj, Iterable):
            try:
                return list(obj)
            except:
                pass
        if callable(getattr(obj, 'to_dict', None)):
            return obj.to_dict()

        if self.dev_mode:
            return repr(obj)  # TODO: blargh
            if isinstance(obj, type) or callable(obj):
                return unicode(repr(obj))
            try:
                return dict([(k, v) for k, v in obj.__dict__.items()
                             if not k.startswith('__')])
            except __HOLE__:
                return unicode(repr(obj))
        else:
            raise TypeError('cannot serialize to JSON: %r' % obj)
dataset/ETHPy150Open mahmoud/clastic/clastic/render/simple.py/ClasticJSONEncoder.default