From c68b94f9b1d23661b2c659882d03b57b6ae926de Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Thu, 11 Jun 2020 13:16:45 +0100 Subject: [PATCH] Tidying --- epicyon.py | 10 ++++------ webfinger.py | 9 +++++---- webinterface.py | 40 ++++++++++++++++++++++------------------ 3 files changed, 31 insertions(+), 28 deletions(-) diff --git a/epicyon.py b/epicyon.py index 46b0cce3..4f923da5 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1041,12 +1041,10 @@ if args.actor: args.actor.startswith('http') or \ args.actor.startswith('dat'): # format: https://domain/@nick - args.actor = args.actor.replace('https://', '') - args.actor = args.actor.replace('http://', '') - args.actor = args.actor.replace('gnunet://', '') - args.actor = args.actor.replace('dat://', '') - args.actor = args.actor.replace('hyper://', '') - args.actor = args.actor.replace('i2p://', '') + prefixes = ('https://', 'http://', 'dat://', 'i2p://', 'gnunet://', + 'hyper://', 'gemini://', 'gopher://') + for prefix in prefixes: + args.actor = args.actor.replace(prefix, '') args.actor = args.actor.replace('/@', '/users/') if '/users/' not in args.actor and \ '/channel/' not in args.actor and \ diff --git a/webfinger.py b/webfinger.py index 02976fab..b3a0f3d7 100644 --- a/webfinger.py +++ b/webfinger.py @@ -26,10 +26,11 @@ from utils import saveJson def parseHandle(handle: str) -> (str, str): if '.' not in handle: return None, None - handleStr = handle.replace('https://', '').replace('http://', '') - handleStr = handleStr.replace('dat://', '').replace('hyper://', '') - handleStr = handleStr.replace('i2p://', '') - handleStr = handleStr.replace('gnunet://', '') + prefixes = ('https://', 'http://', 'dat://', 'i2p://', 'gnunet://', + 'hyper://', 'gemini://', 'gopher://') + handleStr = handle + for prefix in prefixes: + handleStr = handleStr.replace(prefix, '') if '/@' in handle: domain, nickname = handleStr.split('/@') else: diff --git a/webinterface.py b/webinterface.py index 5938e996..73c3cd1f 100644 --- a/webinterface.py +++ b/webinterface.py @@ -100,12 +100,14 @@ def getBlogAddress(actorJson: {}) -> str: if propertyValue['type'] != 'PropertyValue': continue propertyValue['value'] = propertyValue['value'].strip() - if not (propertyValue['value'].startswith('https://') or - propertyValue['value'].startswith('http://') or - propertyValue['value'].startswith('gnunet://') or - propertyValue['value'].startswith('dat://') or - propertyValue['value'].startswith('hyper://') or - propertyValue['value'].startswith('i2p://')): + prefixes = ('https://', 'http://', 'dat://', 'i2p://', 'gnunet://', + 'hyper://', 'gemini://', 'gopher://') + prefixFound = False + for prefix in prefixes: + if propertyValue['value'].startswith(prefix): + prefixFound = True + break + if not prefixFound: continue if '.' not in propertyValue['value']: continue @@ -137,12 +139,15 @@ def setBlogAddress(actorJson: {}, blogAddress: str) -> None: if propertyFound: actorJson['attachment'].remove(propertyFound) - if not (blogAddress.startswith('https://') or - blogAddress.startswith('http://') or - blogAddress.startswith('gnunet://') or - blogAddress.startswith('dat://') or - blogAddress.startswith('hyper://') or - blogAddress.startswith('i2p://')): + prefixes = ('https://', 'http://', 'dat://', 'i2p://', + 'gnunet://', 'hyper://', 'gemini://', + 'gopher://') + prefixFound = False + for prefix in prefixes: + if blogAddress.startswith(prefix): + prefixFound = True + break + if not prefixFound: return if '.' not in blogAddress: return @@ -4002,12 +4007,11 @@ def individualPostAsHtml(recentPostsCache: {}, maxRecentPosts: int, else: postDomain = \ postJsonObject['object']['inReplyTo'] - postDomain = postDomain.replace('https://', '') - postDomain = postDomain.replace('http://', '') - postDomain = postDomain.replace('hyper://', '') - postDomain = postDomain.replace('gnunet://', '') - postDomain = postDomain.replace('dat://', '') - postDomain = postDomain.replace('i2p://', '') + prefixes = ('https://', 'http://', 'dat://', 'i2p://', + 'gnunet://', 'hyper://', 'gemini://', + 'gopher://') + for prefix in prefixes: + postDomain = postDomain.replace(prefix, '') if '/' in postDomain: postDomain = postDomain.split('/', 1)[0] if postDomain: