Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define pkg as a PackageURL class attribute #184

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 7 additions & 3 deletions src/packageurl/__init__.py
Original file line number Diff line number Diff line change
@@ -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("/")
Loading
Oops, something went wrong.