Пример #1
0
    def parse(self, xml, lax_naming):
        """Parse the given interface xml element."""
        #print("Parsing Interface '{0}'".format(xml.get('name')))
        name = xml.get("name")
        self.set_name(name, xml)

        # Make a list of all the objects at this level.
        xml_root_objects = list(xml)

        child_count = 0

        for o in xml_root_objects:
            if o.tag == "signal":
                child_count += 1

                s = signaldef.SignalDef()
                s.parse(o, lax_naming)
                self.add_signal(o, s)
            elif o.tag == "method":
                child_count += 1

                new_method = methoddef.MethodDef()
                new_method.parse(o, lax_naming)
                self.add_method(o, new_method)
            elif o.tag == "property":
                child_count += 1

                new_property = propertydef.PropertyDef()
                new_property.parse(o)
                self.add_property(o, new_property)
            elif o.tag == "annotation":
                # Don't count this as a child for purposes of defining the
                # interface.
                common.get_annotations(xml, self)
            else:
                # Don't count this as a valid child.
                warn_format = "\nWarning! Ignoring interface xml object '{0}'."
                mess = warn_format.format(o.tag)
                mess = validate.get_xml_error(xml, mess)
                print(mess)

        if child_count <= 0:
            mess = "Incompletely specified interface '{0}'.".format(name)
            mess = validate.get_xml_error(xml, mess)
            raise validate.ValidateException(mess)

        self.__add_structs_dictionaries_arrays()

        return
Пример #2
0
def get_annotations(xml, aj_object):
    """Get the annotation value for the AllJoyn object from this xml."""
    annotations = xml.iterfind("annotation")

    for a in annotations:
        name = a.get("name")

        if name == "org.alljoyn.Bus.Item.IsSecure":
            value = __get_true_false_value(xml, a, name)
            aj_object.is_secure = value
        elif name == "org.freedesktop.DBus.Method.NoReply":
            value = __get_true_false_value(xml, a, name)
            aj_object.no_reply = value
        elif name == "org.alljoyn.Bus.Arg.VariantTypes":
            value = a.get("value")
            if value is None:
                __report_missing_value(xml, name)
            validate.data_signature(value)
            aj_object.variant_type = value
        elif name == "org.freedesktop.DBus.Property.EmitsChangedSignal":
            value = a.get("value")
            if value is None:
                __report_missing_value(xml, name)
            aj_object.set_emits_changed_signal(value)
        else:
            f = "\nIgnoring interface annotation '{0}'."
            mess = f.format(name)
            mess = validate.get_xml_error(xml, mess)
            print(mess)

    return
Пример #3
0
def __get_true_false_value(xml, annotation, name):
    """Get a true or false value from the annotation xml.

    xml is the parent xml object to annotation xml.
    annotation is the xml object which should have a attribute of value
    containing the 'true' or 'false' value.
    name is the of the parent AllJoyn object."""
    value = annotation.get("value")

    if value is not None:
        if value == "true":
            value = True
        elif value == "false":
            value = False
        else:
            f = "Unexpected annotation value '{0}' for {1}."
            mess = f.format(value, name)
            f = "{0}\nExpected values are 'true' and 'false'."
            mess = f.format(mess)
            mess = validate.get_xml_error(xml, mess)
            raise validate.ValidateException(mess)
    else:
        __report_missing_value(xml, name)

    return value
Пример #4
0
def get_annotations(xml, aj_object):
    """Get the annotation value for the AllJoyn object from this xml."""
    annotations = xml.iterfind("annotation")

    for a in annotations:
        name = a.get("name")

        if name == "org.alljoyn.Bus.Item.IsSecure":
            value = __get_true_false_value(xml, a, name)
            aj_object.is_secure = value
        elif name == "org.freedesktop.DBus.Method.NoReply":
            value = __get_true_false_value(xml, a, name)
            aj_object.no_reply = value
        elif name == "org.alljoyn.Bus.Arg.VariantTypes":
            value = a.get("value")
            if value is None:
                __report_missing_value(xml, name)
            validate.data_signature(value)
            aj_object.variant_type = value
        else:
            f = "\nIgnoring interface annotation '{0}'."
            mess = f.format(name)
            mess = validate.get_xml_error(xml, mess)
            print(mess)

    return
