Download a file from ``filepath``. ``get_local_path`` is decorated by :meth:`contxtlib.contextmanager`. It can be called with ``with`` statement, and when exists from the ``with`` statement, the temporary path will be released. Args: filepath (str): Down
(
self, filepath: str)
| 723 | |
| 724 | @contextmanager |
| 725 | def get_local_path( |
| 726 | self, filepath: str) -> Generator[Union[str, Path], None, None]: |
| 727 | """Download a file from ``filepath``. |
| 728 | |
| 729 | ``get_local_path`` is decorated by :meth:`contxtlib.contextmanager`. It |
| 730 | can be called with ``with`` statement, and when exists from the |
| 731 | ``with`` statement, the temporary path will be released. |
| 732 | |
| 733 | Args: |
| 734 | filepath (str): Download a file from ``filepath``. |
| 735 | |
| 736 | Examples: |
| 737 | >>> client = HTTPBackend() |
| 738 | >>> # After existing from the ``with`` clause, |
| 739 | >>> # the path will be removed |
| 740 | >>> with client.get_local_path('http://path/of/your/file') as path: |
| 741 | ... # do something here |
| 742 | """ |
| 743 | try: |
| 744 | f = tempfile.NamedTemporaryFile(delete=False) |
| 745 | f.write(self.get(filepath)) |
| 746 | f.close() |
| 747 | yield f.name |
| 748 | finally: |
| 749 | os.remove(f.name) |
| 750 | |
| 751 | |
| 752 | class FileClient: |