4.3. CIM data types

Python classes for representing values of CIM data types, and related conversion functions.

The following table shows how CIM data types are represented in Python. Note that some basic CIM data types are represented with built-in Python types.

CIM data type Python type
boolean bool
char16 string
string string
string (EmbeddedInstance) CIMInstance
string (EmbeddedObject) CIMInstance or CIMClass
datetime CIMDateTime
reference CIMInstanceName
uint8 Uint8
uint16 Uint16
uint32 Uint32
uint64 Uint64
sint8 Sint8
sint16 Sint16
sint32 Sint32
sint64 Sint64
real32 Real32
real64 Real64
[] (array) list

The CIM NULL value is represented with Python None which can be used for any CIM typed value to represent NULL.

Note that init methods of pywbem classes that take CIM typed values as input may support Python types in addition to those shown above. For example, the CIMProperty class represents property values of CIM datetime type internally as CIMDateTime objects, but its init method accepts datetime.timedelta objects, datetime.datetime objects, string, in addition to CIMDateTime objects.

class pywbem.CIMType[source]

Base type for all CIM data types defined in this package.

Methods

Attributes

cimtype The name of the CIM datatype, as a string.

Details

cimtype = None

The name of the CIM datatype, as a string. See CIM data types for details.

__repr__()[source]

Return a string representation suitable for debugging.

class pywbem.CIMDateTime(dtarg)[source]

A value of CIM data type datetime.

The object represents either a timezone-aware point in time, or a time interval.

Two objects of this class compare equal if their public attributes compare equal. Objects of this class are immutable and hashable, with the hash value being based on their public attributes.

Parameters:dtarg

The value from which the object is initialized, as one of the following types:

  • A string object will be interpreted as CIM datetime format (see DSP0004) and will result in a point in time or a time interval. The use of asterisk characters in the value is supported according to the rules defined in DSP0004 (e.g. “20180911124613.128***:000”).
  • A datetime.datetime object will result in a point in time. If the datetime.datetime object is timezone-aware (see MinutesFromUTC), the specified timezone will be used. Otherwise, a default timezone of UTC will be assumed.
  • A datetime.timedelta object will result in a time interval.
  • Another CIMDateTime object will be copied.

Methods

fromtimestamp Factory method that returns a new CIMDateTime object from a POSIX timestamp value and optional timezone information.
get_local_utcoffset Return the timezone offset of the current local timezone as +/- minutes from UTC.
now Factory method that returns a new CIMDateTime object representing the current date and time.

Attributes

cimtype The name of the CIM datatype "datetime"
datetime The point in time represented by this object, as a datetime.datetime object.
is_interval A boolean indicating whether this object represents a time interval (True) or a point in time (False).
minutes_from_utc The timezone offset of this point in time object as +/- minutes from UTC.
precision Precision of the time interval or point in time represented by this object, if the datetime input string contained asterisk characters.
timedelta The time interval represented by this object, as a datetime.timedelta object.

Details

cimtype = 'datetime'

The name of the CIM datatype "datetime"

minutes_from_utc

The timezone offset of this point in time object as +/- minutes from UTC.

A positive value of the timezone offset indicates minutes east of UTC, and a negative value indicates minutes west of UTC.

0, if this object represents a time interval.

datetime

The point in time represented by this object, as a datetime.datetime object.

None if this object represents a time interval.

timedelta

The time interval represented by this object, as a datetime.timedelta object.

None if this object represents a point in time.

precision

Precision of the time interval or point in time represented by this object, if the datetime input string contained asterisk characters.

The precision is the 0-based index of the first asterisk character in the datetime input string, or None if there were no asterisk characters. For example, the precision of the timestamp value “201809121230**.******+000” is 12.

is_interval

A boolean indicating whether this object represents a time interval (True) or a point in time (False).

static get_local_utcoffset()[source]

Return the timezone offset of the current local timezone as +/- minutes from UTC.

A positive value indicates minutes east of UTC, and a negative value indicates minutes west of UTC.

