Skip to content

Commit 20afd2c

Browse files
committed
Asset.get_absoulte_href returns None if no abs href possible
1 parent 6236686 commit 20afd2c

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

pystac/asset.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,20 @@ def set_owner(self, obj: Union["Collection_Type", "Item_Type"]) -> None:
7979
def get_absolute_href(self) -> Optional[str]:
8080
"""Gets the absolute href for this asset, if possible.
8181
82-
If this Asset has no associated Item, this will return whatever the
83-
href is (as it cannot determine the absolute path, if the asset
84-
href is relative).
82+
If this Asset has no associated Item, and the asset HREF is a relative path,
83+
this method will return None.
8584
8685
Returns:
87-
str: The absolute HREF of this asset, or a relative HREF if an absolute HREF
88-
cannot be determined.
86+
str: The absolute HREF of this asset, or None if an absolute HREF could not
87+
be determined.
8988
"""
90-
if not is_absolute_href(self.href):
89+
if is_absolute_href(self.href):
90+
return self.href
91+
else:
9192
if self.owner is not None:
9293
return make_absolute_href(self.href, self.owner.get_self_href())
93-
94-
return self.href
94+
else:
95+
return None
9596

9697
def to_dict(self) -> Dict[str, Any]:
9798
"""Generate a dictionary representing the JSON of this Asset.

pystac/utils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ def make_absolute_href(
100100
101101
Returns:
102102
str: The absolute HREF. If the source_href is already an absolute href,
103-
then it will be returned unchanged. If the source_href it None, it will
104-
return None.
103+
then it will be returned unchanged.
105104
"""
106105
if start_href is None:
107106
start_href = os.getcwd()

0 commit comments

Comments
 (0)