Remove carriage returns

main
Bob Mottram 2020-05-22 11:32:38 +00:00
parent 48f6bbf482
commit e75f1a0abb
19 changed files with 119 additions and 79 deletions

15
auth.py
View File

@ -40,7 +40,10 @@ def verifyPassword(storedPassword: str, providedPassword: str) -> bool:
def createBasicAuthHeader(nickname: str, password: str) -> str:
"""This is only used by tests
"""
authStr = nickname.replace('\n', '') + ':' + password.replace('\n', '')
authStr = \
nickname.replace('\n', '').replace('\r', '') + \
':' + \
password.replace('\n', '').replace('\r', '')
return 'Basic ' + base64.b64encode(authStr.encode('utf-8')).decode('utf-8')
@ -65,7 +68,8 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
print('DEBUG: This is not a users endpoint')
return False
nicknameFromPath = pathUsersSection.split('/')[0]
base64Str = authHeader.split(' ')[1].replace('\n', '')
base64Str = \
authHeader.split(' ')[1].replace('\n', '').replace('\r', '')
plain = base64.b64decode(base64Str).decode('utf-8')
if ':' not in plain:
if debug:
@ -88,7 +92,8 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
passfile = open(passwordFile, "r")
for line in passfile:
if line.startswith(nickname+':'):
storedPassword = line.split(':')[1].replace('\n', '')
storedPassword = \
line.split(':')[1].replace('\n', '').replace('\r', '')
success = verifyPassword(storedPassword, providedPassword)
if not success:
if debug:
@ -104,8 +109,8 @@ def storeBasicCredentials(baseDir: str, nickname: str, password: str) -> bool:
"""
if ':' in nickname or ':' in password:
return False
nickname = nickname.replace('\n', '').strip()
password = password.replace('\n', '').strip()
nickname = nickname.replace('\n', '').replace('\r', '').strip()
password = password.replace('\n', '').replace('\r', '').strip()
if not os.path.isdir(baseDir + '/accounts'):
os.mkdir(baseDir + '/accounts')

View File

@ -69,7 +69,7 @@ def removeGlobalBlock(baseDir: str,
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w') as fpnew:
for line in fp:
handle = line.replace('\n', '')
handle = line.replace('\n', '').replace('\r', '')
if unblockHandle not in line:
fpnew.write(handle + '\n')
if os.path.isfile(unblockingFilename + '.new'):
@ -82,7 +82,8 @@ def removeGlobalBlock(baseDir: str,
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w') as fpnew:
for line in fp:
blockLine = line.replace('\n', '')
blockLine = \
line.replace('\n', '').replace('\r', '')
if unblockHashtag not in line:
fpnew.write(blockLine + '\n')
if os.path.isfile(unblockingFilename + '.new'):
@ -105,7 +106,7 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w') as fpnew:
for line in fp:
handle = line.replace('\n', '')
handle = line.replace('\n', '').replace('\r', '')
if unblockHandle not in line:
fpnew.write(handle + '\n')
if os.path.isfile(unblockingFilename + '.new'):
@ -119,7 +120,7 @@ def isBlockedHashtag(baseDir: str, hashtag: str) -> bool:
"""
globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if os.path.isfile(globalBlockingFilename):
hashtag = hashtag.strip('\n')
hashtag = hashtag.strip('\n').strip('\r')
if hashtag + '\n' in open(globalBlockingFilename).read():
return True
return False

16
blog.py
View File

