コード例 #1
0
 def resolve_local_path(self, location, namespace):
     """Resolve the given namespace to one of the local standard schemas or
     fallback to the external file path."""
     if not location or location.startswith("http"):
         ns = Namespace.get_enum(namespace)
         return ns.location if ns else None
     else:
         return self.resolve_path(location)
コード例 #2
0
ファイル: parser.py プロジェクト: rmr1154/xsdata
    def resolve_local_path(self, location: Optional[str],
                           namespace: Optional[str]) -> Optional[str]:
        """Resolve the given namespace to one of the local standard schemas or
        fallback to the external file path."""

        common_ns = Namespace.get_enum(namespace)
        if common_ns:
            return common_ns.location

        return self.resolve_path(location)
コード例 #3
0
    def add(self, uri: Optional[str], prefix: Optional[str] = None):
        if not uri or uri in self.items and not prefix:
            return

        namespace = Namespace.get_enum(uri)
        prefix = namespace.prefix if namespace else prefix
        if not prefix:
            prefix = f"ns{self.auto_ns}"
            self.auto_ns += 1

        self.items[uri].add(prefix)
コード例 #4
0
    def resolve_local_path(self, location: Optional[str],
                           namespace: Optional[str]) -> Optional[str]:
        """Resolve the given namespace to one of the local standard schemas or
        fallback to the external file path."""

        common_ns = Namespace.get_enum(namespace)
        local_path = common_ns.location if common_ns else None

        if local_path and (not location or location.find("w3.org/") > 0):
            return local_path

        return self.resolve_path(location)
コード例 #5
0
ファイル: namespaces.py プロジェクト: neriusmika/xsdata
def generate_prefix(uri: str, ns_map: Dict) -> str:
    """Generate and add a prefix for the given uri in the prefix-URI namespace
    mapping."""
    namespace = Namespace.get_enum(uri)
    if namespace:
        prefix = namespace.prefix
    else:
        number = len(ns_map)
        prefix = f"ns{number}"

    ns_map[prefix] = uri

    return prefix
コード例 #6
0
ファイル: builder.py プロジェクト: rmr1154/xsdata
    def build_data_type(
        cls, target: Class, name: str, index: int = 0, forward: bool = False
    ) -> AttrType:
        """Create an attribute type for the target class."""
        prefix, suffix = text.split(name)
        native = False
        namespace = target.ns_map.get(prefix)

        if Namespace.get_enum(namespace) and DataType.get_enum(suffix):
            name = suffix
            native = True

        return AttrType(name=name, index=index, native=native, forward=forward,)
コード例 #7
0
    def build_data_type(
        cls, target: Class, name: str, index: int = 0, forward: bool = False
    ) -> AttrType:
        """Create an attribute type for the target class."""
        prefix, suffix = text.split(name)
        namespace = target.ns_map.get(prefix, target.qname.namespace)
        native = (
            Namespace.get_enum(namespace) is not None
            and DataType.get_enum(suffix) is not None
        )

        return AttrType(
            qname=QName(namespace, suffix), index=index, native=native, forward=forward,
        )
コード例 #8
0
    def build_data_type(self,
                        target: Class,
                        name: str,
                        index: int = 0,
                        forward_ref: bool = False) -> AttrType:
        prefix, suffix = text.split(name)
        native = False
        namespace = target.ns_map.get(prefix)

        if Namespace.get_enum(namespace) and DataType.get_enum(suffix):
            name = suffix
            native = True

        return AttrType(
            name=name,
            index=index,
            native=native,
            forward_ref=forward_ref,
        )
コード例 #9
0
ファイル: generics.py プロジェクト: rmr1154/xsdata
    def add(self, uri: Optional[str], prefix: Optional[str] = None):
        """
        Add the given uri and optional prefix to the data storage.

        If the prefix is missing and the uri exists in the storage skip the process.

        If the namespace is one of the common use the predefined prefix to
        follow the lxml convention.

        If the prefix is none assign the next auto increment prefix ns0,ns1,ns2 ...
        """
        if not uri or uri in self.data and prefix is None:
            return

        namespace = Namespace.get_enum(uri)
        prefix = namespace.prefix if namespace else prefix
        if prefix is None:
            prefix = f"ns{self.auto_ns}"

        self.auto_ns += 1
        self._ns_map = None
        self.data[uri].add(prefix)
コード例 #10
0
 def unregister(self):
     for prefix, uri in self.ns_map.items():
         if prefix and not prefix.startswith("ns") and not Namespace.get_enum(uri):
             register_namespace(prefix, "")
コード例 #11
0
ファイル: generics.py プロジェクト: rmr1154/xsdata
 def unregister(self):
     """Remove from lxml global registry the current namespaces map."""
     for prefix, uri in self.ns_map.items():
         if prefix and not prefix.startswith("ns") and not Namespace.get_enum(uri):
             register_namespace(prefix, "")