|
4 | 4 | from collections.abc import Callable |
5 | 5 | from pathlib import Path |
6 | 6 | from typing import TYPE_CHECKING |
7 | | -from urllib.parse import urlparse |
8 | 7 |
|
9 | 8 | from openml.enums import ResourceType |
10 | | -from openml.exceptions import OpenMLCacheRequiredError |
11 | 9 |
|
12 | 10 | from .base import ResourceAPI |
13 | 11 |
|
@@ -72,27 +70,13 @@ def download( |
72 | 70 | file_name: str = "response.txt", |
73 | 71 | md5_checksum: str | None = None, |
74 | 72 | ) -> Path: |
75 | | - if self._http.cache is None: |
76 | | - raise OpenMLCacheRequiredError( |
77 | | - "A cache object is required for download, but none was provided in the HTTPClient." |
78 | | - ) |
79 | | - base = self._http.cache.path |
80 | | - file_path = base / "downloads" / urlparse(url).path.lstrip("/") / file_name |
81 | | - file_path = file_path.expanduser() |
82 | | - file_path.parent.mkdir(parents=True, exist_ok=True) |
83 | | - if file_path.exists(): |
84 | | - return file_path |
85 | | - |
86 | | - response = self._http.get(url, md5_checksum=md5_checksum) |
87 | | - if handler is not None: |
88 | | - return handler(response, file_path, encoding) |
89 | | - |
90 | | - return self._text_handler(response, file_path, encoding) |
91 | | - |
92 | | - def _text_handler(self, response: Response, path: Path, encoding: str) -> Path: |
93 | | - with path.open("w", encoding=encoding) as f: |
94 | | - f.write(response.text) |
95 | | - return path |
| 73 | + return self._http.download( |
| 74 | + url=url, |
| 75 | + handler=handler, |
| 76 | + encoding=encoding, |
| 77 | + file_name=file_name, |
| 78 | + md5_checksum=md5_checksum, |
| 79 | + ) |
96 | 80 |
|
97 | 81 |
|
98 | 82 | class EvaluationMeasureAPI(ResourceAPI): |
|
0 commit comments