From d983c452de8caa01bf5d08778ff3cc182ec82953 Mon Sep 17 00:00:00 2001 From: Yoshihiro OKUMURA Date: Wed, 17 May 2023 14:51:19 +0900 Subject: [PATCH] set user agent string. --- mdrsclient/__init__.py | 3 +++ mdrsclient/__main__.py | 2 +- mdrsclient/connection.py | 9 ++++++++- mdrsclient/utils.py | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/mdrsclient/__init__.py b/mdrsclient/__init__.py index e69de29..9835614 100644 --- a/mdrsclient/__init__.py +++ b/mdrsclient/__init__.py @@ -0,0 +1,3 @@ +from mdrsclient.__version__ import __version__ + +__all__ = ["__version__"] diff --git a/mdrsclient/__main__.py b/mdrsclient/__main__.py index 6a1c317..ee712ce 100644 --- a/mdrsclient/__main__.py +++ b/mdrsclient/__main__.py @@ -21,7 +21,7 @@ from mdrsclient.exceptions import MDRSException def main() -> None: - description = """This is a command-line program to up files.""" + description = """This is a command-line program for up- and downloading files to and from MDRS based repository.""" parser = argparse.ArgumentParser(description=description, formatter_class=argparse.RawDescriptionHelpFormatter) parsers = parser.add_subparsers(title="subcommands") diff --git a/mdrsclient/connection.py b/mdrsclient/connection.py index bd1648f..79ece4d 100644 --- a/mdrsclient/connection.py +++ b/mdrsclient/connection.py @@ -1,7 +1,9 @@ +import platform import threading from requests import Response, Session +from mdrsclient.__version__ import __version__ from mdrsclient.cache import CacheFile from mdrsclient.exceptions import MissingConfigurationException from mdrsclient.models import Laboratories, Token, User @@ -74,6 +76,11 @@ class MDRSConnection: return "/".join(parts) def __prepare_headers(self) -> None: - self.session.headers.update({"accept": "application/json"}) + self.session.headers.update( + { + "User-Agent": f"MdrsClient/{__version__} (Python {platform.python_version()} - {platform.platform()})", + "Accept": "application/json", + } + ) if self.token is not None: self.session.headers.update({"Authorization": f"Bearer {self.token.access}"}) diff --git a/mdrsclient/utils.py b/mdrsclient/utils.py index 97c066a..a002d30 100644 --- a/mdrsclient/utils.py +++ b/mdrsclient/utils.py @@ -20,5 +20,5 @@ class FileLock: def unlock(file: IO[Any]) -> None: if os.name == "nt": msvcrt.locking(file.fileno(), msvcrt.LK_UNLCK, 1) - else: + elif os.name == "posix": fcntl.flock(file.fileno(), fcntl.LOCK_UN)