Exception variable names

main
Bob Mottram 2021-12-25 15:28:52 +00:00
parent b9390bfc56
commit 8c0c6b08ff
24 changed files with 308 additions and 306 deletions

View File

@ -175,9 +175,9 @@ def storeBasicCredentials(baseDir: str, nickname: str, password: str) -> bool:
fout.write(line)
else:
fout.write(storeStr + '\n')
except OSError as e:
except OSError as ex:
print('EX: unable to save password ' + passwordFile +
' ' + str(e))
' ' + str(ex))
return False
try:
@ -215,8 +215,8 @@ def removePassword(baseDir: str, nickname: str) -> None:
for line in fin:
if not line.startswith(nickname + ':'):
fout.write(line)
except OSError as e:
print('EX: unable to remove password from file ' + str(e))
except OSError as ex:
print('EX: unable to remove password from file ' + str(ex))
return
try:

View File

@ -157,9 +157,9 @@ def removeGlobalBlock(baseDir: str,
line.replace('\n', '').replace('\r', '')
if unblockHandle not in line:
fpnew.write(handle + '\n')
except OSError as e:
except OSError as ex:
print('EX: failed to remove global block ' +
unblockingFilename + ' ' + str(e))
unblockingFilename + ' ' + str(ex))
return False
if os.path.isfile(unblockingFilename + '.new'):
@ -182,9 +182,9 @@ def removeGlobalBlock(baseDir: str,
line.replace('\n', '').replace('\r', '')
if unblockHashtag not in line:
fpnew.write(blockLine + '\n')
except OSError as e:
except OSError as ex:
print('EX: failed to remove global hashtag block ' +
unblockingFilename + ' ' + str(e))
unblockingFilename + ' ' + str(ex))
return False
if os.path.isfile(unblockingFilename + '.new'):
@ -214,9 +214,9 @@ def removeBlock(baseDir: str, nickname: str, domain: str,
handle = line.replace('\n', '').replace('\r', '')
if unblockHandle not in line:
fpnew.write(handle + '\n')
except OSError as e:
except OSError as ex:
print('EX: failed to remove block ' +
unblockingFilename + ' ' + str(e))
unblockingFilename + ' ' + str(ex))
return False
if os.path.isfile(unblockingFilename + '.new'):
@ -291,8 +291,8 @@ def updateBlockedCache(baseDir: str,
# update the cache
blockedCache.clear()
blockedCache += blockedLines
except OSError as e:
print('EX: unable to read ' + globalBlockingFilename + ' ' + str(e))
except OSError as ex:
print('EX: unable to read ' + globalBlockingFilename + ' ' + str(ex))
return currTime
@ -340,9 +340,9 @@ def isBlockedDomain(baseDir: str, domain: str,
if shortDomain:
if '*@' + shortDomain in blockedStr:
return True
except OSError as e:
except OSError as ex:
print('EX: unable to read ' + globalBlockingFilename +
' ' + str(e))
' ' + str(ex))
else:
allowFilename = baseDir + '/accounts/allowedinstances.txt'
# instance allow list
@ -927,9 +927,9 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
handleDomain = handle.split('@')[1]
if handleDomain not in allowedDomains:
allowedDomains.append(handleDomain)
except OSError as e:
except OSError as ex:
print('EX: failed to read ' + followingFilename +
' ' + str(e))
' ' + str(ex))
break
# write the allow file
@ -939,8 +939,8 @@ def setBrochMode(baseDir: str, domainFull: str, enabled: bool) -> None:
for d in allowedDomains:
allowFile.write(d + '\n')
print('Broch mode enabled')
except OSError as e:
print('EX: Broch mode not enabled due to file write ' + str(e))
except OSError as ex:
print('EX: Broch mode not enabled due to file write ' + str(ex))
return
setConfigParam(baseDir, "brochMode", enabled)

View File

@ -102,9 +102,9 @@ def _noOfBlogReplies(baseDir: str, httpPrefix: str, translate: {},
replyPostId.replace('\n', '').replace('\r', '')
if replyPostId not in removals:
f.write(replyPostId + '\n')
except OSError as e:
except OSError as ex:
print('EX: unable to remove replies from post ' +
postFilename + ' ' + str(e))
postFilename + ' ' + str(ex))
return replies

View File

@ -234,9 +234,9 @@ def updateBookmarksCollection(recentPostsCache: {},
bmIndexFile.write(bookmarkIndex + '\n' + content)
if debug:
print('DEBUG: bookmark added to index')
except Exception as e:
except Exception as ex:
print('WARN: Failed to write entry to bookmarks index ' +
bookmarksIndexFilename + ' ' + str(e))
bookmarksIndexFilename + ' ' + str(ex))
else:
try:
with open(bookmarksIndexFilename, 'w+') as bookmarksIndexFile:

View File

@ -171,9 +171,9 @@ def setHashtagCategory(baseDir: str, hashtag: str, category: str,
with open(categoryFilename, 'w+') as fp:
fp.write(category)
categoryWritten = True
except OSError as e:
except OSError as ex:
print('EX: unable to write category ' + categoryFilename +
' ' + str(e))
' ' + str(ex))
if categoryWritten:
if update:

320
daemon.py
View File

