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
¶ Base type for all CIM data types defined in this package.
Methods
Attributes
cimtype
Details
-
class
pywbem.
CIMDateTime
(dtarg)¶ 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 thedatetime.datetime
object is timezone-aware (seeMinutesFromUTC
), 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
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
-
__repr__
()¶ Return a string representation suitable for debugging.
-
__str__
()¶ Return a string representing the object in CIM datetime format.
-
datetime
¶ The point in time represented by this object, as a
datetime.datetime
object.None if this object represents a time interval.
-
classmethod
fromtimestamp
(ts, tzi=None)¶ 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.
-
static
get_local_utcoffset
()¶ 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.
-
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.
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.
-
classmethod
now
(tzi=None)¶ 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.
-
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.
-
timedelta
¶ The time interval represented by this object, as a
datetime.timedelta
object.None if this object represents a point in time.
-
class
pywbem.
MinutesFromUTC
(offset)¶ 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-awareCIMDateTime
type.They are also used to provide timezone information to
now()
andfromtimestamp()
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 adatetime.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 adatetime.timedelta
object.Attributes
Details
-
dst
(dt)¶ 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 adatetime.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.
-
utcoffset
(dt)¶ 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 adatetime.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.
-
-
class
pywbem.
CIMInt
¶ Base type for CIM integer data types. Derived from
CIMType
andint
(for Python 3) orlong
(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 aValueError
. The enforcement of the valid value range can be disabled via the configuration variableENFORCE_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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
__repr__
()¶ Return a string representation suitable for debugging.
-
-
class
pywbem.
Uint8
¶ 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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
class
pywbem.
Sint8
¶ 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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
class
pywbem.
Uint16
¶ 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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
class
pywbem.
Sint16
¶ 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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
class
pywbem.
Uint32
¶ 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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
class
pywbem.
Sint32
¶ 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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
class
pywbem.
Uint64
¶ 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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
class
pywbem.
Sint64
¶ 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
denominator
the denominator of a rational number in lowest terms imag
the imaginary part of a complex number maxvalue
minvalue
numerator
the numerator of a rational number in lowest terms real
the real part of a complex number Details
-
class
pywbem.
CIMFloat
¶ 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
imag
the imaginary part of a complex number real
the real part of a complex number Details
-
__repr__
()¶ Return a string representation suitable for debugging.
-
-
class
pywbem.
Real32
¶ 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
imag
the imaginary part of a complex number real
the real part of a complex number Details
-
class
pywbem.
Real64
¶ 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
imag
the imaginary part of a complex number real
the real part of a complex number Details