Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, a):
Guard.against_empty(a, "Argument a is required")
pass
def parse_avg(self, query, column):
seq = self.parse_select_many(query)
if len(seq) == 0:
return 0
error_message = "The attribute '%s' was not found in the specified collection's items. If you meant to use the raw value of each item in the collection just use the word 'item' as a parameter to .avg or use .avg()" % column
Guard.against_empty(column, error_message)
attribute = column.replace("item.","")
if "item." in column:
try:
seq = [self.rec_getattr(item, attribute) for item in seq]
except AttributeError:
raise ValueError(error_message)
else:
if attribute.lower() != "item":
raise ValueError(error_message)
return reduce(operator.add,seq)/len(seq)
def __perform_operation_on_all(self, query, column, operation, command_name):
seq = self.parse_select_many(query)
if len(seq) == 0:
return 0
error_message = "The attribute '%s' was not found in the specified collection's items. If you meant to use the raw value of each item in the collection just use the word 'item' as a parameter to .%s or use .%s()" % (column, command_name, command_name)
Guard.against_empty(column, error_message)
attribute = column.replace("item.","")
if "item." in column:
try:
seq = [self.rec_getattr(item, attribute) for item in seq]
except AttributeError:
raise ValueError(error_message)
else:
if attribute.lower() != "item":
raise ValueError(error_message)
return operation(seq)
def __init__(self, *args):
Guard.against_empty(args, "In order to create a new attribute expression you need to provide some attributes.")
self.attributes = []
self.add_attributes(args)
def __init__(self, provider):
error_message = "The provider cannot be None. If you meant to use the CollectionProvider pass in a tuple or list"
Guard.against_none(provider, error_message)
if isinstance(provider, (list, tuple)):
self.provider = CollectionProvider(provider)
else:
self.provider = provider
self.expressions = []
self.order_expressions = []
self.group_expression = None
self.parser = ExpressionParser()