@ -1009,12 +1009,12 @@ class PubServer(BaseHTTPRequestHandler):
try:
self.wfile.write(msg)
return True
except BrokenPipeError as e:
except BrokenPipeError as ex:
if self.server.debug:
print('ERROR: _write error ' + str(tries) + ' ' + str(e))
print('ERROR: _write error ' + str(tries) + ' ' + str(ex))
break
except Exception as e:
print('ERROR: _write error ' + str(tries) + ' ' + str(e))
except Exception as ex:
print('ERROR: _write error ' + str(tries) + ' ' + str(ex))
time.sleep(0.5)
tries += 1
return False
@ -1655,8 +1655,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
loginParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST login read ' +
'connection reset by peer')
else:
@ -1665,8 +1665,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: POST login read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST login read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -1770,16 +1770,16 @@ class PubServer(BaseHTTPRequestHandler):
try:
with open(saltFilename, 'r') as fp:
salt = fp.read()
except OSError as e:
except OSError as ex:
print('EX: Unable to read salt for ' +
loginNickname + ' ' + str(e))
loginNickname + ' ' + str(ex))
else:
try:
with open(saltFilename, 'w+') as fp:
fp.write(salt)
except OSError as e:
except OSError as ex:
print('EX: Unable to save salt for ' +
loginNickname + ' ' + str(e))
loginNickname + ' ' + str(ex))
tokenText = loginNickname + loginPassword + salt
token = sha256(tokenText.encode('utf-8')).hexdigest()
@ -1791,9 +1791,9 @@ class PubServer(BaseHTTPRequestHandler):
try:
with open(tokenFilename, 'w+') as fp:
fp.write(token)
except OSError as e:
except OSError as ex:
print('EX: Unable to save token for ' +
loginNickname + ' ' + str(e))
loginNickname + ' ' + str(ex))
personUpgradeActor(baseDir, None, loginHandle,
baseDir + '/accounts/' +
@ -1848,8 +1848,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
moderationParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST moderationParams connection was reset')
else:
print('WARN: POST moderationParams ' +
@ -1858,8 +1858,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: POST moderationParams rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST moderationParams rfile.read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -2052,8 +2052,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
accessKeysParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST accessKeysParams ' +
'connection reset by peer')
else:
@ -2062,8 +2062,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: POST accessKeysParams rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST accessKeysParams rfile.read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -2139,8 +2139,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
themeParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST themeParams ' +
'connection reset by peer')
else:
@ -2149,8 +2149,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: POST themeParams rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST themeParams rfile.read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -2281,8 +2281,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
optionsConfirmParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST optionsConfirmParams ' +
'connection reset by peer')
else:
@ -2291,9 +2291,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: ' +
'POST optionsConfirmParams rfile.read failed, ' + str(e))
'POST optionsConfirmParams rfile.read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -2505,9 +2505,9 @@ class PubServer(BaseHTTPRequestHandler):
with open(nwFilename, 'w+') as noNewswireFile:
noNewswireFile.write('\n')
nwWritten = True
except OSError as e:
except OSError as ex:
print('EX: unable to write ' + nwFilename +
' ' + str(e))
' ' + str(ex))
if nwWritten:
refreshNewswire(self.server.baseDir)
usersPathStr = \
@ -2551,9 +2551,9 @@ class PubServer(BaseHTTPRequestHandler):
with open(featFilename, 'w+') as noFeaturesFile:
noFeaturesFile.write('\n')
featWritten = True
except OSError as e:
except OSError as ex:
print('EX: unable to write ' + featFilename +
' ' + str(e))
' ' + str(ex))
if featWritten:
refreshNewswire(self.server.baseDir)
usersPathStr = \
@ -2893,8 +2893,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
followConfirmParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST followConfirmParams ' +
'connection was reset')
else:
@ -2903,9 +2903,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: POST followConfirmParams rfile.read failed, ' +
str(e))
str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -2980,8 +2980,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
followConfirmParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST followConfirmParams ' +
'connection was reset')
else:
@ -2990,9 +2990,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: POST followConfirmParams rfile.read failed, ' +
str(e))
str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -3080,8 +3080,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
blockConfirmParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST blockConfirmParams ' +
'connection was reset')
else:
@ -3090,9 +3090,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: POST blockConfirmParams rfile.read failed, ' +
str(e))
str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -3167,8 +3167,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
blockConfirmParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST blockConfirmParams ' +
'connection was reset')
else:
@ -3177,9 +3177,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: POST blockConfirmParams rfile.read failed, ' +
str(e))
str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -3250,8 +3250,8 @@ class PubServer(BaseHTTPRequestHandler):
length = int(self.headers['Content-length'])
try:
searchParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST searchParams connection was reset')
else:
print('WARN: POST searchParams socket error')
@ -3259,8 +3259,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: POST searchParams rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST searchParams rfile.read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -3698,8 +3698,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
questionParams = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST questionParams connection was reset')
else:
print('WARN: POST questionParams socket error')
@ -3707,8 +3707,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: POST questionParams rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST questionParams rfile.read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -3776,8 +3776,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
mediaBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST mediaBytes ' +
'connection reset by peer')
else:
@ -3786,8 +3786,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: POST mediaBytes rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST mediaBytes rfile.read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -3824,8 +3824,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
removeShareConfirmParams = \
self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST removeShareConfirmParams ' +
'connection was reset')
else:
@ -3834,9 +3834,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: POST removeShareConfirmParams rfile.read failed, ' +
str(e))
str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -3891,8 +3891,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
removeShareConfirmParams = \
self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST removeShareConfirmParams ' +
'connection was reset')
else:
@ -3901,9 +3901,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: POST removeShareConfirmParams rfile.read failed, ' +
str(e))
str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -3961,8 +3961,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
removePostConfirmParams = \
self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST removePostConfirmParams ' +
'connection was reset')
else:
@ -3971,9 +3971,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: POST removePostConfirmParams rfile.read failed, ' +
str(e))
str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -4085,8 +4085,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
# read the bytes of the http form POST
postBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset while ' +
'reading bytes from http form POST')
else:
@ -4096,8 +4096,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: failed to read bytes for POST, ' + str(e))
except ValueError as ex:
print('ERROR: failed to read bytes for POST, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -4244,8 +4244,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
# read the bytes of the http form POST
postBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset while ' +
'reading bytes from http form POST')
else:
@ -4255,8 +4255,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: failed to read bytes for POST, ' + str(e))
except ValueError as ex:
print('ERROR: failed to read bytes for POST, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -4327,8 +4327,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
# read the bytes of the http form POST
postBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset while ' +
'reading bytes from http form POST')
else:
@ -4338,8 +4338,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: failed to read bytes for POST, ' + str(e))
except ValueError as ex:
print('ERROR: failed to read bytes for POST, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -4481,8 +4481,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
# read the bytes of the http form POST
postBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset while ' +
'reading bytes from http form ' +
'citation screen POST')
@ -4493,9 +4493,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: failed to read bytes for ' +
'citations screen POST, ' + str(e))
'citations screen POST, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -4581,8 +4581,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
# read the bytes of the http form POST
postBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset while ' +
'reading bytes from http form POST')
else:
@ -4592,8 +4592,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: failed to read bytes for POST, ' + str(e))
except ValueError as ex:
print('ERROR: failed to read bytes for POST, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -4642,8 +4642,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
saveJson(self.server.newswire,
newswireStateFilename)
except Exception as e:
print('ERROR: saving newswire state, ' + str(e))
except Exception as ex:
print('ERROR: saving newswire state, ' + str(ex))
# remove any previous cached news posts
newsId = removeIdEnding(postJsonObject['object']['id'])
@ -4702,8 +4702,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
# read the bytes of the http form POST
postBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset while ' +
'reading bytes from http form POST')
else:
@ -4713,8 +4713,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: failed to read bytes for POST, ' + str(e))
except ValueError as ex:
print('ERROR: failed to read bytes for POST, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -5711,9 +5711,9 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
except OSError as ex:
print('EX: unable to write editors ' +
editorsFile + ' ' + str(e))
editorsFile + ' ' + str(ex))
for edNick in eds:
edNick = edNick.strip()
@ -5738,9 +5738,9 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
except OSError as ex:
print('EX: unable to write editors ' +
editorsFile + ' ' + str(e))
editorsFile + ' ' + str(ex))
for edNick in eds:
edNick = edNick.strip()
@ -5775,10 +5775,10 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
except OSError as ex:
print('EX: ' +
'unable to write counselors ' +
counselorsFile + ' ' + str(e))
counselorsFile + ' ' + str(ex))
for edNick in eds:
edNick = edNick.strip()
@ -5803,10 +5803,10 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
except OSError as ex:
print('EX: ' +
'unable to write counselors ' +
counselorsFile + ' ' + str(e))
counselorsFile + ' ' + str(ex))
for edNick in eds:
edNick = edNick.strip()
@ -5840,9 +5840,9 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
except OSError as ex:
print('EX: unable to write artists ' +
artistsFile + ' ' + str(e))
artistsFile + ' ' + str(ex))
for edNick in eds:
edNick = edNick.strip()
@ -5866,9 +5866,9 @@ class PubServer(BaseHTTPRequestHandler):
'@' + domain
if os.path.isdir(edDir):
edFile.write(edNick + '\n')
except OSError as e:
except OSError as ex:
print('EX: unable to write artists ' +
artistsFile + ' ' + str(e))
artistsFile + ' ' + str(ex))
for edNick in eds:
edNick = edNick.strip()
@ -7948,8 +7948,8 @@ class PubServer(BaseHTTPRequestHandler):
baseDir + '/accounts/.newswirestate.json'
try:
saveJson(newswire, newswireStateFilename)
except Exception as e:
print('ERROR: saving newswire state, ' + str(e))
except Exception as ex:
print('ERROR: saving newswire state, ' + str(ex))
if filename:
saveJson(newswireItem[votesIndex],
filename + '.votes')
@ -8002,8 +8002,8 @@ class PubServer(BaseHTTPRequestHandler):
baseDir + '/accounts/.newswirestate.json'
try:
saveJson(newswire, newswireStateFilename)
except Exception as e:
print('ERROR: saving newswire state, ' + str(e))
except Exception as ex:
print('ERROR: saving newswire state, ' + str(ex))
if filename:
saveJson(newswireItem[votesIndex],
filename + '.votes')
@ -12441,8 +12441,9 @@ class PubServer(BaseHTTPRequestHandler):
self.server.cssCache)
if css:
break
except Exception as e:
print('ERROR: _getStyleSheet ' + str(tries) + ' ' + str(e))
except Exception as ex:
print('ERROR: _getStyleSheet ' +
str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
msg = css.encode('utf-8')
@ -12480,8 +12481,8 @@ class PubServer(BaseHTTPRequestHandler):
with open(qrFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
print('ERROR: _showQRcode ' + str(tries) + ' ' + str(e))
except Exception as ex:
print('ERROR: _showQRcode ' + str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
if mediaBinary:
@ -12524,9 +12525,9 @@ class PubServer(BaseHTTPRequestHandler):
with open(bannerFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
except Exception as ex:
print('ERROR: _searchScreenBanner ' +
str(tries) + ' ' + str(e))
str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
if mediaBinary:
@ -12568,8 +12569,8 @@ class PubServer(BaseHTTPRequestHandler):
with open(bannerFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
print('ERROR: _columnImage ' + str(tries) + ' ' + str(e))
except Exception as ex:
print('ERROR: _columnImage ' + str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
if mediaBinary:
@ -12612,9 +12613,9 @@ class PubServer(BaseHTTPRequestHandler):
with open(bgFilename, 'rb') as avFile:
bgBinary = avFile.read()
break
except Exception as e:
except Exception as ex:
print('ERROR: _showBackgroundImage ' +
str(tries) + ' ' + str(e))
str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
if bgBinary:
@ -12657,9 +12658,9 @@ class PubServer(BaseHTTPRequestHandler):
with open(bgFilename, 'rb') as avFile:
bgBinary = avFile.read()
break
except Exception as e:
except Exception as ex:
print('ERROR: _showDefaultProfileBackground ' +
str(tries) + ' ' + str(e))
str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
if bgBinary:
@ -14561,9 +14562,9 @@ class PubServer(BaseHTTPRequestHandler):
with open(mediaFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
except Exception as ex:
print('ERROR: manifest logo ' +
str(tries) + ' ' + str(e))
str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
if mediaBinary:
@ -14603,9 +14604,9 @@ class PubServer(BaseHTTPRequestHandler):
with open(screenFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
except Exception as ex:
print('ERROR: manifest screenshot ' +
str(tries) + ' ' + str(e))
str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
if mediaBinary:
@ -14645,9 +14646,9 @@ class PubServer(BaseHTTPRequestHandler):
with open(iconFilename, 'rb') as avFile:
mediaBinary = avFile.read()
break
except Exception as e:
except Exception as ex:
print('ERROR: login screen image ' +
str(tries) + ' ' + str(e))
str(tries) + ' ' + str(ex))
time.sleep(1)
tries += 1
if mediaBinary:
@ -17226,15 +17227,16 @@ class PubServer(BaseHTTPRequestHandler):
try:
postBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST postBytes ' +
'connection reset by peer')
else:
print('WARN: POST postBytes socket error')
return None
except ValueError as e:
print('ERROR: POST postBytes rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST postBytes rfile.read failed, ' +
str(ex))
return None
# second length check from the bytes received
@ -17268,16 +17270,16 @@ class PubServer(BaseHTTPRequestHandler):
return {}
try:
messageBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: handle POST messageBytes ' +
'connection reset by peer')
else:
print('WARN: handle POST messageBytes socket error')
return {}
except ValueError as e:
except ValueError as ex:
print('ERROR: handle POST messageBytes rfile.read failed ' +
str(e))
str(ex))
return {}
lenMessage = len(messageBytes)
@ -17311,15 +17313,15 @@ class PubServer(BaseHTTPRequestHandler):
return {}
try:
messageBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST messageBytes ' +
'connection reset by peer')
else:
print('WARN: POST messageBytes socket error')
return {}
except ValueError as e:
print('ERROR: POST messageBytes rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST messageBytes rfile.read failed, ' + str(ex))
return {}
lenMessage = len(messageBytes)
@ -18082,8 +18084,8 @@ class PubServer(BaseHTTPRequestHandler):
if length < self.server.maxPostLength:
try:
unknownPost = self.rfile.read(length).decode('utf-8')
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST unknownPost ' +
'connection reset by peer')
else:
@ -18092,9 +18094,9 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
except ValueError as ex:
print('ERROR: POST unknownPost rfile.read failed, ' +
str(e))
str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -18129,8 +18131,8 @@ class PubServer(BaseHTTPRequestHandler):
try:
messageBytes = self.rfile.read(length)
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: POST messageBytes ' +
'connection reset by peer')
else:
@ -18139,8 +18141,8 @@ class PubServer(BaseHTTPRequestHandler):
self.end_headers()
self.server.POSTbusy = False
return
except ValueError as e:
print('ERROR: POST messageBytes rfile.read failed, ' + str(e))
except ValueError as ex:
print('ERROR: POST messageBytes rfile.read failed, ' + str(ex))
self.send_response(400)
self.end_headers()
self.server.POSTbusy = False
@ -18367,9 +18369,9 @@ def loadTokens(baseDir: str, tokensDict: {}, tokensLookup: {}) -> None:
try:
with open(tokenFilename, 'r') as fp:
token = fp.read()
except Exception as e:
except Exception as ex:
print('WARN: Unable to read token for ' +
nickname + ' ' + str(e))
nickname + ' ' + str(ex))
if not token:
continue
tokensDict[nickname] = token
@ -18453,13 +18455,13 @@ def runDaemon(contentLicenseUrl: str,
try:
httpd = EpicyonServer(serverAddress, pubHandler)
except Exception as e:
if e.errno == 98:
except Exception as ex:
if ex.errno == 98:
print('ERROR: HTTP server address is already in use. ' +
str(serverAddress))
return False
print('ERROR: HTTP server failed to start. ' + str(e))
print('ERROR: HTTP server failed to start. ' + str(ex))
print('serverAddress: ' + str(serverAddress))
return False

View File

@ -175,8 +175,8 @@ def _markPostAsRead(actor: str, postId: str, postCategory: str) -> None:
if postId not in content:
readFile.seek(0, 0)
readFile.write(postId + content)
except Exception as e:
print('WARN: Failed to mark post as read' + str(e))
except Exception as ex:
print('WARN: Failed to mark post as read' + str(ex))
else:
with open(readPostsFilename, 'w+') as readFile:
readFile.write(postId + '\n')

View File

@ -63,8 +63,8 @@ def removeFilter(baseDir: str, nickname: str, domain: str,
line = line.replace('\n', '')
if line != words:
fpnew.write(line + '\n')
except OSError as e:
print('EX: unable to remove filter ' + filtersFilename + ' ' + str(e))
except OSError as ex:
print('EX: unable to remove filter ' + filtersFilename + ' ' + str(ex))
if os.path.isfile(newFiltersFilename):
os.rename(newFiltersFilename, filtersFilename)
return True
@ -87,9 +87,9 @@ def removeGlobalFilter(baseDir: str, words: str) -> bool:
line = line.replace('\n', '')
if line != words:
fpnew.write(line + '\n')
except OSError as e:
except OSError as ex:
print('EX: unable to remove global filter ' +
filtersFilename + ' ' + str(e))
filtersFilename + ' ' + str(ex))
if os.path.isfile(newFiltersFilename):
os.rename(newFiltersFilename, filtersFilename)
return True
@ -130,8 +130,8 @@ def _isFilteredBase(filename: str, content: str) -> bool:
if word not in content:
return False
return True
except OSError as e:
print('EX: _isFilteredBase ' + filename + ' ' + str(e))
except OSError as ex:
print('EX: _isFilteredBase ' + filename + ' ' + str(ex))
return False

View File

@ -139,9 +139,9 @@ def _removeFromFollowBase(baseDir: str,
for approveHandle in approvefile:
if acceptDenyActor not in approveHandle:
approvefilenew.write(approveHandle)
except OSError as e:
except OSError as ex:
print('EX: _removeFromFollowBase ' +
approveFollowsFilename + ' ' + str(e))
approveFollowsFilename + ' ' + str(ex))
os.rename(approveFollowsFilename + '.new', approveFollowsFilename)
@ -322,8 +322,8 @@ def unfollowAccount(baseDir: str, nickname: str, domain: str,
if checkHandle != handleToUnfollowLower and \
checkHandle != '!' + handleToUnfollowLower:
f.write(line)
except OSError as e:
print('EX: unable to write ' + filename + ' ' + str(e))
except OSError as ex:
print('EX: unable to write ' + filename + ' ' + str(ex))
# write to an unfollowed file so that if a follow accept
# later arrives then it can be ignored

4
git.py
View File

@ -216,6 +216,6 @@ def receiveGitPatch(baseDir: str, nickname: str, domain: str,
with open(patchNotifyFilename, 'w+') as patchFile:
patchFile.write(patchStr)
return True
except OSError as e:
print('EX: receiveGitPatch ' + patchFilename + ' ' + str(e))
except OSError as ex:
print('EX: receiveGitPatch ' + patchFilename + ' ' + str(ex))
return False

View File

@ -104,9 +104,9 @@ def saveEventPost(baseDir: str, handle: str, postId: str,
if eventId + '\n' not in content:
tlEventsFile.seek(0, 0)
tlEventsFile.write(eventId + '\n' + content)
except OSError as e:
except OSError as ex:
print('EX: Failed to write entry to events file ' +
tlEventsFilename + ' ' + str(e))
tlEventsFilename + ' ' + str(ex))
return False
else:
try:

View File

@ -258,9 +258,9 @@ def storeHashTags(baseDir: str, nickname: str, domain: str,
if tagline not in content:
tagsFile.seek(0, 0)
tagsFile.write(tagline + content)
except OSError as e:
except OSError as ex:
print('EX: Failed to write entry to tags file ' +
tagsFilename + ' ' + str(e))
tagsFilename + ' ' + str(ex))
removeOldHashtags(baseDir, 3)
# automatically assign a category to the tag if possible
@ -2740,15 +2740,15 @@ def inboxUpdateIndex(boxname: str, baseDir: str, handle: str,
indexFile.write(destinationFilename + '\n' + content)
written = True
return True
except OSError as e:
print('EX: Failed to write entry to index ' + str(e))
except OSError as ex:
print('EX: Failed to write entry to index ' + str(ex))
else:
try:
with open(indexFilename, 'w+') as indexFile:
indexFile.write(destinationFilename + '\n')
written = True
except OSError as e:
print('EX: Failed to write initial entry to index ' + str(e))
except OSError as ex:
print('EX: Failed to write initial entry to index ' + str(ex))
return written
@ -4035,10 +4035,10 @@ def _receiveFollowRequest(session, baseDir: str, httpPrefix: str,
else:
followersFile.write('!' + approveHandle +
'\n' + content)
except Exception as e:
except Exception as ex:
print('WARN: ' +
'Failed to write entry to followers file ' +
str(e))
str(ex))
else:
try:
with open(followersFilename, 'w+') as followersFile:

View File

@ -239,9 +239,9 @@ def manualApproveFollowRequest(session, baseDir: str,
followersFile.seek(0, 0)
followersFile.write(approveHandleFull + '\n' +
content)
except Exception as e:
except Exception as ex:
print('WARN: Manual follow accept. ' +
'Failed to write entry to followers file ' + str(e))
'Failed to write entry to followers file ' + str(ex))
else:
print('WARN: Manual follow accept: ' + approveHandleFull +
' already exists in ' + followersFilename)

View File

@ -53,9 +53,9 @@ def _updateFeedsOutboxIndex(baseDir: str, domain: str, postId: str) -> None:
feedsFile.seek(0, 0)
feedsFile.write(postId + '\n' + content)
print('DEBUG: feeds post added to index')
except Exception as e:
except Exception as ex:
print('WARN: Failed to write entry to feeds posts index ' +
indexFilename + ' ' + str(e))
indexFilename + ' ' + str(ex))
else:
try:
with open(indexFilename, 'w+') as feedsFile:

View File

@ -903,19 +903,19 @@ def getRSS(baseDir: str, domain: str, session, url: str,
'or contains invalid characters: ' + url)
else:
print('WARN: no result returned for feed ' + url)
except requests.exceptions.RequestException as e:
except requests.exceptions.RequestException as ex:
print('WARN: getRSS failed\nurl: ' + str(url) + ', ' +
'headers: ' + str(sessionHeaders) + ', ' +
'params: ' + str(sessionParams) + ', ' + str(e))
except ValueError as e:
'params: ' + str(sessionParams) + ', ' + str(ex))
except ValueError as ex:
print('WARN: getRSS failed\nurl: ' + str(url) + ', ' +
'headers: ' + str(sessionHeaders) + ', ' +
'params: ' + str(sessionParams) + ', ' + str(e))
except SocketError as e:
if e.errno == errno.ECONNRESET:
print('WARN: connection was reset during getRSS ' + str(e))
'params: ' + str(sessionParams) + ', ' + str(ex))
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset during getRSS ' + str(ex))
else:
print('WARN: getRSS, ' + str(e))
print('WARN: getRSS, ' + str(ex))
return None
@ -940,8 +940,8 @@ def getRSSfromDict(baseDir: str, newswire: {},
published = publishedWithOffset.strftime("%Y-%m-%dT%H:%M:%SZ")
try:
pubDate = datetime.strptime(published, "%Y-%m-%dT%H:%M:%SZ")
except Exception as e:
print('WARN: Unable to convert date ' + published + ' ' + str(e))
except Exception as ex:
print('WARN: Unable to convert date ' + published + ' ' + str(ex))
continue
rssStr += \
'<item>\n' + \

View File

@ -1043,9 +1043,9 @@ def reenableAccount(baseDir: str, nickname: str) -> None:
for suspended in lines:
if suspended.strip('\n').strip('\r') != nickname:
suspendedFile.write(suspended)
except OSError as e:
except OSError as ex:
print('EX: unable to save ' + suspendedFilename +
' ' + str(e))
' ' + str(ex))
def suspendAccount(baseDir: str, nickname: str, domain: str) -> None:

View File

@ -901,8 +901,8 @@ def deleteAllPosts(baseDir: str,
os.unlink(filePath)
elif os.path.isdir(filePath):
shutil.rmtree(filePath, ignore_errors=False, onerror=None)
except Exception as e:
print('ERROR: deleteAllPosts ' + str(e))
except Exception as ex:
print('ERROR: deleteAllPosts ' + str(ex))
def savePostToBox(baseDir: str, httpPrefix: str, postId: str,
@ -963,9 +963,9 @@ def _updateHashtagsIndex(baseDir: str, tag: {}, newPostId: str) -> None:
if tagline not in content:
tagsFile.seek(0, 0)
tagsFile.write(tagline + content)
except Exception as e:
except Exception as ex:
print('WARN: Failed to write entry to tags file ' +
tagsFilename + ' ' + str(e))
tagsFilename + ' ' + str(ex))
def _addSchedulePost(baseDir: str, nickname: str, domain: str,
@ -985,9 +985,9 @@ def _addSchedulePost(baseDir: str, nickname: str, domain: str,
scheduleFile.seek(0, 0)
scheduleFile.write(indexStr + '\n' + content)
print('DEBUG: scheduled post added to index')
except Exception as e:
except Exception as ex:
print('WARN: Failed to write entry to scheduled posts index ' +
scheduleIndexFilename + ' ' + str(e))
scheduleIndexFilename + ' ' + str(ex))
else:
with open(scheduleIndexFilename, 'w+') as scheduleFile:
scheduleFile.write(indexStr + '\n')
@ -2223,8 +2223,8 @@ def threadSendPost(session, postJsonStr: str, federationList: [],
if debug:
print('Obtained postJsonString for ' + inboxUrl +
' unauthorized: ' + str(unauthorized))
except Exception as e:
print('ERROR: postJsonString failed ' + str(e))
except Exception as ex:
print('ERROR: postJsonString failed ' + str(ex))
if unauthorized:
print('WARN: threadSendPost: Post is unauthorized ' +
inboxUrl + ' ' + postJsonStr)
@ -2358,8 +2358,8 @@ def sendPost(signingPrivateKeyPem: str, projectVersion: str,
signedPostJsonObject = postJsonObject.copy()
generateJsonSignature(signedPostJsonObject, privateKeyPem)
postJsonObject = signedPostJsonObject
except Exception as e:
print('WARN: failed to JSON-LD sign post, ' + str(e))
except Exception as ex:
print('WARN: failed to JSON-LD sign post, ' + str(ex))
pass
# convert json to string so that there are no
@ -2729,8 +2729,8 @@ def sendSignedJson(postJsonObject: {}, session, baseDir: str,
signedPostJsonObject = postJsonObject.copy()
generateJsonSignature(signedPostJsonObject, privateKeyPem)
postJsonObject = signedPostJsonObject
except Exception as e:
print('WARN: failed to JSON-LD sign post, ' + str(e))
except Exception as ex:
print('WARN: failed to JSON-LD sign post, ' + str(ex))
pass
# convert json to string so that there are no
@ -3033,13 +3033,13 @@ def sendToNamedAddressesThread(session, baseDir: str,
signingPrivateKeyPem), daemon=True)
try:
sendThread.start()
except SocketError as e:
except SocketError as ex:
print('WARN: socket error while starting ' +
'thread to send to named addresses. ' + str(e))
'thread to send to named addresses. ' + str(ex))
return None
except ValueError as e:
except ValueError as ex:
print('WARN: error while starting ' +
'thread to send to named addresses. ' + str(e))
'thread to send to named addresses. ' + str(ex))
return None
return sendThread
@ -3282,13 +3282,13 @@ def sendToFollowersThread(session, baseDir: str,
signingPrivateKeyPem), daemon=True)
try:
sendThread.start()
except SocketError as e:
except SocketError as ex:
print('WARN: socket error while starting ' +
'thread to send to followers. ' + str(e))
'thread to send to followers. ' + str(ex))
return None
except ValueError as e:
except ValueError as ex:
print('WARN: error while starting ' +
'thread to send to followers. ' + str(e))
'thread to send to followers. ' + str(ex))
return None
return sendThread

