From 27168a2a6e8fb0a40ba074476951b1d8afd30762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Thu, 4 May 2023 10:38:25 +0200 Subject: [PATCH] Allow missing values of remote block for GTS support --- mastodon_blocklist_deploy/models.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/mastodon_blocklist_deploy/models.py b/mastodon_blocklist_deploy/models.py index 7b360a1..c8284b4 100644 --- a/mastodon_blocklist_deploy/models.py +++ b/mastodon_blocklist_deploy/models.py @@ -37,14 +37,19 @@ class Instance: return exportable def parse_remote_block(self, instance_dict): - self.domain = instance_dict["domain"] - self.id = instance_dict["id"] - self.severity = instance_dict["severity"] - self.public_comment = instance_dict["public_comment"] - self.private_comment = instance_dict["private_comment"] - self.obfuscate = instance_dict["obfuscate"] - self.reject_media = instance_dict["reject_media"] - self.reject_reports = instance_dict["reject_reports"] + # this specifies possible properties and default values if not found on the remote source. If a default is None + # the value is required and the parse will fail + properties_and_defaults = [("domain", None), ("id", None), ("severity", "suspend"), ("public_comment", ""), + ("private_comment", ""), ("obfuscate", False), ("reject_media", True), + ("reject_reports", True)] + for key, default in properties_and_defaults: + try: + setattr(self, key, instance_dict[key]) + except KeyError: + if default is not None: + setattr(self, key, default) + else: + raise KeyError(f"The key {key} was not in the remote servers response.") def parse_local_block(self, instance_dict): try: