Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
---------------------------------------------------------------
commit d30b54a6a79d68778339f6b3e8d17c1dd75bbe3a
Author: Peter Hatina <phatina(a)redhat.com>
Date: Mon Sep 2 16:37:47 2013 +0200
drop lmi_get_item_or_default
---------------------------------------------------------------
cli/lmi/shell/LMIConnection.py | 3 +--
cli/lmi/shell/LMIMethod.py | 9 +++------
cli/lmi/shell/LMIShellConfig.py | 13 ++++---------
cli/lmi/shell/LMIUtil.py | 14 +-------------
4 files changed, 9 insertions(+), 30 deletions(-)
diff --git a/cli/lmi/shell/LMIConnection.py b/cli/lmi/shell/LMIConnection.py
index 27191d3..cd8b9a2 100644
--- a/cli/lmi/shell/LMIConnection.py
+++ b/cli/lmi/shell/LMIConnection.py
@@ -31,7 +31,6 @@ from LMISubscription import LMISubscription
from LMIExceptions import LMIIndicationError
-from LMIUtil import lmi_get_item_or_default
from LMIUtil import lmi_raise_or_dump_exception
from LMIUtil import lmi_get_use_exceptions
from LMIUtil import lmi_set_use_exceptions
@@ -330,7 +329,7 @@ class LMIConnection(object):
lmi_raise_or_dump_exception(LMIIndicationError(errorstr))
return LMIReturnValue(rval=False, errorstr=errorstr)
# XXX: Should we auto-delete all the indications?
- permanent = lmi_get_item_or_default(kwargs, "Permanent", True)
+ permanent = kwargs.get("Permanent", True)
self._indications[kwargs["Name"]] = LMISubscription(
self._client,
(cim_filter, not cim_filter_provided),
diff --git a/cli/lmi/shell/LMIMethod.py b/cli/lmi/shell/LMIMethod.py
index b863371..8168ca4 100644
--- a/cli/lmi/shell/LMIMethod.py
+++ b/cli/lmi/shell/LMIMethod.py
@@ -42,7 +42,6 @@ from LMIUtil import LMIPassByRef
from LMIUtil import lmi_raise_or_dump_exception
from LMIUtil import lmi_cast_to_cim
from LMIUtil import lmi_transform_to_lmi
-from LMIUtil import lmi_get_item_or_default
from LMIExceptions import LMIIndicationListenerError
from LMIExceptions import LMIMethodCallError
@@ -130,7 +129,7 @@ class LMIMethod(LMIWrapperBaseObject):
if not refreshed:
raise LMISynchroMethodCallError(errorstr)
(exc_rval, exc_rparams, exc_errorstr) = job_inst.GetError()
- error_inst = lmi_get_item_or_default(exc_rparams, "error", None)
+ error_inst = exc_rparams.get("error", None)
if not error_inst:
raise LMISynchroMethodCallError("Could not get Job error
message")
errorstr = error_inst.Message
@@ -349,9 +348,7 @@ class LMIMethod(LMIWrapperBaseObject):
args -- CIMMethod arguments
kwargs -- CIMMethod keyword arguments
"""
- synchro_method_polling = False
- if "PreferPolling" in kwargs:
- synchro_method_polling = kwargs.pop("PreferPolling")
+ synchro_method_polling = kwargs.pop("PreferPolling", False)
for (param, value) in kwargs.iteritems():
if param in self._method.parameters:
t = self._method.parameters[param].type
@@ -372,7 +369,7 @@ class LMIMethod(LMIWrapperBaseObject):
lmi_raise_or_dump_exception(LMIMethodCallError(errorstr))
return LMIReturnValue(rval=rval, errorstr=errorstr)
# Check if we can perform synchronous method call
- job = call_rparams["job"] if "job" in call_rparams else
None
+ job = call_rparams.get("job", None)
can_perform_sync_call = job.classname in LMIMethod._INDICATION_JOB_CLASSNAMES
if job else False
if self._sync_method and job and can_perform_sync_call:
# Synchronous method calls
diff --git a/cli/lmi/shell/LMIShellConfig.py b/cli/lmi/shell/LMIShellConfig.py
index 66e05c8..c0fd24c 100644
--- a/cli/lmi/shell/LMIShellConfig.py
+++ b/cli/lmi/shell/LMIShellConfig.py
@@ -16,8 +16,6 @@
import os
import sys
-from LMIUtil import lmi_get_item_or_default
-
class LMIShellConfig(object):
"""
Class representing the shell's configuration. The class is responsible for
loading the
@@ -39,14 +37,11 @@ class LMIShellConfig(object):
try:
conf = {}
execfile(os.path.expanduser(LMIShellConfig.DEFAULT_CONFIG_FILE), conf)
- self._history_file = os.path.expanduser(lmi_get_item_or_default(conf,
"history_file",
+ self._history_file = os.path.expanduser(conf.get("history_file",
LMIShellConfig.DEFAULT_HISTORY_FILE))
- self._history_length = lmi_get_item_or_default(conf,
"history_length",
- LMIShellConfig.DEFAULT_HISTORY_LENGTH)
- self._use_cache = lmi_get_item_or_default(conf, "use_cache",
- LMIShellConfig.DEFAULT_USE_CACHE)
- self._use_exceptions = lmi_get_item_or_default(conf,
"use_exceptions",
- LMIShellConfig.DEFAULT_USE_EXCEPTIONS)
+ self._history_length = conf.get("history_length",
LMIShellConfig.DEFAULT_HISTORY_LENGTH)
+ self._use_cache = conf.get("use_cache",
LMIShellConfig.DEFAULT_USE_CACHE)
+ self._use_exceptions = conf.get("use_exceptions",
LMIShellConfig.DEFAULT_USE_EXCEPTIONS)
except (SyntaxError, IOError), e:
if isinstance(e, SyntaxError):
sys.stderr.write("Error: %s\n" % e)
diff --git a/cli/lmi/shell/LMIUtil.py b/cli/lmi/shell/LMIUtil.py
index f536b80..94f38b4 100644
--- a/cli/lmi/shell/LMIUtil.py
+++ b/cli/lmi/shell/LMIUtil.py
@@ -87,18 +87,6 @@ class LMIPassByRef(object):
"""
self._val[0] = new_val
-def lmi_get_item_or_default(dic, item, default):
- """
- Helper function, which returns either the dictionary member, or specified default
- value.
-
- Arguments:
- dic -- dictionary
- item -- dictionary key
- default -- default return value, if item is not present in the dictionary
- """
- return dic[item] if item in dic else default
-
def lmi_get_use_exceptions():
"""
Returns a global flag indicating, if the LMIShell should use the exceptions,
@@ -134,7 +122,7 @@ def _lmi_do_cast(t, value, cast):
value -- variable to cast
cast -- dictionary with type:cast_func
"""
- cast_func = cast[t.lower()] if t.lower() in cast else lambda x: x
+ cast_func = cast.get(t.lower(), lambda x: x)
if isinstance(value, (dict, pywbem.NocaseDict)):
return pywbem.NocaseDict({
k: _lmi_do_cast(t, val, cast) for k, val in value.iteritems()})