Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def query(self, key, value, lookup, filters):
if '__' in key:
key, op = key.split('__',1)
else:
op = 'eq'
if self.__index:
if op == 'eq':
op = ':'
else:
raise TypeError("Unsupported query operator '%s'" % op)
if isinstance(value, strings):
value = '"%s"' % value # TODO: we might need escaping
lookup.append("%s%s%s" % (self.__index_key,op,value))
else:
if op == 'eq':
predicate = lambda entity: self.get(entity[key]) == value
else:
raise TypeError("Unsupported query operator '%s'" % op)
filters.append(predicate)
def property_type(type):
if type is None: return DynamicProperty
if issubclass(type, strings): return StringProperty
if type in integers: return NumberProperty
if type is float: return NumberProperty
if type is datetime.datetime: return DateProperty
def set(self, value):
if isinstance(value, strings): return value
if isinstance(value, integers): return value
if isinstance(value, float): return value
raise ValueError("Invalid property type: '%s'" % type(value).__name__)