Ejemplo n.º 1
0
def items(**kwargs):
    def wrapper(arg):
        for key, value in kwargs.items():
            if key in arg and (arg[key] == value or value is ANYTHING):
                continue
            else:
                break
        else:
            return True
        return False

    return fpm.GuardFunc(wrapper)
Ejemplo n.º 2
0
def item(item, value=None, operation=None):
    def wrapper(arg):
        try:
            if operation and not value:
                return operation(arg[item])
            elif value and not operation:
                return arg[item] == value
            elif not operation and not value:
                return item in arg
            else:
                return operation(arg[item], value)
        except KeyError:
            return False

    return fpm.GuardFunc(wrapper)
Ejemplo n.º 3
0
def attr(attr, value=None, operation=None):
    def wrapper(arg):
        try:
            if operation and not value:
                return operation(getattr(arg, attr))
            elif value and not operation:
                return getattr(arg, attr) == value
            elif not operation and not value:
                return hasattr(arg, attr)
            else:
                return operation(getattr(arg, attr), value)
        except AttributeError:
            return False

    return fpm.GuardFunc(wrapper)