Skip to content

Commit

Permalink
Remove percent formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
urschrei committed Dec 27, 2024
1 parent 8132f75 commit 5217327
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions src/pyzotero/zotero.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,11 @@ def default_headers(self):
It's always OK to include these headers
"""
_headers = {
"User-Agent": "Pyzotero/%s" % pz.__version__,
"Zotero-API-Version": "%s" % __api_version__,
"User-Agent": f"Pyzotero/{pz.__version__}",
"Zotero-API-Version": f"{__api_version__}",
}
if self.api_key:
_headers["Authorization"] = "Bearer %s" % self.api_key
_headers["Authorization"] = f"Bearer {self.api_key}"
return _headers

def _cache(self, response, key):
Expand Down Expand Up @@ -560,12 +560,12 @@ def _build_query(self, query_string, no_params=False):
try:
query = quote(query_string.format(u=self.library_id, t=self.library_type))
except KeyError as err:
raise ze.ParamNotPassed("There's a request parameter missing: %s" % err)
raise ze.ParamNotPassed(f"There's a request parameter missing: {err}")
# Add the URL parameters and the user key, if necessary
if no_params is False:
if not self.url_params:
self.add_parameters()
query = "%s?%s" % (query, self.url_params)
query = f"{query}?{self.url_params}"
return query

@retrieve
Expand Down Expand Up @@ -1117,7 +1117,7 @@ def add_tags(self, item, *tags):
except AssertionError:
item["data"]["tags"] = list()
for tag in tags:
item["data"]["tags"].append({"tag": "%s" % tag})
item["data"]["tags"].append({"tag": f"{tag}"})
# make sure everything's OK
assert self.check_items([item])
return self.update_item(item)
Expand Down Expand Up @@ -1658,13 +1658,7 @@ def error_handler(zot, req, exc=None):

def err_msg(req):
"""Return a nicely-formatted error message"""
return "\nCode: %s\nURL: %s\nMethod: %s\nResponse: %s" % (
req.status_code,
# error.msg,
req.url,
req.request.method,
req.text,
)
return f"\nCode: {req.status_code}\nURL: {req.url}\nMethod: {req.request.method}\nResponse: {req.text}"

if error_codes.get(req.status_code):
# check to see whether its 429
Expand Down Expand Up @@ -1833,12 +1827,11 @@ def _validate(self, conditions):
for condition in conditions:
if set(condition.keys()) != allowed_keys:
raise ze.ParamNotPassed(
"Keys must be all of: %s" % ", ".join(self.searchkeys)
f"Keys must be all of: {', '.join(self.searchkeys)}"
)
if condition.get("operator") not in operators_set:
raise ze.ParamNotPassed(
"You have specified an unknown operator: %s"
% condition.get("operator")
f"You have specified an unknown operator: {condition.get('operator')}"
)
# dict keys of allowed operators for the current condition
permitted_operators = self.conditions_operators.get(
Expand All @@ -1850,12 +1843,7 @@ def _validate(self, conditions):
)
if condition.get("operator") not in permitted_operators_list:
raise ze.ParamNotPassed(
"You may not use the '%s' operator when selecting the '%s' condition. \nAllowed operators: %s"
% (
condition.get("operator"),
condition.get("condition"),
", ".join(list(permitted_operators_list)),
)
f"You may not use the '{condition.get('operator')}' operator when selecting the '{condition.get('condition')}' condition. \nAllowed operators: {', '.join(list(permitted_operators_list))}"
)


Expand Down Expand Up @@ -1893,14 +1881,12 @@ def _verify(self, payload):
pass
except IOError:
raise ze.FileDoesNotExist(
"The file at %s couldn't be opened or found."
% str(self.basedir.joinpath(templt["filename"]))
f"The file at {str(self.basedir.joinpath(templt['filename']))} couldn't be opened or found."
)
# no point in continuing if the file isn't a file
else:
raise ze.FileDoesNotExist(
"The file at %s couldn't be opened or found."
% str(self.basedir.joinpath(templt["filename"]))
f"The file at {str(self.basedir.joinpath(templt['filename']))} couldn't be opened or found."
)

def _create_prelim(self):
Expand Down Expand Up @@ -2012,7 +1998,7 @@ def _upload_file(self, authdata, attachment, reg_key):
upload = requests.post(
url=authdata["url"],
files=upload_pairs,
headers={"User-Agent": "Pyzotero/%s" % pz.__version__},
headers={"User-Agent": f"Pyzotero/{pz.__version__}"},
)
except requests.exceptions.ConnectionError:
raise ze.UploadError("ConnectionError")
Expand Down

0 comments on commit 5217327

Please sign in to comment.