From 2180f28c7809bba16d57ded007838aae54547191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian-Samuel=20Geb=C3=BChr?= Date: Thu, 4 May 2023 10:47:06 +0200 Subject: [PATCH] Add support for diff and deploy for GTS --- mastodon_blocklist_deploy/models.py | 35 ++++------------------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/mastodon_blocklist_deploy/models.py b/mastodon_blocklist_deploy/models.py index c8284b4..b33e00d 100644 --- a/mastodon_blocklist_deploy/models.py +++ b/mastodon_blocklist_deploy/models.py @@ -11,12 +11,7 @@ class Instance: self.reject_reports = False self.id = None - """Remote blocks and local blocks are parsed differently""" - try: - instance_dict["id"] - self.parse_remote_block(instance_dict) - except KeyError: - self.parse_local_block(instance_dict) + self.parse_block(instance_dict) def __str__(self): return f"{self.domain}: {self.severity}" @@ -36,10 +31,10 @@ class Instance: exportable[key] = getattr(self, key) return exportable - def parse_remote_block(self, instance_dict): + def parse_block(self, instance_dict): # 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", ""), + properties_and_defaults = [("domain", None), ("severity", "suspend"), ("public_comment", ""), ("private_comment", ""), ("obfuscate", False), ("reject_media", True), ("reject_reports", True)] for key, default in properties_and_defaults: @@ -49,29 +44,7 @@ class Instance: 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: - self.name = instance_dict["name"] - except KeyError: - pass - self.domain = instance_dict["domain"] - self.severity = instance_dict["severity"] - self.public_comment = instance_dict["public_comment"] - self.private_comment = instance_dict["private_comment"] - try: - self.obfuscate = instance_dict["obfuscate"] - except KeyError: - pass - try: - self.reject_media = instance_dict["reject_media"] - except KeyError: - pass - try: - self.reject_reports = instance_dict["reject_reports"] - except KeyError: - pass + raise KeyError(f"The key {key} was not in the instance_dict response.") def apply(self, server, token, block_id=None): """Applies instance block on the remote server"""