Exemplo n.º 1
0
    def from_obj(cls, obj):
        if 'filters' in obj and isinstance(obj['filters'], list):
            if not obj['filters']:
                raise FilterValueError('Empty filters for And/Or')

            return cls(*[filter_from_obj(f) for f in obj['filters']])

        raise FilterValueError('Invalid object for {0}'.format(cls.__name__))
Exemplo n.º 2
0
    def deserialize(obj):
        if not isinstance(obj, dict):
            return BaseFilter(obj)

        if len(obj) != 1:
            raise FilterValueError('Malformatted filter')

        for name, value in obj.items():
            break

        for filter_class in filter_classes:
            if filter_class.__name__ == name:
                break
        else:
            raise FilterValueError('No such filter: {0}'.format(name))

        return filter_class.deserialize_value(value)
Exemplo n.º 3
0
    def __init__(self, value):
        if type(self) == BaseFilter and isinstance(value, bool):
            pass
        elif isinstance(value, (int, float)):
            pass
        elif isinstance(value, tuple(s[0] for s in STR_BASED_DATATYPES)):
            pass
        elif isinstance(value, str):
            for char in '\'"':
                if char in value:
                    raise FilterValueError(
                        '"{}" character is not allowed on filter values'.
                        format(char))
        else:
            raise FilterValueError('Filter value cannot be {}'.format(
                type(value).__name__))

        self.value = value
Exemplo n.º 4
0
 def __init__(self, value):
     self.value = value
     try:
         self._regexp_obj = re_compile(value)
     except re_error as error:
         raise FilterValueError(str(error))
Exemplo n.º 5
0
 def deserialize_value(cls, value):
     if value is not None:
         raise FilterValueError('Invalid value for {}()'.format(
             cls.__name__))
     return cls()
Exemplo n.º 6
0
 def deserialize_value(cls, value):
     if not isinstance(value, list):
         raise FilterValueError('Invalid value for {}()'.format(
             cls.__name__))
     return cls(*[cls.deserialize(v) for v in value])
Exemplo n.º 7
0
    def from_obj(cls, obj):
        if 'value' in obj:
            return cls(obj['value'])

        raise FilterValueError('Invalid object for ExactMatch')
Exemplo n.º 8
0
    def from_obj(cls, obj):
        if 'value' in obj:
            return cls(obj['value'])

        raise FilterValueError('Invalid object for Startswith')
Exemplo n.º 9
0
    def from_obj(cls, obj):
        if 'networks' in obj and isinstance(obj['networks'], (tuple, list)):
            return cls(*obj['networks'])

        raise FilterValueError('Invalid object for {0}'.format(cls))
Exemplo n.º 10
0
    def from_obj(cls, obj):
        if 'filter' in obj:
            return cls(filter_from_obj(obj['filter']))

        raise FilterValueError('Invalid object for Not')
Exemplo n.º 11
0
 def from_obj(cls, obj):
     if 'values' in obj and isinstance(obj['values'], list):
         return cls(*obj['values'])
     raise FilterValueError('Invalid object for Any')
Exemplo n.º 12
0
    def from_obj(cls, obj):
        if 'comparator' in obj and 'value' in obj:
            return cls(obj['comparator'], obj['value'])

        raise FilterValueError('Invalid object for Comparison')
Exemplo n.º 13
0
 def deserialize_value(cls, value):
     if not isinstance(value, list) or len(value) != 2:
         raise FilterValueError(
             'Invalid value for {}()'.format(cls.__name__)
         )
     return cls(value[0], value[1])
Exemplo n.º 14
0
 def __init__(self, comparator, value):
     if comparator not in ('<', '>', '<=', '>='):
         raise FilterValueError('Invalid operator: ' + comparator)
     self.comparator = comparator
     self.value = value
Exemplo n.º 15
0
    def from_obj(cls, obj):
        if 'regexp' in obj:
            return cls(obj['regexp'])

        raise FilterValueError('Invalid object for Regexp')