mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
string format -> f-function
This commit is contained in:
@@ -6,9 +6,7 @@ from common.exceptions import InvalidParameter
|
||||
|
||||
def parse_register_arguments(tower_id, host, port, config):
|
||||
if not isinstance(tower_id, str):
|
||||
raise InvalidParameter(
|
||||
"tower id must be a compressed public key (33-byte hex value) not {}".format(str(tower_id))
|
||||
)
|
||||
raise InvalidParameter(f"tower id must be a compressed public key (33-byte hex value) not {str(tower_id)}")
|
||||
|
||||
# tower_id is of the form tower_id@[ip][:][port]
|
||||
if "@" in tower_id:
|
||||
@@ -20,18 +18,18 @@ def parse_register_arguments(tower_id, host, port, config):
|
||||
|
||||
# Only host was specified or colons where specified but not port
|
||||
if ":" not in tower_netaddr or tower_netaddr.endswith(":"):
|
||||
tower_netaddr = "{}:{}".format(tower_netaddr, config.get("DEFAULT_PORT"))
|
||||
tower_netaddr = f"{tower_netaddr}:{config.get('DEFAULT_PORT')}"
|
||||
|
||||
else:
|
||||
raise InvalidParameter("cannot specify host as both xxx@yyy and separate arguments")
|
||||
|
||||
# host was specified, but no port, defaulting
|
||||
elif host:
|
||||
tower_netaddr = "{}:{}".format(host, config.get("DEFAULT_PORT"))
|
||||
tower_netaddr = f"{host}:{config.get('DEFAULT_PORT')}"
|
||||
|
||||
# host and port specified
|
||||
elif host and port:
|
||||
tower_netaddr = "{}:{}".format(host, port)
|
||||
tower_netaddr = f"{host}:{port}"
|
||||
|
||||
else:
|
||||
raise InvalidParameter("tower host is missing")
|
||||
|
||||
@@ -40,21 +40,17 @@ class TowersDBM(DBManager):
|
||||
if is_compressed_pk(tower_id):
|
||||
try:
|
||||
self.create_entry(tower_id, json.dumps(tower_data.to_dict()))
|
||||
self.plugin.log("Adding tower to Tower's db (id={})".format(tower_id))
|
||||
self.plugin.log(f"Adding tower to Tower's db (id={tower_id})")
|
||||
return True
|
||||
|
||||
except (json.JSONDecodeError, TypeError):
|
||||
self.plugin.log(
|
||||
"Could't add tower to db. Wrong tower data format (tower_id={}, tower_data={})".format(
|
||||
tower_id, tower_data
|
||||
)
|
||||
f"Could't add tower to db. Wrong tower data format (tower_id={tower_id}, tower_data={tower_data})"
|
||||
)
|
||||
return False
|
||||
|
||||
else:
|
||||
self.plugin.log(
|
||||
"Could't add user to db. Wrong pk format (tower_id={}, tower_data={})".format(tower_id, tower_data)
|
||||
)
|
||||
self.plugin.log(f"Could't add user to db. Wrong pk format (tower_id={tower_id}, tower_data={tower_data})")
|
||||
return False
|
||||
|
||||
def load_tower_record(self, tower_id):
|
||||
@@ -92,11 +88,11 @@ class TowersDBM(DBManager):
|
||||
|
||||
try:
|
||||
self.delete_entry(tower_id)
|
||||
self.plugin.log("Deleting tower from Tower's db (id={})".format(tower_id))
|
||||
self.plugin.log(f"Deleting tower from Tower's db (id={tower_id})")
|
||||
return True
|
||||
|
||||
except TypeError:
|
||||
self.plugin.log("Cannot delete user from db, user key has wrong type (id={})".format(tower_id))
|
||||
self.plugin.log(f"Cannot delete user from db, user key has wrong type (id={tower_id})")
|
||||
return False
|
||||
|
||||
def load_all_tower_records(self):
|
||||
|
||||
Reference in New Issue
Block a user