Esempio n. 1
0
    def __init__(self):
        """Initialise the module.

        Module initialisation will ensures the class is correctly constructed.
        If the xml_schema is set, initialisation will set the schema based on the xml_schema.

        """
        if len(set([self.schema, self.xml_schema, self.xml_schema_path])) > 2:
            raise Exception(
                "Class '{}' in {} has multiple schema sources set.".format(
                    self.__class__.__name__,
                    os.path.abspath(inspect.getfile(self.__class__))))

        if self.schema is NOTHING:
            if self.xml_schema_path is not NOTHING:
                xml_schema_document = xml_parse_file(self.xml_schema_path)
            elif self.xml_schema is not NOTHING:
                filename = sys.modules[self.__class__.__module__].__file__
                xml_schema_document = xml_parse_string(
                    self.xml_schema, '{}!xml_schema'.format(filename))
            else:
                raise Exception(
                    "Class '{}' in {} has none of the possible schema sources (schema, xml_schema, \
xml_schema_path) set as a class member.".format(
                        self.__class__.__name__,
                        os.path.abspath(inspect.getfile(self.__class__))))
            self.schema = xml2schema(xml_schema_document)
Esempio n. 2
0
    def _configure_from_xml(self, dom):
        """Configure a module based on XML input. This may be XML that was
        extracted from a marked-up comment, or directly in an XML file.

        """
        cg_el = maybe_single_named_child(dom, 'code_gen')
        if cg_el:
            code_gen = single_text_child(cg_el)
            if code_gen not in ['template']:
                raise SystemParseError(xml_error_str(cg_el, "not a supported code_gen type: %s" % code_gen))
            self.code_gen = code_gen

        # Get all headers
        hdr_els = maybe_get_element_list(dom, "headers", "header")
        if hdr_els is None:
            hdr_els = []

        def fix_path(hdr):
            if os.path.isabs(hdr):
                return hdr
            else:
                return os.path.join(os.path.dirname(self.filename), hdr)

        for hdr_el in hdr_els:
            code_gen = hdr_el.getAttributeNode('code_gen')
            code_gen = code_gen.value if code_gen is not None else None
            if code_gen not in [None, 'template']:
                raise SystemParseError(xml_error_str(hdr_el, "not a supported code_gen type: %s" % code_gen))
            self.headers.append(Header(fix_path(get_attribute(hdr_el, "path")), code_gen, hdr_el))

        schema = maybe_single_named_child(dom, 'schema')
        self.schema = xml2schema(schema) if schema else None
Esempio n. 3
0
    def _configure_from_xml(self, dom):
        """Configure a module based on XML input. This may be XML that was
        extracted from a marked-up comment, or directly in an XML file.

        """
        cg_el = maybe_single_named_child(dom, 'code_gen')
        if cg_el:
            code_gen = single_text_child(cg_el)
            if code_gen not in ['template']:
                raise SystemParseError(xml_error_str(cg_el, "not a supported code_gen type: %s" % code_gen))
            self.code_gen = code_gen

        # Get all headers
        hdr_els = maybe_get_element_list(dom, "headers", "header")
        if hdr_els is None:
            hdr_els = []

        def fix_path(hdr):
            if os.path.isabs(hdr):
                return hdr
            return os.path.join(os.path.dirname(self.filename), hdr)

        for hdr_el in hdr_els:
            code_gen = hdr_el.getAttributeNode('code_gen')
            code_gen = code_gen.value if code_gen is not None else None
            if code_gen not in [None, 'template']:
                raise SystemParseError(xml_error_str(hdr_el, "not a supported code_gen type: %s" % code_gen))
            self.headers.append(Header(fix_path(get_attribute(hdr_el, "path")), code_gen, hdr_el))

        schema = maybe_single_named_child(dom, 'schema')
        self.schema = xml2schema(schema) if schema else None
Esempio n. 4
0
    def __init__(self):
        """Initialise the module.

        Module initialisation will ensures the class is correctly constructed.
        If the xml_schema is set, initialisation will set the schema based on the xml_schema.

        """
        if len(set([self.schema, self.xml_schema, self.xml_schema_path])) > 2:
            raise Exception("Class '{}' in {} has multiple schema sources set.".format(self.__class__.__name__,
                            os.path.abspath(inspect.getfile(self.__class__))))

        if self.schema is NOTHING:
            if self.xml_schema_path is not NOTHING:
                xml_schema_document = xml_parse_file(self.xml_schema_path)
            elif self.xml_schema is not NOTHING:
                filename = sys.modules[self.__class__.__module__].__file__
                xml_schema_document = xml_parse_string(self.xml_schema, '{}!xml_schema'.format(filename))
            else:
                raise Exception("Class '{}' in {} has none of the possible schema sources (schema, xml_schema, \
xml_schema_path) set as a class member.".format(self.__class__.__name__,
                                                os.path.abspath(inspect.getfile(self.__class__))))
            self.schema = xml2schema(xml_schema_document)