Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/packageurl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
if TYPE_CHECKING:
from collections.abc import Callable
from collections.abc import Iterable
from typing import ClassVar

from typing_extensions import Literal
from typing_extensions import Self
Expand Down Expand Up @@ -314,6 +315,8 @@ class PackageURL(
https://github.com/package-url/purl-spec
"""

SCHEME: ClassVar[str] = "pkg"

type: str
namespace: str | None
name: str
Expand Down Expand Up @@ -409,7 +412,7 @@ def to_string(self) -> str:
encode=True,
)

purl = ["pkg:", type, "/"]
purl = [self.SCHEME, ":", type, "/"]

if namespace:
purl.extend((namespace, "/"))
Expand Down Expand Up @@ -440,8 +443,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("/")
Expand Down
Loading