Skip to content

Commit

Permalink
Merge 90fef69 into c199e04
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-maier committed Oct 25, 2019
2 parents c199e04 + 90fef69 commit 3e17746
Show file tree
Hide file tree
Showing 5 changed files with 37,989 additions and 21,922 deletions.
16 changes: 16 additions & 0 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ Released: not yet

**Bug fixes:**

* Fixed that the embedded_object attribute was not copied in CIMProperty.copy().

* Fixed that inconsistent names (between key and object name) were not detected
when setting CIMMethod.parameters from an input dictionary.

* Docs: Fixed errors in description of CIMInstance.update_existing().

**Enhancements:**

* Removed the use of the 'pbr' package because it caused too many undesirable
Expand Down Expand Up @@ -55,6 +62,15 @@ Released: not yet
inserted into the mock repository when mof instances are compiled. Duplicate
instances (CIMInstanceName) will now cause an exception. See issue #1852

* Added support for byte string values in keybindings of CIMInstanceName
method to_wbem_uri(), consistent with other methods.

**Cleanup:**

* Removed unnecessary code from cim_obj._scalar_value_tomof() that processed
native Python types int, long, float. These types cannot occur in this
function, so no tests could be written that test that code.

**Known issues:**

* See `list of open issues`_.
Expand Down
79 changes: 59 additions & 20 deletions pywbem/cim_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ def _scalar_value_tomof(
Parameters:
value (:term:`CIM data type`, :term:`number`, :class:`~pywbem.CIMInstance`, :class:`~pywbem.CIMClass`):
value (:term:`CIM data type`, :class:`~pywbem.CIMInstance`, :class:`~pywbem.CIMClass`):
The scalar CIM-typed value. May be `None`.
Must not be an array/list/tuple. Must not be a :ref:`CIM object` other
Expand Down Expand Up @@ -837,15 +837,12 @@ def _scalar_value_tomof(
elif type == 'reference':
val = value.to_wbem_uri()
return mofstr(val, indent, maxline, line_pos, end_space, avoid_splits)
elif isinstance(value, (CIMFloat, CIMInt, int, _Longint)):
val = six.text_type(value)
return mofval(val, indent, maxline, line_pos, end_space)
else:
assert isinstance(value, float), \
assert isinstance(value, (CIMFloat, CIMInt)), \
_format("Scalar value of CIM type {0} has invalid Python type {1} "
"for conversion to a MOF string",
type, builtin_type(value))
val = repr(value)
val = six.text_type(value)
return mofval(val, indent, maxline, line_pos, end_space)


Expand Down Expand Up @@ -1059,6 +1056,32 @@ def _cim_method(key, value):
return value


def _cim_parameter(key, value):
"""
Return a CIMParameter object, from dict item input (key+value), after
performing some checks.
The input value must be a CIMParameter object, which is returned.
"""

if key is None:
raise ValueError("Parameter name must not be None")

try:
assert isinstance(value, CIMParameter)
except AssertionError:
raise TypeError(
_format("Parameter must be a CIMParameter object, but is: {0}",
type(value)))

if value.name.lower() != key.lower():
raise ValueError(
_format("CIMParameter.name must be dictionary key {0!A}, but is ",
"{1!A}", key, value.name))

return value


def _cim_qualifier(key, value):
"""
Return a CIMQualifier object, from dict item input (key+value), after
Expand Down Expand Up @@ -2111,7 +2134,10 @@ def case_sorted(keys):
ret.append(key)
ret.append('=')

if isinstance(value, six.string_types):
if isinstance(value, six.binary_type):
value = _to_unicode(value)

if isinstance(value, six.text_type):
# string, char16
ret.append('"')
ret.append(value.
Expand Down Expand Up @@ -2733,28 +2759,40 @@ def update(self, *args, **kwargs):

def update_existing(self, *args, **kwargs):
"""
Update already existing properties of this CIM instance.
Update the values of already existing properties of this CIM instance.
Existing properties will be updated, and new properties will be
ignored without further notice.
From the specified new properties, only those properties will be
updated that already exist in the instance. No new properties will
be added to the instance, ignoring their specified new properties
without further notice.
Parameters:
*args (list):
Properties for updating the properties of the instance, specified
as positional arguments. Each positional argument must be a tuple
(key, value), where key and value are described for setting the
:attr:`~pywbem.CIMInstance.properties` property.
New properties, specified as positional arguments. Each
positional argument must be one of:
- an iterable of tuple (name, value), where each tuple specifies
the name of the property to be updated and its new value.
- an object with an ``items()`` method that iterates through
tuple (name, value), where each tuple specifies the name of the
property to be updated and its new value.
Examples of such objects are :attr:`~pywbem.CIMInstanceName`
(where its keybindings will be used as new properties) or
:attr:`~pywbem.CIMInstance` (where its properties will be used
as new properties).
**kwargs (dict):
Properties for updating the properties of the instance, specified
as keyword arguments. The name and value of the keyword arguments
are described as key and value for setting the
:attr:`~pywbem.CIMInstance.properties` property.
New properties, specified as keyword arguments. Each keyword
argument specifies one new property, where the argument name is
the name of the property to be updated and the argument value is
its new value.
"""

for mapping in args:
if hasattr(mapping, 'items'):
if hasattr(mapping, 'items'): # CIMInstanceName, etc.
for key, value in mapping.items():
try:
prop = self.properties[key]
Expand Down Expand Up @@ -4842,6 +4880,7 @@ def copy(self):
propagated=self.propagated,
is_array=self.is_array,
reference_class=self.reference_class,
embedded_object=self.embedded_object,
qualifiers=self.qualifiers) # setter copies

def __str__(self):
Expand Down Expand Up @@ -5422,7 +5461,7 @@ def parameters(self, parameters):
raise TypeError(
_format("Input object for parameters has invalid item "
"in iterable: {0!A}", item))
self.parameters[key] = value
self.parameters[key] = _cim_parameter(key, value)

@property
def qualifiers(self):
Expand Down
Loading

0 comments on commit 3e17746

Please sign in to comment.