From 1571d350e3a94e4982b7c9e63e3ac2486452f10a Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 28 Jun 2019 21:43:37 +0100 Subject: [PATCH] Consistent terminology --- daemon.py | 4 ++-- epicyon.py | 6 +++--- posts.py | 14 +++++++------- session.py | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/daemon.py b/daemon.py index da832f71..df8dcbaf 100644 --- a/daemon.py +++ b/daemon.py @@ -154,11 +154,11 @@ class PubServer(BaseHTTPRequestHandler): self._set_headers('application/json') self.wfile.write(json.dumps(message).encode('utf-8')) -def runDaemon(domain: str,port=80,allowedDomains,useTor=False) -> None: +def runDaemon(domain: str,port=80,fedList,useTor=False) -> None: global thisDomain global federationList thisDomain=domain - federationList=allowedDomains + federationList=fedList.copy() if len(domain)==0: domain='127.0.0.1' diff --git a/epicyon.py b/epicyon.py index 805a939b..c1165ee9 100644 --- a/epicyon.py +++ b/epicyon.py @@ -20,7 +20,7 @@ from httpsig import testHttpsig from daemon import runDaemon import socket -allowedDomains=['mastodon.social'] +federationList=['mastodon.social'] username='testuser' #domain=socket.gethostname() domain='mydomain.com' @@ -32,7 +32,7 @@ session = createSession(useTor) privateKeyPem,publicKeyPem,person,wfEndpoint=createPerson(username,domain,https,True) setPreferredUsername(username,domain,'badger') setBio(username,domain,'Some personal info') -runDaemon(domain,port,allowedDomains,useTor) +runDaemon(domain,port,federationList,useTor) #testHttpsig() #sys.exit() @@ -52,5 +52,5 @@ if not wfRequest: maxMentions=10 maxEmoji=10 maxAttachments=5 -userPosts = getUserPosts(session,wfRequest,2,maxMentions,maxEmoji,maxAttachments,allowedDomains) +userPosts = getUserPosts(session,wfRequest,2,maxMentions,maxEmoji,maxAttachments,federationList) print(str(userPosts)) diff --git a/posts.py b/posts.py index d6d87ef6..7fcdcbc4 100644 --- a/posts.py +++ b/posts.py @@ -16,10 +16,10 @@ try: except ImportError: from bs4 import BeautifulSoup -def permitted(url: str,allowedDomains) -> bool: +def permitted(url: str,federationList) -> bool: """Is a url from one of the permitted domains? """ - for domain in allowedDomains: + for domain in federationList: if domain in url: return True return False @@ -53,7 +53,7 @@ def parseUserFeed(session,feedUrl,asHeader) -> None: for item in parseUserFeed(session,nextUrl,asHeader): yield item -def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,allowedDomains) -> {}: +def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments,federationList) -> {}: userPosts={} asHeader = {'Accept': 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'} userUrl = getUserUrl(wfRequest) @@ -85,7 +85,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments, if tagItem.get('name') and tagItem.get('icon'): if tagItem['icon'].get('url'): # No emoji from non-permitted domains - if permitted(tagItem['icon']['url'],allowedDomains): + if permitted(tagItem['icon']['url'],federationList): emojiName=tagItem['name'] emojiIcon=tagItem['icon']['url'] emoji[emojiName]=emojiIcon @@ -107,7 +107,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments, if item['object'].get('inReplyTo'): if item['object']['inReplyTo']: # No replies to non-permitted domains - if not permitted(item['object']['inReplyTo'],allowedDomains): + if not permitted(item['object']['inReplyTo'],federationList): continue inReplyTo = item['object']['inReplyTo'] @@ -115,7 +115,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments, if item['object'].get('conversation'): if item['object']['conversation']: # no conversations originated in non-permitted domains - if permitted(item['object']['conversation'],allowedDomains): + if permitted(item['object']['conversation'],federationList): conversation = item['object']['conversation'] attachment = [] @@ -124,7 +124,7 @@ def getUserPosts(session,wfRequest,maxPosts,maxMentions,maxEmoji,maxAttachments, for attach in item['object']['attachment']: if attach.get('name') and attach.get('url'): # no attachments from non-permitted domains - if permitted(attach['url'],allowedDomains): + if permitted(attach['url'],federationList): attachment.append([attach['name'],attach['url']]) sensitive = False diff --git a/session.py b/session.py index 31e2f34e..ef5b3b44 100644 --- a/session.py +++ b/session.py @@ -28,12 +28,12 @@ def getJson(session,url: str,headers,params): session.cookies.clear() return session.get(url, headers=sessionHeaders, params=sessionParams).json() -def postJson(session,postJson,allowedDomains,inboxUrl: str): +def postJson(session,postJson,federationList,inboxUrl: str): """Post a json message to the inbox of another person """ # check that we are posting to a permitted domain permittedDomain=False - for domain in allowedDomains: + for domain in federationList: if domain in inboxUrl: permittedDomain=True break