Skip to content

Commit 2398b5f

Browse files
committed
update download
1 parent 0981b2e commit 2398b5f

1 file changed

Lines changed: 7 additions & 23 deletions

File tree

openml/_api/resources/base/resources.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
from collections.abc import Callable
55
from pathlib import Path
66
from typing import TYPE_CHECKING
7-
from urllib.parse import urlparse
87

98
from openml.enums import ResourceType
10-
from openml.exceptions import OpenMLCacheRequiredError
119

1210
from .base import ResourceAPI
1311

@@ -72,27 +70,13 @@ def download(
7270
file_name: str = "response.txt",
7371
md5_checksum: str | None = None,
7472
) -> 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+
)
9680

9781

9882
class EvaluationMeasureAPI(ResourceAPI):

0 commit comments

Comments
 (0)