View File

@ -439,8 +439,8 @@ def load_document(url):
}
return doc
return None
except JsonLdError as e:
raise e
except JsonLdError as ex:
raise ex
except Exception as cause:
raise JsonLdError(
'Could not retrieve a JSON-LD document from the URL.',

View File

@ -24,17 +24,17 @@ def createSession(proxyType: str):
session = None
try:
session = requests.session()
except requests.exceptions.RequestException as e:
print('WARN: requests error during createSession ' + str(e))
except requests.exceptions.RequestException as ex:
print('WARN: requests error during createSession ' + str(ex))
return None
except SocketError as e:
if e.errno == errno.ECONNRESET:
print('WARN: connection was reset during createSession ' + str(e))
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset during createSession ' + str(ex))
else:
print('WARN: socket error during createSession ' + str(e))
print('WARN: socket error during createSession ' + str(ex))
return None
except ValueError as e:
print('WARN: error during createSession ' + str(e))
except ValueError as ex:
print('WARN: error during createSession ' + str(ex))
return None
if not session:
return None
@ -112,27 +112,27 @@ def _getJsonRequest(session, url: str, domainFull: str, sessionHeaders: {},
if returnJson:
return result.json()
return result.content
except requests.exceptions.RequestException as e:
except requests.exceptions.RequestException as ex:
sessionHeaders2 = sessionHeaders.copy()
if sessionHeaders2.get('Authorization'):
sessionHeaders2['Authorization'] = 'REDACTED'
if debug and not quiet:
print('ERROR: getJson failed, url: ' + str(url) + ', ' +
'headers: ' + str(sessionHeaders2) + ', ' +
'params: ' + str(sessionParams) + ', ' + str(e))
except ValueError as e:
'params: ' + str(sessionParams) + ', ' + str(ex))
except ValueError as ex:
sessionHeaders2 = sessionHeaders.copy()
if sessionHeaders2.get('Authorization'):
sessionHeaders2['Authorization'] = 'REDACTED'
if debug and not quiet:
print('ERROR: getJson failed, url: ' + str(url) + ', ' +
'headers: ' + str(sessionHeaders2) + ', ' +
'params: ' + str(sessionParams) + ', ' + str(e))
except SocketError as e:
'params: ' + str(sessionParams) + ', ' + str(ex))
except SocketError as ex:
if not quiet:
if e.errno == errno.ECONNRESET:
if ex.errno == errno.ECONNRESET:
print('WARN: getJson failed, ' +
'connection was reset during getJson ' + str(e))
'connection was reset during getJson ' + str(ex))
return None
@ -312,27 +312,27 @@ def postJson(httpPrefix: str, domainFull: str,
session.post(url=inboxUrl,
data=json.dumps(postJsonObject),
headers=headers, timeout=timeoutSec)
except requests.Timeout as e:
except requests.Timeout as ex:
if not quiet:
print('ERROR: postJson timeout ' + inboxUrl + ' ' +
json.dumps(postJsonObject) + ' ' + str(headers))
print(e)
print(ex)
return ''
except requests.exceptions.RequestException as e:
except requests.exceptions.RequestException as ex:
if not quiet:
print('ERROR: postJson requests failed ' + inboxUrl + ' ' +
json.dumps(postJsonObject) + ' ' + str(headers) +
' ' + str(e))
' ' + str(ex))
return None
except SocketError as e:
if not quiet and e.errno == errno.ECONNRESET:
except SocketError as ex:
if not quiet and ex.errno == errno.ECONNRESET:
print('WARN: connection was reset during postJson')
return None
except ValueError as e:
except ValueError as ex:
if not quiet:
print('ERROR: postJson failed ' + inboxUrl + ' ' +
json.dumps(postJsonObject) + ' ' + str(headers) +
' ' + str(e))
' ' + str(ex))
return None
if postResult:
return postResult.text
@ -356,20 +356,20 @@ def postJsonString(session, postJsonStr: str,
postResult = \
session.post(url=inboxUrl, data=postJsonStr,
headers=headers, timeout=timeoutSec)
except requests.exceptions.RequestException as e:
except requests.exceptions.RequestException as ex:
if not quiet:
print('WARN: error during postJsonString requests ' + str(e))
print('WARN: error during postJsonString requests ' + str(ex))
return None, None, 0
except SocketError as e:
if not quiet and e.errno == errno.ECONNRESET:
except SocketError as ex:
if not quiet and ex.errno == errno.ECONNRESET:
print('WARN: connection was reset during postJsonString')
if not quiet:
print('ERROR: postJsonString failed ' + inboxUrl + ' ' +
postJsonStr + ' ' + str(headers))
return None, None, 0
except ValueError as e:
except ValueError as ex:
if not quiet:
print('WARN: error during postJsonString ' + str(e))
print('WARN: error during postJsonString ' + str(ex))
return None, None, 0
if postResult.status_code < 200 or postResult.status_code > 202:
if postResult.status_code >= 400 and \
@ -422,17 +422,17 @@ def postImage(session, attachImageFilename: str, federationList: [],
try:
postResult = session.post(url=inboxUrl, data=mediaBinary,
headers=headers)
except requests.exceptions.RequestException as e:
print('WARN: error during postImage requests ' + str(e))
except requests.exceptions.RequestException as ex:
print('WARN: error during postImage requests ' + str(ex))
return None
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: connection was reset during postImage')
print('ERROR: postImage failed ' + inboxUrl + ' ' +
str(headers) + ' ' + str(e))
str(headers) + ' ' + str(ex))
return None
except ValueError as e:
print('WARN: error during postImage ' + str(e))
except ValueError as ex:
print('WARN: error during postImage ' + str(ex))
return None
if postResult:
return postResult.text
@ -497,9 +497,9 @@ def downloadImage(session, baseDir: str, url: str,
if debug:
print('Image downloaded from ' + url)
return True
except Exception as e:
except Exception as ex:
print('EX: Failed to download image: ' +
str(url) + ' ' + str(e))
str(url) + ' ' + str(ex))
return False
@ -514,18 +514,18 @@ def downloadImageAnyMimeType(session, url: str, timeoutSec: int, debug: bool):
}
try:
result = session.get(url, headers=sessionHeaders, timeout=timeoutSec)
except requests.exceptions.RequestException as e:
except requests.exceptions.RequestException as ex:
print('ERROR: downloadImageAnyMimeType failed: ' +
str(url) + ', ' + str(e))
str(url) + ', ' + str(ex))
return None, None
except ValueError as e:
except ValueError as ex:
print('ERROR: downloadImageAnyMimeType failed: ' +
str(url) + ', ' + str(e))
str(url) + ', ' + str(ex))
return None, None
except SocketError as e:
if e.errno == errno.ECONNRESET:
except SocketError as ex:
if ex.errno == errno.ECONNRESET:
print('WARN: downloadImageAnyMimeType failed, ' +
'connection was reset ' + str(e))
'connection was reset ' + str(ex))
return None, None
if not result:

