From eeb95973d96213606b2bba0bb7898c4454d653c9 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Fri, 29 Oct 2021 23:40:09 +0100 Subject: [PATCH] Remove default arguments for better static analysis --- epicyon.py | 2 +- inbox.py | 4 ++-- posts.py | 10 +++++----- shares.py | 4 ++-- siteactive.py | 2 +- tests.py | 7 ++++--- threads.py | 2 +- utils.py | 7 +++---- webapp_media.py | 4 ++-- webapp_moderation.py | 4 ++-- webapp_post.py | 2 +- 11 files changed, 24 insertions(+), 24 deletions(-) diff --git a/epicyon.py b/epicyon.py index 912d0f48c..a0c9e1f64 100644 --- a/epicyon.py +++ b/epicyon.py @@ -2127,7 +2127,7 @@ if args.followers: followersList = \ downloadFollowCollection(signingPrivateKeyPem, 'followers', session, - httpPrefix, personUrl, 1, 3) + httpPrefix, personUrl, 1, 3, args.debug) if followersList: for actor in followersList: print(actor) diff --git a/inbox.py b/inbox.py index aa015c921..2ff5d6f83 100644 --- a/inbox.py +++ b/inbox.py @@ -1688,7 +1688,7 @@ def _receiveAnnounce(recentPostsCache: {}, if '/statuses/' in lookupActor: lookupActor = lookupActor.split('/statuses/')[0] - if isRecentPost(postJsonObject): + if isRecentPost(postJsonObject, 3): if not os.path.isfile(postFilename + '.tts'): domainFull = getFullDomain(domain, port) updateSpeaker(baseDir, httpPrefix, @@ -2945,7 +2945,7 @@ def _inboxAfterInitial(recentPostsCache: {}, maxRecentPosts: int, print('ERROR: unable to update ' + boxname + ' index') else: if boxname == 'inbox': - if isRecentPost(postJsonObject): + if isRecentPost(postJsonObject, 3): domainFull = getFullDomain(domain, port) updateSpeaker(baseDir, httpPrefix, nickname, domain, domainFull, diff --git a/posts.py b/posts.py index 464f52e76..71a87bbc9 100644 --- a/posts.py +++ b/posts.py @@ -2536,7 +2536,7 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str, toDomain = getFullDomain(toDomain, toPort) toDomainUrl = httpPrefix + '://' + toDomain - if not siteIsActive(toDomainUrl): + if not siteIsActive(toDomainUrl, 10): print('Domain is inactive: ' + toDomainUrl) return 9 print('Domain is active: ' + toDomainUrl) @@ -3043,7 +3043,7 @@ def sendToFollowers(session, baseDir: str, # check that the follower's domain is active followerDomainUrl = httpPrefix + '://' + followerDomain - if not siteIsActive(followerDomainUrl): + if not siteIsActive(followerDomainUrl, 10): print('Sending post to followers domain is inactive: ' + followerDomainUrl) continue @@ -3547,7 +3547,7 @@ def _createBoxIndexed(recentPostsCache: {}, nickname: str, domain: str, port: int, httpPrefix: str, itemsPerPage: int, headerOnly: bool, authorized: bool, newswireVotesThreshold: int, positiveVoting: bool, - votingTimeMins: int, pageNumber: int = None) -> {}: + votingTimeMins: int, pageNumber: int) -> {}: """Constructs the box feed for a person with the given nickname """ if not authorized or not pageNumber: @@ -4072,8 +4072,8 @@ def getPublicPostDomains(session, baseDir: str, nickname: str, domain: str, def downloadFollowCollection(signingPrivateKeyPem: str, followType: str, session, httpPrefix: str, - actor: str, pageNumber: int = 1, - noOfPages: int = 1, debug: bool = False) -> []: + actor: str, pageNumber: int, + noOfPages: int, debug: bool) -> []: """Returns a list of following/followers for the given actor by downloading the json for their following/followers collection """ diff --git a/shares.py b/shares.py index 57473901d..a00e47458 100644 --- a/shares.py +++ b/shares.py @@ -452,7 +452,7 @@ def getSharesFeedForPerson(baseDir: str, domain: str, port: int, path: str, httpPrefix: str, sharesFileType: str, - sharesPerPage: int = 12) -> {}: + sharesPerPage: int) -> {}: """Returns the shares for an account from GET requests """ if '/' + sharesFileType not in path: @@ -1574,7 +1574,7 @@ def _updateFederatedSharesCache(session, sharedItemsFederatedDomains: [], if not tokensJson.get(federatedDomainFull): # token has been obtained for the other domain continue - if not siteIsActive(httpPrefix + '://' + federatedDomainFull): + if not siteIsActive(httpPrefix + '://' + federatedDomainFull, 10): continue if sharesFileType == 'shares': url = httpPrefix + '://' + federatedDomainFull + '/catalog' diff --git a/siteactive.py b/siteactive.py index 368e59340..10394b503 100644 --- a/siteactive.py +++ b/siteactive.py @@ -93,7 +93,7 @@ def _siteActiveHttpRequest(loc, timeout: int): return result -def siteIsActive(url: str, timeout: int = 10) -> bool: +def siteIsActive(url: str, timeout: int) -> bool: """Returns true if the current url is resolvable. This can be used to check that an instance is online before trying to send posts to it. diff --git a/tests.py b/tests.py index 911d49d54..28870da73 100644 --- a/tests.py +++ b/tests.py @@ -3579,9 +3579,10 @@ def _testJsonld(): def _testSiteIsActive(): print('testSiteIsActive') - assert(siteIsActive('https://archive.org')) - assert(siteIsActive('https://mastodon.social')) - assert(not siteIsActive('https://notarealwebsite.a.b.c')) + timeout = 10 + assert(siteIsActive('https://archive.org', timeout)) + assert(siteIsActive('https://mastodon.social', timeout)) + assert(not siteIsActive('https://notarealwebsite.a.b.c', timeout)) def _testRemoveHtml(): diff --git a/threads.py b/threads.py index 28a10a0bc..c4d3be8a8 100644 --- a/threads.py +++ b/threads.py @@ -75,7 +75,7 @@ class threadWithTrace(threading.Thread): def removeDormantThreads(baseDir: str, threadsList: [], debug: bool, - timeoutMins: int = 30) -> None: + timeoutMins: int) -> None: """Removes threads whose execution has completed """ if len(threadsList) == 0: diff --git a/utils.py b/utils.py index ec2621d45..72856f336 100644 --- a/utils.py +++ b/utils.py @@ -209,8 +209,7 @@ def hasUsersPath(pathStr: str) -> bool: return False -def validPostDate(published: str, maxAgeDays: int = 90, - debug: bool = False) -> bool: +def validPostDate(published: str, maxAgeDays: int, debug: bool) -> bool: """Returns true if the published date is recent and is not in the future """ baselineTime = datetime.datetime(1970, 1, 1) @@ -254,7 +253,7 @@ def getFullDomain(domain: str, port: int) -> str: def isDormant(baseDir: str, nickname: str, domain: str, actor: str, - dormantMonths: int = 3) -> bool: + dormantMonths: int) -> bool: """Is the given followed actor dormant, from the standpoint of the given account """ @@ -2433,7 +2432,7 @@ def mediaFileMimeType(filename: str) -> str: return extensions[fileExt] -def isRecentPost(postJsonObject: {}, maxDays: int = 3) -> bool: +def isRecentPost(postJsonObject: {}, maxDays: int) -> bool: """ Is the given post recent? """ if not hasObjectDict(postJsonObject): diff --git a/webapp_media.py b/webapp_media.py index aa01b74b4..a20f06fa4 100644 --- a/webapp_media.py +++ b/webapp_media.py @@ -32,7 +32,7 @@ def loadPeertubeInstances(baseDir: str, peertubeInstances: []) -> None: def _addEmbeddedVideoFromSites(translate: {}, content: str, peertubeInstances: [], - width: int = 400, height: int = 300) -> str: + width: int, height: int) -> str: """Adds embedded videos """ if '>vimeo.com/' in content: @@ -250,6 +250,6 @@ def addEmbeddedElements(translate: {}, content: str, """Adds embedded elements for various media types """ content = _addEmbeddedVideoFromSites(translate, content, - peertubeInstances) + peertubeInstances, 400, 300) content = _addEmbeddedAudio(translate, content) return _addEmbeddedVideo(translate, content) diff --git a/webapp_moderation.py b/webapp_moderation.py index 21009939a..5b421fbbd 100644 --- a/webapp_moderation.py +++ b/webapp_moderation.py @@ -132,7 +132,7 @@ def htmlAccountInfo(cssCache: {}, translate: {}, followersList = \ downloadFollowCollection(signingPrivateKeyPem, 'followers', session, - httpPrefix, searchActor, 1, 5) + httpPrefix, searchActor, 1, 5, debug) blockedFollowers = [] for followerActor in followersList: followerNickname = getNicknameFromActor(followerActor) @@ -146,7 +146,7 @@ def htmlAccountInfo(cssCache: {}, translate: {}, followingList = \ downloadFollowCollection(signingPrivateKeyPem, 'following', session, - httpPrefix, searchActor, 1, 5) + httpPrefix, searchActor, 1, 5, debug) blockedFollowing = [] for followingActor in followingList: followingNickname = getNicknameFromActor(followingActor) diff --git a/webapp_post.py b/webapp_post.py index 74d90a6b1..e05d521a7 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -1403,7 +1403,7 @@ def individualPostAsHtml(signingPrivateKeyPem: str, postActor, nickname, domainFull, False) # create a file for use by text-to-speech - if isRecentPost(postJsonObject): + if isRecentPost(postJsonObject, 3): if postJsonObject.get('actor'): if not os.path.isfile(announceFilename + '.tts'): updateSpeaker(baseDir, httpPrefix,