classmethod now(tzi=None)[source]

Factory method that returns a new CIMDateTime object representing the current date and time.

The optional timezone information is used to convert the CIM datetime value into the desired timezone. That does not change the point in time that is represented by the value, but it changes the value of the hhmmss components of the CIM datetime value to compensate for changes in the timezone offset component.

Parameters:tzi (MinutesFromUTC) – Timezone information. None means that the current local timezone is used.
Returns:A new CIMDateTime object representing the current date and time.
classmethod fromtimestamp(ts, tzi=None)[source]

Factory method that returns a new CIMDateTime object from a POSIX timestamp value and optional timezone information.

A POSIX timestamp value is the number of seconds since “the epoch”, i.e. 1970-01-01 00:00:00 UTC. Thus, a POSIX timestamp value is unambiguous w.r.t. the timezone, but it is not timezone-aware.

The optional timezone information is used to convert the CIM datetime value into the desired timezone. That does not change the point in time that is represented by the value, but it changes the value of the hhmmss components of the CIM datetime value to compensate for changes in the timezone offset component.

Parameters:
  • ts (integer) – POSIX timestamp value.
  • tzi (MinutesFromUTC) – Timezone information. None means that the current local timezone is used.
Returns:

A new CIMDateTime object representing the specified point in time.

__str__()[source]

Return a string representing the object in CIM datetime format.

__repr__()[source]

Return a string representation suitable for debugging.

class pywbem.MinutesFromUTC(offset)[source]

Timezone information (an implementation of datetime.tzinfo) that represents a fixed offset in +/- minutes from UTC and is thus suitable for the CIM datetime data type.

Objects of this class are needed in order to make datetime.datetime objects timezone-aware, in order to be useable as input data to the timezone-aware CIMDateTime type.

They are also used to provide timezone information to now() and fromtimestamp()

Example:

from datetime import datetime
from time import time
import pywbem

# Create a timezone-aware datetime object (for CEDT = UTC+2h), and
# convert that to CIM datetime:

dt = datetime(year=2016, month=3, day=31, hour=19, minute=30,
              second=40, microsecond=654321,
              tzinfo=pywbem.MinutesFromUTC(120))
cim_dt = pywbem.CIMDateTime(dt)

# Convert a POSIX timestamp value to CIM datetime (for EST = UTC-5h):

posix_ts = time()  # seconds since the epoch, not timezone-aware
cim_dt = pywbem.CIMDateTime.fromtimestamp(posix_ts,
                                          pywbem.MinutesFromUTC(-300))
Parameters:offset (integer) –

Timezone offset to be represented in the CIM datetime value in +/- minutes from UTC.

This is the offset of local time to UTC (including DST offset), where a positive value indicates minutes east of UTC, and a negative value indicates minutes west of UTC.

Methods

dst An implementation of the corresponding base class method, (see datetime.tzinfo.dst() for its description), which needs to return the offset caused by DST, as a datetime.timedelta object.
fromutc datetime in UTC -> datetime in local time.
tzname datetime -> string name of time zone.
utcoffset An implementation of the corresponding base class method (see datetime.tzinfo.utcoffset() for its description), which needs to return the offset of local time to UTC (including DST offset), as a datetime.timedelta object.

Attributes

Details

utcoffset(dt)[source]

An implementation of the corresponding base class method (see datetime.tzinfo.utcoffset() for its description), which needs to return the offset of local time to UTC (including DST offset), as a datetime.timedelta object. This method is called by the Python datetime classes, and a pywbem user normally does not have to deal with it.

This implementation returns the offset used to initialize the object, for any specified dt parameter.

dst(dt)[source]

An implementation of the corresponding base class method, (see datetime.tzinfo.dst() for its description), which needs to return the offset caused by DST, as a datetime.timedelta object. This method is called by the Python datetime classes, and a pywbem user normally does not have to deal with it.

This implementation returns an offset of 0 (indicating that DST is not in effect), for any specified dt parameter, because CIM datetime values do not represent DST information.