View File

@ -24,8 +24,8 @@ class threadWithTrace(threading.Thread):
threading.Thread.__init__(self, *self._args, **self._keywords)
self.killed = False
break
except Exception as e:
print('ERROR: threads.py/__init__ failed - ' + str(e))
except Exception as ex:
print('ERROR: threads.py/__init__ failed - ' + str(ex))
time.sleep(1)
tries += 1
@ -37,8 +37,8 @@ class threadWithTrace(threading.Thread):
self.run = self.__run
threading.Thread.start(self)
break
except Exception as e:
print('ERROR: threads.py/start failed - ' + str(e))
except Exception as ex:
print('ERROR: threads.py/start failed - ' + str(ex))
time.sleep(1)
tries += 1
# note that this is set True even if all tries failed
@ -49,8 +49,8 @@ class threadWithTrace(threading.Thread):
try:
self.__run_backup()
self.run = self.__run_backup
except Exception as e:
print('ERROR: threads.py/__run failed - ' + str(e))
except Exception as ex:
print('ERROR: threads.py/__run failed - ' + str(ex))
pass
def globaltrace(self, frame, event, arg):

View File

@ -1196,9 +1196,9 @@ def followPerson(baseDir: str, nickname: str, domain: str,
f.seek(0, 0)
f.write(handleToFollow + '\n' + content)
print('DEBUG: follow added')
except Exception as e:
except Exception as ex:
print('WARN: Failed to write entry to follow file ' +
filename + ' ' + str(e))
filename + ' ' + str(ex))
else:
# first follow
if debug:

