From 5217327b6239e1e91e5a5b68a520c8dfab180cee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20H=C3=BCgel?= Date: Fri, 27 Dec 2024 03:20:05 +0000 Subject: [PATCH] Remove percent formatting --- src/pyzotero/zotero.py | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) diff --git a/src/pyzotero/zotero.py b/src/pyzotero/zotero.py index 9fa85f8..ea81846 100644 --- a/src/pyzotero/zotero.py +++ b/src/pyzotero/zotero.py @@ -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): @@ -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 @@ -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) @@ -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 @@ -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( @@ -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))}" ) @@ -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): @@ -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")