diff --git a/announce.py b/announce.py index f39732979..814728c15 100644 --- a/announce.py +++ b/announce.py @@ -7,7 +7,7 @@ __email__ = "bob@freedombone.net" __status__ = "Production" __module_group__ = "ActivityPub" -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasObjectDict from utils import removeIdEnding from utils import hasUsersPath diff --git a/blocking.py b/blocking.py index 0c81fcd8a..128209aaa 100644 --- a/blocking.py +++ b/blocking.py @@ -11,7 +11,7 @@ import os import json import time from datetime import datetime -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasObjectDict from utils import isAccountDir from utils import getCachedPostFilename diff --git a/bookmarks.py b/bookmarks.py index 414f748bd..5cee25bc1 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -11,7 +11,7 @@ import os from pprint import pprint from webfinger import webfingerHandle from auth import createBasicAuthHeader -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasUsersPath from utils import getFullDomain from utils import removeIdEnding diff --git a/content.py b/content.py index be1eec89d..85f233767 100644 --- a/content.py +++ b/content.py @@ -11,7 +11,7 @@ import os import email.parser import urllib.parse from shutil import copyfile -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import isValidLanguage from utils import getImageExtensions from utils import loadJson diff --git a/delete.py b/delete.py index b51d5c7a0..834e8c46e 100644 --- a/delete.py +++ b/delete.py @@ -9,7 +9,7 @@ __module_group__ = "ActivityPub" import os from datetime import datetime -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasUsersPath from utils import getFullDomain from utils import removeIdEnding diff --git a/domainhandler.py b/domainhandler.py deleted file mode 100644 index b7875b32a..000000000 --- a/domainhandler.py +++ /dev/null @@ -1,32 +0,0 @@ -__filename__ = "domainhandler.py" -__author__ = "Bob Mottram" -__license__ = "AGPL3+" -__version__ = "1.2.0" -__maintainer__ = "Bob Mottram" -__email__ = "bob@freedombone.net" -__status__ = "Production" -__module_group__ = "Core" - - -def removeDomainPort(domain: str) -> str: - """If the domain has a port appended then remove it - eg. mydomain.com:80 becomes mydomain.com - """ - if ':' in domain: - if domain.startswith('did:'): - return domain - domain = domain.split(':')[0] - return domain - - -def getPortFromDomain(domain: str) -> int: - """If the domain has a port number appended then return it - eg. mydomain.com:80 returns 80 - """ - if ':' in domain: - if domain.startswith('did:'): - return None - portStr = domain.split(':')[1] - if portStr.isdigit(): - return int(portStr) - return None diff --git a/epicyon.py b/epicyon.py index 6e4abafdb..aa3966cea 100644 --- a/epicyon.py +++ b/epicyon.py @@ -61,8 +61,8 @@ from tests import testUpdateActor from tests import runAllTests from auth import storeBasicCredentials from auth import createPassword -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain +from utils import removeDomainPort +from utils import getPortFromDomain from utils import hasUsersPath from utils import getFullDomain from utils import setConfigParam diff --git a/follow.py b/follow.py index 2745c8ec5..096394dd4 100644 --- a/follow.py +++ b/follow.py @@ -9,7 +9,7 @@ __module_group__ = "ActivityPub" from pprint import pprint import os -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasObjectDict from utils import hasUsersPath from utils import getFullDomain diff --git a/followingCalendar.py b/followingCalendar.py index 68bef2973..af38b10b0 100644 --- a/followingCalendar.py +++ b/followingCalendar.py @@ -8,7 +8,18 @@ __status__ = "Production" __module_group__ = "Calendar" import os -from domainhandler import removeDomainPort + + +def _portDomainRemove(domain: str) -> str: + """If the domain has a port appended then remove it + eg. mydomain.com:80 becomes mydomain.com + same as removeDomainPort in utils.py + """ + if ':' in domain: + if domain.startswith('did:'): + return domain + domain = domain.split(':')[0] + return domain def receivingCalendarEvents(baseDir: str, nickname: str, domain: str, @@ -44,7 +55,7 @@ def _receiveCalendarEvents(baseDir: str, nickname: str, domain: str, indicating whether to receive calendar events from that account """ # check that a following file exists - domain = removeDomainPort(domain) + domain = _portDomainRemove(domain) followingFilename = baseDir + '/accounts/' + \ nickname + '@' + domain + '/following.txt' if not os.path.isfile(followingFilename): diff --git a/inbox.py b/inbox.py index 1f5c86e18..cbc5f2da6 100644 --- a/inbox.py +++ b/inbox.py @@ -13,8 +13,8 @@ import datetime import time import random from linked_data_sig import verifyJsonSignature -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain +from utils import removeDomainPort +from utils import getPortFromDomain from utils import hasObjectDict from utils import dmAllowedFromDomain from utils import isRecentPost diff --git a/like.py b/like.py index ee42afead..ad0bff5da 100644 --- a/like.py +++ b/like.py @@ -7,7 +7,7 @@ __email__ = "bob@freedombone.net" __status__ = "Production" __module_group__ = "ActivityPub" -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import hasObjectDict from utils import hasUsersPath from utils import getFullDomain diff --git a/manualapprove.py b/manualapprove.py index 91c78ffac..91948a344 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -12,8 +12,8 @@ from follow import followedAccountAccepts from follow import followedAccountRejects from follow import removeFromFollowRequests from utils import loadJson -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain +from utils import removeDomainPort +from utils import getPortFromDomain def manualDenyFollowRequest(session, baseDir: str, diff --git a/person.py b/person.py index e148397e2..2f5b357c2 100644 --- a/person.py +++ b/person.py @@ -38,7 +38,7 @@ from roles import setRole from roles import setRolesFromList from roles import getActorRolesList from media import processMetaData -from domainhandler import removeDomainPort +from utils import removeDomainPort from utils import getStatusNumber from utils import getFullDomain from utils import validNickname diff --git a/posts.py b/posts.py index 41713a7cc..230b7d72f 100644 --- a/posts.py +++ b/posts.py @@ -32,8 +32,8 @@ from session import postImage from webfinger import webfingerHandle from httpsig import createSignedHeader from siteactive import siteIsActive -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain +from utils import removeDomainPort +from utils import getPortFromDomain from utils import hasObjectDict from utils import rejectPostId from utils import removeInvalidChars diff --git a/roles.py b/roles.py index 7f9010c67..7fb00e38a 100644 --- a/roles.py +++ b/roles.py @@ -11,7 +11,7 @@ import os from utils import loadJson from utils import saveJson from utils import getStatusNumber -from domainhandler import removeDomainPort +from utils import removeDomainPort def _clearRoleStatus(baseDir: str, role: str) -> None: diff --git a/shares.py b/shares.py index 488a276fb..2a2261c7c 100644 --- a/shares.py +++ b/shares.py @@ -20,7 +20,7 @@ from utils import loadJson from utils import saveJson from utils import getImageExtensions from utils import hasObjectDict -from domainhandler import removeDomainPort +from utils import removeDomainPort from media import processMetaData diff --git a/tests.py b/tests.py index 55bd01b1c..d16baa84c 100644 --- a/tests.py +++ b/tests.py @@ -2900,6 +2900,7 @@ def _moduleInGroups(modName: str, includeGroups: [], modGroups: {}) -> bool: def _diagramGroups(includeGroups: [], + excludeExtraModules: [], modules: {}, modGroups: {}, maxModuleCalls: int) -> None: """Draws a dot diagram containing only the given module groups @@ -2907,9 +2908,10 @@ def _diagramGroups(includeGroups: [], callGraphStr = 'digraph EpicyonGroups {\n\n' callGraphStr += ' graph [fontsize=10 fontname="Verdana" compound=true];\n' callGraphStr += ' node [fontsize=10 fontname="Verdana"];\n\n' - excludeModulesFromDiagram = ( + excludeModulesFromDiagram = [ 'setup', 'tests', '__init__' - ) + ] + excludeModulesFromDiagram += excludeExtraModules # colors of modules nodes for modName, modProperties in modules.items(): if modName in excludeModulesFromDiagram: @@ -3223,15 +3225,21 @@ def _testFunctions(): modules[modName]['calls'] = [modCall] lineCtr += 1 - _diagramGroups(['Commandline Interface', 'ActivityPub', 'Core'], + _diagramGroups(['Commandline Interface', 'ActivityPub'], ['utils'], modules, modGroups, maxModuleCalls) - _diagramGroups(['Timeline', 'Core'], + _diagramGroups(['Commandline Interface', 'Core'], ['utils'], modules, modGroups, maxModuleCalls) - _diagramGroups(['Web Interface', 'Core'], + _diagramGroups(['Timeline', 'Core'], ['utils'], modules, modGroups, maxModuleCalls) - _diagramGroups(['Web Interface Columns', 'Core'], + _diagramGroups(['Web Interface', 'Core'], ['utils'], modules, modGroups, maxModuleCalls) - _diagramGroups(['Core'], + _diagramGroups(['Web Interface Columns', 'Core'], ['utils'], + modules, modGroups, maxModuleCalls) + _diagramGroups(['Core'], [], + modules, modGroups, maxModuleCalls) + _diagramGroups(['ActivityPub'], [], + modules, modGroups, maxModuleCalls) + _diagramGroups(['ActivityPub', 'Core'], ['utils'], modules, modGroups, maxModuleCalls) callGraphStr = 'digraph Epicyon {\n\n' diff --git a/utils.py b/utils.py index 5562aa794..c2a79642f 100644 --- a/utils.py +++ b/utils.py @@ -16,8 +16,6 @@ import json import idna import locale from pprint import pprint -from domainhandler import removeDomainPort -from domainhandler import getPortFromDomain from followingCalendar import addPersonToCalendar from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives import hashes @@ -2453,3 +2451,27 @@ def getActorPropertyUrl(actorJson: {}, propertyName: str) -> str: continue return propertyValue['value'] return '' + + +def removeDomainPort(domain: str) -> str: + """If the domain has a port appended then remove it + eg. mydomain.com:80 becomes mydomain.com + """ + if ':' in domain: + if domain.startswith('did:'): + return domain + domain = domain.split(':')[0] + return domain + + +def getPortFromDomain(domain: str) -> int: + """If the domain has a port number appended then return it + eg. mydomain.com:80 returns 80 + """ + if ':' in domain: + if domain.startswith('did:'): + return None + portStr = domain.split(':')[1] + if portStr.isdigit(): + return int(portStr) + return None diff --git a/webapp_calendar.py b/webapp_calendar.py index 14dbec8ca..65cdb7de0 100644 --- a/webapp_calendar.py +++ b/webapp_calendar.py @@ -19,7 +19,7 @@ from utils import locatePost from utils import loadJson from utils import weekDayOfMonthStart from utils import getAltPath -from domainhandler import removeDomainPort +from utils import removeDomainPort from happening import getTodaysEvents from happening import getCalendarEvents from webapp_utils import htmlHeaderWithExternalStyle diff --git a/webapp_column_left.py b/webapp_column_left.py index b3111b9a2..eea4ace02 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -11,7 +11,7 @@ import os from utils import getConfigParam from utils import getNicknameFromActor from utils import isEditor -from domainhandler import removeDomainPort +from utils import removeDomainPort from webapp_utils import sharesTimelineJson from webapp_utils import htmlPostSeparator from webapp_utils import getLeftImageFile diff --git a/webapp_column_right.py b/webapp_column_right.py index 17d1a0acf..3ea61e1c9 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -17,7 +17,7 @@ from utils import votesOnNewswireItem from utils import getNicknameFromActor from utils import isEditor from utils import getConfigParam -from domainhandler import removeDomainPort +from utils import removeDomainPort from posts import isModerator from webapp_utils import getRightImageFile from webapp_utils import htmlHeaderWithExternalStyle diff --git a/webfinger.py b/webfinger.py index c774a0c85..c82a5199c 100644 --- a/webfinger.py +++ b/webfinger.py @@ -17,7 +17,7 @@ from utils import loadJson from utils import loadJsonOnionify from utils import saveJson from utils import getProtocolPrefixes -from domainhandler import removeDomainPort +from utils import removeDomainPort def _parseHandle(handle: str) -> (str, str):