From d352b27dd859aeeb04de8e92b5dc2f28f62fb865 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 11 Jun 2020 13:04:42 +0100 Subject: [PATCH] Tidying --- inbox.py | 12 +++++------- utils.py | 30 ++++++++++++++---------------- 2 files changed, 19 insertions(+), 23 deletions(-) diff --git a/inbox.py b/inbox.py index 9a247ef76..66fb8b010 100644 --- a/inbox.py +++ b/inbox.py @@ -1359,14 +1359,12 @@ def receiveAnnounce(recentPostsCache: {}, messageJson['type']) return False + prefixes = ('https://', 'http://', 'dat://', 'i2p://', 'gnunet://', + 'hyper://', 'gemini://', 'gopher://') # is the domain of the announce actor blocked? - objectDomain = \ - messageJson['object'].replace('https://', '') - objectDomain = objectDomain.replace('http://', '') - objectDomain = objectDomain.replace('i2p://', '') - objectDomain = objectDomain.replace('gnunet://', '') - objectDomain = objectDomain.replace('dat://', '') - objectDomain = objectDomain.replace('hyper://', '') + objectDomain = messageJson['object'] + for prefix in prefixes: + objectDomain = objectDomain.replace(prefix, '') if '/' in objectDomain: objectDomain = objectDomain.split('/')[0] if isBlockedDomain(baseDir, objectDomain): diff --git a/utils.py b/utils.py index e51cf49d5..2e642dda0 100644 --- a/utils.py +++ b/utils.py @@ -228,30 +228,28 @@ def getDomainFromActor(actor: str) -> (str, int): """Returns the domain name from an actor url """ port = None + prefixes = ('https://', 'http://', 'dat://', 'i2p://', 'gnunet://', + 'hyper://', 'gemini://', 'gopher://') if '/profile/' in actor: - domain = actor.split('/profile/')[0].replace('https://', '') - domain = domain.replace('http://', '').replace('i2p://', '') - domain = domain.replace('dat://', '').replace('hyper://', '') - domain = domain.replace('gnunet://', '') + domain = actor.split('/profile/')[0] + for prefix in prefixes: + domain = domain.replace(prefix, '') else: if '/channel/' in actor: - domain = actor.split('/channel/')[0].replace('https://', '') - domain = domain.replace('http://', '').replace('i2p://', '') - domain = domain.replace('dat://', '').replace('hyper://', '') - domain = domain.replace('gnunet://', '') + domain = actor.split('/channel/')[0] + for prefix in prefixes: + domain = domain.replace(prefix, '') else: if '/users/' not in actor: - domain = actor.replace('https://', '').replace('http://', '') - domain = domain.replace('i2p://', '') - domain = domain.replace('dat://', '').replace('hyper://', '') - domain = domain.replace('gnunet://', '') + domain = actor + for prefix in prefixes: + domain = domain.replace(prefix, '') if '/' in actor: domain = domain.split('/')[0] else: - domain = actor.split('/users/')[0].replace('https://', '') - domain = domain.replace('http://', '').replace('i2p://', '') - domain = domain.replace('dat://', '').replace('hyper://', '') - domain = domain.replace('gnunet://', '') + domain = actor.split('/users/')[0] + for prefix in prefixes: + domain = domain.replace(prefix, '') if ':' in domain: portStr = domain.split(':')[1] if not portStr.isdigit():