Reduce indentation

main
Bob Mottram 2020-12-01 10:30:24 +00:00
parent 963f8dc696
commit a84e060f5e
1 changed files with 282 additions and 280 deletions

View File

@ -646,8 +646,7 @@ def getBlogCitationsHtml(boxName: str,
'<cite>' + tagJson['name'] + '</cite></a></li>\n' '<cite>' + tagJson['name'] + '</cite></a></li>\n'
if citationsStr: if citationsStr:
citationsStr = '<p><b>' + translate['Citations'] + \ citationsStr = '<p><b>' + translate['Citations'] + ':</b></p>' + \
':</b></p>' + \
'<ul>\n' + citationsStr + '</ul>\n' '<ul>\n' + citationsStr + '</ul>\n'
return citationsStr return citationsStr
@ -676,302 +675,305 @@ def getPostTitleHtml(baseDir: str,
""" """
titleStr = '' titleStr = ''
replyAvatarImageInPost = '' replyAvatarImageInPost = ''
if showRepeatIcon: if not showRepeatIcon:
if isAnnounced: return (titleStr, replyAvatarImageInPost,
if postJsonObject['object'].get('attributedTo'): containerClassIcons, containerClass)
attributedTo = ''
if isinstance(postJsonObject['object']['attributedTo'], str):
attributedTo = postJsonObject['object']['attributedTo']
if attributedTo.startswith(postActor):
titleStr += \
' <img loading="lazy" title="' + \
translate['announces'] + \
'" alt="' + translate['announces'] + \
'" src="/' + iconsPath + \
'/repeat_inactive.png" class="announceOrReply"/>\n'
else:
# benchmark 13.2
if enableTimingLog:
timeDiff = int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 13.2 = ' + str(timeDiff))
announceNickname = None
if attributedTo:
announceNickname = getNicknameFromActor(attributedTo)
if announceNickname:
announceDomain, announcePort = \
getDomainFromActor(attributedTo)
getPersonFromCache(baseDir, attributedTo,
personCache, allowDownloads)
announceDisplayName = \
getDisplayName(baseDir, attributedTo, personCache)
if announceDisplayName:
# benchmark 13.3
if enableTimingLog:
timeDiff = \
int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 13.3 = ' + str(timeDiff))
if ':' in announceDisplayName: if isAnnounced:
announceDisplayName = \ if postJsonObject['object'].get('attributedTo'):
addEmojiToDisplayName(baseDir, httpPrefix, attributedTo = ''
nickname, domain, if isinstance(postJsonObject['object']['attributedTo'], str):
announceDisplayName, attributedTo = postJsonObject['object']['attributedTo']
False) if attributedTo.startswith(postActor):
# benchmark 13.3.1 titleStr += \
if enableTimingLog: ' <img loading="lazy" title="' + \
timeDiff = \ translate['announces'] + \
int((time.time() - postStartTime) * 1000) '" alt="' + translate['announces'] + \
if timeDiff > 100: '" src="/' + iconsPath + \
print('TIMING INDIV ' + boxName + '/repeat_inactive.png" class="announceOrReply"/>\n'
' 13.3.1 = ' + str(timeDiff)) else:
# benchmark 13.2
if enableTimingLog:
timeDiff = int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 13.2 = ' + str(timeDiff))
announceNickname = None
if attributedTo:
announceNickname = getNicknameFromActor(attributedTo)
if announceNickname:
announceDomain, announcePort = \
getDomainFromActor(attributedTo)
getPersonFromCache(baseDir, attributedTo,
personCache, allowDownloads)
announceDisplayName = \
getDisplayName(baseDir, attributedTo, personCache)
if announceDisplayName:
# benchmark 13.3
if enableTimingLog:
timeDiff = \
int((time.time() - postStartTime) * 1000)
if timeDiff > 100:
print('TIMING INDIV ' + boxName +
' 13.3 = ' + str(timeDiff))
titleStr += \ if ':' in announceDisplayName:
' ' + \ announceDisplayName = \
'<img loading="lazy" title="' + \ addEmojiToDisplayName(baseDir, httpPrefix,
translate['announces'] + '" alt="' + \ nickname, domain,
translate['announces'] + '" src="/' + \ announceDisplayName,
iconsPath + '/repeat_inactive.png" ' + \ False)
'class="announceOrReply"/>\n' + \ # benchmark 13.3.1
' <a href="' + \ if enableTimingLog:
postJsonObject['object']['id'] + '" ' + \ timeDiff = \
'class="announceOrReply">' + \ int((time.time() - postStartTime) * 1000)
announceDisplayName + '</a>\n' if timeDiff > 100:
# show avatar of person replied to print('TIMING INDIV ' + boxName +
announceActor = \ ' 13.3.1 = ' + str(timeDiff))
postJsonObject['object']['attributedTo']
announceAvatarUrl = \
getPersonAvatarUrl(baseDir, announceActor,
personCache, allowDownloads)
# benchmark 13.4 titleStr += \
if enableTimingLog: ' ' + \
timeDiff = \ '<img loading="lazy" title="' + \
int((time.time() - postStartTime) * 1000) translate['announces'] + '" alt="' + \
if timeDiff > 100: translate['announces'] + '" src="/' + \
print('TIMING INDIV ' + boxName + iconsPath + '/repeat_inactive.png" ' + \
' 13.4 = ' + str(timeDiff)) 'class="announceOrReply"/>\n' + \
' <a href="' + \
postJsonObject['object']['id'] + '" ' + \
'class="announceOrReply">' + \
announceDisplayName + '</a>\n'
# show avatar of person replied to
announceActor = \
postJsonObject['object']['attributedTo']
announceAvatarUrl = \
getPersonAvatarUrl(baseDir, announceActor,
personCache, allowDownloads)
if announceAvatarUrl: # benchmark 13.4
idx = 'Show options for this person' if enableTimingLog:
if '/users/news/' not in announceAvatarUrl: timeDiff = \
replyAvatarImageInPost = \ int((time.time() - postStartTime) * 1000)
' ' \ if timeDiff > 100:
'<div class=' + \ print('TIMING INDIV ' + boxName +
'"timeline-avatar-reply">\n' \ ' 13.4 = ' + str(timeDiff))
' ' + \
'<a class="imageAnchor" ' + \ if announceAvatarUrl:
'href="/users/' + nickname + \ idx = 'Show options for this person'
'?options=' + \ if '/users/news/' not in announceAvatarUrl:
announceActor + ';' + \ replyAvatarImageInPost = \
str(pageNumber) + \ ' ' \
';' + announceAvatarUrl + \ '<div class=' + \
messageIdStr + '">' \ '"timeline-avatar-reply">\n' \
'<img loading="lazy" src="' + \ ' ' + \
announceAvatarUrl + '" ' \ '<a class="imageAnchor" ' + \
'title="' + translate[idx] + \ 'href="/users/' + nickname + \
'" alt=" "' + avatarPosition + \ '?options=' + \
'/></a>\n </div>\n' announceActor + ';' + \
else: str(pageNumber) + \
titleStr += \ ';' + announceAvatarUrl + \
' <img loading="lazy" title="' + \ messageIdStr + '">' \
translate['announces'] + \ '<img loading="lazy" src="' + \
'" alt="' + translate['announces'] + \ announceAvatarUrl + '" ' \
'" src="/' + iconsPath + \ 'title="' + translate[idx] + \
'/repeat_inactive.png" ' + \ '" alt=" "' + avatarPosition + \
'class="announceOrReply"/>\n' + \ '/></a>\n </div>\n'
' <a href="' + \
postJsonObject['object']['id'] + '" ' + \
'class="announceOrReply">@' + \
announceNickname + '@' + \
announceDomain + '</a>\n'
else: else:
titleStr += \ titleStr += \
' <img loading="lazy" title="' + \ ' <img loading="lazy" title="' + \
translate['announces'] + '" alt="' + \ translate['announces'] + \
translate['announces'] + '" src="/' + iconsPath + \ '" alt="' + translate['announces'] + \
'" src="/' + iconsPath + \
'/repeat_inactive.png" ' + \ '/repeat_inactive.png" ' + \
'class="announceOrReply"/>\n' + \ 'class="announceOrReply"/>\n' + \
' <a href="' + \ ' <a href="' + \
postJsonObject['object']['id'] + \ postJsonObject['object']['id'] + '" ' + \
'" class="announceOrReply">@unattributed</a>\n' 'class="announceOrReply">@' + \
else: announceNickname + '@' + \
titleStr += \ announceDomain + '</a>\n'
' ' + \ else:
'<img loading="lazy" title="' + translate['announces'] + \
'" alt="' + translate['announces'] + \
'" src="/' + iconsPath + \
'/repeat_inactive.png" ' + \
'class="announceOrReply"/>\n' + \
' <a href="' + \
postJsonObject['object']['id'] + '" ' + \
'class="announceOrReply">@unattributed</a>\n'
else:
if postJsonObject['object'].get('inReplyTo'):
containerClassIcons = 'containericons darker'
containerClass = 'container darker'
if postJsonObject['object']['inReplyTo'].startswith(postActor):
titleStr += \ titleStr += \
' <img loading="lazy" title="' + \ ' <img loading="lazy" title="' + \
translate['replying to themselves'] + \ translate['announces'] + '" alt="' + \
'" alt="' + translate['replying to themselves'] + \ translate['announces'] + '" src="/' + iconsPath + \
'" src="/' + iconsPath + \ '/repeat_inactive.png" ' + \
'/reply.png" class="announceOrReply"/>\n' 'class="announceOrReply"/>\n' + \
else: ' <a href="' + \
if '/statuses/' in postJsonObject['object']['inReplyTo']: postJsonObject['object']['id'] + \
inReplyTo = postJsonObject['object']['inReplyTo'] '" class="announceOrReply">@unattributed</a>\n'
replyActor = inReplyTo.split('/statuses/')[0] else:
replyNickname = getNicknameFromActor(replyActor) titleStr += \
if replyNickname: ' ' + \
replyDomain, replyPort = \ '<img loading="lazy" title="' + translate['announces'] + \
getDomainFromActor(replyActor) '" alt="' + translate['announces'] + \
if replyNickname and replyDomain: '" src="/' + iconsPath + \
getPersonFromCache(baseDir, replyActor, '/repeat_inactive.png" ' + \
personCache, 'class="announceOrReply"/>\n' + \
allowDownloads) ' <a href="' + \
replyDisplayName = \ postJsonObject['object']['id'] + '" ' + \
getDisplayName(baseDir, replyActor, 'class="announceOrReply">@unattributed</a>\n'
personCache) else:
if replyDisplayName: if postJsonObject['object'].get('inReplyTo'):
if ':' in replyDisplayName: containerClassIcons = 'containericons darker'
# benchmark 13.5 containerClass = 'container darker'
if enableTimingLog: if postJsonObject['object']['inReplyTo'].startswith(postActor):
timeDiff = \ titleStr += \
int((time.time() - ' <img loading="lazy" title="' + \
postStartTime) * 1000) translate['replying to themselves'] + \
if timeDiff > 100: '" alt="' + translate['replying to themselves'] + \
print('TIMING INDIV ' + '" src="/' + iconsPath + \
boxName + ' 13.5 = ' + '/reply.png" class="announceOrReply"/>\n'
str(timeDiff)) else:
repDisp = replyDisplayName if '/statuses/' in postJsonObject['object']['inReplyTo']:
replyDisplayName = \ inReplyTo = postJsonObject['object']['inReplyTo']
addEmojiToDisplayName(baseDir, replyActor = inReplyTo.split('/statuses/')[0]
httpPrefix, replyNickname = getNicknameFromActor(replyActor)
nickname, if replyNickname:
domain, replyDomain, replyPort = \
repDisp, getDomainFromActor(replyActor)
False) if replyNickname and replyDomain:
# benchmark 13.6 getPersonFromCache(baseDir, replyActor,
if enableTimingLog: personCache,
timeDiff = \ allowDownloads)
int((time.time() - replyDisplayName = \
postStartTime) * 1000) getDisplayName(baseDir, replyActor,
if timeDiff > 100: personCache)
print('TIMING INDIV ' + if replyDisplayName:
boxName + ' 13.6 = ' + if ':' in replyDisplayName:
str(timeDiff)) # benchmark 13.5
titleStr += \
' ' + \
'<img loading="lazy" title="' + \
translate['replying to'] + \
'" alt="' + \
translate['replying to'] + \
'" src="/' + \
iconsPath + '/reply.png" ' + \
'class="announceOrReply"/>\n' + \
' ' + \
'<a href="' + inReplyTo + \
'" class="announceOrReply">' + \
replyDisplayName + '</a>\n'
# benchmark 13.7
if enableTimingLog: if enableTimingLog:
timeDiff = int((time.time() - timeDiff = \
postStartTime) * 1000) int((time.time() -
postStartTime) * 1000)
if timeDiff > 100: if timeDiff > 100:
print('TIMING INDIV ' + boxName + print('TIMING INDIV ' +
' 13.7 = ' + str(timeDiff)) boxName + ' 13.5 = ' +
str(timeDiff))
# show avatar of person replied to repDisp = replyDisplayName
replyAvatarUrl = \ replyDisplayName = \
getPersonAvatarUrl(baseDir, addEmojiToDisplayName(baseDir,
replyActor, httpPrefix,
personCache, nickname,
allowDownloads) domain,
repDisp,
# benchmark 13.8 False)
# benchmark 13.6
if enableTimingLog: if enableTimingLog:
timeDiff = int((time.time() - timeDiff = \
postStartTime) * 1000) int((time.time() -
postStartTime) * 1000)
if timeDiff > 100: if timeDiff > 100:
print('TIMING INDIV ' + boxName + print('TIMING INDIV ' +
' 13.8 = ' + str(timeDiff)) boxName + ' 13.6 = ' +
str(timeDiff))
titleStr += \
' ' + \
'<img loading="lazy" title="' + \
translate['replying to'] + \
'" alt="' + \
translate['replying to'] + \
'" src="/' + \
iconsPath + '/reply.png" ' + \
'class="announceOrReply"/>\n' + \
' ' + \
'<a href="' + inReplyTo + \
'" class="announceOrReply">' + \
replyDisplayName + '</a>\n'
if replyAvatarUrl: # benchmark 13.7
replyAvatarImageInPost = \ if enableTimingLog:
' <div class=' + \ timeDiff = int((time.time() -
'"timeline-avatar-reply">\n' postStartTime) * 1000)
replyAvatarImageInPost += \ if timeDiff > 100:
' ' + \ print('TIMING INDIV ' + boxName +
'<a class="imageAnchor" ' + \ ' 13.7 = ' + str(timeDiff))
'href="/users/' + nickname + \
'?options=' + replyActor + \ # show avatar of person replied to
';' + str(pageNumber) + ';' + \ replyAvatarUrl = \
replyAvatarUrl + \ getPersonAvatarUrl(baseDir,
messageIdStr + '">\n' replyActor,
replyAvatarImageInPost += \ personCache,
' ' + \ allowDownloads)
'<img loading="lazy" src="' + \
replyAvatarUrl + '" ' # benchmark 13.8
replyAvatarImageInPost += \ if enableTimingLog:
'title="' + \ timeDiff = int((time.time() -
translate['Show profile'] postStartTime) * 1000)
replyAvatarImageInPost += \ if timeDiff > 100:
'" alt=" "' + \ print('TIMING INDIV ' + boxName +
avatarPosition + '/></a>\n' + \ ' 13.8 = ' + str(timeDiff))
' </div>\n'
else: if replyAvatarUrl:
inReplyTo = \ replyAvatarImageInPost = \
postJsonObject['object']['inReplyTo'] ' <div class=' + \
titleStr += \ '"timeline-avatar-reply">\n'
' ' + \ replyAvatarImageInPost += \
'<img loading="lazy" title="' + \ ' ' + \
translate['replying to'] + \ '<a class="imageAnchor" ' + \
'" alt="' + \ 'href="/users/' + nickname + \
translate['replying to'] + \ '?options=' + replyActor + \
'" src="/' + \ ';' + str(pageNumber) + ';' + \
iconsPath + '/reply.png" ' + \ replyAvatarUrl + \
'class="announceOrReply"/>\n' + \ messageIdStr + '">\n'
' <a href="' + \ replyAvatarImageInPost += \
inReplyTo + '" ' + \ ' ' + \
'class="announceOrReply">@' + \ '<img loading="lazy" src="' + \
replyNickname + '@' + \ replyAvatarUrl + '" '
replyDomain + '</a>\n' replyAvatarImageInPost += \
else: 'title="' + \
titleStr += \ translate['Show profile']
' <img loading="lazy" title="' + \ replyAvatarImageInPost += \
translate['replying to'] + \ '" alt=" "' + \
'" alt="' + \ avatarPosition + '/></a>\n' + \
translate['replying to'] + \ ' </div>\n'
'" src="/' + \ else:
iconsPath + \ inReplyTo = \
'/reply.png" class="announceOrReply"/>\n' + \ postJsonObject['object']['inReplyTo']
' <a href="' + \ titleStr += \
postJsonObject['object']['inReplyTo'] + \ ' ' + \
'" class="announceOrReply">@unknown</a>\n' '<img loading="lazy" title="' + \
translate['replying to'] + \
'" alt="' + \
translate['replying to'] + \
'" src="/' + \
iconsPath + '/reply.png" ' + \
'class="announceOrReply"/>\n' + \
' <a href="' + \
inReplyTo + '" ' + \
'class="announceOrReply">@' + \
replyNickname + '@' + \
replyDomain + '</a>\n'
else: else:
postDomain = \ titleStr += \
postJsonObject['object']['inReplyTo'] ' <img loading="lazy" title="' + \
prefixes = getProtocolPrefixes() translate['replying to'] + \
for prefix in prefixes: '" alt="' + \
postDomain = postDomain.replace(prefix, '') translate['replying to'] + \
if '/' in postDomain: '" src="/' + \
postDomain = postDomain.split('/', 1)[0] iconsPath + \
if postDomain: '/reply.png" class="announceOrReply"/>\n' + \
titleStr += \ ' <a href="' + \
' <img loading="lazy" title="' + \ postJsonObject['object']['inReplyTo'] + \
translate['replying to'] + \ '" class="announceOrReply">@unknown</a>\n'
'" alt="' + translate['replying to'] + \ else:
'" src="/' + \ postDomain = \
iconsPath + '/reply.png" ' + \ postJsonObject['object']['inReplyTo']
'class="announceOrReply"/>\n' + \ prefixes = getProtocolPrefixes()
' <a href="' + \ for prefix in prefixes:
postJsonObject['object']['inReplyTo'] + \ postDomain = postDomain.replace(prefix, '')
'" class="announceOrReply">' + \ if '/' in postDomain:
postDomain + '</a>\n' postDomain = postDomain.split('/', 1)[0]
if postDomain:
titleStr += \
' <img loading="lazy" title="' + \
translate['replying to'] + \
'" alt="' + translate['replying to'] + \
'" src="/' + \
iconsPath + '/reply.png" ' + \
'class="announceOrReply"/>\n' + \
' <a href="' + \
postJsonObject['object']['inReplyTo'] + \
'" class="announceOrReply">' + \
postDomain + '</a>\n'
return (titleStr, replyAvatarImageInPost, return (titleStr, replyAvatarImageInPost,
containerClassIcons, containerClass) containerClassIcons, containerClass)