Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def represent(self, obj, fieldtype, tablename=None):
if isinstance(obj, ndb.Key):
return obj
elif fieldtype == 'id' and tablename:
if isinstance(obj, list):
return [self.represent(item,fieldtype,tablename) for item in obj]
elif obj is None:
return None
else:
return ndb.Key(tablename, long(obj))
elif fieldtype == "json":
return serializers.json(obj)
elif isinstance(obj, (Expression, Field)):
raise SyntaxError("non supported on GAE")
elif isinstance(fieldtype, gae.Property):
return obj
elif fieldtype.startswith('list:') and not isinstance(obj, list):
if fieldtype=='list:string': return str(obj)
else: return long(obj)
else:
obj = NoSQLAdapter.represent(self, obj, fieldtype)
return obj
def represent(self, obj, fieldtype):
value = NoSQLAdapter.represent(self, obj, fieldtype)
if fieldtype == 'id':
return repr(str(long(value)))
elif fieldtype in ('date', 'time', 'datetime', 'boolean'):
return serializers.json(value)
return repr(not isinstance(value, unicode) and value
or value and value.encode('utf8'))
def _json(self, value):
return serializers.json(value)
):
"""
serializes the row to a JSON object
kwargs are passed to .as_dict method
only "object" mode supported
`serialize = False` used by Rows.as_json
TODO: return array mode with query column order
mode and colnames are not implemented
"""
item = self.as_dict(**kwargs)
if serialize:
return serializers.json(item)
else:
return item
def _datetime(self, value):
return serializers.json(value)
def _json(self, value):
return serializers.json(value)