|
10 | 10 | Iterable, |
11 | 11 | List, |
12 | 12 | Optional, |
| 13 | + Pattern, |
13 | 14 | TypeVar, |
14 | 15 | Union, |
15 | 16 | cast, |
|
29 | 30 |
|
30 | 31 | T = TypeVar("T", pystac.Item, pystac.Asset, item_assets.AssetDefinition, RasterBand) |
31 | 32 |
|
32 | | -SCHEMA_URI: str = "https://stac-extensions.github.io/classification/v1.0.0/schema.json" |
33 | | -PREFIX: str = "classification:" |
| 33 | +SCHEMA_URI_PATTERN: str = ( |
| 34 | + "https://stac-extensions.github.io/classification/v{version}/schema.json" |
| 35 | +) |
| 36 | +DEFAULT_VERSION: str = "1.1.0" |
| 37 | +SUPPORTED_VERSIONS: List[str] = ["1.1.0", "1.0.0"] |
34 | 38 |
|
35 | 39 | # Field names |
| 40 | +PREFIX: str = "classification:" |
36 | 41 | BITFIELDS_PROP: str = PREFIX + "bitfields" |
37 | 42 | CLASSES_PROP: str = PREFIX + "classes" |
38 | 43 | RASTER_BANDS_PROP: str = "raster:bands" |
39 | 44 |
|
| 45 | +COLOR_HINT_PATTERN: Pattern[str] = re.compile("^([0-9A-Fa-f]{6})$") |
| 46 | + |
40 | 47 |
|
41 | 48 | class Classification: |
42 | 49 | """Represents a single category of a classification. |
@@ -73,8 +80,7 @@ def apply( |
73 | 80 | self.color_hint = color_hint |
74 | 81 |
|
75 | 82 | if color_hint is not None: |
76 | | - color_hint_pattern = re.compile("^([0-9A-F]{6})$") |
77 | | - match = color_hint_pattern.match(color_hint) |
| 83 | + match = COLOR_HINT_PATTERN.match(color_hint) |
78 | 84 | assert ( |
79 | 85 | color_hint is None or match is not None and match.group() == color_hint |
80 | 86 | ), "Must format color hints as '^([0-9A-F]{6})$'" |
@@ -171,8 +177,7 @@ def color_hint(self) -> Optional[str]: |
171 | 177 | @color_hint.setter |
172 | 178 | def color_hint(self, v: Optional[str]) -> None: |
173 | 179 | if v is not None: |
174 | | - color_hint_pattern = re.compile("^([0-9A-F]{6})$") |
175 | | - match = color_hint_pattern.match(v) |
| 180 | + match = COLOR_HINT_PATTERN.match(v) |
176 | 181 | assert ( |
177 | 182 | v is None or match is not None and match.group() == v |
178 | 183 | ), "Must format color hints as '^([0-9A-F]{6})$'" |
@@ -502,7 +507,11 @@ def _get_bitfields(self) -> Optional[List[Bitfield]]: |
502 | 507 |
|
503 | 508 | @classmethod |
504 | 509 | def get_schema_uri(cls) -> str: |
505 | | - return SCHEMA_URI |
| 510 | + return SCHEMA_URI_PATTERN.format(version=DEFAULT_VERSION) |
| 511 | + |
| 512 | + @classmethod |
| 513 | + def get_schema_uris(cls) -> List[str]: |
| 514 | + return [SCHEMA_URI_PATTERN.format(version=v) for v in SUPPORTED_VERSIONS] |
506 | 515 |
|
507 | 516 | @classmethod |
508 | 517 | def ext(cls, obj: T, add_if_missing: bool = False) -> ClassificationExtension[T]: |
@@ -634,7 +643,7 @@ def __repr__(self) -> str: |
634 | 643 |
|
635 | 644 |
|
636 | 645 | class ClassificationExtensionHooks(ExtensionHooks): |
637 | | - schema_uri: str = SCHEMA_URI |
| 646 | + schema_uri: str = SCHEMA_URI_PATTERN.format(version=DEFAULT_VERSION) |
638 | 647 | prev_extension_ids = {"classification"} |
639 | 648 | stac_object_types = {pystac.STACObjectType.ITEM} |
640 | 649 |
|
|
0 commit comments