class pywbem.CIMInt[source]

Base type for CIM integer data types. Derived from CIMType and int (for Python 3) or long (for Python 2).

This class has a concept of a valid range for the represented integer, based upon the capability of the CIM data type as defined in DSP0004. The additional constraints defined by possible MinValue or MaxValue qualifiers are not taken into account at this level.

The valid value range is enforced when an instance of a subclass of this class (e.g. Uint8) is created. Values outside of the valid range raise a ValueError. The enforcement of the valid value range can be disabled via the configuration variable ENFORCE_INTEGER_RANGE.

Two objects of subclasses of this base class compare equal if their numeric values compare equal. Objects of this class are immutable and hashable, with the hash value being based on its numeric value.

Instances of subclasses of this class can be initialized with the usual input arguments supported by integer, for example:

>>> pywbem.Uint8(42)
Uint8(cimtype='uint8', 42)

>>> pywbem.Uint8('42')
Uint8(cimtype='uint8', 42)

>>> pywbem.Uint8('2A', 16)
Uint8(cimtype='uint8', 42)

>>> pywbem.Uint8('100', 16)
Traceback (most recent call last):
  . . .
ValueError: Integer value 256 is out of range for CIM datatype uint8

>>> pywbem.Uint8(100, 10)
Traceback (most recent call last):
  . . .
TypeError: int() can't convert non-string with explicit base

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype, as a string.
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the integer, according to the capabilities of its CIM data type.
minvalue The minimum valid value for the integer, according to the capabilities of its CIM data type.
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

minvalue = None

The minimum valid value for the integer, according to the capabilities of its CIM data type. See CIM data types for a list of CIM integer data types.

maxvalue = None

The maximum valid value for the integer, according to the capabilities of its CIM data type. See CIM data types for a list of CIM integer data types.

__repr__()[source]

Return a string representation suitable for debugging.

class pywbem.Uint8[source]

A value of CIM data type uint8. Derived from CIMInt.

For details on CIM integer data types, see CIMInt.

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the CIM datatype
minvalue The minimum valid value for the CIM datatype
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

cimtype = 'uint8'

The name of the CIM datatype

minvalue = 0

The minimum valid value for the CIM datatype

maxvalue = 255

The maximum valid value for the CIM datatype

class pywbem.Sint8[source]

A value of CIM data type sint8. Derived from CIMInt.

For details on CIM integer data types, see CIMInt.

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the CIM datatype
minvalue The minimum valid value for the CIM datatype
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

cimtype = 'sint8'

The name of the CIM datatype

minvalue = -128

The minimum valid value for the CIM datatype

maxvalue = 127

The maximum valid value for the CIM datatype

class pywbem.Uint16[source]

A value of CIM data type uint16. Derived from CIMInt.

For details on CIM integer data types, see CIMInt.

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the CIM datatype
minvalue The minimum valid value for the CIM datatype
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

cimtype = 'uint16'

The name of the CIM datatype

minvalue = 0

The minimum valid value for the CIM datatype

maxvalue = 65535

The maximum valid value for the CIM datatype

class pywbem.Sint16[source]

A value of CIM data type sint16. Derived from CIMInt.

For details on CIM integer data types, see CIMInt.

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the CIM datatype
minvalue The minimum valid value for the CIM datatype
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

cimtype = 'sint16'

The name of the CIM datatype

minvalue = -32768

The minimum valid value for the CIM datatype

maxvalue = 32767

The maximum valid value for the CIM datatype

class pywbem.Uint32[source]

A value of CIM data type uint32. Derived from CIMInt.

For details on CIM integer data types, see CIMInt.

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the CIM datatype
minvalue The minimum valid value for the CIM datatype
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

cimtype = 'uint32'

The name of the CIM datatype

minvalue = 0

The minimum valid value for the CIM datatype

maxvalue = 4294967295

The maximum valid value for the CIM datatype

class pywbem.Sint32[source]

A value of CIM data type sint32. Derived from CIMInt.