Пример #5
0
def __get_true_false_value(xml, annotation, name):
    """Get a true or false value from the annotation xml.

    xml is the parent xml object to annotation xml.
    annotation is the xml object which should have a attribute of value
    containing the 'true' or 'false' value.
    name is the of the parent AllJoyn object."""
    value = annotation.get("value")

    if value is not None:
        if value == "true":
            value = True
        elif value == "false":
            value = False
        else:
            f = "Unexpected annotation value '{0}' for {1}."
            mess = f.format(value, name)
            f = "{0}\nExpected values are 'true' and 'false'."
            mess = f.format(mess)
            mess = validate.get_xml_error(xml, mess)
            raise validate.ValidateException(mess)
    else:
        __report_missing_value(xml, name)

    return value
Пример #6
0
    def add_interface(self, interface, xml):
        """Add this interface to the list of interfaces. Returns the interface.

        If the interface already exists then the existing interface is returned
        and the new interface is not added. If an interface with the same name
        but different signature exist then an exception is raised."""

        # First check to see if the interface already exists.
        i = self.get_interface(interface.interface_full_name)

        if i is None:
            self.interfaces[interface.interface_full_name] = interface
            i = interface

            # Because one or more of the following properties may have been set
            # to False and the addition of this interface may change that we now
            # set them to None so the previously cached value can be reevaluated
            # as needed in has_read_properties(), etc.
            self.__has_read_properties = None
            self.__has_write_properties = None
            self.__number_of_signals = None
            self.__has_dictionaries = None
        elif i != interface:
            error1_format = "Interface '{0}' has multiple definitions"
            error1 = error1_format.format(interface.interface_full_name)
            error2 = "with different signatures."
            error = " ".join([error1, error2])
            error = validate.get_xml_error(xml, error)
            raise validate.ValidateException(error)

        return i
Пример #7
0
    def add_interface(self, interface, xml):
        """Add this interface to the list of interfaces. Returns the interface.

        If the interface already exists then the existing interface is returned
        and the new interface is not added. If an interface with the same name
        but different signature exist then an exception is raised."""

        # First check to see if the interface already exists.
        i = self.get_interface(interface.interface_full_name)

        if i is None:
            self.interfaces[interface.interface_full_name] = interface
            i = interface

            # Because one or more of the following properties may have been set
            # to False and the addition of this interface may change that we now
            # set them to None so the previously cached value can be reevaluated
            # as needed in has_read_properties(), etc.
            self.__has_read_properties = None
            self.__has_write_properties = None
            self.__number_of_signals = None
            self.__has_dictionaries = None
        elif i != interface:
            error1_format = "Interface '{0}' has multiple definitions"
            error1 = error1_format.format(interface.interface_full_name)
            error2 = "with different signatures."
            error = " ".join([error1, error2])
            error = validate.get_xml_error(xml, error)
            raise validate.ValidateException(error)

        return i
Пример #8
0
    def __validate_name(self, xml):
        """Check for a valid name and throw an exception if not valid."""

        if self.name is None or len(self.name) <= 0:
            error = "Attribute 'name' required for <node>."
            error = validate.get_xml_error(xml, error)
            raise validate.ValidateException(error)

        # If we have a node with a full path make sure it has no parent.
        if self.name[0] == '/' and self.parent is not None:
            error = "Nested nodes cannot specify object paths."
            error = validate.get_xml_error(xml, error)
            raise validate.ValidateException(error)

        full_name = self.get_full_name()
        # print("obj:: {0}\nfull: {1}".format(self.name, full_name))
        validate.bus_object_path(full_name, xml)
        return
Пример #9
0
    def __add_arg(self, xml, new_arg):
        for a in self.args:
            if a.name == new_arg.name:
                mess = "Duplicate argument name '{0}'.".format(a.name)
                mess = validate.get_xml_error(xml, mess)
                raise validate.ValidateException(mess)

        self.args.append(new_arg)
        return
Пример #10
0
    def __add_arg(self, xml, new_arg):
        for a in self.args:
            if a.name == new_arg.name:
                mess = "Duplicate argument name '{0}'.".format(a.name)
                mess = validate.get_xml_error(xml, mess)
                raise validate.ValidateException(mess)

        self.args.append(new_arg)
        return
