|
11 | 11 | Type,
|
12 | 12 | Union,
|
13 | 13 | )
|
14 |
| -import warnings |
15 | 14 |
|
16 | 15 | from urllib.request import urlopen
|
17 | 16 | from urllib.error import HTTPError
|
@@ -388,169 +387,3 @@ def _report_duplicate_object_names(
|
388 | 387 | else:
|
389 | 388 | result[key] = value
|
390 | 389 | return result
|
391 |
| - |
392 |
| - |
393 |
| -class STAC_IO: |
394 |
| - """DEPRECATED: Methods used to read and save STAC json. |
395 |
| - Allows users of the library to set their own methods |
396 |
| - (e.g. for reading and writing from cloud storage) |
397 |
| -
|
398 |
| - Note: The static methods of this class are deprecated. Move to using |
399 |
| - instance methods of a specific instance of StacIO. |
400 |
| - """ |
401 |
| - |
402 |
| - @staticmethod |
403 |
| - def issue_deprecation_warning() -> None: |
404 |
| - warnings.warn( |
405 |
| - "STAC_IO is deprecated and will be removed in v1.0.0. " |
406 |
| - "Please use instances of StacIO (e.g. StacIO.default()) instead.", |
407 |
| - DeprecationWarning, |
408 |
| - ) |
409 |
| - |
410 |
| - def __init__(self) -> None: |
411 |
| - STAC_IO.issue_deprecation_warning() |
412 |
| - |
413 |
| - def __init_subclass__(cls) -> None: |
414 |
| - STAC_IO.issue_deprecation_warning() |
415 |
| - |
416 |
| - @staticmethod |
417 |
| - def read_text_method(uri: str) -> str: |
418 |
| - STAC_IO.issue_deprecation_warning() |
419 |
| - return StacIO.default().read_text(uri) |
420 |
| - |
421 |
| - @staticmethod |
422 |
| - def write_text_method(uri: str, txt: str) -> None: |
423 |
| - """Default method for writing text.""" |
424 |
| - STAC_IO.issue_deprecation_warning() |
425 |
| - return StacIO.default().write_text(uri, txt) |
426 |
| - |
427 |
| - @staticmethod |
428 |
| - def stac_object_from_dict( |
429 |
| - d: Dict[str, Any], |
430 |
| - href: Optional[str] = None, |
431 |
| - root: Optional["Catalog_Type"] = None, |
432 |
| - ) -> "STACObject_Type": |
433 |
| - STAC_IO.issue_deprecation_warning() |
434 |
| - if identify_stac_object_type(d) == pystac.STACObjectType.ITEM: |
435 |
| - collection_cache = None |
436 |
| - if root is not None: |
437 |
| - collection_cache = root._resolved_objects.as_collection_cache() |
438 |
| - |
439 |
| - # Merge common properties in case this is an older STAC object. |
440 |
| - merge_common_properties( |
441 |
| - d, json_href=href, collection_cache=collection_cache |
442 |
| - ) |
443 |
| - |
444 |
| - info = identify_stac_object(d) |
445 |
| - |
446 |
| - d = migrate_to_latest(d, info) |
447 |
| - |
448 |
| - if info.object_type == pystac.STACObjectType.CATALOG: |
449 |
| - return pystac.Catalog.from_dict(d, href=href, root=root, migrate=False) |
450 |
| - |
451 |
| - if info.object_type == pystac.STACObjectType.COLLECTION: |
452 |
| - return pystac.Collection.from_dict(d, href=href, root=root, migrate=False) |
453 |
| - |
454 |
| - if info.object_type == pystac.STACObjectType.ITEM: |
455 |
| - return pystac.Item.from_dict(d, href=href, root=root, migrate=False) |
456 |
| - |
457 |
| - raise ValueError(f"Unknown STAC object type {info.object_type}") |
458 |
| - |
459 |
| - # This is set in __init__.py |
460 |
| - _STAC_OBJECT_CLASSES = None |
461 |
| - |
462 |
| - @classmethod |
463 |
| - def read_text(cls, uri: str) -> str: |
464 |
| - """Read text from the given URI. |
465 |
| -
|
466 |
| - Args: |
467 |
| - uri : The URI from which to read text. |
468 |
| -
|
469 |
| - Returns: |
470 |
| - str: The text contained in the file at the location specified by the uri. |
471 |
| -
|
472 |
| - Note: |
473 |
| - This method uses the :func:`STAC_IO.read_text_method |
474 |
| - <STAC_IO.read_text_method>`. If you want to modify the behavior of |
475 |
| - STAC_IO in order to enable additional URI types, replace that member |
476 |
| - with your own implementation. |
477 |
| - """ |
478 |
| - return cls.read_text_method(uri) |
479 |
| - |
480 |
| - @classmethod |
481 |
| - def write_text(cls, uri: str, txt: str) -> None: |
482 |
| - """Write the given text to a file at the given URI. |
483 |
| -
|
484 |
| - Args: |
485 |
| - uri : The URI of the file to write the text to. |
486 |
| - txt : The text to write. |
487 |
| -
|
488 |
| - Note: |
489 |
| - This method uses the :func:`STAC_IO.write_text_method |
490 |
| - <STAC_IO.write_text_method>`. If you want to modify the behavior of |
491 |
| - STAC_IO in order to enable additional URI types, replace that member |
492 |
| - with your own implementation. |
493 |
| - """ |
494 |
| - cls.write_text_method(uri, txt) |
495 |
| - |
496 |
| - @classmethod |
497 |
| - def read_json(cls, uri: str) -> Dict[str, Any]: |
498 |
| - """Read a dict from the given URI. |
499 |
| -
|
500 |
| - Args: |
501 |
| - uri : The URI from which to read. |
502 |
| -
|
503 |
| - Returns: |
504 |
| - dict: A dict representation of the JSON contained in the file at the |
505 |
| - given uri. |
506 |
| -
|
507 |
| - Note: |
508 |
| - This method uses the :func:`STAC_IO.read_text_method |
509 |
| - <STAC_IO.read_text_method>`. If you want to modify the behavior of |
510 |
| - STAC_IO in order to enable additional URI types, replace that member |
511 |
| - with your own implementation. |
512 |
| - """ |
513 |
| - STAC_IO.issue_deprecation_warning() |
514 |
| - result: Dict[str, Any] = json.loads(STAC_IO.read_text(uri)) |
515 |
| - return result |
516 |
| - |
517 |
| - @classmethod |
518 |
| - def read_stac_object( |
519 |
| - cls, uri: str, root: Optional["Catalog_Type"] = None |
520 |
| - ) -> "STACObject_Type": |
521 |
| - """Read a STACObject from a JSON file at the given URI. |
522 |
| -
|
523 |
| - Args: |
524 |
| - uri : The URI from which to read. |
525 |
| - root : Optional root of the catalog for this object. |
526 |
| - If provided, the root's resolved object cache can be used to search for |
527 |
| - previously resolved instances of the STAC object. |
528 |
| -
|
529 |
| - Returns: |
530 |
| - STACObject: The deserialized STACObject from the serialized JSON |
531 |
| - contained in the file at the given uri. |
532 |
| -
|
533 |
| - Note: |
534 |
| - This method uses the :func:`STAC_IO.read_text_method |
535 |
| - <STAC_IO.read_text_method>`. If you want to modify the behavior of |
536 |
| - STAC_IO in order to enable additional URI types, replace that member |
537 |
| - with your own implementation. |
538 |
| - """ |
539 |
| - d = cls.read_json(uri) |
540 |
| - return cls.stac_object_from_dict(d, uri, root) |
541 |
| - |
542 |
| - @classmethod |
543 |
| - def save_json(cls, uri: str, json_dict: Dict[str, Any]) -> None: |
544 |
| - """Write a dict to the given URI as JSON. |
545 |
| -
|
546 |
| - Args: |
547 |
| - uri : The URI of the file to write the text to. |
548 |
| - json_dict : The JSON dict to write. |
549 |
| -
|
550 |
| - Note: |
551 |
| - This method uses the :func:`STAC_IO.write_text_method |
552 |
| - <STAC_IO.write_text_method>`. If you want to modify the behavior of |
553 |
| - STAC_IO in order to enable additional URI types, replace that member |
554 |
| - with your own implementation. |
555 |
| - """ |
556 |
| - STAC_IO.write_text(uri, json.dumps(json_dict, indent=4)) |
0 commit comments