From 93083020e5e6c0c966c5093474cf3eb0370d8859 Mon Sep 17 00:00:00 2001 From: Michael Ketchel Date: Tue, 5 Nov 2024 18:39:03 -0500 Subject: [PATCH] Fixed formatting --- wlanpi_core/models/network/wlan/exceptions.py | 2 + .../network/wlan/wlan_dbus_interface.py | 7 +- wlanpi_core/services/network_service.py | 75 +++++++++++++------ 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/wlanpi_core/models/network/wlan/exceptions.py b/wlanpi_core/models/network/wlan/exceptions.py index 6c57a32..d9fe2d2 100644 --- a/wlanpi_core/models/network/wlan/exceptions.py +++ b/wlanpi_core/models/network/wlan/exceptions.py @@ -5,9 +5,11 @@ class WlanDBUSException(Exception): class WlanDBUSInterfaceException(WlanDBUSException): pass + class WlanDBUSInterfaceCreationError(WlanDBUSInterfaceException): pass + class WDIScanError(WlanDBUSInterfaceException): pass diff --git a/wlanpi_core/models/network/wlan/wlan_dbus_interface.py b/wlanpi_core/models/network/wlan/wlan_dbus_interface.py index add89c3..e9d7372 100644 --- a/wlanpi_core/models/network/wlan/wlan_dbus_interface.py +++ b/wlanpi_core/models/network/wlan/wlan_dbus_interface.py @@ -19,7 +19,8 @@ WDIConnectionException, WDIDisconnectedException, WDIScanError, - WlanDBUSInterfaceException, WlanDBUSInterfaceCreationError, + WlanDBUSInterfaceCreationError, + WlanDBUSInterfaceException, ) from wlanpi_core.schemas.network import ( NetworkSetupStatus, @@ -63,7 +64,9 @@ def __init__( ) except dbus.DBusException as exc: if not str(exc).startswith("fi.w1.wpa_supplicant1.InterfaceUnknown:"): - raise WlanDBUSInterfaceCreationError(f"Interface unknown : {exc}") from exc + raise WlanDBUSInterfaceCreationError( + f"Interface unknown : {exc}" + ) from exc try: self.interface_dbus_path = self.wpa_supplicant.CreateInterface( {"Ifname": self.interface_name, "Driver": "nl80211"} diff --git a/wlanpi_core/services/network_service.py b/wlanpi_core/services/network_service.py index e6557d4..f90012a 100644 --- a/wlanpi_core/services/network_service.py +++ b/wlanpi_core/services/network_service.py @@ -2,7 +2,10 @@ from enum import Enum from typing import Optional -from wlanpi_core.models.network.wlan.exceptions import WlanDBUSException, WlanDBUSInterfaceCreationError +from wlanpi_core.models.network.wlan.exceptions import ( + WlanDBUSException, + WlanDBUSInterfaceCreationError, +) from wlanpi_core.models.network.wlan.wlan_dbus import WlanDBUS from wlanpi_core.models.network.wlan.wlan_dbus_interface import WlanDBUSInterface from wlanpi_core.models.validation_error import ValidationError @@ -24,8 +27,11 @@ async def get_systemd_network_interfaces(timeout: int): logging.info(f"Available interfaces: {available_interfaces}") return {"interfaces": available_interfaces} except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except WlanDBUSException as err: # Need to Split exceptions into validation and actual failures raise ValidationError(str(err), status_code=400) from err @@ -53,8 +59,11 @@ async def get_wireless_network_scan_async( "nets": await interface_obj.get_network_scan(scan_type, timeout=timeout) } except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except (WlanDBUSException, ValueError) as err: # Need to Split exceptions into validation and actual failures raise ValidationError(str(err), status_code=400) from err @@ -75,8 +84,11 @@ async def add_wireless_network( wlan_config=net_config, remove_others=remove_all_first, timeout=timeout ) except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except ValueError as error: raise ValidationError(f"{error}", status_code=400) @@ -89,8 +101,11 @@ async def get_current_wireless_network_details(interface: str, timeout: int): wlan_dbus = WlanDBUS() return wlan_dbus.get_interface(interface).get_current_network_details() except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except WlanDBUSException as err: raise ValidationError(str(err), status_code=400) from err @@ -106,8 +121,11 @@ async def disconnect_wireless_network( wlan_dbus = WlanDBUS() return wlan_dbus.get_interface(interface).disconnect() except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except ValueError as error: raise ValidationError(f"{error}", status_code=400) @@ -122,8 +140,11 @@ async def remove_all_networks( wlan_dbus = WlanDBUS() return wlan_dbus.get_interface(interface).remove_all_networks() except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except ValueError as error: raise ValidationError(f"{error}", status_code=400) @@ -139,8 +160,11 @@ async def remove_network( wlan_dbus = WlanDBUS() return wlan_dbus.get_interface(interface).remove_network(network_id) except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except ValueError as error: raise ValidationError(f"{error}", status_code=400) @@ -156,8 +180,11 @@ async def get_network( wlan_dbus = WlanDBUS() return wlan_dbus.get_interface(interface).get_network(network_id) except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except ValueError as error: raise ValidationError(f"{error}", status_code=400) @@ -172,8 +199,11 @@ async def networks( wlan_dbus = WlanDBUS() return wlan_dbus.get_interface(interface).networks() except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except ValueError as error: raise ValidationError(f"{error}", status_code=400) @@ -188,7 +218,10 @@ async def current_network( wlan_dbus = WlanDBUS() return wlan_dbus.get_interface(interface).current_network() except WlanDBUSInterfaceCreationError as error: - raise ValidationError("Could not create interface. Check that the requested interface exists.\n" - f"Original error: {str(error)}", status_code=400) + raise ValidationError( + "Could not create interface. Check that the requested interface exists.\n" + f"Original error: {str(error)}", + status_code=400, + ) except ValueError as error: raise ValidationError(f"{error}", status_code=400)