Skip to content

Commit f5ad1a7

Browse files
committed
Dry up
1 parent 0ecb14e commit f5ad1a7

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- Top-level `item_assets` dict on `Collection`s ([#1476](https://github.com/stac-utils/pystac/pull/1476))
88
- Render Extension ([#1465](https://github.com/stac-utils/pystac/pull/1465))
9+
- Filter by links by list of media_types
910

1011
### Changed
1112

@@ -16,6 +17,7 @@
1617
- Update Projection Extension to version 2 - proj:epsg -> proj:code ([#1287](https://github.com/stac-utils/pystac/pull/1287))
1718
- Update migrate code to handle license changes in STAC spec 1.1.0 ([#1491](https://github.com/stac-utils/pystac/pull/1491))
1819
- Allow links to have `file://` prefix - but don't write them that way by default ([#1489](https://github.com/stac-utils/pystac/pull/1489))
20+
- For `get_root_link`, `get_child_links`, `get_item_links`: Ensure json media types ([#1497](https://github.com/stac-utils/pystac/pull/1497))
1921
- Raise `STACError` with message when a link is expected to resolve to a STAC object but doesn't ([#1500](https://github.com/stac-utils/pystac/pull/1500))
2022

2123
### Fixed

pystac/catalog.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414

1515
import pystac
16+
import pystac.media_type
1617
from pystac.cache import ResolvedObjectCache
1718
from pystac.errors import STACTypeError
1819
from pystac.layout import (
@@ -466,7 +467,7 @@ def get_child_links(self) -> list[Link]:
466467
"""
467468
return self.get_links(
468469
rel=pystac.RelType.CHILD,
469-
media_type=[None, pystac.MediaType.GEOJSON, pystac.MediaType.JSON],
470+
media_type=pystac.media_type.STAC_JSON,
470471
)
471472

472473
def clear_children(self) -> None:
@@ -628,8 +629,7 @@ def get_item_links(self) -> list[Link]:
628629
List[Link]: List of links of this catalog with ``rel == 'item'``
629630
"""
630631
return self.get_links(
631-
rel=pystac.RelType.ITEM,
632-
media_type=[None, pystac.MediaType.GEOJSON, pystac.MediaType.JSON],
632+
rel=pystac.RelType.ITEM, media_type=pystac.media_type.STAC_JSON
633633
)
634634

635635
def to_dict(

pystac/media_type.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ class MediaType(StringEnum):
2424
PDF = "application/pdf"
2525
ZARR = "application/vnd+zarr" # https://github.com/openMetadataInitiative/openMINDS_core/blob/v4/instances/data/contentTypes/zarr.jsonld
2626
NETCDF = "application/netcdf" # https://github.com/Unidata/netcdf/issues/42#issuecomment-1007618822
27+
28+
29+
#: Media types that can be resolved as STAC Objects
30+
STAC_JSON = [None, MediaType.GEOJSON, MediaType.JSON]

pystac/stac_object.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
S = TypeVar("S", bound="STACObject")
2424

25-
STACObject_MediaType: TypeAlias = str | pystac.MediaType | None
25+
OptionalMediaType: TypeAlias = str | pystac.MediaType | None
2626

2727

2828
class STACObjectType(StringEnum):
@@ -174,7 +174,7 @@ def traverse(obj: str | STACObject, visited: set[str | STACObject]) -> bool:
174174
def get_single_link(
175175
self,
176176
rel: str | pystac.RelType | None = None,
177-
media_type: STACObject_MediaType | Iterable[STACObject_MediaType] = None,
177+
media_type: OptionalMediaType | Iterable[OptionalMediaType] = None,
178178
) -> Link | None:
179179
"""Get a single :class:`~pystac.Link` instance associated with this
180180
object.
@@ -208,7 +208,7 @@ def get_single_link(
208208
def get_links(
209209
self,
210210
rel: str | pystac.RelType | None = None,
211-
media_type: STACObject_MediaType | Iterable[STACObject_MediaType] = None,
211+
media_type: OptionalMediaType | Iterable[OptionalMediaType] = None,
212212
) -> list[Link]:
213213
"""Gets the :class:`~pystac.Link` instances associated with this object.
214214
@@ -256,7 +256,7 @@ def get_root_link(self) -> Link | None:
256256
"""
257257
return self.get_single_link(
258258
rel=pystac.RelType.ROOT,
259-
media_type=[None, pystac.MediaType.GEOJSON, pystac.MediaType.JSON],
259+
media_type=pystac.media_type.STAC_JSON,
260260
)
261261

262262
@property

0 commit comments

Comments
 (0)