Esempio n. 1
0
def _parse_cim_obj(param_type, obj):
    try:
        obj = cim_obj.tocimobj(param_type, obj)
    except ValueError:
        # not a cim type, do nothing
        pass
    return obj
Esempio n. 2
0
def _parse_by_type(raw_val, val_type):
    if isinstance(raw_val, list):
        ret = list(map(lambda x: _parse_cim_obj(val_type, x), raw_val))
    elif len(raw_val) == 0 and val_type != 'string':
        ret = None
    else:
        ret = cim_obj.tocimobj(val_type, raw_val)
    return ret
Esempio n. 3
0
def parse_qualifier_declaration(tt):
    # <!ELEMENT QUALIFIER.DECLARATION (SCOPE?, (VALUE | VALUE.ARRAY)?)>
    # <!ATTLIST QUALIFIER.DECLARATION
    #     %CIMName;
    #     %CIMType;               #REQUIRED
    #     ISARRAY    (true|false) #IMPLIED
    #     %ArraySize;
    #     %QualifierFlavor;>

    check_node(tt, 'QUALIFIER.DECLARATION', ['NAME', 'TYPE'], [
        'ISARRAY', 'ARRAYSIZE', 'OVERRIDABLE', 'TOSUBCLASS', 'TOINSTANCE',
        'TRANSLATABLE'
    ], ['SCOPE', 'VALUE', 'VALUE.ARRAY'])

    a = attrs(tt)
    qname = a['NAME']
    type = a['TYPE']
    try:
        is_array = a['ISARRAY'].lower() == 'true'
    except KeyError:
        is_array = False
    try:
        array_size = int(a['ARRAYSIZE'])
    except KeyError:
        array_size = None

    flavors = {}
    for f in ['OVERRIDABLE', 'TOSUBCLASS', 'TOINSTANCE', 'TRANSLATABLE']:
        try:
            flavors[f.lower()] = a[f].lower() == 'true'
        except KeyError:
            pass

    scopes = None
    value = None
    for child in kids(tt):
        if name(child) == 'SCOPE':
            if scopes is not None:
                raise ParseError("Multiple SCOPE tags encountered")
            scopes = parse_any(child)
        else:
            if value is not None:
                raise ParseError("Multiple VALUE/VALUE.ARRAY tags encountered")
            value = cim_obj.tocimobj(type, parse_any(child))

    return CIMQualifierDeclaration(qname, type, value, is_array, array_size,
                                   scopes, **flavors)
Esempio n. 4
0
def parse_property_array(parser, event, node):
    name = _get_required_attribute(node, 'NAME')
    type = _get_required_attribute(node, 'TYPE')

    array_size = _get_attribute(node, 'ARRAYSIZE')
    class_origin = _get_attribute(node, 'CLASSORIGIN')
    propagated = _get_attribute(node, 'PROPAGATED')

    qualifiers = []
    value = None

    (next_event, next_node) = parser.next()

    if _is_start(next_event, next_node, 'QUALIFIER'):

        qualifiers.append(parse_qualifier(parser, next_event, next_node))

        while 1:

            (next_event, next_node) = parser.next()

            if _is_start(next_event, next_node, 'VALUE.ARRAY'):
                break

            if _is_start(next_event, next_node, 'QUALIFIER'):
                qualifiers.append(
                    parse_qualifier(parser, next_event, next_node))
            else:
                raise ParseError('Expecting QUALIFIER')

    if _is_start(next_event, next_node, 'VALUE.ARRAY'):
        value = parse_value_array(parser, next_event, next_node)
        (next_event, next_node) = parser.next()

    if not _is_end(next_event, next_node, 'PROPERTY.ARRAY'):
        raise ParseError('Expecting end PROPERTY.ARRAY')

    return CIMProperty(name,
                       cim_obj.tocimobj(type, value),
                       _type=type,
                       class_origin=class_origin,
                       propagated=propagated,
                       is_array=True,
                       qualifiers=dict([(x.name, x) for x in qualifiers]))
Esempio n. 5
0
def parse_qualifier(parser, event, node):
    name = _get_required_attribute(node, 'NAME')
    type = _get_required_attribute(node, 'TYPE')
    propagated = _get_attribute(node, 'PROPAGATED')

    (next_event, next_node) = parser.next()

    if _is_end(next_event, next_node, 'QUALIFIER'):
        return CIMQualifier(name, None, type=type)

    if _is_start(next_event, next_node, 'VALUE'):
        value = parse_value(parser, next_event, next_node)
    elif _is_start(next_event, next_node, 'VALUE.ARRAY'):
        value = parse_value_array(parser, next_event, next_node)
    else:
        raise ParseError('Expecting (VALUE | VALUE.ARRAY)')

    result = CIMQualifier(name, cim_obj.tocimobj(type, value))

    _get_end_event(parser, 'QUALIFIER')

    return result