Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def st_dwithin(self, value, distance):
return Query(self.db, self._dialect.st_dwithin, self, (value, distance))
def startswith(self, value):
if self.type not in ("string", "text", "json", "jsonb", "upload"):
raise SyntaxError("startswith used with incompatible field type")
return Query(self.db, self._dialect.startswith, self, value)
def expand(self,expression,field_type=None):
if expression is None:
return None
elif isinstance(expression,Field):
if expression.type in ('text', 'blob', 'json'):
raise SyntaxError('AppEngine does not index by: %s' % expression.type)
return expression.name
elif isinstance(expression, (Expression, Query)):
if not expression.second is None:
return expression.op(expression.first, expression.second)
elif not expression.first is None:
return expression.op(expression.first)
else:
return expression.op()
elif field_type:
return self.represent(expression,field_type)
elif isinstance(expression,(list,tuple)):
return ','.join([self.represent(item,field_type) for item in expression])
elif hasattr(expression, "_FilterNode__name"):
# check for _FilterNode__name to avoid explicit import of FilterNode
return expression
else:
raise NotImplementedError
def st_equals(self, value):
return Query(self.db, self._dialect.st_equals, self, value)
def check_unique(self, table, values):
if len(table._uniques) > 0:
db = table._db
unique_queries = []
for fieldname in table._uniques:
if fieldname in values:
value = values[fieldname]
else:
value = table[fieldname].default
unique_queries.append(
Query(db, self.dialect.eq, table[fieldname], value))
if len(unique_queries) > 0:
unique_query = unique_queries[0]
# if more than one field, build a query of ORs
for query in unique_queries[1:]:
unique_query = Query(
db, self.dialect._or, unique_query, query)
if self.count(unique_query, distinct=False) != 0:
for query in unique_queries:
if self.count(query, distinct=False) != 0:
# one of the 'OR' queries failed, see which one
raise Exception(
"NOT UNIQUE constraint failed: %s" %
query.first.name)
def st_overlaps(self, value):
return Query(self.db, self._dialect.st_overlaps, self, value)
db = table._db
unique_queries = []
for fieldname in table._uniques:
if fieldname in values:
value = values[fieldname]
else:
value = table[fieldname].default
unique_queries.append(
Query(db, self.dialect.eq, table[fieldname], value))
if len(unique_queries) > 0:
unique_query = unique_queries[0]
# if more than one field, build a query of ORs
for query in unique_queries[1:]:
unique_query = Query(
db, self.dialect._or, unique_query, query)
if self.count(unique_query, distinct=False) != 0:
for query in unique_queries:
if self.count(query, distinct=False) != 0:
# one of the 'OR' queries failed, see which one
raise Exception(
"NOT UNIQUE constraint failed: %s" %
query.first.name)
def regexp(self, value):
return Query(self.db, self._dialect.regexp, self, value)
"""
returns a query with all accessible records for user_id or
the current logged in user
this method does not work on GAE because uses JOIN and IN
example:
db(auth.accessible_query('read', db.mytable)).select(db.mytable.ALL)
"""
if not user_id:
user_id = self.user_id
db = self.db
if isinstance(table, str) and table in self.db.tables():
table = self.db[table]
elif isinstance(table, (Set, Query)):
# experimental: build a chained query for all tables
if isinstance(table, Set):
cquery = table.query
else:
cquery = table
tablenames = db._adapter.tables(cquery)
for tablename in tablenames:
cquery &= self.accessible_query(name, tablename,
user_id=user_id)
return cquery
if not isinstance(table, str) and\
self.has_permission(name, table, 0, user_id):
return table.id > 0
query = table.id.belongs(db(self.table_membership.user_id == user_id)(
self.table_membership.group_id == self.table_permission.group_id)(
self.table_permission.name == name)(