Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def default(self, o):
if isinstance(o, time.struct_time):
return time.mktime(o)
if isinstance(o, Exception):
return repr(o)
return json.JSONEncoder.default(self, o)
def default(self, o):
if isinstance(o, ZvmNode) or isinstance(o, ZvmChannel):
return o.__dict__
if isinstance(o, ObjPath):
return o.url
return json.JSONEncoder.default(self, o)
def default(self, obj):
if isinstance(obj, (bytes, bytearray)):
return obj.decode("utf-8")
return json.JSONEncoder.default(self, obj)
def default(self, obj): # pylint: disable=method-hidden
if hasattr(obj, '__json__') and six.callable(obj.__json__):
return obj.__json__()
else:
return JSONEncoder.default(self, obj)
def default(self, o):
if isinstance(o, _LazyString):
return o.value
elif isinstance(o, UserDict):
return dict(o)
elif isinstance(o, datetime):
return {'date': str(o.date()), 'time': str(o.time()), 'tz': str(o.tzinfo)}
elif isinstance(o, date):
return str(o)
return _json.JSONEncoder.default(self, o)
def default(self, obj):
try:
return simplejson.JSONEncoder.default(self, obj)
except TypeError:
if isinstance(obj, Decimal):
return float(obj)
if isinstance(obj, datetime):
return obj.strftime('%a, %d %b %Y %H:%M:%S %z')
return smart_unicode(obj)
def default(self, o):
if isinstance(o, datetime):
return o.isoformat()
return json.JSONEncoder.default(self, o)
def default(self, obj):
try:
return json.JSONEncoder.default(self, obj)
except TypeError, e:
if isinstance(obj, (datetime, date)):
return obj.isoformat()
elif isinstance(obj, Model):
return dict(obj)
elif isinstance(obj, ColProxy):
return list(obj)
elif isinstance(obj, RowProxy):
return dict(obj)
else:
raise e
def default(self, obj):
if isinstance(obj, datetime.datetime):
return (obj - EPOCH).total_seconds()
return json.JSONEncoder.default(self, obj)
def default(self, obj):
if isinstance(obj, (datetime.datetime, datetime.date)):
return obj.isoformat()
elif isinstance(obj, ObjectId):
return unicode(obj)
return json.JSONEncoder.default(self, obj)