File reading exception handling

merge-requests/30/head
Bob Mottram 2021-11-26 12:28:20 +00:00
parent 48154066bf
commit cb0675cf5e
8 changed files with 236 additions and 124 deletions

View File

@ -132,6 +132,7 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
print('DEBUG: passwords file missing') print('DEBUG: passwords file missing')
return False return False
providedPassword = plain.split(':')[1] providedPassword = plain.split(':')[1]
try:
with open(passwordFile, 'r') as passfile: with open(passwordFile, 'r') as passfile:
for line in passfile: for line in passfile:
if not line.startswith(nickname + ':'): if not line.startswith(nickname + ':'):
@ -143,6 +144,9 @@ def authorizeBasic(baseDir: str, path: str, authHeader: str,
if debug: if debug:
print('DEBUG: Password check failed for ' + nickname) print('DEBUG: Password check failed for ' + nickname)
return success return success
except OSError:
print('EX: failed to open password file')
return False
print('DEBUG: Did not find credentials for ' + nickname + print('DEBUG: Did not find credentials for ' + nickname +
' in ' + passwordFile) ' in ' + passwordFile)
return False return False
@ -272,15 +276,15 @@ def recordLoginFailure(baseDir: str, ipAddress: str,
if not os.path.isfile(failureLog): if not os.path.isfile(failureLog):
writeType = 'w+' writeType = 'w+'
currTime = datetime.datetime.utcnow() currTime = datetime.datetime.utcnow()
currTimeStr = currTime.strftime("%Y-%m-%d %H:%M:%SZ")
try: try:
with open(failureLog, writeType) as fp: with open(failureLog, writeType) as fp:
# here we use a similar format to an ssh log, so that # here we use a similar format to an ssh log, so that
# systems such as fail2ban can parse it # systems such as fail2ban can parse it
fp.write(currTime.strftime("%Y-%m-%d %H:%M:%SZ") + ' ' + fp.write(currTimeStr + ' ' +
'ip-127-0-0-1 sshd[20710]: ' + 'ip-127-0-0-1 sshd[20710]: ' +
'Disconnecting invalid user epicyon ' + 'Disconnecting invalid user epicyon ' +
ipAddress + ' port 443: ' + ipAddress + ' port 443: ' +
'Too many authentication failures [preauth]\n') 'Too many authentication failures [preauth]\n')
except OSError: except OSError:
print('EX: recordLoginFailure failed ' + str(failureLog)) print('EX: recordLoginFailure failed ' + str(failureLog))
pass

View File

@ -94,11 +94,13 @@ def addBlock(baseDir: str, nickname: str, domain: str,
try: try:
with open(followingFilename, 'r') as followingFile: with open(followingFilename, 'r') as followingFile:
followingStr = followingFile.read() followingStr = followingFile.read()
followingStr = followingStr.replace(blockHandle + '\n', '')
except OSError: except OSError:
print('EX: Unable to read following ' + followingFilename) print('EX: Unable to read following ' + followingFilename)
return False return False
if followingStr:
followingStr = followingStr.replace(blockHandle + '\n', '')
try: try:
with open(followingFilename, 'w+') as followingFile: with open(followingFilename, 'w+') as followingFile:
followingFile.write(followingStr) followingFile.write(followingStr)
@ -114,11 +116,13 @@ def addBlock(baseDir: str, nickname: str, domain: str,
try: try:
with open(followersFilename, 'r') as followersFile: with open(followersFilename, 'r') as followersFile:
followersStr = followersFile.read() followersStr = followersFile.read()
followersStr = followersStr.replace(blockHandle + '\n', '')
except OSError: except OSError:
print('EX: Unable to read followers ' + followersFilename) print('EX: Unable to read followers ' + followersFilename)
return False return False
if followersStr:
followersStr = followersStr.replace(blockHandle + '\n', '')
try: try:
with open(followersFilename, 'w+') as followersFile: with open(followersFilename, 'w+') as followersFile:
followersFile.write(followersStr) followersFile.write(followersStr)
@ -145,8 +149,8 @@ def removeGlobalBlock(baseDir: str,
unblockHandle = unblockNickname + '@' + unblockDomain unblockHandle = unblockNickname + '@' + unblockDomain
if os.path.isfile(unblockingFilename): if os.path.isfile(unblockingFilename):
if unblockHandle in open(unblockingFilename).read(): if unblockHandle in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp:
try: try:
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew: with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp: for line in fp:
handle = \ handle = \
@ -157,15 +161,21 @@ def removeGlobalBlock(baseDir: str,
print('EX: failed to remove global block ' + print('EX: failed to remove global block ' +
unblockingFilename + ' ' + str(e)) unblockingFilename + ' ' + str(e))
return False return False
if os.path.isfile(unblockingFilename + '.new'): if os.path.isfile(unblockingFilename + '.new'):
os.rename(unblockingFilename + '.new', unblockingFilename) try:
os.rename(unblockingFilename + '.new',
unblockingFilename)
except OSError:
print('EX: unable to rename ' + unblockingFilename)
return False
return True return True
else: else:
unblockHashtag = unblockNickname unblockHashtag = unblockNickname
if os.path.isfile(unblockingFilename): if os.path.isfile(unblockingFilename):
if unblockHashtag + '\n' in open(unblockingFilename).read(): if unblockHashtag + '\n' in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp:
try: try:
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew: with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp: for line in fp:
blockLine = \ blockLine = \
@ -176,8 +186,14 @@ def removeGlobalBlock(baseDir: str,
print('EX: failed to remove global hashtag block ' + print('EX: failed to remove global hashtag block ' +
unblockingFilename + ' ' + str(e)) unblockingFilename + ' ' + str(e))
return False return False
if os.path.isfile(unblockingFilename + '.new'): if os.path.isfile(unblockingFilename + '.new'):
os.rename(unblockingFilename + '.new', unblockingFilename) try:
os.rename(unblockingFilename + '.new',
unblockingFilename)
except OSError:
print('EX: unable to rename 2 ' + unblockingFilename)
return False
return True return True
return False return False
@ -191,8 +207,8 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
unblockHandle = unblockNickname + '@' + unblockDomain unblockHandle = unblockNickname + '@' + unblockDomain
if os.path.isfile(unblockingFilename): if os.path.isfile(unblockingFilename):
if unblockHandle in open(unblockingFilename).read(): if unblockHandle in open(unblockingFilename).read():
with open(unblockingFilename, 'r') as fp:
try: try:
with open(unblockingFilename, 'r') as fp:
with open(unblockingFilename + '.new', 'w+') as fpnew: with open(unblockingFilename + '.new', 'w+') as fpnew:
for line in fp: for line in fp:
handle = line.replace('\n', '').replace('\r', '') handle = line.replace('\n', '').replace('\r', '')
@ -202,8 +218,13 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
print('EX: failed to remove block ' + print('EX: failed to remove block ' +
unblockingFilename + ' ' + str(e)) unblockingFilename + ' ' + str(e))
return False return False
if os.path.isfile(unblockingFilename + '.new'): if os.path.isfile(unblockingFilename + '.new'):
try:
os.rename(unblockingFilename + '.new', unblockingFilename) os.rename(unblockingFilename + '.new', unblockingFilename)
except OSError:
print('EX: unable to rename 3 ' + unblockingFilename)
return False
return True return True
return False return False
@ -237,8 +258,11 @@ def getDomainBlocklist(baseDir: str) -> str:
globalBlockingFilename = baseDir + '/accounts/blocking.txt' globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if not os.path.isfile(globalBlockingFilename): if not os.path.isfile(globalBlockingFilename):
return blockedStr return blockedStr
try:
with open(globalBlockingFilename, 'r') as fpBlocked: with open(globalBlockingFilename, 'r') as fpBlocked:
blockedStr += fpBlocked.read() blockedStr += fpBlocked.read()
except OSError:
print('EX: unable to read ' + globalBlockingFilename)
return blockedStr return blockedStr
@ -258,6 +282,7 @@ def updateBlockedCache(baseDir: str,
globalBlockingFilename = baseDir + '/accounts/blocking.txt' globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if not os.path.isfile(globalBlockingFilename): if not os.path.isfile(globalBlockingFilename):
return blockedCacheLastUpdated return blockedCacheLastUpdated
try:
with open(globalBlockingFilename, 'r') as fpBlocked: with open(globalBlockingFilename, 'r') as fpBlocked:
blockedLines = fpBlocked.readlines() blockedLines = fpBlocked.readlines()
# remove newlines # remove newlines
@ -266,6 +291,8 @@ def updateBlockedCache(baseDir: str,
# update the cache # update the cache
blockedCache.clear() blockedCache.clear()
blockedCache += blockedLines blockedCache += blockedLines
except OSError as e:
print('EX: unable to read ' + globalBlockingFilename + ' ' + str(e))
return currTime return currTime
@ -305,6 +332,7 @@ def isBlockedDomain(baseDir: str, domain: str,
# instance block list # instance block list
globalBlockingFilename = baseDir + '/accounts/blocking.txt' globalBlockingFilename = baseDir + '/accounts/blocking.txt'
if os.path.isfile(globalBlockingFilename): if os.path.isfile(globalBlockingFilename):
try:
with open(globalBlockingFilename, 'r') as fpBlocked: with open(globalBlockingFilename, 'r') as fpBlocked:
blockedStr = fpBlocked.read() blockedStr = fpBlocked.read()
if '*@' + domain in blockedStr: if '*@' + domain in blockedStr:
@ -312,6 +340,9 @@ def isBlockedDomain(baseDir: str, domain: str,
if shortDomain: if shortDomain:
if '*@' + shortDomain in blockedStr: if '*@' + shortDomain in blockedStr:
return True return True
except OSError as e:
print('EX: unable to read ' + globalBlockingFilename +
' ' + str(e))
else: else:
allowFilename = baseDir + '/accounts/allowedinstances.txt' allowFilename = baseDir + '/accounts/allowedinstances.txt'
# instance allow list # instance allow list
@ -572,10 +603,10 @@ def mutePost(baseDir: str, nickname: str, domain: str, port: int,
try: try:
with open(postFilename + '.muted', 'w+') as muteFile: with open(postFilename + '.muted', 'w+') as muteFile:
muteFile.write('\n') muteFile.write('\n')
print('MUTE: ' + postFilename + '.muted file added')
except OSError: except OSError:
print('EX: Failed to save mute file ' + postFilename + '.muted') print('EX: Failed to save mute file ' + postFilename + '.muted')
return return
print('MUTE: ' + postFilename + '.muted file added')
# if the post is in the recent posts cache then mark it as muted # if the post is in the recent posts cache then mark it as muted
if recentPostsCache.get('index'): if recentPostsCache.get('index'):
@ -886,6 +917,7 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
followingFilename = accountDir + '/' + followFileType followingFilename = accountDir + '/' + followFileType
if not os.path.isfile(followingFilename): if not os.path.isfile(followingFilename):
continue continue
try:
with open(followingFilename, 'r') as f: with open(followingFilename, 'r') as f:
followList = f.readlines() followList = f.readlines()
for handle in followList: for handle in followList:
@ -895,6 +927,9 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
handleDomain = handle.split('@')[1] handleDomain = handle.split('@')[1]
if handleDomain not in allowedDomains: if handleDomain not in allowedDomains:
allowedDomains.append(handleDomain) allowedDomains.append(handleDomain)
except OSError as e:
print('EX: failed to read ' + followingFilename +
' ' + str(e))
break break
# write the allow file # write the allow file

19
blog.py
View File

@ -72,8 +72,12 @@ def _noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
removals = [] removals = []
replies = 0 replies = 0
lines = [] lines = []
try:
with open(postFilename, 'r') as f: with open(postFilename, 'r') as f:
lines = f.readlines() lines = f.readlines()
except OSError:
print('EX: failed to read blog ' + postFilename)
for replyPostId in lines: for replyPostId in lines:
replyPostId = replyPostId.replace('\n', '').replace('\r', '') replyPostId = replyPostId.replace('\n', '').replace('\r', '')
replyPostId = replyPostId.replace('.json', '') replyPostId = replyPostId.replace('.json', '')
@ -135,12 +139,21 @@ def _getBlogReplies(baseDir: str, httpPrefix: str, translate: {},
'/postcache/' + \ '/postcache/' + \
postId.replace('/', '#') + '.html' postId.replace('/', '#') + '.html'
if os.path.isfile(postFilename): if os.path.isfile(postFilename):
try:
with open(postFilename, 'r') as postFile: with open(postFilename, 'r') as postFile:
return postFile.read() + '\n' return postFile.read() + '\n'
except OSError:
print('EX: unable to read blog 3 ' + postFilename)
return '' return ''
lines = []
try:
with open(postFilename, 'r') as f: with open(postFilename, 'r') as f:
lines = f.readlines() lines = f.readlines()
except OSError:
print('EX: unable to read blog 4 ' + postFilename)
if lines:
repliesStr = '' repliesStr = ''
for replyPostId in lines: for replyPostId in lines:
replyPostId = replyPostId.replace('\n', '').replace('\r', '') replyPostId = replyPostId.replace('\n', '').replace('\r', '')
@ -151,8 +164,11 @@ def _getBlogReplies(baseDir: str, httpPrefix: str, translate: {},
replyPostId.replace('/', '#') + '.html' replyPostId.replace('/', '#') + '.html'
if not os.path.isfile(postFilename): if not os.path.isfile(postFilename):
continue continue
try:
with open(postFilename, 'r') as postFile: with open(postFilename, 'r') as postFile:
repliesStr += postFile.read() + '\n' repliesStr += postFile.read() + '\n'
except OSError:
print('EX: unable to read blog replies ' + postFilename)
rply = _getBlogReplies(baseDir, httpPrefix, translate, rply = _getBlogReplies(baseDir, httpPrefix, translate,
nickname, domain, domainFull, nickname, domain, domainFull,
replyPostId, depth+1) replyPostId, depth+1)
@ -770,8 +786,11 @@ def htmlEditBlog(mediaInstance: bool, translate: {},
editBlogText = '<h1">' + translate['Write your post text below.'] + '</h1>' editBlogText = '<h1">' + translate['Write your post text below.'] + '</h1>'
if os.path.isfile(baseDir + '/accounts/newpost.txt'): if os.path.isfile(baseDir + '/accounts/newpost.txt'):
try:
with open(baseDir + '/accounts/newpost.txt', 'r') as file: with open(baseDir + '/accounts/newpost.txt', 'r') as file:
editBlogText = '<p>' + file.read() + '</p>' editBlogText = '<p>' + file.read() + '</p>'
except OSError:
print('EX: unable to read ' + baseDir + '/accounts/newpost.txt')
cssFilename = baseDir + '/epicyon-profile.css' cssFilename = baseDir + '/epicyon-profile.css'
if os.path.isfile(baseDir + '/epicyon.css'): if os.path.isfile(baseDir + '/epicyon.css'):

View File

@ -71,8 +71,12 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
if bookmarkIndex not in open(bookmarksIndexFilename).read(): if bookmarkIndex not in open(bookmarksIndexFilename).read():
return return
indexStr = '' indexStr = ''
try:
with open(bookmarksIndexFilename, 'r') as indexFile: with open(bookmarksIndexFilename, 'r') as indexFile:
indexStr = indexFile.read().replace(bookmarkIndex + '\n', '') indexStr = indexFile.read().replace(bookmarkIndex + '\n', '')
except OSError:
print('EX: unable to read ' + bookmarksIndexFilename)
if indexStr:
try: try:
with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile: with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile:
bookmarksIndexFile.write(indexStr) bookmarksIndexFile.write(indexStr)

View File

@ -23,8 +23,12 @@ def getHashtagCategory(baseDir: str, hashtag: str) -> str:
if not os.path.isfile(categoryFilename): if not os.path.isfile(categoryFilename):
return '' return ''
categoryStr = None
try:
with open(categoryFilename, 'r') as fp: with open(categoryFilename, 'r') as fp:
categoryStr = fp.read() categoryStr = fp.read()
except OSError:
print('EX: unable to read category ' + categoryFilename)
if categoryStr: if categoryStr:
return categoryStr return categoryStr
return '' return ''
@ -161,15 +165,21 @@ def setHashtagCategory(baseDir: str, hashtag: str, category: str,
# don't overwrite any existing categories # don't overwrite any existing categories
if os.path.isfile(categoryFilename): if os.path.isfile(categoryFilename):
return False return False
categoryWritten = False
try: try:
with open(categoryFilename, 'w+') as fp: with open(categoryFilename, 'w+') as fp:
fp.write(category) fp.write(category)
if update: categoryWritten = True
updateHashtagCategories(baseDir)
return True
except OSError as e: except OSError as e:
print('EX: unable to write category ' + categoryFilename + print('EX: unable to write category ' + categoryFilename +
' ' + str(e)) ' ' + str(e))
if categoryWritten:
if update:
updateHashtagCategories(baseDir)
return True
return False return False

10
city.py
View File

@ -196,16 +196,23 @@ def spoofGeolocation(baseDir: str,
default_latdirection, default_longdirection, default_latdirection, default_longdirection,
"", "", 0) "", "", 0)
cities = [] cities = []
try:
with open(locationsFilename, 'r') as f: with open(locationsFilename, 'r') as f:
cities = f.readlines() cities = f.readlines()
except OSError:
print('EX: unable to read locations ' + locationsFilename)
nogo = [] nogo = []
if nogoList: if nogoList:
nogo = nogoList nogo = nogoList
else: else:
if os.path.isfile(nogoFilename): if os.path.isfile(nogoFilename):
nogoList = []
try:
with open(nogoFilename, 'r') as f: with open(nogoFilename, 'r') as f:
nogoList = f.readlines() nogoList = f.readlines()
except OSError:
print('EX: unable to read ' + nogoFilename)
for line in nogoList: for line in nogoList:
if line.startswith(city + ':'): if line.startswith(city + ':'):
polygon = parseNogoString(line) polygon = parseNogoString(line)
@ -295,8 +302,11 @@ def getSpoofedCity(city: str, baseDir: str, nickname: str, domain: str) -> str:
city = '' city = ''
cityFilename = acctDir(baseDir, nickname, domain) + '/city.txt' cityFilename = acctDir(baseDir, nickname, domain) + '/city.txt'
if os.path.isfile(cityFilename): if os.path.isfile(cityFilename):
try:
with open(cityFilename, 'r') as fp: with open(cityFilename, 'r') as fp:
city = fp.read().replace('\n', '') city = fp.read().replace('\n', '')
except OSError:
print('EX: unable to read ' + cityFilename)
return city return city

View File

@ -178,9 +178,14 @@ def dangerousCSS(filename: str, allowLocalNetworkAccess: bool) -> bool:
if not os.path.isfile(filename): if not os.path.isfile(filename):
return False return False
content = None
try:
with open(filename, 'r') as fp: with open(filename, 'r') as fp:
content = fp.read().lower() content = fp.read().lower()
except OSError:
print('EX: unable to read css file ' + filename)
if content:
cssMatches = ('behavior:', ':expression', '?php', '.php', cssMatches = ('behavior:', ':expression', '?php', '.php',
'google', 'regexp', 'localhost', 'google', 'regexp', 'localhost',
'127.0.', '192.168', '10.0.', '@import') '127.0.', '192.168', '10.0.', '@import')
@ -221,8 +226,11 @@ def switchWords(baseDir: str, nickname: str, domain: str, content: str,
acctDir(baseDir, nickname, domain) + '/replacewords.txt' acctDir(baseDir, nickname, domain) + '/replacewords.txt'
if not os.path.isfile(switchWordsFilename): if not os.path.isfile(switchWordsFilename):
return content return content
try:
with open(switchWordsFilename, 'r') as fp: with open(switchWordsFilename, 'r') as fp:
rules = fp.readlines() rules = fp.readlines()
except OSError:
print('EX: unable to read switches ' + switchWordsFilename)
for line in rules: for line in rules:
replaceStr = line.replace('\n', '').replace('\r', '') replaceStr = line.replace('\n', '').replace('\r', '')
@ -779,8 +787,11 @@ def _loadAutoTags(baseDir: str, nickname: str, domain: str) -> []:
filename = acctDir(baseDir, nickname, domain) + '/autotags.txt' filename = acctDir(baseDir, nickname, domain) + '/autotags.txt'
if not os.path.isfile(filename): if not os.path.isfile(filename):
return [] return []
try:
with open(filename, 'r') as f: with open(filename, 'r') as f:
return f.readlines() return f.readlines()
except OSError:
print('EX: unable to read auto tags ' + filename)
return [] return []
@ -853,8 +864,12 @@ def addHtmlTags(baseDir: str, httpPrefix: str,
petnames = None petnames = None
if '@' in words: if '@' in words:
if os.path.isfile(followingFilename): if os.path.isfile(followingFilename):
following = []
try:
with open(followingFilename, 'r') as f: with open(followingFilename, 'r') as f:
following = f.readlines() following = f.readlines()
except OSError:
print('EX: unable to read ' + followingFilename)
for handle in following: for handle in following:
pet = getPetName(baseDir, nickname, domain, handle) pet = getPetName(baseDir, nickname, domain, handle)
if pet: if pet:

View File

@ -2355,13 +2355,16 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isdir(accountDir): if os.path.isdir(accountDir):
nwFilename = newswireBlockedFilename nwFilename = newswireBlockedFilename
nwWritten = False
try: try:
with open(nwFilename, 'w+') as noNewswireFile: with open(nwFilename, 'w+') as noNewswireFile:
noNewswireFile.write('\n') noNewswireFile.write('\n')
refreshNewswire(self.server.baseDir) nwWritten = True
except OSError as e: except OSError as e:
print('EX: unable to write ' + nwFilename + print('EX: unable to write ' + nwFilename +
' ' + str(e)) ' ' + str(e))
if nwWritten:
refreshNewswire(self.server.baseDir)
usersPathStr = \ usersPathStr = \
usersPath + '/' + self.server.defaultTimeline + \ usersPath + '/' + self.server.defaultTimeline + \
'?page=' + str(pageNumber) '?page=' + str(pageNumber)
@ -2398,13 +2401,16 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
if os.path.isdir(accountDir): if os.path.isdir(accountDir):
featFilename = featuresBlockedFilename featFilename = featuresBlockedFilename
featWritten = False
try: try:
with open(featFilename, 'w+') as noFeaturesFile: with open(featFilename, 'w+') as noFeaturesFile:
noFeaturesFile.write('\n') noFeaturesFile.write('\n')
refreshNewswire(self.server.baseDir) featWritten = True
except OSError as e: except OSError as e:
print('EX: unable to write ' + featFilename + print('EX: unable to write ' + featFilename +
' ' + str(e)) ' ' + str(e))
if featWritten:
refreshNewswire(self.server.baseDir)
usersPathStr = \ usersPathStr = \
usersPath + '/' + self.server.defaultTimeline + \ usersPath + '/' + self.server.defaultTimeline + \
'?page=' + str(pageNumber) '?page=' + str(pageNumber)
@ -3906,8 +3912,11 @@ class PubServer(BaseHTTPRequestHandler):
if fields.get('editedLinks'): if fields.get('editedLinks'):
linksStr = fields['editedLinks'] linksStr = fields['editedLinks']
try:
with open(linksFilename, 'w+') as linksFile: with open(linksFilename, 'w+') as linksFile:
linksFile.write(linksStr) linksFile.write(linksStr)
except OSError:
print('EX: _linksUpdate unable to write ' + linksFilename)
else: else:
if os.path.isfile(linksFilename): if os.path.isfile(linksFilename):
try: try:
@ -3923,8 +3932,11 @@ class PubServer(BaseHTTPRequestHandler):
aboutStr = fields['editedAbout'] aboutStr = fields['editedAbout']
if not dangerousMarkup(aboutStr, if not dangerousMarkup(aboutStr,
allowLocalNetworkAccess): allowLocalNetworkAccess):
try:
with open(aboutFilename, 'w+') as aboutFile: with open(aboutFilename, 'w+') as aboutFile:
aboutFile.write(aboutStr) aboutFile.write(aboutStr)
except OSError:
print('EX: unable to write about ' + aboutFilename)
else: else:
if os.path.isfile(aboutFilename): if os.path.isfile(aboutFilename):
try: try:
@ -3937,8 +3949,11 @@ class PubServer(BaseHTTPRequestHandler):
TOSStr = fields['editedTOS'] TOSStr = fields['editedTOS']
if not dangerousMarkup(TOSStr, if not dangerousMarkup(TOSStr,
allowLocalNetworkAccess): allowLocalNetworkAccess):
try:
with open(TOSFilename, 'w+') as TOSFile: with open(TOSFilename, 'w+') as TOSFile:
TOSFile.write(TOSStr) TOSFile.write(TOSStr)
except OSError:
print('EX: unable to write TOS ' + TOSFilename)
else: else:
if os.path.isfile(TOSFilename): if os.path.isfile(TOSFilename):
try: try: