Skip to content

Commit

Permalink
Changed instance/class path str() back to historical format.
Browse files Browse the repository at this point in the history
Details:

- An earlier change in this release had changed the `__str__()` methods
  of `CIMInstanceName` and `CIMClassName` to return the standard DSP0207
  format for WBEM URIs. Because that is an incompatible change,
  this change changes that back to let those methods again return
  the historical format they returned in pywbem 0.11.

- Redesigned the interface of the `to_wbem_uri()` methods of
  `CIMInstanceName` and `CIMClassName` to no longer have the
  boolean `omit_leading_slash` parameter, but a `format` parameter
  that can be used to select "standard", "cimobject" or "historical"
  format. The `__str__()` methods use "historical" format, the
  creation of the `CIMObject` header field in cim_http.py uses
  "cimobject" format, and the default is "standard" format.

Signed-off-by: Andreas Maier <maiera@de.ibm.com>
  • Loading branch information
andy-maier committed Jan 17, 2018
1 parent e473307 commit 1fd836a
Show file tree
Hide file tree
Showing 4 changed files with 312 additions and 84 deletions.
10 changes: 5 additions & 5 deletions docs/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ Enhancements
of the generated MOF to be more consistent with the CIM Schema MOF.

* Added new methods `CIMInstanceName.to_wbem_uri()` and
`CIMClassName.to_wbem_uri()` that return the path as a WBEM URI compliant to
DSP0207, in order to make the conversion explicit instead of relying
on the string conversion methods. The string conversion methods are still
supported, but see the fix to make them compliant to DSP0207 (added as part
of fixing issue #928).
`CIMClassName.to_wbem_uri()` that return the path as a WBEM URI string that
conforms to untyped WBEM URIs as defined in DSP0207.
The `CIMInstanceName.__str__()` and `CIMClassName.__str__()` methods still
return the same WBEM URI string they previously did, but that is a historical
format close to but not conformant to DSP0207 (issues #928, #943).

* Improved the way CIM-XML parsing errors are handled, by providing the
original traceback information when re-raising a low-level exception
Expand Down
4 changes: 2 additions & 2 deletions pywbem/cim_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,11 +966,11 @@ def get_cimobject_header(obj):

# Local class path
if isinstance(obj, CIMClassName):
return obj.to_wbem_uri(omit_local_slash=True)
return obj.to_wbem_uri(format='cimobject')

# Local instance path
if isinstance(obj, CIMInstanceName):
return obj.to_wbem_uri(omit_local_slash=True)
return obj.to_wbem_uri(format='cimobject')

raise TypeError("Invalid object type %s to generate CIMObject header "
"value from" % type(obj))
153 changes: 118 additions & 35 deletions pywbem/cim_obj.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,11 +1686,31 @@ def __hash__(self):

def __str__(self):
"""
Return the untyped WBEM URI of the CIM instance path represented
by the :class:`~pywbem.CIMInstanceName` object, as returned by
Return a WBEM URI string of the CIM instance path represented by the
:class:`~pywbem.CIMInstanceName` object.
The returned WBEM URI string is in the historical format returned by
:meth:`~pywbem.CIMInstanceName.to_wbem_uri`.
For new code, it is recommended that the standard format is used; it
is returned by :meth:`~pywbem.CIMInstanceName.to_wbem_uri` as the
default format.
Examples (for the historical format):
* With authority and namespace::
//acme.com/cimv2/test:CIM_RegisteredProfile.InstanceID="acme.1"
* Without authority but with namespace::
cimv2/test:CIM_RegisteredProfile.InstanceID="acme.1"
* Without authority and without namespace::
CIM_RegisteredProfile.InstanceID="acme.1"
"""
return self.to_wbem_uri()
return self.to_wbem_uri(format='historical')

def __repr__(self):
"""
Expand Down Expand Up @@ -2146,13 +2166,12 @@ def from_wbem_uri(wbem_uri):

return obj

def to_wbem_uri(self, omit_local_slash=False):
def to_wbem_uri(self, format='standard'):
"""
Return the untyped WBEM URI of the CIM instance path represented
by the :class:`~pywbem.CIMInstanceName` object.
The returned WBEM URI is consistent with :term:`DSP0207`, and contains
its components as follows:
The returned WBEM URI contains its components as follows:
* it does not contain a namespace type (URI scheme).
* it contains an authority component according to the
Expand All @@ -2169,17 +2188,34 @@ def to_wbem_uri(self, omit_local_slash=False):
Parameters:
omit_local_slash (bool): Omit the leading slash in "local" WBEM URIs
(that is, in WBEM URIs without authority component). Note that
:term:`DSP0207` requires a leading slash in "local" WBEM URIs.
format (:term:`string`): Format for the generated WBEM URI string,
using one of the following values:
Examples:
* ``"standard"`` - Standard format that is conformant to untyped
WBEM URIs for instance paths defined in :term:`DSP0207`.
* ``"cimobject"`` - Format for the `CIMObject` header field in
CIM-XML messages for representing instance paths (used
internally, see :term:`DSP0200`).
* ``"historical"`` - Historical format for WBEM URIs (used by
:meth:`~pywbem.CIMInstanceName.__str__`; should not be used by
new code). The historical format has the following differences to
the standard format:
- If the authority component is not present, the slash after the
authority is also omitted. In the standard format, that slash
is always present.
- If the namespace component is not present, the colon after the
namespace is also omitted. In the standard format, that colon
is always present.
Examples for the standard format:
* With authority and namespace::
//jdd:test@acme.com:5989/cimv2/test:CIM_RegisteredProfile.InstanceID="acme.1"
//acme.com/cimv2/test:CIM_RegisteredProfile.InstanceID="acme.1"
//acme.com/root/cimv2:CIM_ComputerSystem.CreationClassName="ACME_CS",Name="sys1"
* Without authority but with namespace::
Expand All @@ -2188,11 +2224,11 @@ def to_wbem_uri(self, omit_local_slash=False):
* Without authority and without namespace::
/:CIM_RegisteredProfile.InstanceID="acme.1"
/:CIM_SubProfile.Main="/:CIM_RegisteredProfile.InstanceID=\"acme.1\"",Sub="/:CIM_RegisteredProfile.InstanceID=\"acme.2\""
Returns:
:term:`unicode string`: Untyped WBEM URI of the CIM instance path.
:term:`unicode string`: Untyped WBEM URI of the CIM instance path,
in the specified format.
Raises:
TypeError: Invalid type in keybindings
Expand All @@ -2204,13 +2240,15 @@ def to_wbem_uri(self, omit_local_slash=False):
ret.append('//')
ret.append(self.host)

if self.host is not None or not omit_local_slash:
if self.host is not None or format == 'standard':
ret.append('/')

if self.namespace is not None:
ret.append(self.namespace)

ret.append(':')
if self.namespace is not None or format in ('standard', 'cimobject'):
ret.append(':')

ret.append(self.classname)

ret.append('.')
Expand Down Expand Up @@ -3095,11 +3133,36 @@ def __hash__(self):

def __str__(self):
"""
Return the untyped WBEM URI of the CIM class path represented by the
:class:`~pywbem.CIMClassName` object, as returned by
Return a WBEM URI string of the CIM class path represented by the
:class:`~pywbem.CIMClassName` object.
The returned WBEM URI string is in the historical format returned by
:meth:`~pywbem.CIMClassName.to_wbem_uri`.
For new code, it is recommended that the standard format is used; it
is returned by :meth:`~pywbem.CIMClassName.to_wbem_uri` as the default
format.
If you want to access the class name, use the
:attr:`~pywbem.CIMClassName.classname` attribute, instead of relying
on the coincidence that the historical format of a WBEM URI without
authority and namespace happens to be the class name.
Examples (for the historical format):
* With authority and namespace::
//acme.com/cimv2/test:CIM_RegisteredProfile
* Without authority but with namespace::
cimv2/test:CIM_RegisteredProfile
* Without authority and without namespace::
CIM_RegisteredProfile
"""
return self.to_wbem_uri()
return self.to_wbem_uri(format='historical')

def __repr__(self):
"""
Expand Down Expand Up @@ -3241,35 +3304,52 @@ def from_wbem_uri(wbem_uri):

return obj

def to_wbem_uri(self, omit_local_slash=False):
def to_wbem_uri(self, format='standard'):
"""
Return the untyped WBEM URI of the CIM class path represented
by the :class:`~pywbem.CIMClassName` object.
Return the untyped WBEM URI of the CIM class path represented by the
:class:`~pywbem.CIMClassName` object.
The returned WBEM URI is consistent with :term:`DSP0207`, and contains
its components as follows:
The returned WBEM URI contains its components as follows:
* it does not contain a namespace type (URI scheme).
* it contains an authority component according to the
:attr:`~pywbem.CIMInstanceName.host` attribute, if that is not
:attr:`~pywbem.CIMClassName.host` attribute, if that is not
`None`. Othwerise, it does not contain the authority component.
* it contains a namespace component according to the
:attr:`~pywbem.CIMInstanceName.namespace` attribute, if that is not
:attr:`~pywbem.CIMClassName.namespace` attribute, if that is not
`None`. Othwerise, it does not contain the namespace component.
* it contains a class name component according to the
:attr:`~pywbem.CIMInstanceName.classname` attribute.
:attr:`~pywbem.CIMClassName.classname` attribute.
Parameters:
omit_local_slash (bool): Omit the leading slash in "local" WBEM URIs
(that is, in WBEM URIs without authority component). Note that
:term:`DSP0207` requires a leading slash in "local" WBEM URIs.
format (:term:`string`): Format for the generated WBEM URI string,
using one of the following values:
Examples:
* ``"standard"`` - Standard format that is conformant to untyped
WBEM URIs for class paths defined in :term:`DSP0207`.
* ``"cimobject"`` - Format for the `CIMObject` header field in
CIM-XML messages for representing class paths (used
internally, see :term:`DSP0200`).
* ``"historical"`` - Historical format for WBEM URIs (used by
:meth:`~pywbem.CIMClassName.__str__`; should not be used by
new code). The historical format has the following differences to
the standard format:
- If the authority component is not present, the slash after the
authority is also omitted. In the standard format, that slash
is always present.
- If the namespace component is not present, the colon after the
namespace is also omitted. In the standard format, that colon
is always present.
Examples for the standard format:
* With authority and namespace::
//jdd:test@acme.com:5989/cimv2/test:CIM_RegisteredProfile
//acme.com/cimv2/test:CIM_RegisteredProfile
* Without authority but with namespace::
Expand All @@ -3282,7 +3362,8 @@ def to_wbem_uri(self, omit_local_slash=False):
Returns:
:term:`unicode string`: Untyped WBEM URI of the CIM class path.
:term:`unicode string`: Untyped WBEM URI of the CIM class path,
in the specified format.
"""

ret = []
Expand All @@ -3291,13 +3372,15 @@ def to_wbem_uri(self, omit_local_slash=False):
ret.append('//')
ret.append(self.host)

if self.host is not None or not omit_local_slash:
if self.host is not None or format == 'standard':
ret.append('/')

if self.namespace is not None:
ret.append(self.namespace)

ret.append(':')
if self.namespace is not None or format in ('standard', 'cimobject'):
ret.append(':')

ret.append(self.classname)

return _ensure_unicode(''.join(ret))
Expand Down

0 comments on commit 1fd836a

Please sign in to comment.