Snake case

main
Bob Mottram 2021-12-26 10:57:03 +00:00
parent 23af1b48ef
commit 594b3beb55
20 changed files with 102 additions and 102 deletions

View File

@ -15,7 +15,7 @@ from utils import hasObjectString
from utils import hasObjectStringObject from utils import hasObjectStringObject
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import removeDomainPort from utils import removeDomainPort
from utils import hasObjectDict from utils import has_object_dict
from utils import isAccountDir from utils import isAccountDir
from utils import getCachedPostFilename from utils import getCachedPostFilename
from utils import loadJson from utils import loadJson
@ -537,7 +537,7 @@ def mutePost(base_dir: str, nickname: str, domain: str, port: int,
postJsonObj = post_json_object postJsonObj = post_json_object
alsoUpdatePostId = None alsoUpdatePostId = None
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
postJsonObj = post_json_object['object'] postJsonObj = post_json_object['object']
else: else:
if hasObjectString(post_json_object, debug): if hasObjectString(post_json_object, debug):
@ -676,7 +676,7 @@ def unmutePost(base_dir: str, nickname: str, domain: str, port: int,
postJsonObj = post_json_object postJsonObj = post_json_object
alsoUpdatePostId = None alsoUpdatePostId = None
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
postJsonObj = post_json_object['object'] postJsonObj = post_json_object['object']
else: else:
if hasObjectString(post_json_object, debug): if hasObjectString(post_json_object, debug):

View File

@ -23,7 +23,7 @@ from utils import locatePost
from utils import getCachedPostFilename from utils import getCachedPostFilename
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import hasObjectDict from utils import has_object_dict
from utils import acctDir from utils import acctDir
from utils import local_actor_url from utils import local_actor_url
from utils import hasActor from utils import hasActor
@ -87,7 +87,7 @@ def undoBookmarksCollectionEntry(recentPostsCache: {},
return return
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return return
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
if debug: if debug:
print('DEBUG: bookmarked post has no object ' + print('DEBUG: bookmarked post has no object ' +
str(post_json_object)) str(post_json_object))
@ -141,7 +141,7 @@ def bookmarkedByPerson(post_json_object: {},
def _noOfBookmarks(post_json_object: {}) -> int: def _noOfBookmarks(post_json_object: {}) -> int:
"""Returns the number of bookmarks ona given post """Returns the number of bookmarks ona given post
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return 0 return 0
if not post_json_object['object'].get('bookmarks'): if not post_json_object['object'].get('bookmarks'):
return 0 return 0

View File

@ -8,7 +8,7 @@ __status__ = "Production"
__module_group__ = "Timeline" __module_group__ = "Timeline"
import os import os
from utils import hasObjectDict from utils import has_object_dict
from utils import acctDir from utils import acctDir
from utils import removeIdEnding from utils import removeIdEnding
@ -17,7 +17,7 @@ def _getConversationFilename(base_dir: str, nickname: str, domain: str,
post_json_object: {}) -> str: post_json_object: {}) -> str:
"""Returns the conversation filename """Returns the conversation filename
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return None return None
if not post_json_object['object'].get('conversation'): if not post_json_object['object'].get('conversation'):
return None return None

View File

@ -258,7 +258,7 @@ from utils import getBaseContentFromPost
from utils import acctDir from utils import acctDir
from utils import getImageExtensionFromMimeType from utils import getImageExtensionFromMimeType
from utils import getImageMimeType from utils import getImageMimeType
from utils import hasObjectDict from utils import has_object_dict
from utils import userAgentDomain from utils import userAgentDomain
from utils import isLocalNetworkAddress from utils import isLocalNetworkAddress
from utils import permittedDir from utils import permittedDir
@ -1414,7 +1414,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.POSTbusy = False self.server.POSTbusy = False
return 3 return 3
if hasObjectDict(message_json): if has_object_dict(message_json):
stringFields = ( stringFields = (
'id', 'actor', 'type', 'content', 'published', 'id', 'actor', 'type', 'content', 'published',
'summary', 'url', 'attributedTo' 'summary', 'url', 'attributedTo'
@ -10018,7 +10018,7 @@ class PubServer(BaseHTTPRequestHandler):
if self._secure_mode(): if self._secure_mode():
if not includeCreateWrapper and \ if not includeCreateWrapper and \
post_json_object['type'] == 'Create' and \ post_json_object['type'] == 'Create' and \
hasObjectDict(post_json_object): has_object_dict(post_json_object):
unwrappedJson = post_json_object['object'] unwrappedJson = post_json_object['object']
unwrappedJson['@context'] = \ unwrappedJson['@context'] = \
getIndividualPostContext() getIndividualPostContext()

View File

@ -17,7 +17,7 @@ import urllib.parse
from pathlib import Path from pathlib import Path
from random import randint from random import randint
from utils import getBaseContentFromPost from utils import getBaseContentFromPost
from utils import hasObjectDict from utils import has_object_dict
from utils import getFullDomain from utils import getFullDomain
from utils import isDM from utils import isDM
from utils import loadTranslationsFromFile from utils import loadTranslationsFromFile
@ -210,7 +210,7 @@ def _postIsToYou(actor: str, post_json_object: {}) -> bool:
if not toYourActor and post_json_object.get('cc'): if not toYourActor and post_json_object.get('cc'):
if actor in post_json_object['cc']: if actor in post_json_object['cc']:
toYourActor = True toYourActor = True
if not toYourActor and hasObjectDict(post_json_object): if not toYourActor and has_object_dict(post_json_object):
if post_json_object['object'].get('to'): if post_json_object['object'].get('to'):
if actor in post_json_object['object']['to']: if actor in post_json_object['object']['to']:
toYourActor = True toYourActor = True
@ -621,7 +621,7 @@ def _getImageDescription(post_json_object: {}) -> str:
def _showLikesOnPost(post_json_object: {}, maxLikes: int) -> None: def _showLikesOnPost(post_json_object: {}, maxLikes: int) -> None:
"""Shows the likes on a post """Shows the likes on a post
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return return
if not post_json_object['object'].get('likes'): if not post_json_object['object'].get('likes'):
return return
@ -644,7 +644,7 @@ def _showLikesOnPost(post_json_object: {}, maxLikes: int) -> None:
def _showRepliesOnPost(post_json_object: {}, max_replies: int) -> None: def _showRepliesOnPost(post_json_object: {}, max_replies: int) -> None:
"""Shows the replies on a post """Shows the replies on a post
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return return
if not post_json_object['object'].get('replies'): if not post_json_object['object'].get('replies'):
return return
@ -715,7 +715,7 @@ def _readLocalBoxPost(session, nickname: str, domain: str,
signing_priv_key_pem, signing_priv_key_pem,
blockedCache) blockedCache)
if post_json_object2: if post_json_object2:
if hasObjectDict(post_json_object2): if has_object_dict(post_json_object2):
if post_json_object2['object'].get('attributedTo') and \ if post_json_object2['object'].get('attributedTo') and \
post_json_object2['object'].get('content'): post_json_object2['object'].get('content'):
attributedTo = post_json_object2['object']['attributedTo'] attributedTo = post_json_object2['object']['attributedTo']
@ -916,7 +916,7 @@ def _desktopGetBoxPostObject(boxJson: {}, index: int) -> {}:
if ctr == index: if ctr == index:
return post_json_object return post_json_object
continue continue
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
continue continue
if not post_json_object['object'].get('published'): if not post_json_object['object'].get('published'):
continue continue
@ -1028,7 +1028,7 @@ def _desktopShowBox(indent: str,
ctr += 1 ctr += 1
continue continue
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
continue continue
if not post_json_object['object'].get('published'): if not post_json_object['object'].get('published'):
continue continue
@ -1973,7 +1973,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
if post_json_object: if post_json_object:
if post_json_object.get('id') and \ if post_json_object.get('id') and \
post_json_object.get('object'): post_json_object.get('object'):
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('attributedTo'): if post_json_object['object'].get('attributedTo'):
blockActor = \ blockActor = \
post_json_object['object']['attributedTo'] post_json_object['object']['attributedTo']
@ -2019,7 +2019,7 @@ def runDesktopClient(base_dir: str, proxy_type: str, http_prefix: str,
if post_json_object and not blockActor: if post_json_object and not blockActor:
if post_json_object.get('id') and \ if post_json_object.get('id') and \
post_json_object.get('object'): post_json_object.get('object'):
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('attributedTo'): if post_json_object['object'].get('attributedTo'):
blockActor = \ blockActor = \
post_json_object['object']['attributedTo'] post_json_object['object']['attributedTo']

View File

@ -16,7 +16,7 @@ from utils import isPublicPost
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import locatePost from utils import locatePost
from utils import hasObjectDict from utils import has_object_dict
from utils import acctDir from utils import acctDir
@ -166,7 +166,7 @@ def _isHappeningPost(post_json_object: {}) -> bool:
""" """
if not post_json_object: if not post_json_object:
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if not post_json_object['object'].get('tag'): if not post_json_object['object'].get('tag'):
return False return False

View File

@ -32,7 +32,7 @@ from utils import getBaseContentFromPost
from utils import acctDir from utils import acctDir
from utils import removeDomainPort from utils import removeDomainPort
from utils import getPortFromDomain from utils import getPortFromDomain
from utils import hasObjectDict from utils import has_object_dict
from utils import dmAllowedFromDomain from utils import dmAllowedFromDomain
from utils import isRecentPost from utils import isRecentPost
from utils import getConfigParam from utils import getConfigParam
@ -133,7 +133,7 @@ def _storeLastPostId(base_dir: str, nickname: str, domain: str,
source but we don't live in that ideal world. source but we don't live in that ideal world.
""" """
actor = postId = None actor = postId = None
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('attributedTo'): if post_json_object['object'].get('attributedTo'):
if isinstance(post_json_object['object']['attributedTo'], str): if isinstance(post_json_object['object']['attributedTo'], str):
actor = post_json_object['object']['attributedTo'] actor = post_json_object['object']['attributedTo']
@ -207,7 +207,7 @@ def storeHashTags(base_dir: str, nickname: str, domain: str,
""" """
if not isPublicPost(post_json_object): if not isPublicPost(post_json_object):
return return
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return return
if not post_json_object['object'].get('tag'): if not post_json_object['object'].get('tag'):
return return
@ -402,7 +402,7 @@ def inboxMessageHasParams(message_json: {}) -> bool:
return False return False
# object should be a dict or a string # object should be a dict or a string
if not hasObjectDict(message_json): if not has_object_dict(message_json):
if not isinstance(message_json['object'], str): if not isinstance(message_json['object'], str):
print('WARN: object from ' + str(message_json['actor']) + print('WARN: object from ' + str(message_json['actor']) +
' should be a dict or string, but is actually: ' + ' should be a dict or string, but is actually: ' +
@ -437,7 +437,7 @@ def inboxPermittedMessage(domain: str, message_json: {},
'Follow', 'Join', 'Like', 'EmojiReact', 'Delete', 'Announce' 'Follow', 'Join', 'Like', 'EmojiReact', 'Delete', 'Announce'
) )
if message_json['type'] not in alwaysAllowedTypes: if message_json['type'] not in alwaysAllowedTypes:
if not hasObjectDict(message_json): if not has_object_dict(message_json):
return True return True
if message_json['object'].get('inReplyTo'): if message_json['object'].get('inReplyTo'):
inReplyTo = message_json['object']['inReplyTo'] inReplyTo = message_json['object']['inReplyTo']
@ -493,7 +493,7 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str,
return None return None
postDomain = getFullDomain(postDomain, postPort) postDomain = getFullDomain(postDomain, postPort)
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('inReplyTo'): if post_json_object['object'].get('inReplyTo'):
if isinstance(post_json_object['object']['inReplyTo'], str): if isinstance(post_json_object['object']['inReplyTo'], str):
inReplyTo = \ inReplyTo = \
@ -653,7 +653,7 @@ def _inboxPostRecipients(base_dir: str, post_json_object: {},
# first get any specific people which the post is addressed to # first get any specific people which the post is addressed to
followerRecipients = False followerRecipients = False
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('to'): if post_json_object['object'].get('to'):
if isinstance(post_json_object['object']['to'], list): if isinstance(post_json_object['object']['to'], list):
recipientsList = post_json_object['object']['to'] recipientsList = post_json_object['object']['to']
@ -1978,7 +1978,7 @@ def _receiveAnnounce(recentPostsCache: {},
if isinstance(post_json_object['attributedTo'], str): if isinstance(post_json_object['attributedTo'], str):
lookupActor = post_json_object['attributedTo'] lookupActor = post_json_object['attributedTo']
else: else:
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('attributedTo'): if post_json_object['object'].get('attributedTo'):
attrib = post_json_object['object']['attributedTo'] attrib = post_json_object['object']['attributedTo']
if isinstance(attrib, str): if isinstance(attrib, str):
@ -2042,7 +2042,7 @@ def _receiveUndoAnnounce(recentPostsCache: {},
return False return False
if not hasActor(message_json, debug): if not hasActor(message_json, debug):
return False return False
if not hasObjectDict(message_json): if not has_object_dict(message_json):
return False return False
if not hasObjectStringObject(message_json, debug): if not hasObjectStringObject(message_json, debug):
return False return False
@ -2095,7 +2095,7 @@ def jsonPostAllowsComments(post_json_object: {}) -> bool:
if 'rejectReplies' in post_json_object: if 'rejectReplies' in post_json_object:
return not post_json_object['rejectReplies'] return not post_json_object['rejectReplies']
if post_json_object.get('object'): if post_json_object.get('object'):
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
elif 'commentsEnabled' in post_json_object['object']: elif 'commentsEnabled' in post_json_object['object']:
return post_json_object['object']['commentsEnabled'] return post_json_object['object']['commentsEnabled']
@ -2120,7 +2120,7 @@ def populateReplies(base_dir: str, http_prefix: str, domain: str,
""" """
if not message_json.get('id'): if not message_json.get('id'):
return False return False
if not hasObjectDict(message_json): if not has_object_dict(message_json):
return False return False
if not message_json['object'].get('inReplyTo'): if not message_json['object'].get('inReplyTo'):
return False return False
@ -2206,7 +2206,7 @@ def _validPostContent(base_dir: str, nickname: str, domain: str,
Check if it's a git patch Check if it's a git patch
Check number of tags and mentions is reasonable Check number of tags and mentions is reasonable
""" """
if not hasObjectDict(message_json): if not has_object_dict(message_json):
return True return True
if not message_json['object'].get('content'): if not message_json['object'].get('content'):
return True return True
@ -2305,7 +2305,7 @@ def _obtainAvatarForReplyPost(session, base_dir: str, http_prefix: str,
"""Tries to obtain the actor for the person being replied to """Tries to obtain the actor for the person being replied to
so that their avatar can later be shown so that their avatar can later be shown
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return return
if not post_json_object['object'].get('inReplyTo'): if not post_json_object['object'].get('inReplyTo'):
@ -2370,7 +2370,7 @@ def _alreadyLiked(base_dir: str, nickname: str, domain: str,
post_json_object = loadJson(postFilename, 1) post_json_object = loadJson(postFilename, 1)
if not post_json_object: if not post_json_object:
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if not post_json_object['object'].get('likes'): if not post_json_object['object'].get('likes'):
return False return False
@ -2400,7 +2400,7 @@ def _alreadyReacted(base_dir: str, nickname: str, domain: str,
post_json_object = loadJson(postFilename, 1) post_json_object = loadJson(postFilename, 1)
if not post_json_object: if not post_json_object:
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if not post_json_object['object'].get('reactions'): if not post_json_object['object'].get('reactions'):
return False return False
@ -2646,7 +2646,7 @@ def _sendToGroupMembers(session, base_dir: str, handle: str, port: int,
return return
if not post_json_object.get('object'): if not post_json_object.get('object'):
return return
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return return
nickname = handle.split('@')[0].replace('!', '') nickname = handle.split('@')[0].replace('!', '')
domain = handle.split('@')[1] domain = handle.split('@')[1]
@ -2693,7 +2693,7 @@ def _inboxUpdateCalendar(base_dir: str, handle: str,
""" """
if not post_json_object.get('actor'): if not post_json_object.get('actor'):
return return
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return return
if not post_json_object['object'].get('tag'): if not post_json_object['object'].get('tag'):
return return

View File

@ -12,7 +12,7 @@ import json
from urllib import request, parse from urllib import request, parse
from utils import get_actor_languages_list from utils import get_actor_languages_list
from utils import removeHtml from utils import removeHtml
from utils import hasObjectDict from utils import has_object_dict
from utils import getConfigParam from utils import getConfigParam
from utils import local_actor_url from utils import local_actor_url
from cache import getPersonFromCache from cache import getPersonFromCache
@ -98,7 +98,7 @@ def understoodPostLanguage(base_dir: str, nickname: str, domain: str,
understood by this account understood by this account
""" """
msgObject = message_json msgObject = message_json
if hasObjectDict(message_json): if has_object_dict(message_json):
msgObject = message_json['object'] msgObject = message_json['object']
if not msgObject.get('contentMap'): if not msgObject.get('contentMap'):
return True return True
@ -278,7 +278,7 @@ def autoTranslatePost(base_dir: str, post_json_object: {},
system_language: str, translate: {}) -> str: system_language: str, translate: {}) -> str:
"""Tries to automatically translate the given post """Tries to automatically translate the given post
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return '' return ''
msgObject = post_json_object['object'] msgObject = post_json_object['object']
if not msgObject.get('contentMap'): if not msgObject.get('contentMap'):

View File

@ -13,7 +13,7 @@ from utils import hasObjectString
from utils import hasObjectStringObject from utils import hasObjectStringObject
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import removeDomainPort from utils import removeDomainPort
from utils import hasObjectDict from utils import has_object_dict
from utils import hasUsersPath from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
@ -39,7 +39,7 @@ def noOfLikes(post_json_object: {}) -> int:
"""Returns the number of likes ona given post """Returns the number of likes ona given post
""" """
obj = post_json_object obj = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
obj = post_json_object['object'] obj = post_json_object['object']
if not obj.get('likes'): if not obj.get('likes'):
return 0 return 0
@ -59,7 +59,7 @@ def likedByPerson(post_json_object: {}, nickname: str, domain: str) -> bool:
actorMatch = domain + '/users/' + nickname actorMatch = domain + '/users/' + nickname
obj = post_json_object obj = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
obj = post_json_object['object'] obj = post_json_object['object']
for item in obj['likes']['items']: for item in obj['likes']['items']:
@ -436,7 +436,7 @@ def updateLikesCollection(recentPostsCache: {},
cachedPostFilename) cachedPostFilename)
obj = post_json_object obj = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
obj = post_json_object['object'] obj = post_json_object['object']
if not objectUrl.endswith('/likes'): if not objectUrl.endswith('/likes'):

View File

@ -21,7 +21,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 utils import has_object_dict
from utils import acctDir from utils import acctDir
from shutil import copyfile from shutil import copyfile
from shutil import rmtree from shutil import rmtree
@ -59,7 +59,7 @@ def _replaceSiloDomain(post_json_object: {},
""" """
if not replacementDomain: if not replacementDomain:
return return
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return return
if not post_json_object['object'].get('content'): if not post_json_object['object'].get('content'):
return return

View File

@ -21,7 +21,7 @@ from categories import setHashtagCategory
from utils import dangerousSVG from utils import dangerousSVG
from utils import getFavFilenameFromUrl from utils import getFavFilenameFromUrl
from utils import getBaseContentFromPost from utils import getBaseContentFromPost
from utils import hasObjectDict from utils import has_object_dict
from utils import firstParagraphFromString from utils import firstParagraphFromString
from utils import isPublicPost from utils import isPublicPost
from utils import locatePost from utils import locatePost
@ -970,7 +970,7 @@ def _isNewswireBlogPost(post_json_object: {}) -> bool:
""" """
if not post_json_object: if not post_json_object:
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if post_json_object['object'].get('summary') and \ if post_json_object['object'].get('summary') and \
post_json_object['object'].get('url') and \ post_json_object['object'].get('url') and \
@ -983,7 +983,7 @@ def _isNewswireBlogPost(post_json_object: {}) -> bool:
def _getHashtagsFromPost(post_json_object: {}) -> []: def _getHashtagsFromPost(post_json_object: {}) -> []:
"""Returns a list of any hashtags within a post """Returns a list of any hashtags within a post
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return [] return []
if not post_json_object['object'].get('tag'): if not post_json_object['object'].get('tag'):
return [] return []

View File

@ -18,7 +18,7 @@ from posts import sendToFollowersThread
from posts import sendToNamedAddressesThread from posts import sendToNamedAddressesThread
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import getBaseContentFromPost from utils import getBaseContentFromPost
from utils import hasObjectDict from utils import has_object_dict
from utils import getLocalNetworkAddresses from utils import getLocalNetworkAddresses
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
@ -222,7 +222,7 @@ def postMessageToOutbox(session, translate: {},
# check that the outgoing post doesn't contain any markup # check that the outgoing post doesn't contain any markup
# which can be used to implement exploits # which can be used to implement exploits
if hasObjectDict(message_json): if has_object_dict(message_json):
contentStr = getBaseContentFromPost(message_json, system_language) contentStr = getBaseContentFromPost(message_json, system_language)
if contentStr: if contentStr:
if dangerousMarkup(contentStr, allow_local_network_access): if dangerousMarkup(contentStr, allow_local_network_access):
@ -365,7 +365,7 @@ def postMessageToOutbox(session, translate: {},
# if this is a blog post or an event then save to its own box # if this is a blog post or an event then save to its own box
if message_json['type'] == 'Create': if message_json['type'] == 'Create':
if hasObjectDict(message_json): if has_object_dict(message_json):
if message_json['object'].get('type'): if message_json['object'].get('type'):
if message_json['object']['type'] == 'Article': if message_json['object']['type'] == 'Article':
outboxName = 'tlblogs' outboxName = 'tlblogs'

View File

@ -41,7 +41,7 @@ from utils import hasGroupType
from utils import getBaseContentFromPost from utils import getBaseContentFromPost
from utils import removeDomainPort from utils import removeDomainPort
from utils import getPortFromDomain from utils import getPortFromDomain
from utils import hasObjectDict from utils import has_object_dict
from utils import rejectPostId from utils import rejectPostId
from utils import removeInvalidChars from utils import removeInvalidChars
from utils import fileLastModified from utils import fileLastModified
@ -782,7 +782,7 @@ def getPostDomains(session, outboxUrl: str, maxPosts: int,
i += 1 i += 1
if i > maxPosts: if i > maxPosts:
break break
if not hasObjectDict(item): if not has_object_dict(item):
continue continue
contentStr = getBaseContentFromPost(item, system_language) contentStr = getBaseContentFromPost(item, system_language)
if contentStr: if contentStr:
@ -847,7 +847,7 @@ def _getPostsForBlockedDomains(base_dir: str,
i += 1 i += 1
if i > maxPosts: if i > maxPosts:
break break
if not hasObjectDict(item): if not has_object_dict(item):
continue continue
if item['object'].get('inReplyTo'): if item['object'].get('inReplyTo'):
if isinstance(item['object']['inReplyTo'], str): if isinstance(item['object']['inReplyTo'], str):
@ -924,7 +924,7 @@ def savePostToBox(base_dir: str, http_prefix: str, postId: str,
local_actor_url(http_prefix, nickname, originalDomain) + \ local_actor_url(http_prefix, nickname, originalDomain) + \
'/statuses/' + statusNumber '/statuses/' + statusNumber
post_json_object['id'] = postId + '/activity' post_json_object['id'] = postId + '/activity'
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
post_json_object['object']['id'] = postId post_json_object['object']['id'] = postId
post_json_object['object']['atomUri'] = postId post_json_object['object']['atomUri'] = postId
@ -1611,7 +1611,7 @@ def _postIsAddressedToFollowers(base_dir: str,
toList = [] toList = []
ccList = [] ccList = []
if post_json_object['type'] != 'Update' and \ if post_json_object['type'] != 'Update' and \
hasObjectDict(post_json_object): has_object_dict(post_json_object):
if post_json_object['object'].get('to'): if post_json_object['object'].get('to'):
toList = post_json_object['object']['to'] toList = post_json_object['object']['to']
if post_json_object['object'].get('cc'): if post_json_object['object'].get('cc'):
@ -2595,7 +2595,7 @@ def _addFollowersToPublicPost(post_json_object: {}) -> None:
if post_json_object.get('cc'): if post_json_object.get('cc'):
return return
post_json_object['cc'] = post_json_object['actor'] + '/followers' post_json_object['cc'] = post_json_object['actor'] + '/followers'
elif hasObjectDict(post_json_object): elif has_object_dict(post_json_object):
if not post_json_object['object'].get('to'): if not post_json_object['object'].get('to'):
return return
if len(post_json_object['object']['to']) > 1: if len(post_json_object['object']['to']) > 1:
@ -2808,7 +2808,7 @@ def addToField(activityType: str, post_json_object: {},
toAddress = toAddress.split('/statuses/')[0] toAddress = toAddress.split('/statuses/')[0]
post_json_object['to'] = [toAddress] post_json_object['to'] = [toAddress]
toFieldAdded = True toFieldAdded = True
elif hasObjectDict(post_json_object): elif has_object_dict(post_json_object):
# add a to field to bookmark add or remove # add a to field to bookmark add or remove
if post_json_object.get('type') and \ if post_json_object.get('type') and \
post_json_object.get('actor') and \ post_json_object.get('actor') and \
@ -2879,7 +2879,7 @@ def _sendToNamedAddresses(session, base_dir: str,
if not post_json_object.get('object'): if not post_json_object.get('object'):
return return
isProfileUpdate = False isProfileUpdate = False
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if _isProfileUpdate(post_json_object): if _isProfileUpdate(post_json_object):
# use the original object, which has a 'to' # use the original object, which has a 'to'
recipientsObject = post_json_object recipientsObject = post_json_object
@ -3486,7 +3486,7 @@ def isImageMedia(session, base_dir: str, http_prefix: str,
post_json_object = postJsonAnnounce post_json_object = postJsonAnnounce
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if post_json_object['object'].get('moderationStatus'): if post_json_object['object'].get('moderationStatus'):
return False return False
@ -3572,7 +3572,7 @@ def removePostInteractions(post_json_object: {}, force: bool) -> bool:
Returns False if this is a private post Returns False if this is a private post
""" """
hasObject = False hasObject = False
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
hasObject = True hasObject = True
if hasObject: if hasObject:
postObj = post_json_object['object'] postObj = post_json_object['object']
@ -5188,7 +5188,7 @@ def editedPostFilename(base_dir: str, nickname: str, domain: str,
maxTimeDiffSeconds: int) -> str: maxTimeDiffSeconds: int) -> str:
"""Returns the filename of the edited post """Returns the filename of the edited post
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return '' return ''
if not post_json_object.get('type'): if not post_json_object.get('type'):
return '' return ''
@ -5289,7 +5289,7 @@ def getOriginalPostFromAnnounceUrl(announceUrl: str, base_dir: str,
# we have the original post # we have the original post
origPostJson = loadJson(origFilename, 0, 1) origPostJson = loadJson(origFilename, 0, 1)
if origPostJson: if origPostJson:
if hasObjectDict(origPostJson): if has_object_dict(origPostJson):
if origPostJson['object'].get('attributedTo'): if origPostJson['object'].get('attributedTo'):
if isinstance(origPostJson['object']['attributedTo'], str): if isinstance(origPostJson['object']['attributedTo'], str):
actor = origPostJson['object']['attributedTo'] actor = origPostJson['object']['attributedTo']

View File

@ -11,7 +11,7 @@ import os
from utils import locatePost from utils import locatePost
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import hasObjectDict from utils import has_object_dict
def questionUpdateVotes(base_dir: str, nickname: str, domain: str, def questionUpdateVotes(base_dir: str, nickname: str, domain: str,
@ -19,7 +19,7 @@ def questionUpdateVotes(base_dir: str, nickname: str, domain: str,
""" For a given reply update the votes on a question """ For a given reply update the votes on a question
Returns the question json object if the vote totals were changed Returns the question json object if the vote totals were changed
""" """
if not hasObjectDict(replyJson): if not has_object_dict(replyJson):
return None, None return None, None
if not replyJson['object'].get('inReplyTo'): if not replyJson['object'].get('inReplyTo'):
return None, None return None, None
@ -36,7 +36,7 @@ def questionUpdateVotes(base_dir: str, nickname: str, domain: str,
questionJson = loadJson(questionPostFilename) questionJson = loadJson(questionPostFilename)
if not questionJson: if not questionJson:
return None, None return None, None
if not hasObjectDict(questionJson): if not has_object_dict(questionJson):
return None, None return None, None
if not questionJson['object'].get('type'): if not questionJson['object'].get('type'):
return None, None return None, None
@ -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 hasObjectDict(postObjectJson): if not has_object_dict(postObjectJson):
return False return False
if not postObjectJson['object'].get('type'): if not postObjectJson['object'].get('type'):
return False return False

View File

@ -15,7 +15,7 @@ from utils import hasObjectString
from utils import hasObjectStringObject from utils import hasObjectStringObject
from utils import hasObjectStringType from utils import hasObjectStringType
from utils import removeDomainPort from utils import removeDomainPort
from utils import hasObjectDict from utils import has_object_dict
from utils import hasUsersPath from utils import hasUsersPath
from utils import getFullDomain from utils import getFullDomain
from utils import removeIdEnding from utils import removeIdEnding
@ -466,7 +466,7 @@ def updateReactionCollection(recentPostsCache: {},
cachedPostFilename) cachedPostFilename)
obj = post_json_object obj = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
obj = post_json_object['object'] obj = post_json_object['object']
if not objectUrl.endswith('/reactions'): if not objectUrl.endswith('/reactions'):
@ -519,7 +519,7 @@ def htmlEmojiReactions(post_json_object: {}, interactive: bool,
"""html containing row of emoji reactions """html containing row of emoji reactions
displayed at the bottom of posts, above the icons displayed at the bottom of posts, above the icons
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return '' return ''
if not post_json_object.get('actor'): if not post_json_object.get('actor'):
return '' return ''

View File

@ -10,7 +10,7 @@ __module_group__ = "Calendar"
import os import os
import time import time
import datetime import datetime
from utils import hasObjectDict from utils import has_object_dict
from utils import getStatusNumber from utils import getStatusNumber
from utils import loadJson from utils import loadJson
from utils import isAccountDir from utils import isAccountDir
@ -85,7 +85,7 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd,
statusNumber, published = getStatusNumber() statusNumber, published = getStatusNumber()
if post_json_object.get('published'): if post_json_object.get('published'):
post_json_object['published'] = published post_json_object['published'] = published
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('published'): if post_json_object['object'].get('published'):
post_json_object['published'] = published post_json_object['published'] = published

View File

@ -23,7 +23,7 @@ from utils import removeHtml
from utils import loadJson from utils import loadJson
from utils import saveJson from utils import saveJson
from utils import isPGPEncrypted from utils import isPGPEncrypted
from utils import hasObjectDict from utils import has_object_dict
from utils import acctDir from utils import acctDir
from utils import local_actor_url from utils import local_actor_url
from content import htmlReplaceQuoteMarks from content import htmlReplaceQuoteMarks
@ -412,7 +412,7 @@ def _postToSpeakerJson(base_dir: str, http_prefix: str,
NOTE: There currently appears to be no standardized json NOTE: There currently appears to be no standardized json
format for speech synthesis format for speech synthesis
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return return
if not post_json_object['object'].get('content'): if not post_json_object['object'].get('content'):
return return

View File

@ -83,7 +83,7 @@ def get_content_from_post(post_json_object: {}, system_language: str,
including searching for a matching entry within contentMap including searching for a matching entry within contentMap
""" """
this_post_json = post_json_object this_post_json = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
this_post_json = post_json_object['object'] this_post_json = post_json_object['object']
if not this_post_json.get('content'): if not this_post_json.get('content'):
return '' return ''
@ -110,7 +110,7 @@ def getBaseContentFromPost(post_json_object: {}, system_language: str) -> str:
"""Returns the content from the post in the given language """Returns the content from the post in the given language
""" """
this_post_json = post_json_object this_post_json = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
this_post_json = post_json_object['object'] this_post_json = post_json_object['object']
if not this_post_json.get('content'): if not this_post_json.get('content'):
return '' return ''
@ -1366,7 +1366,7 @@ def _getPublishedDate(post_json_object: {}) -> str:
published = None published = None
if post_json_object.get('published'): if post_json_object.get('published'):
published = post_json_object['published'] published = post_json_object['published']
elif hasObjectDict(post_json_object): elif has_object_dict(post_json_object):
if post_json_object['object'].get('published'): if post_json_object['object'].get('published'):
published = post_json_object['object']['published'] published = post_json_object['object']['published']
if not published: if not published:
@ -1506,7 +1506,7 @@ def _isReplyToBlogPost(base_dir: str, nickname: str, domain: str,
post_json_object: str): post_json_object: str):
"""Is the given post a reply to a blog post? """Is the given post a reply to a blog post?
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if not post_json_object['object'].get('inReplyTo'): if not post_json_object['object'].get('inReplyTo'):
return False return False
@ -1614,7 +1614,7 @@ def _deleteHashtagsOnPost(base_dir: str, post_json_object: {}) -> None:
"""Removes hashtags when a post is deleted """Removes hashtags when a post is deleted
""" """
removeHashtagIndex = False removeHashtagIndex = False
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('content'): if post_json_object['object'].get('content'):
if '#' in post_json_object['object']['content']: if '#' in post_json_object['object']['content']:
removeHashtagIndex = True removeHashtagIndex = True
@ -1668,7 +1668,7 @@ def _deleteConversationPost(base_dir: str, nickname: str, domain: str,
post_json_object: {}) -> None: post_json_object: {}) -> None:
"""Deletes a post from a conversation """Deletes a post from a conversation
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if not post_json_object['object'].get('conversation'): if not post_json_object['object'].get('conversation'):
return False return False
@ -1763,7 +1763,7 @@ def deletePost(base_dir: str, http_prefix: str,
# remove from moderation index file # remove from moderation index file
if hasObject: if hasObject:
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
if post_json_object['object'].get('moderationStatus'): if post_json_object['object'].get('moderationStatus'):
if post_json_object.get('id'): if post_json_object.get('id'):
postId = removeIdEnding(post_json_object['id']) postId = removeIdEnding(post_json_object['id'])
@ -1957,7 +1957,7 @@ def isPublicPost(post_json_object: {}) -> bool:
return False return False
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if not post_json_object['object'].get('to'): if not post_json_object['object'].get('to'):
return False return False
@ -2077,7 +2077,7 @@ def isBlogPost(post_json_object: {}) -> bool:
""" """
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if not hasObjectStringType(post_json_object, False): if not hasObjectStringType(post_json_object, False):
return False return False
@ -2232,7 +2232,7 @@ def undoLikesCollectionEntry(recentPostsCache: {},
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return return
obj = post_json_object obj = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
obj = post_json_object['object'] obj = post_json_object['object']
if not obj.get('likes'): if not obj.get('likes'):
return return
@ -2297,7 +2297,7 @@ def undoReactionCollectionEntry(recentPostsCache: {},
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return return
obj = post_json_object obj = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
obj = post_json_object['object'] obj = post_json_object['object']
if not obj.get('reactions'): if not obj.get('reactions'):
return return
@ -2362,7 +2362,7 @@ def undoAnnounceCollectionEntry(recentPostsCache: {},
return return
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return return
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
if debug: if debug:
pprint(post_json_object) pprint(post_json_object)
print('DEBUG: post has no object') print('DEBUG: post has no object')
@ -2425,7 +2425,7 @@ def updateAnnounceCollection(recentPostsCache: {},
str(cachedPostFilename)) str(cachedPostFilename))
removePostFromCache(post_json_object, recentPostsCache) removePostFromCache(post_json_object, recentPostsCache)
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
if debug: if debug:
pprint(post_json_object) pprint(post_json_object)
print('DEBUG: post ' + postFilename + ' has no object') print('DEBUG: post ' + postFilename + ' has no object')
@ -2509,7 +2509,7 @@ def mediaFileMimeType(filename: str) -> str:
def isRecentPost(post_json_object: {}, maxDays: int) -> bool: def isRecentPost(post_json_object: {}, maxDays: int) -> bool:
""" Is the given post recent? """ Is the given post recent?
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if not post_json_object['object'].get('published'): if not post_json_object['object'].get('published'):
return False return False
@ -2586,7 +2586,7 @@ def isDM(post_json_object: {}) -> bool:
""" """
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if post_json_object['object']['type'] != 'Note' and \ if post_json_object['object']['type'] != 'Note' and \
post_json_object['object']['type'] != 'Page' and \ post_json_object['object']['type'] != 'Page' and \
@ -2613,7 +2613,7 @@ def isReply(post_json_object: {}, actor: str) -> bool:
""" """
if post_json_object['type'] != 'Create': if post_json_object['type'] != 'Create':
return False return False
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False return False
if post_json_object['object'].get('moderationStatus'): if post_json_object['object'].get('moderationStatus'):
return False return False
@ -2845,7 +2845,7 @@ def userAgentDomain(userAgent: str, debug: bool) -> str:
return agentDomain return agentDomain
def hasObjectDict(post_json_object: {}) -> bool: def has_object_dict(post_json_object: {}) -> bool:
"""Returns true if the given post has an object dict """Returns true if the given post has an object dict
""" """
if post_json_object.get('object'): if post_json_object.get('object'):
@ -3173,7 +3173,7 @@ def hasActor(post_json_object: {}, debug: bool) -> bool:
def hasObjectStringType(post_json_object: {}, debug: bool) -> bool: def hasObjectStringType(post_json_object: {}, debug: bool) -> bool:
"""Does the given post have a type field within an object dict? """Does the given post have a type field within an object dict?
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
if debug: if debug:
print('hasObjectStringType no object found') print('hasObjectStringType no object found')
return False return False
@ -3192,7 +3192,7 @@ def hasObjectStringType(post_json_object: {}, debug: bool) -> bool:
def hasObjectStringObject(post_json_object: {}, debug: bool) -> bool: def hasObjectStringObject(post_json_object: {}, debug: bool) -> bool:
"""Does the given post have an object string field within an object dict? """Does the given post have an object string field within an object dict?
""" """
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
if debug: if debug:
print('hasObjectStringType no object found') print('hasObjectStringType no object found')
return False return False

View File

@ -28,7 +28,7 @@ from utils import removeHtml
from utils import get_actor_languages_list from utils import get_actor_languages_list
from utils import getBaseContentFromPost from utils import getBaseContentFromPost
from utils import get_content_from_post from utils import get_content_from_post
from utils import hasObjectDict from utils import has_object_dict
from utils import updateAnnounceCollection from utils import updateAnnounceCollection
from utils import isPGPEncrypted from utils import isPGPEncrypted
from utils import isDM from utils import isDM
@ -93,7 +93,7 @@ def _htmlPostMetadataOpenGraph(domain: str, post_json_object: {}) -> str:
metadata += \ metadata += \
" <meta content=\"article\" property=\"og:type\" />\n" " <meta content=\"article\" property=\"og:type\" />\n"
objJson = post_json_object objJson = post_json_object
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
objJson = post_json_object['object'] objJson = post_json_object['object']
if objJson.get('attributedTo'): if objJson.get('attributedTo'):
if isinstance(objJson['attributedTo'], str): if isinstance(objJson['attributedTo'], str):
@ -1559,7 +1559,7 @@ def individualPostAsHtml(signing_priv_key_pem: str,
_logPostTiming(enableTimingLog, postStartTime, '8') _logPostTiming(enableTimingLog, postStartTime, '8')
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return '' return ''
# if this post should be public then check its recipients # if this post should be public then check its recipients
@ -2076,7 +2076,7 @@ def htmlIndividualPost(cssCache: {},
messageId = removeIdEnding(post_json_object['id']) messageId = removeIdEnding(post_json_object['id'])
# show the previous posts # show the previous posts
if hasObjectDict(post_json_object): if has_object_dict(post_json_object):
while post_json_object['object'].get('inReplyTo'): while post_json_object['object'].get('inReplyTo'):
postFilename = \ postFilename = \
locatePost(base_dir, nickname, domain, locatePost(base_dir, nickname, domain,

View File

@ -12,7 +12,7 @@ from pprint import pprint
from webfinger import webfingerHandle from webfinger import webfingerHandle
from utils import getDisplayName from utils import getDisplayName
from utils import isGroupAccount from utils import isGroupAccount
from utils import hasObjectDict from utils import has_object_dict
from utils import getOccupationName from utils import getOccupationName
from utils import getLockedAccount from utils import getLockedAccount
from utils import getFullDomain from utils import getFullDomain
@ -88,7 +88,7 @@ def _validProfilePreviewPost(post_json_object: {},
if not post_json_object.get('type'): if not post_json_object.get('type'):
return False, None return False, None
if post_json_object['type'] == 'Create': if post_json_object['type'] == 'Create':
if not hasObjectDict(post_json_object): if not has_object_dict(post_json_object):
return False, None return False, None
if post_json_object['type'] != 'Create' and \ if post_json_object['type'] != 'Create' and \
post_json_object['type'] != 'Announce': post_json_object['type'] != 'Announce':