Пример #11
0
    def __validate_name(self, xml):
        """Check for a valid name and throw an exception if not valid."""

        if self.name is None or len(self.name) <= 0:
            error = "Attribute 'name' required for <node>."
            error = validate.get_xml_error(xml, error)
            raise validate.ValidateException(error)

        # If we have a node with a full path make sure it has no parent.
        if self.name[0] == '/' and self.parent is not None:
            error = "Nested nodes cannot specify object paths."
            error = validate.get_xml_error(xml, error)
            raise validate.ValidateException(error)

        full_name = self.get_full_name()
        # print("obj:: {0}\nfull: {1}".format(self.name, full_name))
        validate.bus_object_path(full_name, xml)
        return
Пример #12
0
    def add_method(self, xml, method):
        """Add a new method to this interface."""
        for m in self.methods:
            if m.name == method.name:
                mess = "Duplicate method name '{0}' not allowed.".format(m.name)
                mess = validate.get_xml_error(xml, mess)
                raise validate.ValidateException(mess)

        self.methods.append(method)
        return
Пример #13
0
    def add_signal(self, xml, signal):
        """Add a new signal to this interface."""
        for s in self.signals:
            if s.name == signal.name:
                mess = "Duplicate signal name '{0}' not allowed.".format(s.name)
                mess = validate.get_xml_error(xml, mess)
                raise validate.ValidateException(mess)

        self.signals.append(signal)
        return
Пример #14
0
    def add_property(self, xml, prop):
        """Add a new property to this interface."""
        for p in self.properties:
            if p.name == prop.name:
                mess = "Duplicate property name '{0}' not allowed.".format(p.name)
                mess = validate.get_xml_error(xml, mess)
                raise validate.ValidateException(mess)

        self.properties.append(prop)
        return
Пример #15
0
    def add_property(self, xml, prop):
        """Add a new property to this interface."""
        for p in self.properties:
            if p.name == prop.name:
                mess = "Duplicate property name '{0}' not allowed.".format(
                    p.name)
                mess = validate.get_xml_error(xml, mess)
                raise validate.ValidateException(mess)

        self.properties.append(prop)
        return
Пример #16
0
    def add_signal(self, xml, signal):
        """Add a new signal to this interface."""
        for s in self.signals:
            if s.name == signal.name:
                mess = "Duplicate signal name '{0}' not allowed.".format(
                    s.name)
                mess = validate.get_xml_error(xml, mess)
                raise validate.ValidateException(mess)

        self.signals.append(signal)
        return
Пример #17
0
    def add_method(self, xml, method):
        """Add a new method to this interface."""
        for m in self.methods:
            if m.name == method.name:
                mess = "Duplicate method name '{0}' not allowed.".format(
                    m.name)
                mess = validate.get_xml_error(xml, mess)
                raise validate.ValidateException(mess)

        self.methods.append(method)
        return
Пример #18
0
    def parse(self, xml, lax_naming):
        """Parse the given AllJoyn signal xml element."""
        assert(xml is not None)
        assert(xml.tag == "signal")

        self.name = xml.get("name")
        validate.member_name(self.name, xml)

        # Make a list of all the objects at this level.
        xml_root_objects = list(xml)

        arg_num = 0
        common.get_annotations(xml, self)

        for o in xml_root_objects:
            if o.tag == "arg":
                a = argdef.ArgDef()

                a.parse(o, lax_naming, "Signal", self, arg_num)
                arg_num += 1

                # The default direction is "out".
                if a.direction is None:
                    a.direction = "out"
                elif a.direction != "out":
                    error = "Signal arguments must have a direction of 'out'."
                    error = validate.get_xml_error(xml, error)
                    raise validate.ValidateException(error)

                self.__add_arg(o, a)
            elif o.tag != "annotation":
                # Just ignore annotations. We got them earlier.
                warn_format = "\nWarning! Ignoring xml object '{0}'."
                print(warn_format.format(o.tag))

        return
Пример #19
0
    def parse(self, xml, lax_naming):
        """Parse the given AllJoyn signal xml element."""
        assert(xml is not None)
        assert(xml.tag == "signal")

        self.name = xml.get("name")
        validate.member_name(self.name, xml)

        # Make a list of all the objects at this level.
        xml_root_objects = list(xml)

        arg_num = 0
        common.get_annotations(xml, self)

        for o in xml_root_objects:
            if o.tag == "arg":
                a = argdef.ArgDef()

                a.parse(o, lax_naming, "Signal", self, arg_num)
                arg_num += 1

                # The default direction is "out".
                if a.direction is None:
                    a.direction = "out"
                elif a.direction != "out":
                    error = "Signal arguments must have a direction of 'out'."
                    error = validate.get_xml_error(xml, error)
                    raise validate.ValidateException(error)

                self.__add_arg(o, a)
            elif o.tag != "annotation":
                # Just ignore annotations. We got them earlier.
                warn_format = "\nWarning! Ignoring xml object '{0}'."
                print(warn_format.format(o.tag))

        return
