예제 #1
0
 def resolve_imports(self):
     """Walk the import qualified names, check for naming collisions and add
     the necessary code generator import instance."""
     existing = {
         alnum(local_name(qname))
         for qname in self.class_map.keys()
     }
     for qname in self.import_classes():
         package = self.find_package(qname)
         name = alnum(local_name(qname))
         exists = name in existing
         existing.add(name)
         self.add_import(qname=qname, package=package, exists=exists)
예제 #2
0
파일: definitions.py 프로젝트: gramm/xsdata
 def attributes(cls, elements: Iterator[AnyElement]) -> Dict:
     """Return all attributes from all extended elements as a dictionary."""
     return {
         local_name(qname): value
         for element in elements if isinstance(element, AnyElement)
         for qname, value in element.attributes.items()
     }
예제 #3
0
파일: definitions.py 프로젝트: gramm/xsdata
    def map_binding_message_parts(cls, definitions: Definitions, message: str,
                                  extended: AnyElement,
                                  ns_map: Dict) -> Iterator[Attr]:
        """Find a Message instance and map its parts to attributes according to
        the the extensible element.."""
        parts = []
        if "part" in extended.attributes:
            parts.append(extended.attributes["part"])
        elif "parts" in extended.attributes:
            parts.extend(extended.attributes["parts"].split())

        if "message" in extended.attributes:
            message_name = local_name(extended.attributes["message"])
        else:
            message_name = text.suffix(message)

        definition_message = definitions.find_message(message_name)
        message_parts = definition_message.parts

        if parts:
            message_parts = [
                part for part in message_parts if part.name in parts
            ]

        yield from cls.build_parts_attributes(message_parts, ns_map)
예제 #4
0
    def add_import(self, qname: str, package: str, exists: bool = False):
        """Append an import package to the list of imports with any if
        necessary aliases if the import name exists in the local module."""
        alias = None
        name = local_name(qname)
        if exists:
            module = package.split(".")[-1]
            alias = f"{module}:{name}"
            self.aliases[qname] = alias

        self.imports.append(Import(name=name, source=package, alias=alias))
예제 #5
0
def read_root_name(path: Path) -> str:
    try:
        recovering_parser = etree.XMLParser(recover=True,
                                            resolve_entities=False,
                                            no_network=True)
        tree = etree.parse(str(path), parser=recovering_parser)  # nosec
        name = text.pascal_case(local_name(tree.getroot().tag))

        if text.is_reserved(name):
            return text.pascal_case(f"{name}_Type")

        return name
    except Exception:
        return ""
예제 #6
0
파일: definitions.py 프로젝트: gramm/xsdata
    def build_envelope_class(
        cls,
        definitions: Definitions,
        binding_message: BindingMessage,
        port_type_message: PortTypeMessage,
        name: str,
        style: str,
        namespace: Optional[str],
    ) -> Class:
        """Step 6.1: Build Envelope class for the given binding message with
        attributes from the port type message."""

        target = Class(
            qname=build_qname(definitions.target_namespace, name),
            meta_name="Envelope",
            tag=Tag.BINDING_MESSAGE,
            module=definitions.module,
            ns_map=binding_message.ns_map,
            namespace=namespace,
        )
        message = port_type_message.message

        for ext in binding_message.extended_elements:
            assert ext.qname is not None
            class_name = local_name(ext.qname).title()
            inner = cls.build_inner_class(target, class_name)

            if style == "rpc" and class_name == "Body":
                namespace = ext.attributes.get("namespace")
                attrs = cls.map_port_type_message(port_type_message, namespace)
            else:
                attrs = cls.map_binding_message_parts(definitions, message,
                                                      ext, inner.ns_map)

            inner.attrs.extend(attrs)

        return target
예제 #7
0
파일: models.py 프로젝트: gramm/xsdata
 def name(self) -> str:
     """Shortcut for qname local name."""
     return local_name(self.qname)