From 04c0003a6158d671a8d7c073f27515f0b7078482 Mon Sep 17 00:00:00 2001 From: Yoshihiro OKUMURA Date: Thu, 11 Jun 2026 21:04:28 +0900 Subject: [PATCH] fix(connection): support absolute download urls for public data --- mdrsclient/api/base.py | 7 +------ mdrsclient/api/files.py | 9 +++++++-- mdrsclient/commands/config.py | 4 +++- mdrsclient/connection.py | 2 ++ 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/mdrsclient/api/base.py b/mdrsclient/api/base.py index fd08c68..0c450d6 100644 --- a/mdrsclient/api/base.py +++ b/mdrsclient/api/base.py @@ -5,12 +5,7 @@ from pydantic import TypeAdapter from requests import Response from mdrsclient.connection import MDRSConnection -from mdrsclient.exceptions import ( - BadRequestException, - ForbiddenException, - UnauthorizedException, - UnexpectedException, -) +from mdrsclient.exceptions import BadRequestException, ForbiddenException, UnauthorizedException, UnexpectedException from mdrsclient.models.error import DRFStandardizedErrors diff --git a/mdrsclient/api/files.py b/mdrsclient/api/files.py index e047a9d..99a96e6 100644 --- a/mdrsclient/api/files.py +++ b/mdrsclient/api/files.py @@ -54,7 +54,10 @@ class FilesApi(BaseApi): try: with open(os.path.realpath(path), mode="rb") as fp: data = MultipartEncoder( - fields={"folder_id": folder_id, "file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))} + fields={ + "folder_id": folder_id, + "file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path)), + } ) response = self.connection.post(url, data=data, headers={"Content-Type": data.content_type}) self._raise_response_error(response) @@ -76,7 +79,9 @@ class FilesApi(BaseApi): # update file body try: with open(os.path.realpath(path), mode="rb") as fp: - data = MultipartEncoder(fields={"file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))}) + data = MultipartEncoder( + fields={"file": (normalize("NFC", os.path.basename(path)), fp, self._get_mime_type(path))} + ) response = self.connection.put(url, data=data, headers={"Content-Type": data.content_type}) except OSError: raise UnexpectedException(f"Could not open `{path}` file.") diff --git a/mdrsclient/commands/config.py b/mdrsclient/commands/config.py index 8ef6ffe..c2c01c1 100644 --- a/mdrsclient/commands/config.py +++ b/mdrsclient/commands/config.py @@ -28,7 +28,9 @@ class ConfigCommand(BaseCommand): list_parser = config_parsers.add_parser("list", help="list all the remote hosts", aliases=["ls"]) list_parser.set_defaults(func=cls.func_list) # config delete - delete_parser = config_parsers.add_parser("delete", help="delete an existing remote host", aliases=["remove", "rm"]) + delete_parser = config_parsers.add_parser( + "delete", help="delete an existing remote host", aliases=["remove", "rm"] + ) delete_parser.add_argument("remote", help="label of remote host") delete_parser.set_defaults(func=cls.func_delete) diff --git a/mdrsclient/connection.py b/mdrsclient/connection.py index a4700e2..90718ec 100644 --- a/mdrsclient/connection.py +++ b/mdrsclient/connection.py @@ -92,6 +92,8 @@ class MDRSConnection: self.__cache.laboratories = laboratories def __build_url(self, path: str) -> str: + if path.startswith("http://") or path.startswith("https://"): + return path if self.url == "": raise MissingConfigurationException("remote host is not configured") return f"{self.url}/{path}"