diff --git a/roles.py b/roles.py index 22db327b..ecbf237b 100644 --- a/roles.py +++ b/roles.py @@ -11,6 +11,7 @@ from webfinger import webfingerHandle from auth import createBasicAuthHeader from posts import getPersonBox from session import postJson +from utils import getFullDomain from utils import getNicknameFromActor from utils import getDomainFromActor from utils import loadJson @@ -259,12 +260,7 @@ def sendRoleViaServer(baseDir: str, session, print('WARN: No session for sendRoleViaServer') return 6 - delegatorDomainFull = delegatorDomain - if delegatorPort: - if delegatorPort != 80 and delegatorPort != 443: - if ':' not in delegatorDomain: - delegatorDomainFull = \ - delegatorDomain + ':' + str(delegatorPort) + delegatorDomainFull = getFullDomain(delegatorDomain, delegatorPort) toUrl = \ httpPrefix + '://' + delegatorDomainFull + '/users/' + nickname diff --git a/shares.py b/shares.py index d4b19b36..1926395a 100644 --- a/shares.py +++ b/shares.py @@ -13,6 +13,7 @@ from auth import createBasicAuthHeader from posts import getPersonBox from session import postJson from session import postImage +from utils import getFullDomain from utils import validNickname from utils import loadJson from utils import saveJson @@ -115,11 +116,7 @@ def addShare(baseDir: str, imageFilename = sharesImageFilename + '.' + ext moveImage = True - domainFull = domain - if port: - if port != 80 and port != 443: - if ':' not in domain: - domainFull = domain + ':' + str(port) + domainFull = getFullDomain(domain, port) # copy or move the image for the shared item to its destination if imageFilename: @@ -247,10 +244,7 @@ def getSharesFeedForPerson(baseDir: str, if not validNickname(domain, nickname): return None - if port: - if port != 80 and port != 443: - if ':' not in domain: - domain = domain + ':' + str(port) + domain = getFullDomain(domain, port) handleDomain = domain if ':' in handleDomain: @@ -331,11 +325,7 @@ def sendShareViaServer(baseDir, session, print('WARN: No session for sendShareViaServer') return 6 - fromDomainFull = fromDomain - if fromPort: - if fromPort != 80 and fromPort != 443: - if ':' not in fromDomain: - fromDomainFull = fromDomain + ':' + str(fromPort) + fromDomainFull = getFullDomain(fromDomain, fromPort) toUrl = 'https://www.w3.org/ns/activitystreams#Public' ccUrl = httpPrefix + '://' + fromDomainFull + \ @@ -439,11 +429,7 @@ def sendUndoShareViaServer(baseDir: str, session, print('WARN: No session for sendUndoShareViaServer') return 6 - fromDomainFull = fromDomain - if fromPort: - if fromPort != 80 and fromPort != 443: - if ':' not in fromDomain: - fromDomainFull = fromDomain + ':' + str(fromPort) + fromDomainFull = getFullDomain(fromDomain, fromPort) toUrl = 'https://www.w3.org/ns/activitystreams#Public' ccUrl = httpPrefix + '://' + fromDomainFull + \ diff --git a/skills.py b/skills.py index 175e6ab0..2b4930ff 100644 --- a/skills.py +++ b/skills.py @@ -11,6 +11,7 @@ from webfinger import webfingerHandle from auth import createBasicAuthHeader from posts import getPersonBox from session import postJson +from utils import getFullDomain from utils import getNicknameFromActor from utils import getDomainFromActor from utils import loadJson @@ -108,11 +109,7 @@ def sendSkillViaServer(baseDir: str, session, nickname: str, password: str, print('WARN: No session for sendSkillViaServer') return 6 - domainFull = domain - if port: - if port != 80 and port != 443: - if ':' not in domain: - domainFull = domain + ':' + str(port) + domainFull = getFullDomain(domain, port) actor = httpPrefix + '://' + domainFull + '/users/' + nickname toUrl = actor diff --git a/tests.py b/tests.py index d23a0869..654f977b 100644 --- a/tests.py +++ b/tests.py @@ -33,6 +33,7 @@ from follow import clearFollows from follow import clearFollowers from follow import sendFollowRequestViaServer from follow import sendUnfollowRequestViaServer +from utils import getFullDomain from utils import validNickname from utils import firstParagraphFromString from utils import removeIdEnding @@ -127,11 +128,7 @@ def testHttpsigBase(withDigest): } messageBodyJsonStr = json.dumps(messageBodyJson) - headersDomain = domain - if port: - if port != 80 and port != 443: - if ':' not in domain: - headersDomain = domain + ':' + str(port) + headersDomain = getFullDomain(domain, port) dateStr = strftime("%a, %d %b %Y %H:%M:%S %Z", gmtime()) boxpath = '/inbox' diff --git a/webapp_confirm.py b/webapp_confirm.py index a7396f9d..a0f87f74 100644 --- a/webapp_confirm.py +++ b/webapp_confirm.py @@ -8,6 +8,7 @@ __status__ = "Production" import os from shutil import copyfile +from utils import getFullDomain from utils import getNicknameFromActor from utils import getDomainFromActor from utils import locatePost @@ -35,10 +36,7 @@ def htmlConfirmDelete(cssCache: {}, actor = messageId.split('/statuses/')[0] nickname = getNicknameFromActor(actor) domain, port = getDomainFromActor(actor) - domainFull = domain - if port: - if port != 80 and port != 443: - domainFull = domain + ':' + str(port) + domainFull = getFullDomain(domain, port) postFilename = locatePost(baseDir, nickname, domain, messageId) if not postFilename: @@ -103,10 +101,7 @@ def htmlConfirmRemoveSharedItem(cssCache: {}, translate: {}, baseDir: str, itemID = getValidSharedItemID(shareName) nickname = getNicknameFromActor(actor) domain, port = getDomainFromActor(actor) - domainFull = domain - if port: - if port != 80 and port != 443: - domainFull = domain + ':' + str(port) + domainFull = getFullDomain(domain, port) sharesFile = baseDir + '/accounts/' + \ nickname + '@' + domain + '/shares.json' if not os.path.isfile(sharesFile): diff --git a/webapp_person_options.py b/webapp_person_options.py index b18d5460..e27189b5 100644 --- a/webapp_person_options.py +++ b/webapp_person_options.py @@ -11,6 +11,7 @@ from shutil import copyfile from petnames import getPetName from person import isPersonSnoozed from posts import isModerator +from utils import getFullDomain from utils import isDormant from utils import removeHtml from utils import getDomainFromActor @@ -45,10 +46,7 @@ def htmlPersonOptions(defaultTimeline: str, """Show options for a person: view/follow/block/report """ optionsDomain, optionsPort = getDomainFromActor(optionsActor) - optionsDomainFull = optionsDomain - if optionsPort: - if optionsPort != 80 and optionsPort != 443: - optionsDomainFull = optionsDomain + ':' + str(optionsPort) + optionsDomainFull = getFullDomain(optionsDomain, optionsPort) if os.path.isfile(baseDir + '/accounts/options-background-custom.jpg'): if not os.path.isfile(baseDir + '/accounts/options-background.jpg'): @@ -74,10 +72,7 @@ def htmlPersonOptions(defaultTimeline: str, dormantMonths) optionsNickname = getNicknameFromActor(optionsActor) - optionsDomainFull = optionsDomain - if optionsPort: - if optionsPort != 80 and optionsPort != 443: - optionsDomainFull = optionsDomain + ':' + str(optionsPort) + optionsDomainFull = getFullDomain(optionsDomain, optionsPort) if isBlocked(baseDir, nickname, domain, optionsNickname, optionsDomainFull): blockStr = 'Block' diff --git a/webapp_post.py b/webapp_post.py index e788ac6e..5ad02932 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -22,6 +22,7 @@ from posts import getPersonBox from posts import isDM from posts import downloadAnnounce from posts import populateRepliesJson +from utils import getFullDomain from utils import isEditor from utils import locatePost from utils import loadJson @@ -1135,11 +1136,7 @@ def individualPostAsHtml(allowDownloads: bool, if messageId: messageIdStr = ';' + messageId - domainFull = domain - if port: - if port != 80 and port != 443: - if ':' not in domain: - domainFull = domain + ':' + str(port) + domainFull = getFullDomain(domain, port) pageNumberParam = '' if pageNumber: @@ -1604,19 +1601,14 @@ def htmlIndividualPost(cssCache: {}, if likedBy: likedByNickname = getNicknameFromActor(likedBy) likedByDomain, likedByPort = getDomainFromActor(likedBy) - if likedByPort: - if likedByPort != 80 and likedByPort != 443: - likedByDomain += ':' + str(likedByPort) + likedByDomain = getFullDomain(likedByDomain, likedByPort) likedByHandle = likedByNickname + '@' + likedByDomain postStr += \ '
' + translate['Liked by'] + \ ' @' + \ likedByHandle + '\n' - domainFull = domain - if port: - if port != 80 and port != 443: - domainFull = domain + ':' + str(port) + domainFull = getFullDomain(domain, port) actor = '/users/' + nickname followStr = '