For details on CIM integer data types, see CIMInt.

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the CIM datatype
minvalue The minimum valid value for the CIM datatype
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

cimtype = 'sint32'

The name of the CIM datatype

minvalue = -2147483648

The minimum valid value for the CIM datatype

maxvalue = 2147483647

The maximum valid value for the CIM datatype

class pywbem.Uint64[source]

A value of CIM data type uint64. Derived from CIMInt.

For details on CIM integer data types, see CIMInt.

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the CIM datatype
minvalue The minimum valid value for the CIM datatype
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

cimtype = 'uint64'

The name of the CIM datatype

minvalue = 0

The minimum valid value for the CIM datatype

maxvalue = 18446744073709551615L

The maximum valid value for the CIM datatype

class pywbem.Sint64[source]

A value of CIM data type sint64. Derived from CIMInt.

For details on CIM integer data types, see CIMInt.

Methods

bit_length Number of bits necessary to represent self in binary.
conjugate Returns self, the complex conjugate of any long.

Attributes

cimtype The name of the CIM datatype
denominator the denominator of a rational number in lowest terms
imag the imaginary part of a complex number
maxvalue The maximum valid value for the CIM datatype
minvalue The minimum valid value for the CIM datatype
numerator the numerator of a rational number in lowest terms
real the real part of a complex number

Details

cimtype = 'sint64'

The name of the CIM datatype

minvalue = -9223372036854775808L

The minimum valid value for the CIM datatype

maxvalue = 9223372036854775807L

The maximum valid value for the CIM datatype

class pywbem.CIMFloat[source]

Base type for real (floating point) CIM data types.

Two objects of subclasses of this base class compare equal if their numeric values compare equal. Objects of this class are immutable and hashable, with the hash value being based on its numeric value.

Note that equality comparison of floating point numbers in Python (and in almost any programming language) comes with some surprises. See “Floating Point Arithmetic: Issues and Limitations” for details, and specifically “Comparing Floating Point Numbers, 2012 Edition” on the topic of equality comparison. The same issues apply to hash values that are based on the numeric value of floating point numbers. Therefore, it is not recommended to perform equality comparison of objects of subclasses of this class, or to use them as dictionary keys or as members in sets.

Methods

as_integer_ratio Return a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator.
conjugate Return self, the complex conjugate of any float.
fromhex Create a floating-point number from a hexadecimal string.
hex Return a hexadecimal representation of a floating-point number.
is_integer Return True if the float is an integer.

Attributes

cimtype The name of the CIM datatype, as a string.
imag the imaginary part of a complex number
real the real part of a complex number

Details

class pywbem.Real32[source]

A value of CIM data type real32. Derived from CIMFloat.

It is not recommended to perform equality comparison on objects of this class, or to use them as dictionary keys or as members in sets. See CIMFloat for details.

Methods

as_integer_ratio Return a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator.
conjugate Return self, the complex conjugate of any float.
fromhex Create a floating-point number from a hexadecimal string.
hex Return a hexadecimal representation of a floating-point number.
is_integer Return True if the float is an integer.

Attributes

cimtype The name of the CIM datatype
imag the imaginary part of a complex number
real the real part of a complex number

Details

cimtype = 'real32'

The name of the CIM datatype

class pywbem.Real64[source]

A value of CIM data type real64. Derived from CIMFloat.

It is not recommended to perform equality comparison on objects of this class, or to use them as dictionary keys or as members in sets. See CIMFloat for details.

Methods

as_integer_ratio Return a pair of integers, whose ratio is exactly equal to the original float and with a positive denominator.
conjugate Return self, the complex conjugate of any float.
fromhex Create a floating-point number from a hexadecimal string.
hex Return a hexadecimal representation of a floating-point number.
is_integer Return True if the float is an integer.

Attributes

cimtype The name of the CIM datatype
imag the imaginary part of a complex number
real the real part of a complex number

Details

cimtype = 'real64'

The name of the CIM datatype