1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
from __future__ import annotations
import re
from enum import Enum
class ConformanceClasses(Enum):
"""Enumeration class for Conformance Classes"""
# defined conformance classes regexes
CORE = "/core"
COLLECTIONS = "/collections"
# this is ogcapi-features instead of just features for historical reasons,
# even thought this is a STAC API conformance class
FEATURES = "/ogcapi-features"
ITEM_SEARCH = "/item-search"
CONTEXT = "/item-search#context"
FIELDS = "/item-search#fields"
SORT = "/item-search#sort"
QUERY = "/item-search#query"
FILTER = "/item-search#filter"
# collection search
COLLECTION_SEARCH = "/collection-search"
COLLECTION_SEARCH_FREE_TEXT = "/collection-search#free-text"
@classmethod
def get_by_name(cls, name: str) -> ConformanceClasses:
for member in cls:
if member.name == name.upper():
return member
raise ValueError(
f"Invalid conformance class '{name}'. Options are: {list(cls)}"
)
def __str__(self) -> str:
return f"{self.name}"
def __repr__(self) -> str:
return str(self)
@property
def valid_uri(self) -> str:
return f"https://api.stacspec.org/v1.0.*{self.value}"
@property
def pattern(self) -> re.Pattern[str]:
return re.compile(
rf"{re.escape('https://api.stacspec.org/v1.0.')}(.*){re.escape(self.value)}"
)
|