Skip to content

Commit

Permalink
Use f-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhollowe committed Nov 20, 2022
1 parent cd92589 commit bcec27a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions proxmoxer/backends/command_base.py
Expand Up @@ -74,7 +74,7 @@ def request(self, method, url, data=None, params=None, headers=None):
tmp_filename = ""
if url.endswith("upload"):
# copy file to temporary location on proxmox host
tmp_filename, tmp_err = self._exec(
tmp_filename, _ = self._exec(
[
"python3",
"-c",
Expand All @@ -86,9 +86,9 @@ def request(self, method, url, data=None, params=None, headers=None):
data["filename"] = data["filename"].name
data["tmpfilename"] = tmp_filename

command = ["{0}sh".format(self.service), cmd, url]
command = [f"{self.service}sh", cmd, url]
# convert the options dict into a 2-tuple with the key formatted as a flag
option_pairs = [("-{0}".format(k), str(v)) for k, v in chain(data.items(), params.items())]
option_pairs = [(f"-{k}", str(v)) for k, v in chain(data.items(), params.items())]
# add back in all the command arguments as their own pairs
if data_command is not None:
if isinstance(data_command, list):
Expand Down
8 changes: 4 additions & 4 deletions proxmoxer/backends/https.py
Expand Up @@ -112,7 +112,7 @@ def get_tokens(self):
def __call__(self, req):
# refresh ticket if older than `renew_age`
if (get_time() - self.birth_time) >= self.renew_age:
logger.debug("refreshing ticket (age %d)", (get_time() - self.birth_time))
logger.debug(f"refreshing ticket (age {get_time() - self.birth_time})")
self._get_new_tokens()

# only attach CSRF token if needed (reduce interception risk)
Expand Down Expand Up @@ -282,7 +282,7 @@ def __init__(
if "]:" in host:
host, host_port = host.rsplit(":", 1)
else:
host = "[{0}]".format(host)
host = f"[{host}]"
elif ":" in host:
host, host_port = host.split(":")
port = host_port if host_port.isdigit() else port
Expand All @@ -293,9 +293,9 @@ def __init__(

self.mode = mode
if path_prefix is not None:
self.base_url = "https://{0}:{1}/{2}/api2/{3}".format(host, port, path_prefix, mode)
self.base_url = f"https://{host}:{port}/{path_prefix}/api2/{mode}"
else:
self.base_url = "https://{0}:{1}/api2/{2}".format(host, port, mode)
self.base_url = f"https://{host}:{port}/api2/{mode}"

if token_name is not None:
if "token" not in SERVICES[service]["supported_https_auths"]:
Expand Down
4 changes: 2 additions & 2 deletions proxmoxer/core.py
Expand Up @@ -77,7 +77,7 @@ def __getattr__(self, item):
def url_join(self, base, *args):
scheme, netloc, path, query, fragment = urlparse.urlsplit(base)
path = path if len(path) else "/"
path = posixpath.join(path, *[("%s" % x) for x in args])
path = posixpath.join(path, *[str(x) for x in args])
return urlparse.urlunsplit([scheme, netloc, path, query, fragment])

def __call__(self, resource_id=None):
Expand All @@ -102,7 +102,7 @@ def _request(self, method, data=None, params=None):
else:
logger.info(f"{method} {url}")
resp = self._store["session"].request(method, url, data=data, params=params)
logger.debug("Status code: %s, output: %s", resp.status_code, resp.content)
logger.debug(f"Status code: {resp.status_code}, output: {resp.content}")

This comment has been minimized.

Copy link
@wdoekes

wdoekes Jan 17, 2023

Contributor

This now produces this warning:

  logger.debug(f"Status code: {resp.status_code}, output: {resp.content}")
proxmoxer/core.py:145: BytesWarning: str() on a bytes instance

Fix:

--- proxmoxer/core.py.orig  2023-01-12 09:34:15.027363604 +0100
+++ proxmoxer/core.py       2023-01-12 09:32:40.693535780 +0100
@@ -142,7 +142,7 @@ class ProxmoxResource:
                 del data[key]

         resp = self._store["session"].request(method, url, data=data, params=params)
-        logger.debug(f"Status code: {resp.status_code}, output: {resp.content}")
+        logger.debug(f"Status code: {resp.status_code}, output: {resp.content!r}")

         if resp.status_code >= 400:
             if hasattr(resp, "reason"):

This comment has been minimized.

Copy link
@wdoekes

wdoekes Jan 17, 2023

Contributor

PR #131


if resp.status_code >= 400:
if hasattr(resp, "reason"):
Expand Down

0 comments on commit bcec27a

Please sign in to comment.