Пример #20
0
    def parse(self, xml, lax_naming):
        """Parse the given signal xml element."""
        assert(xml is not None)
        assert(xml.tag == "method")

        #print("Parsing method '{0}'".format(xml.get('name')))
        self.name = xml.get("name")
        validate.member_name(self.name, xml)

        # Make a list of all the objects at this level.
        xml_root_objects = list(xml)

        arg_num = 0

        common.get_annotations(xml, self)

        for o in xml_root_objects:
            if o.tag == "arg":
                a = argdef.ArgDef()

                a.parse(o, lax_naming, "Method", self, arg_num)
                arg_num += 1

                # The default direction is "in".
                if a.direction is None:
                    a.direction = "in"

                self.__add_arg(xml, a)
            elif o.tag != "annotation":
                # Just ignore annotations. We got them earlier.
                warn_format = "\nWarning! Ignoring method xml object '{0}'."
                mess = warn_format.format(o.tag)
                mess = validate.get_xml_error(xml, mess)
                print(mess)

        return
Пример #21
0
    def parse(self, xml, lax_naming):
        """Parse the given signal xml element."""
        assert (xml is not None)
        assert (xml.tag == "method")

        #print("Parsing method '{0}'".format(xml.get('name')))
        self.name = xml.get("name")
        validate.member_name(self.name, xml)

        # Make a list of all the objects at this level.
        xml_root_objects = list(xml)

        arg_num = 0

        common.get_annotations(xml, self)

        for o in xml_root_objects:
            if o.tag == "arg":
                a = argdef.ArgDef()

                a.parse(o, lax_naming, "Method", self, arg_num)
                arg_num += 1

                # The default direction is "in".
                if a.direction is None:
                    a.direction = "in"

                self.__add_arg(xml, a)
            elif o.tag != "annotation":
                # Just ignore annotations. We got them earlier.
                warn_format = "\nWarning! Ignoring method xml object '{0}'."
                mess = warn_format.format(o.tag)
                mess = validate.get_xml_error(xml, mess)
                print(mess)

        return
Пример #22
0
def __report_missing_value(xml, name):
    f = "Annotation '{0}' is required to have an attribute of 'value'."
    mess = f.format(name)
    mess = validate.get_xml_error(xml, mess)
    raise validate.ValidateException(mess)
Пример #23
0
    def parse(self, xml, service, lax_naming):
        """Parses the xml to acquire the interface."""

        # Since we are parsing a new object the service cache is now invalid.
        service.delete_object_cache()

        self.__validate_name(xml)
        # print("Parsing the AllJoynObject '{0}'.".format(self.name))

        # Make a list of all the objects at this level.
        xml_root_objects = list(xml)

        child_count = 0

        for o in xml_root_objects:
            if o.tag == "interface":
                child_count += 1

                i = interface.Interface()
                i.parse(o, lax_naming)

                # Ignore the built in interfaces.
                built_in = {"org.freedesktop.DBus.Peer",
                            "org.freedesktop.DBus.Introspectable",
                            "org.freedesktop.DBus.Properties",
                            "org.freedesktop.DBus.ObjectManager"}

                if i.interface_full_name in built_in:
                    print("Ignoring built in interface '{0}'".format(i.interface_full_name))
                    continue

                # If this is new interface it is added. If it is not a new
                # interface the existing one is returned.
                i = service.add_interface(i, o)
                self.interfaces.append(i)
                i.add_parent(self)
            elif o.tag == "node":
                child_count += 1

                new_node_name = o.get("name")

                if new_node_name in self.alljoyn_objects:
                    error_format = "Duplicate node name '{0}'."
                    error = error_format.format(new_node_name)
                    error = validate.get_xml_error(o, error)
                    raise validate.ValidateException(error)

                new_node = AllJoynObject(new_node_name, self)
                new_node.parse(o, service, lax_naming)
                self.alljoyn_objects[new_node_name] = new_node
            else:
                # Don't count this as a valid child.
                warn_format = "\nWarning! Ignoring xml object '{0}'."
                print(warn_format.format(o.tag))

        if child_count <= 0:
            mess = "Child interfaces and/or nodes expected."
            mess = validate.get_xml_error(xml, mess)
            raise validate.ValidateException(mess)

        return
