How to use the pynq.guard.Guard function in pynq

To help you get started, we’ve selected a few pynq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github heynemann / pynq / tests / unit / test_guard.py View on Github external
def __init__(self, a):
                Guard.against_empty(a, "Argument a is required")
                pass
github heynemann / pynq / pynq / providers / __init__.py View on Github external
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)
github heynemann / pynq / pynq / providers / __init__.py View on Github external
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)
github heynemann / pynq / pynq / expressions.py View on Github external
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)
github heynemann / pynq / pynq / __init__.py View on Github external
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()