View File

@ -262,8 +262,8 @@ def _saveIndividualPostAsHtmlToCache(baseDir: str,
with open(cachedPostFilename, 'w+') as fp:
fp.write(postHtml)
return True
except Exception as e:
print('ERROR: saving post to cache, ' + str(e))
except Exception as ex:
print('ERROR: saving post to cache, ' + str(ex))
return False

View File

@ -292,9 +292,9 @@ def updateAvatarImageCache(signingPrivateKeyPem: str,
if debug:
print('avatar image downloaded for ' + actor)
return avatarImageFilename.replace(baseDir + '/cache', '')
except Exception as e:
except Exception as ex:
print('EX: Failed to download avatar image: ' +
str(avatarUrl) + ' ' + str(e))
str(avatarUrl) + ' ' + str(ex))
prof = 'https://www.w3.org/ns/activitystreams'
if '/channel/' not in actor or '/accounts/' not in actor:
sessionHeaders = {
@ -879,9 +879,9 @@ def loadIndividualPostAsHtmlFromCache(baseDir: str,
with open(cachedPostFilename, 'r') as file:
postHtml = file.read()
break
except Exception as e:
except Exception as ex:
print('ERROR: loadIndividualPostAsHtmlFromCache ' +
str(tries) + ' ' + str(e))
str(tries) + ' ' + str(ex))
# no sleep
tries += 1
if postHtml:

View File

@ -94,8 +94,8 @@ def webfingerHandle(session, handle: str, httpPrefix: str,
result = \
getJson(signingPrivateKeyPem, session, url, hdr, par,
debug, projectVersion, httpPrefix, fromDomain)
except Exception as e:
print('ERROR: webfingerHandle ' + str(e))
except Exception as ex:
print('ERROR: webfingerHandle ' + str(ex))
return None
if result: