LMIDecorators Package

LMIDecorators.lmi_class_fetch_lazy(fn)[source]

Decorator for LMIClass, which first fetches a wrapped CIMClass object and then executes a wrapped method.

Parameters:fn (instancemethod) – wrapped method
class LMIDecorators.lmi_possibly_deleted(expr_ret, Self=False, *expr_ret_args, **expr_ret_kwargs)[source]

Decorator, which returns None, if provided test expression is True.

Parameters:
  • expr_ret – callable or return value used, if expr_test fails
  • expr_ret_args – expr_ret position arguments
  • expr_ret_kwargs – expr_ret keyword arguments
  • Self (bool) – flag, which specifies, if to pass self variable to the expr_ret, if expr_test failed

Example of usage:

class Foo:
    def __init__(self, deleted):
        self._deleted = deleted

    @lmi_possibly_deleted(lambda obj: obj._member, lambda: False)
    def some_method(self):
        print "some_method called"
        return True

f = Foo(None)
f.some_method() == False

f = Foo(True)
f.some_method() == True
class LMIDecorators.lmi_return_expr_if_fail(expr_test, expr_ret, Self=False, *expr_ret_args, **expr_ret_kwargs)[source]

Decorator, which calls a specified expression and returns its return value instead of calling the decorated method, if provided test expression is False; otherwise a method is called.

Parameters:
  • expr_test – expression which determines, if to execute a return value expression
  • expr_ret – expression, which is called, if the expr_test returns False
  • expr_ret_argsexpr_ret position arguments
  • expr_ret_kwargsexpr_ret keyword arguments
  • Self (bool) – flag, which specifies, if to pass self variable to the expr_ret, if expr_test failed

Example of usage:

class Foo:
    def __init__(self, member):
        self._member = member

    def failed(self):
        print "expression failed"
        return False

    # NOTE: the self parameter to the method call needs to be passed via expr_ret_args,
    # therefore, there is a dummy lambda obj: obj, which is basically self variable.
    @lmi_return_expr_if_fail(lambda obj: obj._member, failed, lambda obj: obj)
    def some_method(self):
        print "some_method called"
        return True

f = Foo(None)
f.some_method() == False

f = Foo(True)
f.some_method() == True
class LMIDecorators.lmi_return_if_fail(expr_test)[source]

Decorator, which returns None and no method call is performed, if provided test expression is False; otherwise a method is called.

Parameters:expr_test – if the expression expr_test returns True, a method is called

Example of usage:

class Foo:
    def __init__(self, member):
        self._member = member

    @lmi_return_if_fail(lambda obj: obj._member)
    def some_method(self):
        print "some_method called"
        return True

f = Foo(None)
f.some_method() == None

f = Foo(True)
f.some_method() == True
class LMIDecorators.lmi_return_val_if_fail(expr_test, rval)[source]

Decorator, which returns a specified value and no method call is performed, if provided test expression is False; otherwise a method is called.

Parameters:
  • expr_test – if the expression returns False, a method call is called
  • rval – return value of the method, if the object attribute as expression failed

Example of usage:

class Foo:
    def __init__(self, member):
        self._member = member

    @lmi_return_val_if_fail(lambda obj: obj._member, False)
    def some_method(self):
        print "some_method called"
        return True

f = Foo(None)
f.some_method() == False

f = Foo(True)
f.some_method() == True

This Page