diff --git a/src/packageurl/__init__.py b/src/packageurl/__init__.py index 8199e39..ef82bc4 100644 --- a/src/packageurl/__init__.py +++ b/src/packageurl/__init__.py @@ -314,6 +314,8 @@ class PackageURL( https://github.com/package-url/purl-spec """ + SCHEME: str = "pkg" + type: str namespace: str | None name: str @@ -409,7 +411,7 @@ def to_string(self) -> str: encode=True, ) - purl = ["pkg:", type, "/"] + purl = [f"{self.SCHEME}:", type, "/"] if namespace: purl.extend((namespace, "/")) @@ -440,8 +442,10 @@ def from_string(cls, purl: str) -> Self: raise ValueError("A purl string argument is required.") scheme, sep, remainder = purl.partition(":") - if not sep or scheme != "pkg": - raise ValueError(f'purl is missing the required "pkg" scheme component: {purl!r}.') + if not sep or scheme != cls.SCHEME: + raise ValueError( + f'purl is missing the required "{cls.SCHEME}" scheme component: {purl!r}.' + ) # this strip '/, // and /// as possible in :// or :/// remainder = remainder.strip().lstrip("/")