|
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})$'" |
@@ -164,8 +170,7 @@ def color_hint(self) -> Optional[str]: |
164 | 170 | @color_hint.setter |
165 | 171 | def color_hint(self, v: Optional[str]) -> None: |
166 | 172 | if v is not None: |
167 | | - color_hint_pattern = re.compile("^([0-9A-F]{6})$") |
168 | | - match = color_hint_pattern.match(v) |
| 173 | + match = COLOR_HINT_PATTERN.match(v) |
169 | 174 | assert ( |
170 | 175 | v is None or match is not None and match.group() == v |
171 | 176 | ), "Must format color hints as '^([0-9A-F]{6})$'" |
@@ -495,7 +500,11 @@ def _get_bitfields(self) -> Optional[List[Bitfield]]: |
495 | 500 |
|
496 | 501 | @classmethod |
497 | 502 | def get_schema_uri(cls) -> str: |
498 | | - return SCHEMA_URI |
| 503 | + return SCHEMA_URI_PATTERN.format(version=DEFAULT_VERSION) |
| 504 | + |
| 505 | + @classmethod |
| 506 | + def get_schema_uris(cls) -> List[str]: |
| 507 | + return [SCHEMA_URI_PATTERN.format(version=v) for v in SUPPORTED_VERSIONS] |
499 | 508 |
|
500 | 509 | @classmethod |
501 | 510 | def ext(cls, obj: T, add_if_missing: bool = False) -> ClassificationExtension[T]: |
@@ -627,7 +636,7 @@ def bitfields(self, v: Optional[List[Bitfield]]) -> None: |
627 | 636 |
|
628 | 637 |
|
629 | 638 | class ClassificationExtensionHooks(ExtensionHooks): |
630 | | - schema_uri: str = SCHEMA_URI |
| 639 | + schema_uri: str = SCHEMA_URI_PATTERN.format(version=DEFAULT_VERSION) |
631 | 640 | prev_extension_ids = {"classification"} |
632 | 641 | stac_object_types = {pystac.STACObjectType.ITEM} |
633 | 642 |
|
|
0 commit comments