Package pywbem :: Module cim_types |
[frames] | no frames]

# Module cim_types

source code

Types to represent CIM typed values, and related conversion functions.

The following table shows how CIM typed values are represented as Python objects:

CIM type | Python type
--- | ---
boolean | `bool`
char16 | `unicode` or `str`
string | `unicode` or `str`
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`

Note that constructors 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 CIM datetime values internally as a CIMDateTime object, but its constructor accepts `datetime.timedelta`, `datetime.datetime`, `str`, and `unicode` objects in addition to CIMDateTime objects.

Classes
| MinutesFromUTC A `datetime.tzinfo` implementation defined using a fixed offset in +/- minutes from UTC.
| CIMType Base type for numeric and datetime CIM types.
| CIMDateTime A value of CIM type datetime.
| CIMInt Base type for integer CIM types.
| Uint8 A value of CIM type uint8.
| Sint8 A value of CIM type sint8.
| Uint16 A value of CIM type uint16.
| Sint16 A value of CIM type sint16.
| Uint32 A value of CIM type uint32.
| Sint32 A value of CIM type sint32.
| Uint64 A value of CIM type uint64.
| Sint64 A value of CIM type sint64.
| CIMFloat Base type for real (floating point) CIM types.
| Real32 A value of CIM type real32.
| Real64 A value of CIM type real64.

Functions
cimtype(obj) Return the CIM type name of a value, as a string. | source code
type_from_name(type_name) Return the Python type object for a given CIM type name. | source code
atomic_to_cim_xml(obj) Convert a value of an atomic scalar CIM type to a CIM-XML unicode string and return that string. | source code

Function Details

### cimtype(obj) | source code
Return the CIM type name of a value, as a string. For an array, the type is determined from the first array element because CIM arrays must be homogeneous. If the array is empty, ValueError is raised. If the type of the value is not a CIM type, TypeError is raised. Parameters: `obj` (CIM typed value) - The value whose CIM type name is returned. Returns: The CIM type name of the value, as a string. Raises: `TypeError` - Type is not a CIM type. `ValueError` - Cannot determine CIM type from empty array.

### type_from_name(type_name) | source code
Return the Python type object for a given CIM type name. For example, type name `'uint8'` will return type Uint8. Parameters: `type_name` (`str` or `unicode`) - The simple (=non-array) CIM type name (e.g. `'uint8'` or `'reference'`). Returns: The Python type object for the CIM type (e.g. Uint8 or CIMInstanceName). Raises: `ValueError` - Unknown CIM type name.

### atomic_to_cim_xml(obj) | source code
Convert a value of an atomic scalar CIM type to a CIM-XML unicode string and return that string. TODO: Verify whether we can change this function to raise a ValueError in case the value is not CIM typed. Parameters: `obj` (CIM typed value.) - The CIM typed value`, including `None`. Must be a scalar. Must be an atomic type (i.e. not CIMInstance or CIMClass). Returns: A unicode string in CIM-XML value format representing the CIM typed value. For a value of `None`, `None` is returned.