Exemple #1
0
    def apply_aliases(self, obj: Class):
        """Walk the attributes tree and set the type aliases."""
        for attr in obj.attrs:
            for attr_type in attr.types:
                attr_type.alias = self.aliases.get(attr_type.qname)

        collections.apply(obj.inner, self.apply_aliases)
Exemple #2
0
    def process(self, uris: List[str], package: str):
        """
        Run main processes.

        :param uris: list of uris to process
        :param package: package name eg foo.bar.xxx
        """

        collections.apply(uris, self.process_schema)

        classes = [
            cls for classes in self.class_map.values() for cls in classes
        ]
        class_num, inner_num = self.count_classes(classes)
        if class_num:
            logger.info("Analyzer input: %d main and %d inner classes",
                        class_num, inner_num)
            self.assign_packages(package)

            classes = self.analyze_classes(classes)
            class_num, inner_num = self.count_classes(classes)
            logger.info("Analyzer output: %d main and %d inner classes",
                        class_num, inner_num)

            writer.designate(classes, self.output)
            if self.print:
                writer.print(classes, self.output)
            else:
                writer.write(classes, self.output)
        else:
            logger.warning("Analyzer returned zero classes!")
Exemple #3
0
    def process_definitions(self, uri: str):
        """Process a single wsdl resource."""
        definitions = self.parse_definitions(uri, namespace=None)

        collections.apply(definitions.schemas, self.convert_schema)

        self.convert_definitions(definitions)
        self.process_classes()
Exemple #4
0
    def process(cls, container: ClassContainer, config: GeneratorConfig):
        """Iterate through all classes and run the sanitizer procedure."""

        sanitizer = cls(container, config)

        collections.apply(container.iterate(), sanitizer.process_class)

        sanitizer.resolve_conflicts()
Exemple #5
0
    def process_schemas(self, uris: List[str]):
        """
        Run main processes.

        :param uris: list of uris to process
        """

        collections.apply(uris, self.process_schema)
        self.process_classes()
Exemple #6
0
    def process_definitions(self, uris: List[str]):
        """Process a list of wsdl resources."""
        definitions = None
        for uri in uris:
            services = self.parse_definitions(uri, namespace=None)
            if definitions is None:
                definitions = services
            elif services:
                definitions.merge(services)

        if definitions is not None:
            collections.apply(definitions.schemas, self.convert_schema)
            self.convert_definitions(definitions)
Exemple #7
0
    def apply_aliases(self, target: Class):
        """Iterate over the target class dependencies and set the type
        aliases."""
        for attr in target.attrs:
            for attr_type in attr.types:
                attr_type.alias = self.aliases.get(attr_type.qname)

            for choice in attr.choices:
                for choice_type in choice.types:
                    choice_type.alias = self.aliases.get(choice_type.qname)

        for ext in target.extensions:
            ext.type.alias = self.aliases.get(ext.type.qname)

        collections.apply(target.inner, self.apply_aliases)
Exemple #8
0
    def process_class(self, target: Class):
        """
        Sanitize the attributes of the given class. After applying all the
        flattening handlers the attributes need to be further sanitized to
        squash common issues like duplicate attribute names.

        Steps:
            1. Sanitize inner classes
            2. Sanitize attributes default value
            3. Sanitize attributes name
            4. Sanitize attributes sequential flag
            5. Sanitize duplicate attribute names
        """
        collections.apply(target.inner, self.process_class)

        for attr in target.attrs:
            self.process_attribute_default(target, attr)
            self.process_attribute_restrictions(attr)
            self.process_attribute_name(attr)
            self.process_attribute_sequence(target, attr)

        self.process_duplicate_attribute_names(target.attrs)
Exemple #9
0
    def process(cls, container: ClassContainer):
        """Iterate through all classes and run the sanitizer procedure."""

        sanitizer = cls(container)

        collections.apply(container.iterate(), sanitizer.process_class)
Exemple #10
0
 def extend(self, items: List[Class]):
     """Add a list of classes the container."""
     collections.apply(items, self.add)
Exemple #11
0
    def process(self):
        """Iterate through all classes and run the sanitizing procedure."""

        collections.apply(self.container.iterate(), self.process_class)