4
4
"""
5
5
6
6
from enum import Enum
7
- from typing import Any , Dict , Generic , List , Optional , Set , TypeVar , cast
7
+ from typing import Any , Dict , List , Optional , Set
8
8
9
9
import pystac
10
10
from pystac .extensions .base import ExtensionManagementMixin , PropertiesExtension
16
16
)
17
17
from pystac .utils import get_required
18
18
19
- T = TypeVar ("T" , bound = pystac .Asset )
20
-
21
19
SCHEMA_URI = "https://stac-extensions.github.io/file/v2.0.0/schema.json"
22
20
23
21
PREFIX = "file:"
@@ -90,15 +88,11 @@ def summary(self, v: str) -> None:
90
88
self .properties ["summary" ] = v
91
89
92
90
93
- class FileExtension (
94
- Generic [T ], PropertiesExtension , ExtensionManagementMixin [pystac .Item ]
95
- ):
96
- """An abstract class that can be used to extend the properties of an
97
- :class:`~pystac.Item` or :class:`~pystac.Asset` with properties from the
98
- :stac-ext:`File Info Extension <file>`. This class is generic over the type of
99
- STAC Object to be extended (e.g. :class:`~pystac.Asset`).
91
+ class FileExtension (PropertiesExtension , ExtensionManagementMixin [pystac .Item ]):
92
+ """A class that can be used to extend the properties of an :class:`~pystac.Asset`
93
+ with properties from the :stac-ext:`File Info Extension <file>`.
100
94
101
- To create a concrete instance of :class:`FileExtension`, use the
95
+ To create an instance of :class:`FileExtension`, use the
102
96
:meth:`FileExtension.ext` method. For example:
103
97
104
98
.. code-block:: python
@@ -107,6 +101,15 @@ class FileExtension(
107
101
>>> file_ext = FileExtension.ext(asset)
108
102
"""
109
103
104
+ def __init__ (self , asset : pystac .Asset ):
105
+ self .asset_href = asset .href
106
+ self .properties = asset .properties
107
+ if asset .owner and isinstance (asset .owner , pystac .Item ):
108
+ self .additional_read_properties = [asset .owner .properties ]
109
+
110
+ def __repr__ (self ) -> str :
111
+ return "<AssetFileExtension Asset href={}>" .format (self .asset_href )
112
+
110
113
def apply (
111
114
self ,
112
115
byte_order : Optional [ByteOrder ] = None ,
@@ -189,42 +192,14 @@ def values(self, v: Optional[List[MappingObject]]) -> None:
189
192
def get_schema_uri (cls ) -> str :
190
193
return SCHEMA_URI
191
194
192
- @staticmethod
193
- def ext (obj : T ) -> "FileExtension[T] " :
195
+ @classmethod
196
+ def ext (cls , obj : pystac . Asset ) -> "FileExtension" :
194
197
"""Extends the given STAC Object with properties from the :stac-ext:`File Info
195
198
Extension <file>`.
196
199
197
200
This extension can be applied to instances of :class:`~pystac.Asset`.
198
-
199
- Raises:
200
-
201
- pystac.ExtensionTypeError : If an invalid object type is passed.
202
201
"""
203
- if isinstance (obj , pystac .Asset ):
204
- return cast (FileExtension [T ], AssetFileExtension (obj ))
205
- else :
206
- raise pystac .ExtensionTypeError (
207
- f"File extension does not apply to type { type (obj )} "
208
- )
209
-
210
-
211
- class AssetFileExtension (FileExtension [pystac .Asset ]):
212
- """A concrete implementation of :class:`FileExtension` on an :class:`~pystac.Asset`
213
- that extends the Asset fields to include properties defined in the
214
- :stac-ext:`File Info Extension <info>`.
215
-
216
- This class should generally not be instantiated directly. Instead, call
217
- :meth:`FileExtension.ext` on an :class:`~pystac.Asset` to extend it.
218
- """
219
-
220
- def __init__ (self , asset : pystac .Asset ):
221
- self .asset_href = asset .href
222
- self .properties = asset .properties
223
- if asset .owner and isinstance (asset .owner , pystac .Item ):
224
- self .additional_read_properties = [asset .owner .properties ]
225
-
226
- def __repr__ (self ) -> str :
227
- return "<AssetFileExtension Asset href={}>" .format (self .asset_href )
202
+ return cls (obj )
228
203
229
204
230
205
class FileExtensionHooks (ExtensionHooks ):
0 commit comments