Check for dictionary objects

merge-requests/30/head
Bob Mottram 2021-07-06 11:00:19 +01:00
parent 457004794c
commit 06eb2b96a3
8 changed files with 18 additions and 16 deletions

View File

@ -77,7 +77,7 @@ def outboxAnnounce(recentPostsCache: {},
nickname, domain, debug) nickname, domain, debug)
return True return True
elif messageJson['type'] == 'Undo': elif messageJson['type'] == 'Undo':
if not isinstance(messageJson['object'], dict): if not hasObjectDict(messageJson):
return False return False
if not messageJson['object'].get('type'): if not messageJson['object'].get('type'):
return False return False

View File

@ -298,7 +298,7 @@ def inboxMessageHasParams(messageJson: {}) -> bool:
return False return False
# object should be a dict or a string # object should be a dict or a string
if not isinstance(messageJson['object'], dict): if not hasObjectDict(messageJson):
if not isinstance(messageJson['object'], str): if not isinstance(messageJson['object'], str):
print('WARN: object from ' + str(messageJson['actor']) + print('WARN: object from ' + str(messageJson['actor']) +
' should be a dict or string, but is actually: ' + ' should be a dict or string, but is actually: ' +

View File

@ -18,6 +18,7 @@ from utils import getImageExtensions
from utils import getVideoExtensions from utils import getVideoExtensions
from utils import getAudioExtensions from utils import getAudioExtensions
from utils import getMediaExtensions from utils import getMediaExtensions
from utils import hasObjectDict
from shutil import copyfile from shutil import copyfile
from shutil import rmtree from shutil import rmtree
from shutil import move from shutil import move
@ -30,7 +31,7 @@ def replaceYouTube(postJsonObject: {}, replacementDomain: str) -> None:
""" """
if not replacementDomain: if not replacementDomain:
return return
if not isinstance(postJsonObject['object'], dict): if not hasObjectDict(postJsonObject):
return return
if not postJsonObject['object'].get('content'): if not postJsonObject['object'].get('content'):
return return

View File

@ -1296,7 +1296,7 @@ def _postIsAddressedToFollowers(baseDir: str,
toList = [] toList = []
ccList = [] ccList = []
if postJsonObject['type'] != 'Update' and \ if postJsonObject['type'] != 'Update' and \
isinstance(postJsonObject['object'], dict): hasObjectDict(postJsonObject):
if postJsonObject['object'].get('to'): if postJsonObject['object'].get('to'):
toList = postJsonObject['object']['to'] toList = postJsonObject['object']['to']
if postJsonObject['object'].get('cc'): if postJsonObject['object'].get('cc'):
@ -2169,7 +2169,7 @@ def _addFollowersToPublicPost(postJsonObject: {}) -> None:
if postJsonObject.get('cc'): if postJsonObject.get('cc'):
return return
postJsonObject['cc'] = postJsonObject['actor'] + '/followers' postJsonObject['cc'] = postJsonObject['actor'] + '/followers'
elif isinstance(postJsonObject['object'], dict): elif hasObjectDict(postJsonObject):
if not postJsonObject['object'].get('to'): if not postJsonObject['object'].get('to'):
return return
if len(postJsonObject['object']['to']) > 1: if len(postJsonObject['object']['to']) > 1:
@ -2433,7 +2433,7 @@ def sendToNamedAddresses(session, baseDir: str,
if not postJsonObject.get('object'): if not postJsonObject.get('object'):
return return
isProfileUpdate = False isProfileUpdate = False
if isinstance(postJsonObject['object'], dict): if hasObjectDict(postJsonObject):
if _isProfileUpdate(postJsonObject): if _isProfileUpdate(postJsonObject):
# use the original object, which has a 'to' # use the original object, which has a 'to'
recipientsObject = postJsonObject recipientsObject = postJsonObject

View File

@ -126,7 +126,7 @@ def isQuestion(postObjectJson: {}) -> bool:
if postObjectJson['type'] != 'Create' and \ if postObjectJson['type'] != 'Create' and \
postObjectJson['type'] != 'Update': postObjectJson['type'] != 'Update':
return False return False
if not isinstance(postObjectJson['object'], dict): if not hasObjectDict(postObjectJson):
return False return False
if not postObjectJson['object'].get('type'): if not postObjectJson['object'].get('type'):
return False return False

View File

@ -1401,7 +1401,7 @@ def deletePost(baseDir: str, httpPrefix: str,
# remove from moderation index file # remove from moderation index file
if hasObject: if hasObject:
if isinstance(postJsonObject['object'], dict): if hasObjectDict(postJsonObject):
if postJsonObject['object'].get('moderationStatus'): if postJsonObject['object'].get('moderationStatus'):
if postJsonObject.get('id'): if postJsonObject.get('id'):
postId = removeIdEnding(postJsonObject['id']) postId = removeIdEnding(postJsonObject['id'])

View File

@ -398,9 +398,10 @@ def htmlPersonOptions(defaultTimeline: str,
'accesskey="' + accessKeys['enterNotes'] + '">' + \ 'accesskey="' + accessKeys['enterNotes'] + '">' + \
personNotes + '</textarea>\n' personNotes + '</textarea>\n'
optionsStr += ' </form>\n' optionsStr += \
optionsStr += '</center>\n' ' </form>\n' + \
optionsStr += '</div>\n' '</center>\n' + \
optionsStr += '</div>\n' '</div>\n' + \
'</div>\n'
optionsStr += htmlFooter() optionsStr += htmlFooter()
return optionsStr return optionsStr

View File

@ -22,6 +22,7 @@ from posts import postIsMuted
from posts import getPersonBox from posts import getPersonBox
from posts import downloadAnnounce from posts import downloadAnnounce
from posts import populateRepliesJson from posts import populateRepliesJson
from utils import hasObjectDict
from utils import updateAnnounceCollection from utils import updateAnnounceCollection
from utils import isPGPEncrypted from utils import isPGPEncrypted
from utils import isDM from utils import isDM
@ -840,8 +841,7 @@ def _getPostTitleAnnounceHtml(baseDir: str,
postJsonObject) postJsonObject)
else: else:
titleStr += \ titleStr += \
_announceUnattributedHtml(translate, _announceUnattributedHtml(translate, postJsonObject)
postJsonObject)
else: else:
titleStr += \ titleStr += \
_announceUnattributedHtml(translate, postJsonObject) _announceUnattributedHtml(translate, postJsonObject)
@ -1339,7 +1339,7 @@ def individualPostAsHtml(allowDownloads: bool,
_logPostTiming(enableTimingLog, postStartTime, '8') _logPostTiming(enableTimingLog, postStartTime, '8')
if not isinstance(postJsonObject['object'], dict): if not hasObjectDict(postJsonObject):
return '' return ''
# if this post should be public then check its recipients # if this post should be public then check its recipients
@ -1762,7 +1762,7 @@ def htmlIndividualPost(cssCache: {},
messageId = removeIdEnding(postJsonObject['id']) messageId = removeIdEnding(postJsonObject['id'])
# show the previous posts # show the previous posts
if isinstance(postJsonObject['object'], dict): if hasObjectDict(postJsonObject):
while postJsonObject['object'].get('inReplyTo'): while postJsonObject['object'].get('inReplyTo'):
postFilename = \ postFilename = \
locatePost(baseDir, nickname, domain, locatePost(baseDir, nickname, domain,