From fc7b703531f21e8c7ae905b6c38bcdfa181402c3 Mon Sep 17 00:00:00 2001 From: Quentame Date: Sun, 3 Nov 2024 23:39:53 +0100 Subject: [PATCH] fix: string format Pylint W1202 & C0209 (#716) --- src/freebox_api/access.py | 14 +++++--------- src/freebox_api/aiofreepybox.py | 4 ++-- src/freebox_api/api/fs.py | 8 ++------ tests/example.py | 16 ++++++++-------- 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/src/freebox_api/access.py b/src/freebox_api/access.py index 7f30e932..65081471 100644 --- a/src/freebox_api/access.py +++ b/src/freebox_api/access.py @@ -34,7 +34,7 @@ def __init__( async def _get_challenge(self, base_url, timeout=10): """ - Return challenge from freebox API + Return challenge from Freebox API """ url = urljoin(base_url, "login") resp = await self.session.get(url, timeout=timeout) @@ -43,16 +43,14 @@ async def _get_challenge(self, base_url, timeout=10): # raise exception if resp.success != True if not resp_data.get("success"): raise AuthorizationError( - "Getting challenge failed (APIResponse: {})".format( - json.dumps(resp_data) - ) + f"Getting challenge failed (APIResponse: {json.dumps(resp_data)})" ) return resp_data["result"]["challenge"] async def _get_session_token(self, base_url, app_token, app_id, timeout=10): """ - Get session token from freebox. + Get session token from Freebox. Returns (session_token, session_permissions) """ # Get challenge from API @@ -70,9 +68,7 @@ async def _get_session_token(self, base_url, app_token, app_id, timeout=10): # raise exception if resp.success != True if not resp_data.get("success"): raise AuthorizationError( - "Starting session failed (APIResponse: {})".format( - json.dumps(resp_data) - ) + f"Starting session failed (APIResponse: {json.dumps(resp_data)})" ) session_token = resp_data["result"].get("session_token") @@ -122,7 +118,7 @@ async def _perform_request(self, verb, end_url, **kwargs): resp_data = await resp.json() if not resp_data["success"]: - err_msg = "Request failed (APIResponse: {})".format(json.dumps(resp_data)) + err_msg = f"Request failed (APIResponse: {json.dumps(resp_data)})" if resp_data.get("error_code") == "insufficient_rights": raise InsufficientPermissionsError(err_msg) raise HttpRequestError(err_msg) diff --git a/src/freebox_api/aiofreepybox.py b/src/freebox_api/aiofreepybox.py index a3fb59e4..3f679df0 100644 --- a/src/freebox_api/aiofreepybox.py +++ b/src/freebox_api/aiofreepybox.py @@ -210,7 +210,7 @@ async def _get_freebox_access( # Store application token in file self._writefile_app_token(app_token, track_id, app_desc, token_file) - logger.info("Application token file was generated: {0}".format(token_file)) + logger.info("Application token file was generated: %s", token_file) # Create freebox http access module fbx_access = Access( @@ -255,7 +255,7 @@ async def _get_app_token( # raise exception if resp.success != True if not resp_data.get("success"): raise AuthorizationError( - "Authorization failed (APIResponse: {0})".format(json.dumps(resp_data)) + f"Authorization failed (APIResponse: {json.dumps(resp_data)})" ) app_token: str = resp_data["result"]["app_token"] diff --git a/src/freebox_api/api/fs.py b/src/freebox_api/api/fs.py index 4bc75e54..34ee06b0 100644 --- a/src/freebox_api/api/fs.py +++ b/src/freebox_api/api/fs.py @@ -60,9 +60,7 @@ async def cd(self, path): if await self._path_exists(path): self._path = os.path.join(self._path, path) else: - logger.error( - "{} path does not exist".format(os.path.join(self._path, path)) - ) + logger.error("%s path does not exist", os.path.join(self._path, path)) async def _path_exists(self, path): """ @@ -72,9 +70,7 @@ async def _path_exists(self, path): await self.get_file_info(os.path.join(self._path, path)) return True except freebox_api.exceptions.HttpRequestError: - logger.debug( - "{} path does not exist".format(os.path.join(self._path, path)) - ) + logger.debug("%s path does not exist", os.path.join(self._path, path)) return False async def archive_files(self, archive): diff --git a/tests/example.py b/tests/example.py index c84f8016..f0537547 100755 --- a/tests/example.py +++ b/tests/example.py @@ -15,10 +15,10 @@ async def demo(): # and default token_file location fbx = Freepybox() - # To find out the HTTPS host and port of your freebox, go to + # To find out the HTTPS host and port of your Freebox, go to # http://mafreebox.freebox.fr/api_version - # Connect to the freebox + # Connect to the Freebox # Be ready to authorize the application on the Freebox if you use this # example for the first time await fbx.open(host="abcdefgh.fbxos.fr", port=1234) @@ -32,20 +32,20 @@ async def demo(): m3u8_obj = m3u8.loads(await r.text()) fbx_ts = await fbx.home.get_camera_ts(m3u8_obj.files[0]) # noqa F841 - # Dump freebox configuration using system API + # Dump Freebox configuration using system API # Extract temperature and mac address fbx_config = await fbx.system.get_config() sensors = fbx_config["sensors"] temp_sw = next(s for s in sensors if s["id"] == "temp_sw") - print("Freebox temperature : {0}".format(temp_sw["value"])) - print("Freebox mac address : {0}".format(fbx_config["mac"])) + print(f"Freebox temperature : {temp_sw["value"]}") + print(f"Freebox mac address : {fbx_config["mac"]}") # Dump DHCP configuration using dhcp API fbx_dhcp_config = await fbx.dhcp.get_config() # Modify ip_range configuration fbx_dhcp_config["ip_range_start"] = "192.168.0.10" fbx_dhcp_config["ip_range_end"] = "192.168.0.50" - # Send new configuration to the freebox. This line is commented to + # Send new configuration to the Freebox. This line is commented to # avoid any disaster. # await fbx.dhcp.set_config(fbx_dhcp_config) @@ -53,10 +53,10 @@ async def demo(): fbx_call_list = await fbx.call.get_call_list() print(fbx_call_list[0]) - # Reboot your freebox. This line is commented to avoid any disaster. + # Reboot your Freebox. This line is commented to avoid any disaster. # await fbx.system.reboot() - # Close the freebox session + # Close the Freebox session await fbx.close()