Skip to content

Commit

Permalink
refactor: only create connection pool when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Dec 13, 2024
1 parent 0fe4073 commit b880e27
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions transmission_rpc/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,14 @@ def __init__(
self.__semver_version = None

common_args: dict[str, Any] = {"host": host, "timeout": self.timeout, "retries": False}
self.__http_client = {
"http": urllib3.HTTPConnectionPool(port=port, **common_args),
"https": urllib3.HTTPSConnectionPool(port=port, ca_certs=certifi.where(), **common_args),
"http+unix": UnixHTTPConnectionPool(**common_args),
}[protocol]
if protocol == "http":
self.__http_client = urllib3.HTTPConnectionPool(port=port, **common_args)
elif protocol == "https":
self.__http_client = urllib3.HTTPSConnectionPool(port=port, ca_certs=certifi.where(), **common_args)
elif protocol == "http+unix":
self.__http_client = UnixHTTPConnectionPool(**common_args)
else:
raise ValueError(f"Unknown protocol {protocol!r}, only 'http', 'https' or 'http+unix' is supported")
self.get_session(arguments=["rpc-version", "rpc-version-semver", "version"])
self.__torrent_get_arguments = get_torrent_arguments(self.__protocol_version)

Expand Down

0 comments on commit b880e27

Please sign in to comment.