|
37 | 37 | if TYPE_CHECKING: |
38 | 38 | from collections.abc import Callable |
39 | 39 | from collections.abc import Iterable |
| 40 | + from typing import ClassVar |
40 | 41 |
|
41 | 42 | from typing_extensions import Literal |
42 | 43 | from typing_extensions import Self |
@@ -314,6 +315,8 @@ class PackageURL( |
314 | 315 | https://github.com/package-url/purl-spec |
315 | 316 | """ |
316 | 317 |
|
| 318 | + SCHEME: ClassVar[str] = "pkg" |
| 319 | + |
317 | 320 | type: str |
318 | 321 | namespace: str | None |
319 | 322 | name: str |
@@ -409,7 +412,7 @@ def to_string(self) -> str: |
409 | 412 | encode=True, |
410 | 413 | ) |
411 | 414 |
|
412 | | - purl = ["pkg:", type, "/"] |
| 415 | + purl = [self.SCHEME, ":", type, "/"] |
413 | 416 |
|
414 | 417 | if namespace: |
415 | 418 | purl.extend((namespace, "/")) |
@@ -440,8 +443,10 @@ def from_string(cls, purl: str) -> Self: |
440 | 443 | raise ValueError("A purl string argument is required.") |
441 | 444 |
|
442 | 445 | scheme, sep, remainder = purl.partition(":") |
443 | | - if not sep or scheme != "pkg": |
444 | | - raise ValueError(f'purl is missing the required "pkg" scheme component: {purl!r}.') |
| 446 | + if not sep or scheme != cls.SCHEME: |
| 447 | + raise ValueError( |
| 448 | + f'purl is missing the required "{cls.SCHEME}" scheme component: {purl!r}.' |
| 449 | + ) |
445 | 450 |
|
446 | 451 | # this strip '/, // and /// as possible in :// or :/// |
447 | 452 | remainder = remainder.strip().lstrip("/") |
|
0 commit comments