From 09c2df6be11181f3aa2fe5f99cede6331cebb07d Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 5 Aug 2024 10:34:41 +0100 Subject: [PATCH] Tidying --- utils.py | 61 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/utils.py b/utils.py index 225bd27c3..56d8e514a 100644 --- a/utils.py +++ b/utils.py @@ -5398,10 +5398,8 @@ def is_valid_date(date_str: str) -> bool: def resembles_url(text: str) -> bool: """Does the given text look like a url? """ - if '://' in text and \ - '.' in text and \ - ' ' not in text and \ - '<' not in text: + if '://' in text and '.' in text and \ + ' ' not in text and '<' not in text: return True return False @@ -5409,34 +5407,37 @@ def resembles_url(text: str) -> bool: def local_only_is_local(message_json: {}, domain_full: str) -> bool: """Returns True if the given json post is verified as local only """ - if message_json['object']['localOnly'] is True: - # check that the to addresses are local - if isinstance(message_json['object']['to'], list): - for to_actor in message_json['object']['to']: - to_domain, to_port = \ - get_domain_from_actor(to_actor) - if not to_domain: - continue - to_domain_full = \ - get_full_domain(to_domain, to_port) - if domain_full != to_domain_full: - print("REJECT: inbox " + - "local only post isn't local " + - str(message_json)) - return False - # check that the sender is local - attrib_field = message_json['object']['attributedTo'] - local_actor = get_attributed_to(attrib_field) - local_domain, local_port = \ - get_domain_from_actor(local_actor) - if local_domain: - local_domain_full = \ - get_full_domain(local_domain, local_port) - if domain_full != local_domain_full: - print("REJECT: " + - "inbox local only post isn't local " + + if message_json['object']['localOnly'] is not True: + return True + + # check that the to addresses are local + if isinstance(message_json['object']['to'], list): + for to_actor in message_json['object']['to']: + to_domain, to_port = \ + get_domain_from_actor(to_actor) + if not to_domain: + continue + to_domain_full = \ + get_full_domain(to_domain, to_port) + if domain_full != to_domain_full: + print("REJECT: inbox " + + "local only post isn't local " + str(message_json)) return False + + # check that the sender is local + attrib_field = message_json['object']['attributedTo'] + local_actor = get_attributed_to(attrib_field) + local_domain, local_port = \ + get_domain_from_actor(local_actor) + if local_domain: + local_domain_full = \ + get_full_domain(local_domain, local_port) + if domain_full != local_domain_full: + print("REJECT: " + + "inbox local only post isn't local " + + str(message_json)) + return False return True