def test_get_attributes_for_sanity(self):
     '''
     Verifies the parsing of attributes.
     '''
     self.assertEquals(parser.get_attributes('foo=bar'), ('foo', 'bar'))
     self.assertEquals(parser.get_attributes('foo=bar '), ('foo', 'bar'))
     self.assertEquals(parser.get_attributes('foo= "some stuff"'),
                       ('foo', 'some stuff'))
     self.assertEquals(parser.get_attributes('foo = "bar"'), ('foo', 'bar'))
 def test_get_attributes_for_sanity(self):
     '''
     Verifies the parsing of attributes.
     '''
     self.assertEquals(parser.get_attributes('foo=bar'), ('foo', 'bar'))
     self.assertEquals(parser.get_attributes('foo=bar '), ('foo', 'bar'))
     self.assertEquals(parser.get_attributes('foo= "some stuff"'),
                       ('foo', 'some stuff'))
     self.assertEquals(parser.get_attributes('foo = "bar"'),
                       ('foo', 'bar'))
Пример #3
0
def _get_filter(data, registry):
    '''
    Parse categories and attributes from the request.

    data -- the HTTP data.
    registry -- The registry used for this call.
    '''
    categories = []
    attributes = {}

    for cat in data.categories:
        categories.append(parser.get_category(cat, registry.get_categories()))

    for attr in data.attributes:
        key, value = parser.get_attributes(attr)
        attributes[key] = value

    return categories, attributes
Пример #4
0
def _get_filter(data, registry):
    """
    Parse categories and attributes from the request.

    data -- the HTTP data.
    registry -- The registry used for this call.
    """
    categories = []
    attributes = {}

    for cat in data.categories:
        categories.append(parser.get_category(cat, registry.get_categories()))

    for attr in data.attributes:
        key, value = parser.get_attributes(attr)
        attributes[key] = value

    return categories, attributes
Пример #5
0
def _to_entity(data, def_kind, registry):
    '''
    Extract an entity from the HTTP data object.

    kind -- The kind definition.
    registry -- The registry.
    '''

    # disable 'Too many local vars' pylint check (It's a bit ugly but will do)
    # disable 'Too many branches' pylint check (Needs to be improved)
    # pylint: disable=R0914,R0912

    kind = None
    mixins = []

    # first kind & mixins
    kind_found = False
    for category_string in data.categories:
        category = parser.get_category(category_string.strip(),
                                       registry.get_categories())
        if repr(category) == 'kind' and not kind_found:
            kind = category
            kind_found = True
        else:
            mixins.append(category)

    # the attributes
    attributes = {}
    for attr_string in data.attributes:
        key, value = parser.get_attributes(attr_string)
        attributes[key] = value

    # now create the entity
    if kind_found is False and def_kind is None:
        raise AttributeError('Could not find a valid kind.')
    elif def_kind is not None:
        kind = def_kind

    if Resource.kind in kind.related:
        # links
        entity = Resource(None, kind, mixins, [])
        for link_string in data.links:
            entity.links.append(
                parser.get_link(link_string.strip(), entity, registry))
    elif Link.kind in kind.related:
        try:
            source_attr = attributes['occi.core.source']
            target_attr = attributes['occi.core.target']

            if source_attr.find(registry.get_hostname()) == 0:
                source_attr = source_attr.replace(registry.get_hostname(), '')
            if target_attr.find(registry.get_hostname()) == 0:
                target_attr = target_attr.replace(registry.get_hostname(), '')

            source = registry.get_resource(source_attr)
            target = registry.get_resource(target_attr)
        except KeyError:
            raise AttributeError('Both occi.core.[source, target]' +
                                 ' attributes need to be resources.')
        entity = Link(None, kind, mixins, source, target)
    else:
        raise AttributeError('This kind seems not to be related to either' +
                             ' resource or link.')

    entity.attributes = attributes
    return entity
Пример #6
0
def _to_entity(data, def_kind, registry):
    """
    Extract an entity from the HTTP data object.

    kind -- The kind definition.
    registry -- The registry.
    """

    # disable 'Too many local vars' pylint check (It's a bit ugly but will do)
    # disable 'Too many branches' pylint check (Needs to be improved)
    # pylint: disable=R0914,R0912

    kind = None
    mixins = []

    # first kind & mixins
    kind_found = False
    for category_string in data.categories:
        category = parser.get_category(category_string.strip(), registry.get_categories())
        if repr(category) == "kind" and not kind_found:
            kind = category
            kind_found = True
        else:
            mixins.append(category)

    # the attributes
    attributes = {}
    for attr_string in data.attributes:
        key, value = parser.get_attributes(attr_string)
        attributes[key] = value

    # now create the entity
    if kind_found is False and def_kind is None:
        raise AttributeError("Could not find a valid kind.")
    elif def_kind is not None:
        kind = def_kind

    if Resource.kind in kind.related:
        # links
        entity = Resource(None, kind, mixins, [])
        for link_string in data.links:
            entity.links.append(parser.get_link(link_string.strip(), entity, registry))
    elif Link.kind in kind.related:
        try:
            source_attr = attributes["occi.core.source"]
            target_attr = attributes["occi.core.target"]

            if source_attr.find(registry.get_hostname()) == 0:
                source_attr = source_attr.replace(registry.get_hostname(), "")
            if target_attr.find(registry.get_hostname()) == 0:
                target_attr = target_attr.replace(registry.get_hostname(), "")

            source = registry.get_resource(source_attr)
            target = registry.get_resource(target_attr)
        except KeyError:
            raise AttributeError("Both occi.core.[source, target]" + " attributes need to be resources.")
        entity = Link(None, kind, mixins, source, target)
    else:
        raise AttributeError("This kind seems not to be related to either" + " resource or link.")

    entity.attributes = attributes
    return entity