From 5e2b02ad8166e57c9004abe16a986d64f8242876 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 13 Jul 2021 15:40:49 +0100 Subject: [PATCH] File open attribute style --- auth.py | 6 +++--- blocking.py | 2 +- blog.py | 8 ++++---- city.py | 4 ++-- content.py | 4 ++-- follow.py | 14 +++++++------- happening.py | 4 ++-- migrate.py | 6 +++--- newsdaemon.py | 4 ++-- person.py | 12 ++++++------ posts.py | 20 ++++++++++---------- question.py | 4 ++-- roles.py | 6 +++--- tests.py | 8 ++++---- threads.py | 2 +- utils.py | 18 +++++++++--------- webapp_column_left.py | 2 +- webapp_column_right.py | 2 +- webapp_create_post.py | 2 +- webapp_moderation.py | 6 +++--- webapp_profile.py | 10 +++++----- webapp_search.py | 4 ++-- 22 files changed, 74 insertions(+), 74 deletions(-) diff --git a/auth.py b/auth.py index 42cf25fa2..02db756c6 100644 --- a/auth.py +++ b/auth.py @@ -132,7 +132,7 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str, print('DEBUG: passwords file missing') return False providedPassword = plain.split(':')[1] - passfile = open(passwordFile, "r") + passfile = open(passwordFile, 'r') for line in passfile: if line.startswith(nickname + ':'): storedPassword = \ @@ -162,7 +162,7 @@ def storeBasicCredentials(baseDir: str, nickname: str, password: str) -> bool: storeStr = nickname + ':' + _hashPassword(password) if os.path.isfile(passwordFile): if nickname + ':' in open(passwordFile).read(): - with open(passwordFile, "r") as fin: + with open(passwordFile, 'r') as fin: with open(passwordFile + '.new', 'w+') as fout: for line in fin: if not line.startswith(nickname + ':'): @@ -186,7 +186,7 @@ def removePassword(baseDir: str, nickname: str) -> None: """ passwordFile = baseDir + '/accounts/passwords' if os.path.isfile(passwordFile): - with open(passwordFile, "r") as fin: + with open(passwordFile, 'r') as fin: with open(passwordFile + '.new', 'w+') as fout: for line in fin: if not line.startswith(nickname + ':'): diff --git a/blocking.py b/blocking.py index 128209aaa..c26b07728 100644 --- a/blocking.py +++ b/blocking.py @@ -720,7 +720,7 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None: followingFilename = accountDir + '/' + followFileType if not os.path.isfile(followingFilename): continue - with open(followingFilename, "r") as f: + with open(followingFilename, 'r') as f: followList = f.readlines() for handle in followList: if '@' not in handle: diff --git a/blog.py b/blog.py index ef8aed4c5..45c71dd79 100644 --- a/blog.py +++ b/blog.py @@ -65,7 +65,7 @@ def _noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {}, removals = [] replies = 0 lines = [] - with open(postFilename, "r") as f: + with open(postFilename, 'r') as f: lines = f.readlines() for replyPostId in lines: replyPostId = replyPostId.replace('\n', '').replace('\r', '') @@ -124,11 +124,11 @@ def _getBlogReplies(baseDir: str, httpPrefix: str, translate: {}, '/postcache/' + \ postId.replace('/', '#') + '.html' if os.path.isfile(postFilename): - with open(postFilename, "r") as postFile: + with open(postFilename, 'r') as postFile: return postFile.read() + '\n' return '' - with open(postFilename, "r") as f: + with open(postFilename, 'r') as f: lines = f.readlines() repliesStr = '' for replyPostId in lines: @@ -141,7 +141,7 @@ def _getBlogReplies(baseDir: str, httpPrefix: str, translate: {}, replyPostId.replace('/', '#') + '.html' if not os.path.isfile(postFilename): continue - with open(postFilename, "r") as postFile: + with open(postFilename, 'r') as postFile: repliesStr += postFile.read() + '\n' rply = _getBlogReplies(baseDir, httpPrefix, translate, nickname, domain, domainFull, diff --git a/city.py b/city.py index 8a31a7801..4fa0049e4 100644 --- a/city.py +++ b/city.py @@ -195,7 +195,7 @@ def spoofGeolocation(baseDir: str, default_latdirection, default_longdirection, "", "", 0) cities = [] - with open(locationsFilename, "r") as f: + with open(locationsFilename, 'r') as f: cities = f.readlines() nogo = [] @@ -203,7 +203,7 @@ def spoofGeolocation(baseDir: str, nogo = nogoList else: if os.path.isfile(nogoFilename): - with open(nogoFilename, "r") as f: + with open(nogoFilename, 'r') as f: nogoList = f.readlines() for line in nogoList: if line.startswith(city + ':'): diff --git a/content.py b/content.py index 253740358..ff384c7f8 100644 --- a/content.py +++ b/content.py @@ -709,7 +709,7 @@ def _loadAutoTags(baseDir: str, nickname: str, domain: str) -> []: nickname + '@' + domain + '/autotags.txt' if not os.path.isfile(filename): return [] - with open(filename, "r") as f: + with open(filename, 'r') as f: return f.readlines() return [] @@ -784,7 +784,7 @@ def addHtmlTags(baseDir: str, httpPrefix: str, petnames = None if '@' in words: if os.path.isfile(followingFilename): - with open(followingFilename, "r") as f: + with open(followingFilename, 'r') as f: following = f.readlines() for handle in following: pet = getPetName(baseDir, nickname, domain, handle) diff --git a/follow.py b/follow.py index 76129fe55..9389a55e1 100644 --- a/follow.py +++ b/follow.py @@ -257,7 +257,7 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str, print('DEBUG: handle to unfollow ' + handleToUnfollow + ' is not in ' + filename) return - with open(filename, "r") as f: + with open(filename, 'r') as f: lines = f.readlines() with open(filename, 'w+') as f: for line in lines: @@ -271,10 +271,10 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str, if os.path.isfile(unfollowedFilename): if handleToUnfollowLower not in \ open(unfollowedFilename).read().lower(): - with open(unfollowedFilename, "a+") as f: + with open(unfollowedFilename, 'a+') as f: f.write(handleToUnfollow + '\n') else: - with open(unfollowedFilename, "w+") as f: + with open(unfollowedFilename, 'w+') as f: f.write(handleToUnfollow + '\n') return True @@ -324,7 +324,7 @@ def _getNoOfFollows(baseDir: str, nickname: str, domain: str, if not os.path.isfile(filename): return 0 ctr = 0 - with open(filename, "r") as f: + with open(filename, 'r') as f: lines = f.readlines() for line in lines: if '#' in line: @@ -435,7 +435,7 @@ def getFollowingFeed(baseDir: str, domain: str, port: int, path: str, currPage = 1 pageCtr = 0 totalCtr = 0 - with open(filename, "r") as f: + with open(filename, 'r') as f: lines = f.readlines() for line in lines: if '#' not in line: @@ -516,7 +516,7 @@ def _noOfFollowRequests(baseDir: str, if not os.path.isfile(approveFollowsFilename): return 0 ctr = 0 - with open(approveFollowsFilename, "r") as f: + with open(approveFollowsFilename, 'r') as f: lines = f.readlines() if followType == "onion": for fileLine in lines: @@ -600,7 +600,7 @@ def _storeFollowRequest(baseDir: str, print('DEBUG: ' + approveHandleStored + ' is already awaiting approval') else: - with open(approveFollowsFilename, "w+") as fp: + with open(approveFollowsFilename, 'w+') as fp: fp.write(approveHandleStored + '\n') # store the follow request in its own directory diff --git a/happening.py b/happening.py index 2a6b2e842..25ff7ff67 100644 --- a/happening.py +++ b/happening.py @@ -441,11 +441,11 @@ def removeCalendarEvent(baseDir: str, nickname: str, domain: str, if messageId not in open(calendarFilename).read(): return lines = None - with open(calendarFilename, "r") as f: + with open(calendarFilename, 'r') as f: lines = f.readlines() if not lines: return - with open(calendarFilename, "w+") as f: + with open(calendarFilename, 'w+') as f: for line in lines: if messageId not in line: f.write(line) diff --git a/migrate.py b/migrate.py index bae02eb61..94fafe932 100644 --- a/migrate.py +++ b/migrate.py @@ -29,7 +29,7 @@ def _moveFollowingHandlesForAccount(baseDir: str, nickname: str, domain: str, baseDir + '/accounts/' + nickname + '@' + domain + '/following.txt' if not os.path.isfile(followingFilename): return ctr - with open(followingFilename, "r") as f: + with open(followingFilename, 'r') as f: followingHandles = f.readlines() for followHandle in followingHandles: followHandle = followHandle.strip("\n").strip("\r") @@ -114,7 +114,7 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str, followingFilename = \ baseDir + '/accounts/' + nickname + '@' + domain + '/following.txt' if os.path.isfile(followingFilename): - with open(followingFilename, "r") as f: + with open(followingFilename, 'r') as f: followingHandles = f.readlines() movedToHandle = movedToNickname + '@' + movedToDomainFull @@ -152,7 +152,7 @@ def _updateMovedHandle(baseDir: str, nickname: str, domain: str, followersFilename = \ baseDir + '/accounts/' + nickname + '@' + domain + '/followers.txt' if os.path.isfile(followersFilename): - with open(followersFilename, "r") as f: + with open(followersFilename, 'r') as f: followerHandles = f.readlines() handleLower = handle.lower() diff --git a/newsdaemon.py b/newsdaemon.py index ffb5a5abf..71913bb9a 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -374,7 +374,7 @@ def _newswireHashtagProcessing(session, baseDir: str, postJsonObject: {}, if not os.path.isfile(rulesFilename): return True rules = [] - with open(rulesFilename, "r") as f: + with open(rulesFilename, 'r') as f: rules = f.readlines() domainFull = getFullDomain(domain, port) @@ -471,7 +471,7 @@ def _createNewsMirror(baseDir: str, domain: str, for removePostId in removals: indexContent = \ indexContent.replace(removePostId + '\n', '') - with open(mirrorIndexFilename, "w+") as indexFile: + with open(mirrorIndexFilename, 'w+') as indexFile: indexFile.write(indexContent) mirrorArticleDir = mirrorDir + '/' + postIdNumber diff --git a/person.py b/person.py index 1f9d3cd12..98f16d737 100644 --- a/person.py +++ b/person.py @@ -872,7 +872,7 @@ def reenableAccount(baseDir: str, nickname: str) -> None: suspendedFilename = baseDir + '/accounts/suspended.txt' if os.path.isfile(suspendedFilename): lines = [] - with open(suspendedFilename, "r") as f: + with open(suspendedFilename, 'r') as f: lines = f.readlines() with open(suspendedFilename, 'w+') as suspendedFile: for suspended in lines: @@ -893,7 +893,7 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None: # Don't suspend moderators moderatorsFile = baseDir + '/accounts/moderators.txt' if os.path.isfile(moderatorsFile): - with open(moderatorsFile, "r") as f: + with open(moderatorsFile, 'r') as f: lines = f.readlines() for moderator in lines: if moderator.strip('\n').strip('\r') == nickname: @@ -910,7 +910,7 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None: suspendedFilename = baseDir + '/accounts/suspended.txt' if os.path.isfile(suspendedFilename): - with open(suspendedFilename, "r") as f: + with open(suspendedFilename, 'r') as f: lines = f.readlines() for suspended in lines: if suspended.strip('\n').strip('\r') == nickname: @@ -941,7 +941,7 @@ def canRemovePost(baseDir: str, nickname: str, # is the post by a moderator? moderatorsFile = baseDir + '/accounts/moderators.txt' if os.path.isfile(moderatorsFile): - with open(moderatorsFile, "r") as f: + with open(moderatorsFile, 'r') as f: lines = f.readlines() for moderator in lines: if domainFull + '/users/' + moderator.strip('\n') + '/' in postId: @@ -972,7 +972,7 @@ def _removeTagsForNickname(baseDir: str, nickname: str, if matchStr not in open(tagFilename).read(): continue lines = [] - with open(tagFilename, "r") as f: + with open(tagFilename, 'r') as f: lines = f.readlines() with open(tagFilename, 'w+') as tagFile: for tagline in lines: @@ -994,7 +994,7 @@ def removeAccount(baseDir: str, nickname: str, # Don't remove moderators moderatorsFile = baseDir + '/accounts/moderators.txt' if os.path.isfile(moderatorsFile): - with open(moderatorsFile, "r") as f: + with open(moderatorsFile, 'r') as f: lines = f.readlines() for moderator in lines: if moderator.strip('\n') == nickname: diff --git a/posts.py b/posts.py index 07cef6cab..44cc5a662 100644 --- a/posts.py +++ b/posts.py @@ -89,7 +89,7 @@ def isModerator(baseDir: str, nickname: str) -> bool: return True return False - with open(moderatorsFile, "r") as f: + with open(moderatorsFile, 'r') as f: lines = f.readlines() if len(lines) == 0: adminName = getConfigParam(baseDir, 'admin') @@ -113,7 +113,7 @@ def noOfFollowersOnDomain(baseDir: str, handle: str, return 0 ctr = 0 - with open(filename, "r") as followersFilename: + with open(filename, 'r') as followersFilename: for followerHandle in followersFilename: if '@' in followerHandle: followerDomain = followerHandle.split('@')[1] @@ -135,7 +135,7 @@ def _getPersonKey(nickname: str, domain: str, baseDir: str, print('DEBUG: private key file not found: ' + keyFilename) return '' keyPem = '' - with open(keyFilename, "r") as pemFile: + with open(keyFilename, 'r') as pemFile: keyPem = pemFile.read() if len(keyPem) < 20: if debug: @@ -779,7 +779,7 @@ def _loadAutoCW(baseDir: str, nickname: str, domain: str) -> []: nickname + '@' + domain + '/autocw.txt' if not os.path.isfile(filename): return [] - with open(filename, "r") as f: + with open(filename, 'r') as f: return f.readlines() return [] @@ -1350,7 +1350,7 @@ def getPinnedPostAsJson(baseDir: str, httpPrefix: str, actor = httpPrefix + '://' + domainFull + '/users/' + nickname if os.path.isfile(pinnedFilename): pinnedContent = None - with open(pinnedFilename, "r") as pinFile: + with open(pinnedFilename, 'r') as pinFile: pinnedContent = pinFile.read() if pinnedContent: pinnedPostJson = { @@ -1469,7 +1469,7 @@ def _appendCitationsToBlogPost(baseDir: str, if not os.path.isfile(citationsFilename): return citationsSeparator = '#####' - with open(citationsFilename, "r") as f: + with open(citationsFilename, 'r') as f: citations = f.readlines() for line in citations: if citationsSeparator not in line: @@ -1753,7 +1753,7 @@ def createReportPost(baseDir: str, moderatorsList = [] moderatorsFile = baseDir + '/accounts/moderators.txt' if os.path.isfile(moderatorsFile): - with open(moderatorsFile, "r") as fileHandler: + with open(moderatorsFile, 'r') as fileHandler: for line in fileHandler: line = line.strip('\n').strip('\r') if line.startswith('#'): @@ -1865,7 +1865,7 @@ def threadSendPost(session, postJsonStr: str, federationList: [], if debug: # save the log file postLogFilename = baseDir + '/post.log' - with open(postLogFilename, "a+") as logFile: + with open(postLogFilename, 'a+') as logFile: logFile.write(logStr + '\n') if postResult: @@ -2138,7 +2138,7 @@ def groupFollowersByDomain(baseDir: str, nickname: str, domain: str) -> {}: if not os.path.isfile(followersFilename): return None grouped = {} - with open(followersFilename, "r") as f: + with open(followersFilename, 'r') as f: for followerHandle in f: if '@' not in followerHandle: continue @@ -2889,7 +2889,7 @@ def createModeration(baseDir: str, nickname: str, domain: str, port: int, if isModerator(baseDir, nickname): moderationIndexFile = baseDir + '/accounts/moderation.txt' if os.path.isfile(moderationIndexFile): - with open(moderationIndexFile, "r") as f: + with open(moderationIndexFile, 'r') as f: lines = f.readlines() boxHeader['totalItems'] = len(lines) if headerOnly: diff --git a/question.py b/question.py index 60deecdc4..9157aeea6 100644 --- a/question.py +++ b/question.py @@ -77,7 +77,7 @@ def questionUpdateVotes(baseDir: str, nickname: str, domain: str, foundAnswer + '\n') else: # change an entry in the voters file - with open(votersFilename, "r") as votersFile: + with open(votersFilename, 'r') as votersFile: lines = votersFile.readlines() newlines = [] saveVotersFile = False @@ -104,7 +104,7 @@ def questionUpdateVotes(baseDir: str, nickname: str, domain: str, if not possibleAnswer.get('name'): continue totalItems = 0 - with open(votersFilename, "r") as votersFile: + with open(votersFilename, 'r') as votersFile: lines = votersFile.readlines() for voteLine in lines: if voteLine.endswith(votersFileSeparator + diff --git a/roles.py b/roles.py index 7a9a2a569..ec0286f1d 100644 --- a/roles.py +++ b/roles.py @@ -81,7 +81,7 @@ def _addRole(baseDir: str, nickname: str, domain: str, roleFile = baseDir + '/accounts/' + roleFilename if os.path.isfile(roleFile): # is this nickname already in the file? - with open(roleFile, "r") as f: + with open(roleFile, 'r') as f: lines = f.readlines() for roleNickname in lines: roleNickname = roleNickname.strip('\n').strip('\r') @@ -97,7 +97,7 @@ def _addRole(baseDir: str, nickname: str, domain: str, roleNickname + '@' + domain): f.write(roleNickname + '\n') else: - with open(roleFile, "w+") as f: + with open(roleFile, 'w+') as f: if os.path.isdir(baseDir + '/accounts/' + nickname + '@' + domain): f.write(nickname + '\n') @@ -110,7 +110,7 @@ def _removeRole(baseDir: str, nickname: str, roleFilename: str) -> None: roleFile = baseDir + '/accounts/' + roleFilename if not os.path.isfile(roleFile): return - with open(roleFile, "r") as f: + with open(roleFile, 'r') as f: lines = f.readlines() with open(roleFile, 'w+') as f: for roleNickname in lines: diff --git a/tests.py b/tests.py index ba6e5bfb1..c496b4a81 100644 --- a/tests.py +++ b/tests.py @@ -1406,7 +1406,7 @@ def _testFollows(): federationList, False) f = open(baseDir + '/accounts/' + nickname + '@' + domain + - '/following.txt', "r") + '/following.txt', 'r') domainFound = False for followingDomain in f: testDomain = followingDomain.split('@')[1] @@ -1441,7 +1441,7 @@ def _testFollows(): federationList, False) f = open(baseDir + '/accounts/' + nickname + '@' + domain + - '/followers.txt', "r") + '/followers.txt', 'r') for followerDomain in f: testDomain = followerDomain.split('@')[1] testDomain = testDomain.replace('\n', '').replace('\r', '') @@ -3083,10 +3083,10 @@ def _testFunctions(): 'functions': [] } sourceStr = '' - with open(sourceFile, "r") as f: + with open(sourceFile, 'r') as f: sourceStr = f.read() modules[modName]['source'] = sourceStr - with open(sourceFile, "r") as f: + with open(sourceFile, 'r') as f: lines = f.readlines() modules[modName]['lines'] = lines lineCount = 0 diff --git a/threads.py b/threads.py index 0c734c485..fa9ab9acd 100644 --- a/threads.py +++ b/threads.py @@ -141,7 +141,7 @@ def removeDormantThreads(baseDir: str, threadsList: [], debug: bool, if debug: sendLogFilename = baseDir + '/send.csv' try: - with open(sendLogFilename, "a+") as logFile: + with open(sendLogFilename, 'a+') as logFile: logFile.write(currTime.strftime("%Y-%m-%dT%H:%M:%SZ") + ',' + str(noOfActiveThreads) + ',' + str(len(threadsList)) + '\n') diff --git a/utils.py b/utils.py index a20fcd180..434b07132 100644 --- a/utils.py +++ b/utils.py @@ -189,7 +189,7 @@ def isEditor(baseDir: str, nickname: str) -> bool: return True return False - with open(editorsFile, "r") as f: + with open(editorsFile, 'r') as f: lines = f.readlines() if len(lines) == 0: adminName = getConfigParam(baseDir, 'admin') @@ -217,7 +217,7 @@ def isArtist(baseDir: str, nickname: str) -> bool: return True return False - with open(artistsFile, "r") as f: + with open(artistsFile, 'r') as f: lines = f.readlines() if len(lines) == 0: adminName = getConfigParam(baseDir, 'admin') @@ -427,7 +427,7 @@ def isSuspended(baseDir: str, nickname: str) -> bool: suspendedFilename = baseDir + '/accounts/suspended.txt' if os.path.isfile(suspendedFilename): - with open(suspendedFilename, "r") as f: + with open(suspendedFilename, 'r') as f: lines = f.readlines() for suspended in lines: if suspended.strip('\n').strip('\r') == nickname: @@ -446,7 +446,7 @@ def getFollowersList(baseDir: str, if not os.path.isfile(filename): return [] - with open(filename, "r") as f: + with open(filename, 'r') as f: lines = f.readlines() for i in range(len(lines)): lines[i] = lines[i].strip() @@ -1012,7 +1012,7 @@ def followPerson(baseDir: str, nickname: str, domain: str, if handleToFollow in open(unfollowedFilename).read(): # remove them from the unfollowed file newLines = '' - with open(unfollowedFilename, "r") as f: + with open(unfollowedFilename, 'r') as f: lines = f.readlines() for line in lines: if handleToFollow not in line: @@ -1229,9 +1229,9 @@ def removeModerationPostFromIndex(baseDir: str, postUrl: str, return postId = removeIdEnding(postUrl) if postId in open(moderationIndexFile).read(): - with open(moderationIndexFile, "r") as f: + with open(moderationIndexFile, 'r') as f: lines = f.readlines() - with open(moderationIndexFile, "w+") as f: + with open(moderationIndexFile, 'w+') as f: for line in lines: if line.strip("\n").strip("\r") != postId: f.write(line) @@ -1371,7 +1371,7 @@ def _deleteHashtagsOnPost(baseDir: str, postJsonObject: {}) -> None: continue # remove postId from the tag index file lines = None - with open(tagIndexFilename, "r") as f: + with open(tagIndexFilename, 'r') as f: lines = f.readlines() if not lines: continue @@ -1386,7 +1386,7 @@ def _deleteHashtagsOnPost(baseDir: str, postJsonObject: {}) -> None: os.remove(tagIndexFilename) else: # write the new hashtag index without the given post in it - with open(tagIndexFilename, "w+") as f: + with open(tagIndexFilename, 'w+') as f: f.write(newlines) diff --git a/webapp_column_left.py b/webapp_column_left.py index 09b73f782..034153184 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -150,7 +150,7 @@ def getLeftColumnContent(baseDir: str, nickname: str, domainFull: str, linksFileContainsEntries = False linksList = None if os.path.isfile(linksFilename): - with open(linksFilename, "r") as f: + with open(linksFilename, 'r') as f: linksList = f.readlines() if not frontPage: diff --git a/webapp_column_right.py b/webapp_column_right.py index ab3cff465..2327c8149 100644 --- a/webapp_column_right.py +++ b/webapp_column_right.py @@ -342,7 +342,7 @@ def htmlCitations(baseDir: str, nickname: str, domain: str, citationsSelected = [] if os.path.isfile(citationsFilename): citationsSeparator = '#####' - with open(citationsFilename, "r") as f: + with open(citationsFilename, 'r') as f: citations = f.readlines() for line in citations: if citationsSeparator not in line: diff --git a/webapp_create_post.py b/webapp_create_post.py index 1a70401be..cb75eb018 100644 --- a/webapp_create_post.py +++ b/webapp_create_post.py @@ -411,7 +411,7 @@ def htmlNewPost(cssCache: {}, mediaInstance: bool, translate: {}, translate['Citations'] + ':

\n' citationsStr += '