Beispiel #1
0
def _parse_action(element: etree._Element) -> Action:
    """Parse a NoDL action from an xml element."""
    name = element.get('name')
    action_type = element.get('type')

    server = get_bool_attribute(element, 'server')
    client = get_bool_attribute(element, 'client')
    if not (server or client):
        raise errors.AmbiguousActionInterfaceError(element)

    policy = _parse_qos(element.find('qos'))

    return Action(name=name,
                  action_type=action_type,
                  server=server,
                  client=client,
                  qos=policy)
Beispiel #2
0
def _parse_topic(element: etree._Element) -> Topic:
    """Parse a NoDL topic from an xml element."""
    name = element.get('name')
    message_type = element.get('type')

    publisher = get_bool_attribute(element, 'publisher')
    subscription = get_bool_attribute(element, 'subscription')
    if not (publisher or subscription):
        raise errors.AmbiguousTopicInterfaceError(element)

    policy = _parse_qos(element.find('qos'))

    return Topic(
        name=name,
        message_type=message_type,
        publisher=publisher,
        subscription=subscription,
        qos=policy,
    )
Beispiel #3
0
def _parse_service(element: etree._Element) -> Service:
    """Parse a NoDL service from an xml element."""
    name = element.get('name')
    service_type = element.get('type')

    server = get_bool_attribute(element, 'server')
    client = get_bool_attribute(element, 'client')
    if not (server or client):
        raise errors.AmbiguousServiceInterfaceError(element)

    policy = _parse_qos(element.find('qos'))

    return Service(
        name=name,
        service_type=service_type,
        server=server,
        client=client,
        qos=policy,
    )
Beispiel #4
0
def _parse_qos(element: etree._Element) -> qos.QoSProfile:
    """Populate a QoS Profile from a qos NoDL element."""
    kwargs = {}

    if element.get('history'):
        try:
            kwargs['history'] = qos.HistoryPolicy.get_from_short_key(
                element.get('history'))
        except KeyError:
            raise errors.InvalidQOSAttributeValueError('history', element)

    if element.get('reliability'):
        try:
            kwargs['reliability'] = qos.ReliabilityPolicy.get_from_short_key(
                element.get('reliability'))
        except KeyError:
            raise errors.InvalidQOSAttributeValueError('reliability', element)

    if element.get('durability'):
        try:
            kwargs['durability'] = qos.DurabilityPolicy.get_from_short_key(
                element.get('durability', element))
        except KeyError:
            raise errors.InvalidQOSAttributeValueError('durability', element)

    if element.get('depth'):
        kwargs['depth'] = int(element.get('depth'))

    if element.get('lifespan'):
        kwargs['lifespan'] = Duration(
            nanoseconds=float(element.get('lifespan')))

    if element.get('deadline'):
        kwargs['deadline'] = Duration(
            nanoseconds=float(element.get('lifespan')))

    if element.get('liveliness'):
        try:
            kwargs['liveliness'] = qos.LivelinessPolicy.get_from_short_key(
                element.get('liveliness'))
        except KeyError:
            raise errors.InvalidQOSAttributeValueError('liveliness', element)

    if element.get('liveliness_lease_duration'):
        kwargs['liveliness_lease_duration'] = Duration(
            nanoseconds=float(element.get('liveliness_lease_duration')))
    if element.get('avoid_ros_namespace_conventions'):
        kwargs['avoid_ros_namespace_conventions'] = get_bool_attribute(
            element, 'avoid_ros_namespace_conventions')
    try:
        return qos.QoSProfile(**kwargs)
    except qos.InvalidQoSProfileException as e:
        raise errors.InvalidQosProfileError(e, element) from e
Beispiel #5
0
def test_get_bool_attribute_except(mocker):
    foo = etree.Element('foo', {'bar': 'true'})
    assert get_bool_attribute(foo, 'bar')
    foo.set('bar', 'false')
    assert not get_bool_attribute(foo, 'bar')