Пример #24
0
    def parse(self, xml, service, lax_naming):
        """Parses the xml to acquire the interface."""

        # Since we are parsing a new object the service cache is now invalid.
        service.delete_object_cache()

        self.__validate_name(xml)
        # print("Parsing the AllJoynObject '{0}'.".format(self.name))

        # Make a list of all the objects at this level.
        xml_root_objects = list(xml)

        child_count = 0

        for o in xml_root_objects:
            if o.tag == "interface":
                child_count += 1

                i = interface.Interface()
                i.parse(o, lax_naming)

                # Ignore the built in interfaces.
                built_in = {
                    "org.freedesktop.DBus.Peer",
                    "org.freedesktop.DBus.Introspectable",
                    "org.freedesktop.DBus.Properties",
                    "org.freedesktop.DBus.ObjectManager"
                }

                if i.interface_full_name in built_in:
                    print("Ignoring built in interface '{0}'".format(
                        i.interface_full_name))
                    continue

                # If this is new interface it is added. If it is not a new
                # interface the existing one is returned.
                i = service.add_interface(i, o)
                self.interfaces.append(i)
                i.add_parent(self)
            elif o.tag == "node":
                child_count += 1

                new_node_name = o.get("name")

                if new_node_name in self.alljoyn_objects:
                    error_format = "Duplicate node name '{0}'."
                    error = error_format.format(new_node_name)
                    error = validate.get_xml_error(o, error)
                    raise validate.ValidateException(error)

                new_node = AllJoynObject(new_node_name, self)
                new_node.parse(o, service, lax_naming)
                self.alljoyn_objects[new_node_name] = new_node
            else:
                # Don't count this as a valid child.
                warn_format = "\nWarning! Ignoring xml object '{0}'."
                print(warn_format.format(o.tag))

        if child_count <= 0:
            mess = "Child interfaces and/or nodes expected."
            mess = validate.get_xml_error(xml, mess)
            raise validate.ValidateException(mess)

        return
Пример #25
0
def __report_missing_value(xml, name):
    f = "Annotation '{0}' is required to have an attribute of 'value'."
    mess = f.format(name)
    mess = validate.get_xml_error(xml, mess)
    raise validate.ValidateException(mess)
Пример #26
0
    def parse(self, xml, lax_naming):
        """Parse the given interface xml element."""
        #print("Parsing Interface '{0}'".format(xml.get('name')))
        name = xml.get("name")
        self.set_name(name, xml)

        # Make a list of all the objects at this level.
        xml_root_objects = list(xml)

        child_count = 0

        for o in xml_root_objects:
            if o.tag == "signal":
                child_count += 1

                s = signaldef.SignalDef()
                s.parse(o, lax_naming)
                self.add_signal(o, s)
            elif o.tag == "method":
                child_count += 1

                new_method = methoddef.MethodDef()
                new_method.parse(o, lax_naming)
                self.add_method(o, new_method)
            elif o.tag == "property":
                child_count += 1

                new_property = propertydef.PropertyDef()
                new_property.parse(o)
                self.add_property(o, new_property)
            elif o.tag == "annotation":
                # Don't count this as a child for purposes of defining the
                # interface.
                common.get_annotations(xml, self)
            elif o.tag == "struct":
                # Don't count this as a valid child.
                new_struct = structdef.StructDef()
                new_struct.parse(o, lax_naming)
                self.add_declared_struct(o, new_struct)
            elif o.tag == "dict":
                # Don't count this as a valid child.
                new_dict = dictdef.DictDef()
                new_dict.parse(o, lax_naming)
                self.add_declared_dict(o, new_dict)
            else:
                # Don't count this as a valid child.
                warn_format = "\nWarning! Ignoring interface xml object '{0}'."
                mess = warn_format.format(o.tag)
                mess = validate.get_xml_error(xml, mess)
                print(mess)

        if child_count <= 0:
            mess = "Incompletely specified interface '{0}'.".format(name)
            mess = validate.get_xml_error(xml, mess)
            raise validate.ValidateException(mess)

        self.__add_structs_dictionaries_arrays()
        self.__declare_undeclared_types()
        self.__add_interface_to_all_members()

        validate.interface_completeness(self)

        return