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 |
|
char16 |
|
string |
|
string (EmbeddedInstance) |
|
string (EmbeddedObject) |
|
datetime |
|
reference |
|
uint8 |
|
uint16 |
|
uint32 |
|
uint64 |
|
sint8 |
|
sint16 |
|
sint32 |
|
sint64 |
|
real32 |
|
real64 |
|
[] (array) |
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.
Attributes:
The name of the CIM datatype, as a string.
- cimtype = None
The name of the CIM datatype, as a string. See CIM data types for details.
- 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 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:
__eq__
(other)Equality test function for two
CIMDateTime
objects.__hash__
()Return a hash value based on the public attributes of this class.
fromtimestamp
(ts[, tzi])Factory method that returns a new
CIMDateTime
object from a POSIX timestamp value and optional timezone information.Return the timezone offset of the current local timezone as +/- minutes from UTC.
now
([tzi])Factory method that returns a new
CIMDateTime
object representing the current date and time.Attributes:
The name of the CIM datatype
"datetime"
The point in time represented by this object, as a
datetime.datetime
object.A boolean indicating whether this object represents a time interval (True) or a point in time (False).
The timezone offset of this point in time object as +/- minutes from UTC.
Precision of the time interval or point in time represented by this object, if the datetime input string contained asterisk characters.
The time interval represented by this object, as a
datetime.timedelta
object.- __eq__(other)[source]
Equality test function for two
CIMDateTime
objects.The equality is based on their public attributes.
Note that a
CIMDateTime
object represents either a time interval or a point in time but never both. Therefore, an object representing an interval is never equal to an object representing a point in time.Returns False if the other object is not a
CIMDateTime
object.
- __hash__()[source]
Return a hash value based on the public attributes of this class. Because these attributes are not modifiable, objects of this class are hashable (and not just unchanged-hashable).
- cimtype = 'datetime'
The name of the CIM datatype
"datetime"
- property 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)[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.
- 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.
- property is_interval
A boolean indicating whether this object represents a time interval (True) or a point in time (False).
- property 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)[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.
- property 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.
- property 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)[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-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
(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.tzname
(dt)An implementation of the corresponding base class method, (see
datetime.tzinfo.tzname()
for its description), which needs to return the name of the timezone of the specified datetime object.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.- 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 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.
- tzname(dt)[source]
An implementation of the corresponding base class method, (see
datetime.tzinfo.tzname()
for its description), which needs to return the name of the timezone of the specified datetime object.This implementation returns the timezone offset formatted as a signed HH:MM string, where positive values are east of UTC.
- 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 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.Char16(content='')[source]
A value of CIM data type char16.
This class is derived from unicode string.
Normally, values of CIM data type char16 are represented using unicode string objects. This class can be used to represent values of CIM data type char16 when it matters to distinguish them from values of CIM data type string. The only situation where that matters is for keybindings, because that allows properly setting the TYPE attribute on KEYVALUE elements when creating the CIM-XML representation for a keybinding.
Attributes:
The name of the CIM datatype
"char16"
- cimtype = 'char16'
The name of the CIM datatype
"char16"
- class pywbem.CIMInt(*args, **kwargs)[source]
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
Attributes:
The maximum valid value for the integer, according to the capabilities of its CIM data type.
The minimum valid value for the integer, according to the capabilities of its CIM data type.
- 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.
- 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.
- class pywbem.Uint8(*args, **kwargs)[source]
A value of CIM data type uint8. Derived from
CIMInt
.For details on CIM integer data types, see
CIMInt
.Attributes:
The name of the CIM datatype
The maximum valid value for the CIM datatype
The minimum valid value for the CIM datatype
- cimtype = 'uint8'
The name of the CIM datatype
- maxvalue = 255
The maximum valid value for the CIM datatype
- minvalue = 0
The minimum valid value for the CIM datatype
- class pywbem.Sint8(*args, **kwargs)[source]
A value of CIM data type sint8. Derived from
CIMInt
.For details on CIM integer data types, see
CIMInt
.Attributes:
The name of the CIM datatype
The maximum valid value for the CIM datatype
The minimum valid value for the CIM datatype
- cimtype = 'sint8'
The name of the CIM datatype
- maxvalue = 127
The maximum valid value for the CIM datatype
- minvalue = -128
The minimum valid value for the CIM datatype
- class pywbem.Uint16(*args, **kwargs)[source]
A value of CIM data type uint16. Derived from
CIMInt
.For details on CIM integer data types, see
CIMInt
.Attributes:
The name of the CIM datatype
The maximum valid value for the CIM datatype
The minimum valid value for the CIM datatype
- cimtype = 'uint16'
The name of the CIM datatype
- maxvalue = 65535
The maximum valid value for the CIM datatype
- minvalue = 0
The minimum valid value for the CIM datatype
- class pywbem.Sint16(*args, **kwargs)[source]
A value of CIM data type sint16. Derived from
CIMInt
.For details on CIM integer data types, see
CIMInt
.Attributes:
The name of the CIM datatype
The maximum valid value for the CIM datatype
The minimum valid value for the CIM datatype
- cimtype = 'sint16'
The name of the CIM datatype
- maxvalue = 32767
The maximum valid value for the CIM datatype
- minvalue = -32768
The minimum valid value for the CIM datatype
- class pywbem.Uint32(*args, **kwargs)[source]
A value of CIM data type uint32. Derived from
CIMInt
.For details on CIM integer data types, see
CIMInt
.Attributes:
The name of the CIM datatype
The maximum valid value for the CIM datatype
The minimum valid value for the CIM datatype
- cimtype = 'uint32'
The name of the CIM datatype
- maxvalue = 4294967295
The maximum valid value for the CIM datatype
- minvalue = 0
The minimum valid value for the CIM datatype
- class pywbem.Sint32(*args, **kwargs)[source]
A value of CIM data type sint32. Derived from
CIMInt
.For details on CIM integer data types, see
CIMInt
.Attributes:
The name of the CIM datatype
The maximum valid value for the CIM datatype
The minimum valid value for the CIM datatype
- cimtype = 'sint32'
The name of the CIM datatype
- maxvalue = 2147483647
The maximum valid value for the CIM datatype
- minvalue = -2147483648
The minimum valid value for the CIM datatype
- class pywbem.Uint64(*args, **kwargs)[source]
A value of CIM data type uint64. Derived from
CIMInt
.For details on CIM integer data types, see
CIMInt
.Attributes:
The name of the CIM datatype
The maximum valid value for the CIM datatype
The minimum valid value for the CIM datatype
- cimtype = 'uint64'
The name of the CIM datatype
- maxvalue = 18446744073709551615
The maximum valid value for the CIM datatype
- minvalue = 0
The minimum valid value for the CIM datatype
- class pywbem.Sint64(*args, **kwargs)[source]
A value of CIM data type sint64. Derived from
CIMInt
.For details on CIM integer data types, see
CIMInt
.Attributes:
The name of the CIM datatype
The maximum valid value for the CIM datatype
The minimum valid value for the CIM datatype
- cimtype = 'sint64'
The name of the CIM datatype
- maxvalue = 9223372036854775807
The maximum valid value for the CIM datatype
- minvalue = -9223372036854775808
The minimum valid value for the CIM datatype
- class pywbem.CIMFloat(x=0, /)[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.
- class pywbem.Real32(x=0, /)[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.Attributes:
The name of the CIM datatype
- cimtype = 'real32'
The name of the CIM datatype
- class pywbem.Real64(x=0, /)[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.Attributes:
The name of the CIM datatype
- cimtype = 'real64'
The name of the CIM datatype