@ -59,7 +59,8 @@ def noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
with open(postFilename, "r") as f:
lines = f.readlines()
for replyPostId in lines:
replyPostId = replyPostId.replace('\n', '').replace('.json', '')
replyPostId = replyPostId.replace('\n', '').replace('\r', '')
replyPostId = replyPostId.replace('.json', '')
if locatePost(baseDir, nickname, domain, replyPostId):
replyPostId = replyPostId.replace('.replies', '')
replies += 1 + noOfBlogReplies(baseDir, httpPrefix, translate,
@ -75,7 +76,7 @@ def noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
str(len(removals)) + ' entries')
with open(postFilename, "w") as f:
for replyPostId in lines:
replyPostId = replyPostId.replace('\n', '')
replyPostId = replyPostId.replace('\n', '').replace('\r', '')
if replyPostId not in removals:
f.write(replyPostId + '\n')
@ -121,12 +122,13 @@ def getBlogReplies(baseDir: str, httpPrefix: str, translate: {},
lines = f.readlines()
repliesStr = ''
for replyPostId in lines:
replyPostId = replyPostId.replace('\n', '').replace('.json', '')
replyPostId = replyPostId.replace('\n', '').replace('\r', '')
replyPostId = replyPostId.replace('.json', '')
replyPostId = replyPostId.replace('.replies', '')
postFilename = baseDir + '/accounts/' + \
nickname + '@' + domain + \
'/postcache/' + \
replyPostId.replace('\n', '').replace('/', '#') + '.html'
replyPostId.replace('/', '#') + '.html'
if not os.path.isfile(postFilename):
continue
with open(postFilename, "r") as postFile:
@ -334,7 +336,8 @@ def htmlBlogPage(authorized: bool, session,
noOfItems: int, pageNumber: int) -> str:
"""Returns a html blog page containing posts
"""
if ' ' in nickname or '@' in nickname or '\n' in nickname:
if ' ' in nickname or '@' in nickname or \
'\n' in nickname or '\r' in nickname:
return None
blogStr = ''
@ -436,7 +439,8 @@ def htmlBlogPageRSS(authorized: bool, session,
noOfItems: int, pageNumber: int) -> str:
"""Returns an rss feed containing posts
"""
if ' ' in nickname or '@' in nickname or '\n' in nickname:
if ' ' in nickname or '@' in nickname or \
'\n' in nickname or '\r' in nickname:
return None
domainFull = domain

View File

@ -51,7 +51,7 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
bookmarkIndex = postFilename.split('/')[-1].strip()
else:
bookmarkIndex = postFilename.strip()
bookmarkIndex = bookmarkIndex.replace('\n', '')
bookmarkIndex = bookmarkIndex.replace('\n', '').replace('\r', '')
if bookmarkIndex not in open(bookmarksIndexFilename).read():
return
indexStr = ''

View File

@ -22,7 +22,7 @@ def switchWords(baseDir: str, nickname: str, domain: str, content: str) -> str:
return content
with open(switchWordsFilename, 'r') as fp:
for line in fp:
replaceStr = line.replace('\n', '')
replaceStr = line.replace('\n', '').replace('\r', '')
wordTransform = None
if '->' in replaceStr:
wordTransform = replaceStr.split('->')
@ -130,6 +130,7 @@ def addWebLinks(content: str) -> str:
return content
maxLinkLength = 40
content = content.replace('\r', '')
words = content.replace('\n', ' --linebreak-- ').split(' ')
replaceDict = {}
for w in words:
@ -231,7 +232,8 @@ def loadEmojiDict(emojiDataFilename: str, emojiDict: {}) -> None:
continue
if '..' in emojiUnicode:
emojiUnicode = emojiUnicode.split('..')[0]
emojiName = line.split(')', 1)[1].strip().replace('\n', '')
emojiName = line.split(')', 1)[1].strip()
emojiName = emojiName.replace('\n', '').replace('\r', '')
emojiName = emojiName.replace(' ', '').replace('-', '')
if '..' in emojiName:
emojiName = emojiName.split('..')[0]
@ -293,7 +295,8 @@ def addMention(wordStr: str, httpPrefix: str, following: str,
possibleNickname = possibleHandle
for follow in following:
if follow.startswith(possibleNickname + '@'):
replaceDomain = follow.replace('\n', '').split('@')[1]
replaceDomain = \
follow.replace('\n', '').replace('\r', '').split('@')[1]
recipientActor = httpPrefix + "://" + \
replaceDomain + "/users/" + possibleNickname
if recipientActor not in recipients:
@ -317,12 +320,13 @@ def addMention(wordStr: str, httpPrefix: str, following: str,
possibleNickname = possibleHandle.split('@')[0]
if not possibleNickname:
return False
possibleDomain = possibleHandle.split('@')[1].strip('\n')
possibleDomain = \
possibleHandle.split('@')[1].strip('\n').strip('\r')
if not possibleDomain:
return False
if following:
for follow in following:
if follow.replace('\n', '') != possibleHandle:
if follow.replace('\n', '').replace('\r', '') != possibleHandle:
continue
recipientActor = httpPrefix + "://" + \
possibleDomain + "/users/" + possibleNickname
@ -451,6 +455,7 @@ def addHtmlTags(baseDir: str, httpPrefix: str,
if content.startswith('<p>'):
return content
maxWordLength = 40
content = content.replace('\r', '')
content = content.replace('\n', ' --linebreak-- ')
content = addMusicTag(content, 'nowplaying')
words = content.replace(',', ' ').replace(';', ' ').split(' ')

View File

@ -6023,6 +6023,7 @@ class PubServer(BaseHTTPRequestHandler):
searchStr = searchStr.replace('+', ' ')
searchStr = \
urllib.parse.unquote(searchStr.strip())
searchStr2 = searchStr.lower().strip('\n').strip('\r')
print('searchStr: ' + searchStr)
if searchForEmoji:
searchStr = ':' + searchStr + ':'
@ -6135,11 +6136,11 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy = False
return
elif (searchStr.startswith(':') or
searchStr.lower().strip('\n').endswith(' emoji')):
searchStr2.endswith(' emoji')):
# eg. "cat emoji"
if searchStr.lower().strip('\n').endswith(' emoji'):
if searchStr2.endswith(' emoji'):
searchStr = \
searchStr.lower().strip('\n').replace(' emoji', '')
searchStr2.replace(' emoji', '')
# emoji search
emojiStr = \
htmlSearchEmoji(self.server.translate,

View File

@ -628,7 +628,7 @@ if args.followerspending:
if os.path.isfile(approveFollowsFilename):
with open(approveFollowsFilename, 'r') as approvefile:
for approve in approvefile:
print(approve.replace('\n', ''))
print(approve.replace('\n', '').replace('\r', ''))
approveCtr += 1
if approveCtr == 0:
print('There are no follow requests pending approval.')
@ -657,7 +657,8 @@ if args.message:
sys.exit()
if '@' in args.sendto:
toNickname = args.sendto.split('@')[0]
toDomain = args.sendto.split('@')[1].replace('\n', '')
toDomain = args.sendto.split('@')[1]
toDomain = toDomain.replace('\n', '').replace('\r', '')
toPort = 443
if ':' in toDomain:
toPort = toDomain.split(':')[1]
@ -1005,13 +1006,16 @@ if args.actor:
'https://domain/@nick or https://domain/users/nick')
sys.exit()
if '/users/' in args.actor:
nickname = args.actor.split('/users/')[1].replace('\n', '')
nickname = args.actor.split('/users/')[1]
nickname = nickname.replace('\n', '').replace('\r', '')
domain = args.actor.split('/users/')[0]
elif '/profile/' in args.actor:
nickname = args.actor.split('/profile/')[1].replace('\n', '')
nickname = args.actor.split('/profile/')[1]
nickname = nickname.replace('\n', '').replace('\r', '')
domain = args.actor.split('/profile/')[0]
else:
nickname = args.actor.split('/channel/')[1].replace('\n', '')
nickname = args.actor.split('/channel/')[1]
nickname = nickname.replace('\n', '').replace('\r', '')
domain = args.actor.split('/channel/')[0]
else:
# format: @nick@domain
@ -1024,7 +1028,8 @@ if args.actor:
print('Syntax: --actor nickname@domain')
sys.exit()
nickname = args.actor.split('@')[0]
domain = args.actor.split('@')[1].replace('\n', '')
domain = args.actor.split('@')[1]
domain = domain.replace('\n', '').replace('\r', '')
cachedWebfingers = {}
if args.http or domain.endswith('.onion'):
httpPrefix = 'http'
@ -1379,7 +1384,8 @@ if args.block:
sys.exit()
if '@' in args.block:
blockedDomain = args.block.split('@')[1].replace('\n', '')
blockedDomain = args.block.split('@')[1]
blockedDomain = blockedDomain.replace('\n', '').replace('\r', '')
blockedNickname = args.block.split('@')[0]
blockedActor = httpPrefix + '://' + blockedDomain + \
'/users/' + blockedNickname
@ -1488,7 +1494,8 @@ if args.unblock:
sys.exit()
if '@' in args.unblock:
blockedDomain = args.unblock.split('@')[1].replace('\n', '')
blockedDomain = args.unblock.split('@')[1]
blockedDomain = blockedDomain.replace('\n', '').replace('\r', '')
blockedNickname = args.unblock.split('@')[0]
blockedActor = httpPrefix + '://' + blockedDomain + \
'/users/' + blockedNickname

View File

@ -71,7 +71,7 @@ def isFiltered(baseDir: str, nickname: str, domain: str, content: str) -> bool:
if os.path.isfile(filtersFilename):
with open(filtersFilename, 'r') as fp:
for line in fp:
filterStr = line.replace('\n', '')
filterStr = line.replace('\n', '').replace('\r', '')
if '+' not in filterStr:
if filterStr in content:
return True

View File

@ -149,7 +149,9 @@ def getFollowersOfPerson(baseDir: str,
continue
with open(filename, 'r') as followingfile:
for followingHandle in followingfile:
if followingHandle.replace('\n', '') == handle:
followingHandle2 = followingHandle.replace('\n', '')
followingHandle2 = followingHandle2.replace('\r', '')
if followingHandle2 == handle:
if account not in followers:
followers.append(account)
break
@ -209,7 +211,7 @@ def unfollowPerson(baseDir: str, nickname: str, domain: str,
lines = f.readlines()
with open(filename, "w") as f:
for line in lines:
if line.strip("\n") != handleToUnfollow:
if line.strip("\n").strip("\r") != handleToUnfollow:
f.write(line)
# write to an unfollowed file so that if a follow accept
@ -389,17 +391,20 @@ def getFollowingFeed(baseDir: str, domain: str, port: int, path: str,
pageCtr += 1
totalCtr += 1
if currPage == pageNumber:
line2 = \
line.lower().replace('\n', '').replace('\r', '')
url = httpPrefix + '://' + \
line.lower().replace('\n', '').split('@')[1] + \
line2.split('@')[1] + \
'/users/' + \
line.lower().replace('\n', '').split('@')[0]
line2.split('@')[0]
following['orderedItems'].append(url)
elif ((line.startswith('http') or
line.startswith('dat')) and '/users/' in line):
pageCtr += 1
totalCtr += 1
if currPage == pageNumber:
appendStr = line.lower().replace('\n', '')
appendStr = \
line.lower().replace('\n', '').replace('\r', '')
following['orderedItems'].append(appendStr)
if pageCtr >= followsPerPage:
pageCtr = 0

View File

@ -70,7 +70,7 @@ def getTodaysEvents(baseDir: str, nickname: str, domain: str,
recreateEventsFile = False
with open(calendarFilename, 'r') as eventsFile:
for postId in eventsFile:
postId = postId.replace('\n', '')
postId = postId.replace('\n', '').replace('\r', '')
postFilename = locatePost(baseDir, nickname, domain, postId)
if not postFilename:
recreateEventsFile = True
@ -115,7 +115,7 @@ def getTodaysEvents(baseDir: str, nickname: str, domain: str,
if recreateEventsFile:
calendarFile = open(calendarFilename, "w")
for postId in calendarPostIds:
calendarFile.write(postId+'\n')
calendarFile.write(postId + '\n')
calendarFile.close()
return events
@ -138,7 +138,7 @@ def todaysEventsCheck(baseDir: str, nickname: str, domain: str) -> bool:
eventsExist = False
with open(calendarFilename, 'r') as eventsFile:
for postId in eventsFile:
postId = postId.replace('\n', '')
postId = postId.replace('\n', '').replace('\r', '')
postFilename = locatePost(baseDir, nickname, domain, postId)
if not postFilename:
continue
@ -185,7 +185,7 @@ def thisWeeksEventsCheck(baseDir: str, nickname: str, domain: str) -> bool:
eventsExist = False
with open(calendarFilename, 'r') as eventsFile:
for postId in eventsFile:
postId = postId.replace('\n', '')
postId = postId.replace('\n', '').replace('\r', '')
postFilename = locatePost(baseDir, nickname, domain, postId)
if not postFilename:
continue
@ -239,7 +239,7 @@ def getThisWeeksEvents(baseDir: str, nickname: str, domain: str) -> {}:
recreateEventsFile = False
with open(calendarFilename, 'r') as eventsFile:
for postId in eventsFile:
postId = postId.replace('\n', '')
postId = postId.replace('\n', '').replace('\r', '')
postFilename = locatePost(baseDir, nickname, domain, postId)
if not postFilename:
recreateEventsFile = True
@ -324,7 +324,7 @@ def getCalendarEvents(baseDir: str, nickname: str, domain: str,
recreateEventsFile = False
with open(calendarFilename, 'r') as eventsFile:
for postId in eventsFile:
postId = postId.replace('\n', '')
postId = postId.replace('\n', '').replace('\r', '')
postFilename = locatePost(baseDir, nickname, domain, postId)
if not postFilename:
recreateEventsFile = True

View File

@ -45,7 +45,8 @@ def manualDenyFollowRequest(session, baseDir: str,
rejectsFile.close()
denyNickname = denyHandle.split('@')[0]
denyDomain = denyHandle.split('@')[1].replace('\n', '')
denyDomain = \
denyHandle.split('@')[1].replace('\n', '').replace('\r', '')
denyPort = port
if ':' in denyDomain:
denyPort = denyDomain.split(':')[1]
@ -112,7 +113,7 @@ def manualApproveFollowRequest(session, baseDir: str,
# is this the approved follow?
if handleOfFollowRequester.startswith(approveHandle):
handleOfFollowRequester = \
handleOfFollowRequester.replace('\n', '')
handleOfFollowRequester.replace('\n', '').replace('\r', '')
port2 = port
if ':' in handleOfFollowRequester:
port2Str = handleOfFollowRequester.split(':')[1]
@ -125,8 +126,9 @@ def manualApproveFollowRequest(session, baseDir: str,
followJson = loadJson(followActivityfilename)
if followJson:
approveNickname = approveHandle.split('@')[0]
approveDomain = approveHandle.split('@')[1]
approveDomain = \
approveHandle.split('@')[1].replace('\n', '')
approveDomain.replace('\n', '').replace('\r', '')
approvePort = port2
if ':' in approveDomain:
approvePort = approveDomain.split(':')[1]

View File

@ -52,7 +52,7 @@ def setProfileImage(baseDir: str, httpPrefix: str, nickname: str, domain: str,
"""Saves the given image file as an avatar or background
image for the given person
"""
imageFilename = imageFilename.replace('\n', '')
imageFilename = imageFilename.replace('\n', '').replace('\r', '')
if not (imageFilename.endswith('.png') or
imageFilename.endswith('.jpg') or
imageFilename.endswith('.jpeg') or
@ -712,7 +712,7 @@ def isSuspended(baseDir: str, nickname: str) -> bool:
with open(suspendedFilename, "r") as f:
lines = f.readlines()
for suspended in lines:
if suspended.strip('\n') == nickname:
if suspended.strip('\n').strip('\r') == nickname:
return True
return False
@ -726,7 +726,7 @@ def unsuspendAccount(baseDir: str, nickname: str) -> None:
lines = f.readlines()
suspendedFile = open(suspendedFilename, "w+")
for suspended in lines:
if suspended.strip('\n') != nickname:
if suspended.strip('\n').strip('\r') != nickname:
suspendedFile.write(suspended)
suspendedFile.close()
@ -745,7 +745,7 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None:
with open(moderatorsFile, "r") as f:
lines = f.readlines()
for moderator in lines:
if moderator.strip('\n') == nickname:
if moderator.strip('\n').strip('\r') == nickname:
return
saltFilename = baseDir + '/accounts/' + \
@ -762,7 +762,7 @@ def suspendAccount(baseDir: str, nickname: str, domain: str) -> None:
with open(suspendedFilename, "r") as f:
lines = f.readlines()
for suspended in lines:
if suspended.strip('\n') == nickname:
if suspended.strip('\n').strip('\r') == nickname:
return
suspendedFile = open(suspendedFilename, 'a+')
if suspendedFile:
@ -949,7 +949,8 @@ def isPersonSnoozed(baseDir: str, nickname: str, domain: str,
for line in snoozedFile:
# is this the entry for the actor?
if line.startswith(snoozeActor + ' '):
snoozedTimeStr = line.split(' ')[1].replace('\n', '')
snoozedTimeStr = \
line.split(' ')[1].replace('\n', '').replace('\r', '')
# is there a time appended?
if snoozedTimeStr.isdigit():
snoozedTime = int(snoozedTimeStr)

View File

@ -73,7 +73,7 @@ def isModerator(baseDir: str, nickname: str) -> bool:
if getConfigParam(baseDir, 'admin') == nickname:
return True
for moderator in lines:
moderator = moderator.strip('\n')
moderator = moderator.strip('\n').strip('\r')
if moderator == nickname:
return True
return False
@ -91,8 +91,9 @@ def noOfFollowersOnDomain(baseDir: str, handle: str,
with open(filename, "r") as followersFilename:
for followerHandle in followersFilename:
if '@' in followerHandle:
followerDomain = \
followerHandle.split('@')[1].replace('\n', '')
followerDomain = followerHandle.split('@')[1]
followerDomain = followerDomain.replace('\n', '')
followerDomain = followerDomain.replace('\r', '')
if domain == followerDomain:
ctr += 1
return ctr
@ -1105,7 +1106,7 @@ def getMentionedPeople(baseDir: str, httpPrefix: str,
externalDomain == 'localhost'):
continue
mentionedNickname = handle.split('@')[0]
mentionedDomain = handle.split('@')[1].strip('\n')
mentionedDomain = handle.split('@')[1].strip('\n').strip('\r')
if ':' in mentionedDomain:
mentionedDomain = mentionedDomain.split(':')[0]
if not validNickname(mentionedDomain, mentionedNickname):
@ -1188,7 +1189,7 @@ def createReportPost(baseDir: str,
if os.path.isfile(moderatorsFile):
with open(moderatorsFile, "r") as fileHandler:
for line in fileHandler:
line = line.strip('\n')
line = line.strip('\n').strip('\r')
if line.startswith('#'):
continue
if line.startswith('/users/'):
@ -1569,7 +1570,8 @@ def groupFollowersByDomain(baseDir: str, nickname: str, domain: str) -> {}:
with open(followersFilename, "r") as f:
for followerHandle in f:
if '@' in followerHandle:
fHandle = followerHandle.strip().replace('\n', '')
fHandle = \
followerHandle.strip().replace('\n', '').replace('\r', '')
followerDomain = fHandle.split('@')[1]
if not grouped.get(followerDomain):
grouped[followerDomain] = [fHandle]
@ -2221,7 +2223,7 @@ def createModeration(baseDir: str, nickname: str, domain: str, port: int,
startLineNumber = 0
lineNumber = startLineNumber
while lineNumber >= endLineNumber:
pageLines.append(lines[lineNumber].strip('\n'))
pageLines.append(lines[lineNumber].strip('\n').strip('\r'))
lineNumber -= 1
for postUrl in pageLines:
@ -2555,7 +2557,8 @@ def createBoxIndexed(recentPostsCache: {},
# This should also correspond to any index entry in
# the posts cache
postUrl = \
postFilename.replace('\n', '').replace('.json', '').strip()
postFilename.replace('\n', '').replace('\r', '')
postUrl = postUrl.replace('.json', '').strip()
# is the post cached in memory?
if recentPostsCache.get('index'):
@ -2883,12 +2886,13 @@ def populateRepliesJson(baseDir: str, nickname: str, domain: str,
replyFound = False
# examine inbox and outbox
for boxname in repliesBoxes:
messageId2 = messageId.replace('\n', '').replace('\r', '')
searchFilename = \
baseDir + \
'/accounts/' + nickname + '@' + \
domain+'/' + \
boxname+'/' + \
messageId.replace('\n', '').replace('/', '#') + '.json'
messageId2.replace('/', '#') + '.json'
if os.path.isfile(searchFilename):
if authorized or \
pubStr in open(searchFilename).read():
@ -2910,11 +2914,12 @@ def populateRepliesJson(baseDir: str, nickname: str, domain: str,
break
# if not in either inbox or outbox then examine the shared inbox
if not replyFound:
messageId2 = messageId.replace('\n', '').replace('\r', '')
searchFilename = \
baseDir + \
'/accounts/inbox@' + \
domain+'/inbox/' + \
messageId.replace('\n', '').replace('/', '#') + '.json'
messageId2.replace('/', '#') + '.json'
if os.path.isfile(searchFilename):
if authorized or \
pubStr in open(searchFilename).read():

View File

@ -48,13 +48,13 @@ def addModerator(baseDir: str, nickname: str, domain: str) -> None:
with open(moderatorsFile, "r") as f:
lines = f.readlines()
for moderator in lines:
moderator = moderator.strip('\n')
moderator = moderator.strip('\n').strip('\r')
if moderator == nickname:
return
lines.append(nickname)
with open(moderatorsFile, "w") as f:
for moderator in lines:
moderator = moderator.strip('\n')
moderator = moderator.strip('\n').strip('\r')
if len(moderator) > 1:
if os.path.isdir(baseDir + '/accounts/' +
moderator + '@' + domain):
@ -76,7 +76,7 @@ def removeModerator(baseDir: str, nickname: str):
lines = f.readlines()
with open(moderatorsFile, "w") as f:
for moderator in lines:
moderator = moderator.strip('\n')
moderator = moderator.strip('\n').strip('\r')
if len(moderator) > 1 and moderator != nickname:
f.write(moderator + '\n')

View File

@ -37,7 +37,7 @@ def updatePostSchedule(baseDir: str, handle: str, httpd,
dateStr = line.split(' ')[0]
if 'T' not in dateStr:
continue
postId = line.split(' ', 1)[1].replace('\n', '')
postId = line.split(' ', 1)[1].replace('\n', '').replace('\r', '')
postFilename = scheduleDir + postId + '.json'
if deleteSchedulePost:
# delete extraneous scheduled posts

View File

@ -26,7 +26,8 @@ def getValidSharedItemID(displayName: str) -> str:
displayName = displayName.replace(' ', '').replace('+', '-')
displayName = displayName.replace('/', '-').replace('\\', '-')
displayName = displayName.replace('.', '_').replace('?', '-')
displayName = displayName.replace('\n', '').replace("", "'")
displayName = displayName.replace('\n', '').replace('\r', '')
displayName = displayName.replace("", "'")
return displayName.replace('&', '-')

View File

@ -997,7 +997,8 @@ def testFollows():
'/following.txt', "r")
domainFound = False
for followingDomain in f:
testDomain = followingDomain.split('@')[1].replace('\n', '')
testDomain = followingDomain.split('@')[1]
testDomain = testDomain.replace('\n', '').replace('\r', '')
if testDomain == 'mesh.com':
domainFound = True
if testDomain not in federationList:
@ -1009,7 +1010,8 @@ def testFollows():
domainFound = False
for followingDomain in f:
testDomain = followingDomain.split('@')[1].replace('\n', '')
testDomain = followingDomain.split('@')[1]
testDomain = testDomain.replace('\n', '').replace('\r', '')
if testDomain == 'mesh.com':
domainFound = True
assert(domainFound is False)
@ -1029,7 +1031,8 @@ def testFollows():
f = open(baseDir + '/accounts/' + nickname + '@' + domain +
'/followers.txt', "r")
for followerDomain in f:
testDomain = followerDomain.split('@')[1].replace('\n', '')
testDomain = followerDomain.split('@')[1]
testDomain = testDomain.replace('\n', '').replace('\r', '')
if testDomain not in federationList:
print(testDomain)
assert(False)

View File

@ -395,7 +395,7 @@ def removeModerationPostFromIndex(baseDir: str, postUrl: str,
lines = f.readlines()
with open(moderationIndexFile, "w+") as f:
for line in lines:
if line.strip("\n") != postId:
if line.strip("\n").strip("\r") != postId:
f.write(line)
else:
if debug:

View File

@ -285,7 +285,7 @@ def htmlSearchEmoji(translate: {}, baseDir: str, httpPrefix: str,
copyfile(baseDir + '/emoji/default_emoji.json',
baseDir + '/emoji/emoji.json')
searchStr = searchStr.lower().replace(':', '').strip('\n')
searchStr = searchStr.lower().replace(':', '').strip('\n').strip('\r')
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
cssFilename = baseDir + '/epicyon.css'
@ -362,7 +362,7 @@ def htmlSearchSharedItems(translate: {},
ctr = 0
sharedItemsForm = ''
searchStrLower = urllib.parse.unquote(searchStr)
searchStrLower = searchStrLower.lower().strip('\n')
searchStrLower = searchStrLower.lower().strip('\n').strip('\r')
searchStrLowerList = searchStrLower.split('+')
cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'):
@ -647,7 +647,7 @@ def htmlHashtagSearch(nickname: str, domain: str, port: int,
'"></a></center>'
index = startIndex
while index <= endIndex:
postId = lines[index].strip('\n')
postId = lines[index].strip('\n').strip('\r')
if ' ' not in postId:
nickname = getNicknameFromActor(postId)
if not nickname:
@ -710,7 +710,7 @@ def htmlSkillsSearch(translate: {}, baseDir: str,
if skillsearch.startswith('*'):
skillsearch = skillsearch[1:].strip()
skillsearch = skillsearch.lower().strip('\n')
skillsearch = skillsearch.lower().strip('\n').strip('\r')
results = []
# search instance accounts
@ -846,7 +846,7 @@ def htmlHistorySearch(translate: {}, baseDir: str,
if historysearch.startswith('!'):
historysearch = historysearch[1:].strip()
historysearch = historysearch.lower().strip('\n')
historysearch = historysearch.lower().strip('\n').strip('\r')
boxFilenames = \
searchBoxPosts(baseDir, nickname, domain,
@ -4156,8 +4156,8 @@ def htmlTimeline(defaultTimeline: str,
if os.path.isfile(calendarFile):
calendarImage = 'calendar_notify.png'
with open(calendarFile, 'r') as calfile:
calendarPath = \
calfile.read().replace('##sent##', '').replace('\n', '')
calendarPath = calfile.read().replace('##sent##', '')
calendarPath = calendarPath.replace('\n', '').replace('\r', '')
# should the DM button be highlighted?
newDM = False