LMIDecorators

class lmi.shell.LMIDecorators.lmi_class_fetch_lazy(full_fetch=False)[source]

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

Parameters:full_fetch (bool) – True, if wbem.CIMClass should include qualifiers and class origin. Default value is False.
class lmi.shell.LMIDecorators.lmi_instance_name_fetch_lazy(full_fetch=False)[source]

Decorator for LMIInstanceName, which first fetches a wrapped wbem.CIMInstance object and then executes a wrapped method.

Parameters:full_fetch (bool) – True, if wbem.CIMClass should include qualifiers and class origin. Default value is False.
class lmi.shell.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 lmi.shell.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 lmi.shell.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 lmi.shell.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
class lmi.shell.LMIDecorators.lmi_wrap_cim_exceptions(rval=None, error_callable=None, prefix='')[source]

Decorator used for CIM-XML exception wrapping.

Parameters:
  • rval – rval passed to LMIReturnValue.__init__()
  • error_callable – callable used for processing wbem.CIMError and ConnectionError
  • prefix (str) – string prefix for wrapped exception’s args

NOTE: callables need to take 2 arguments: return value and error string.

static default_error_callable(rval, exc)[source]

Default exception handler, which translates exception into LMIReturnValue.

make_cim_error(cim_error)[source]

Returns wrapped CIMError from wbem.CIMError.

make_connection_error(conn_error)[source]

Returns wrapped ConnectionError from wbem.ConnectionError.

make_exception_args(exc, prefix)[source]

Returns a list of exception arguments. String argument is prefixed by make_prefix().

make_prefix()[source]

Returns prefix string for a CIM exception.

class lmi.shell.LMIDecorators.lmi_wrap_cim_exceptions_rval(rval=None, prefix='')[source]

Decorator used for CIM-XML exception wrapping.

Parameters:rval – return value of a decorated method in case of exception