mirror of https://gitlab.com/bashrc2/epicyon
Tidying
parent
8e6084d42d
commit
614e274e24
|
@ -15,11 +15,11 @@ from utils import getDomainFromActor
|
|||
from utils import getNicknameFromActor
|
||||
from utils import domainPermitted
|
||||
from utils import followPerson
|
||||
from utils import hasObjectDict
|
||||
from utils import acctDir
|
||||
from utils import hasGroupType
|
||||
from utils import localActorUrl
|
||||
from utils import hasActor
|
||||
from utils import hasObjectStringType
|
||||
|
||||
|
||||
def _createAcceptReject(baseDir: str, federationList: [],
|
||||
|
@ -78,9 +78,7 @@ def _acceptFollow(baseDir: str, domain: str, messageJson: {},
|
|||
federationList: [], debug: bool) -> None:
|
||||
"""Receiving a follow Accept activity
|
||||
"""
|
||||
if not hasObjectDict(messageJson):
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not messageJson['object']['type'] == 'Follow':
|
||||
if not messageJson['object']['type'] == 'Join':
|
||||
|
|
14
announce.py
14
announce.py
|
@ -9,7 +9,6 @@ __module_group__ = "ActivityPub"
|
|||
|
||||
from utils import hasGroupType
|
||||
from utils import removeDomainPort
|
||||
from utils import hasObjectDict
|
||||
from utils import removeIdEnding
|
||||
from utils import hasUsersPath
|
||||
from utils import getFullDomain
|
||||
|
@ -25,6 +24,7 @@ from utils import updateAnnounceCollection
|
|||
from utils import localActorUrl
|
||||
from utils import replaceUsersWithAt
|
||||
from utils import hasActor
|
||||
from utils import hasObjectStringType
|
||||
from posts import sendSignedJson
|
||||
from posts import getPersonBox
|
||||
from session import postJson
|
||||
|
@ -81,9 +81,7 @@ def outboxAnnounce(recentPostsCache: {},
|
|||
nickname, domain, debug)
|
||||
return True
|
||||
elif messageJson['type'] == 'Undo':
|
||||
if not hasObjectDict(messageJson):
|
||||
return False
|
||||
if not messageJson['object'].get('type'):
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return False
|
||||
if messageJson['object']['type'] == 'Announce':
|
||||
if not isinstance(messageJson['object']['object'], str):
|
||||
|
@ -397,13 +395,7 @@ def outboxUndoAnnounce(recentPostsCache: {},
|
|||
return
|
||||
if not messageJson['type'] == 'Undo':
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: undo like object is not dict')
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: undo like - no type')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not messageJson['object']['type'] == 'Announce':
|
||||
if debug:
|
||||
|
|
13
blocking.py
13
blocking.py
|
@ -11,6 +11,7 @@ import os
|
|||
import json
|
||||
import time
|
||||
from datetime import datetime
|
||||
from utils import hasObjectStringType
|
||||
from utils import removeDomainPort
|
||||
from utils import hasObjectDict
|
||||
from utils import isAccountDir
|
||||
|
@ -402,14 +403,8 @@ def outboxUndoBlock(baseDir: str, httpPrefix: str,
|
|||
if debug:
|
||||
print('DEBUG: not an undo block')
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: undo block object is not string')
|
||||
return
|
||||
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: undo block - no type')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not messageJson['object']['type'] == 'Block':
|
||||
if debug:
|
||||
|
@ -762,9 +757,7 @@ def outboxUndoMute(baseDir: str, httpPrefix: str,
|
|||
return
|
||||
if not messageJson['type'] == 'Undo':
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if messageJson['object']['type'] != 'Ignore':
|
||||
return
|
||||
|
|
17
bookmarks.py
17
bookmarks.py
|
@ -27,6 +27,7 @@ from utils import hasObjectDict
|
|||
from utils import acctDir
|
||||
from utils import localActorUrl
|
||||
from utils import hasActor
|
||||
from utils import hasObjectStringType
|
||||
from posts import getPersonBox
|
||||
from session import postJson
|
||||
|
||||
|
@ -542,17 +543,11 @@ def outboxBookmark(recentPostsCache: {},
|
|||
return
|
||||
if not hasActor(messageJson, debug):
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: no object in bookmark Add')
|
||||
return
|
||||
if not messageJson.get('target'):
|
||||
if debug:
|
||||
print('DEBUG: no target in bookmark Add')
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: no object type in bookmark Add')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not isinstance(messageJson['target'], str):
|
||||
if debug:
|
||||
|
@ -604,17 +599,11 @@ def outboxUndoBookmark(recentPostsCache: {},
|
|||
return
|
||||
if not hasActor(messageJson, debug):
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: no object in unbookmark Remove')
|
||||
return
|
||||
if not messageJson.get('target'):
|
||||
if debug:
|
||||
print('DEBUG: no target in unbookmark Remove')
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: no object type in bookmark Remove')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not isinstance(messageJson['target'], str):
|
||||
if debug:
|
||||
|
|
|
@ -9,9 +9,9 @@ __module_group__ = "ActivityPub"
|
|||
|
||||
from pprint import pprint
|
||||
import os
|
||||
from utils import hasObjectStringType
|
||||
from utils import hasActor
|
||||
from utils import removeDomainPort
|
||||
from utils import hasObjectDict
|
||||
from utils import hasUsersPath
|
||||
from utils import getFullDomain
|
||||
from utils import isSystemAccount
|
||||
|
@ -1488,9 +1488,7 @@ def outboxUndoFollow(baseDir: str, messageJson: {}, debug: bool) -> None:
|
|||
return
|
||||
if not messageJson['type'] == 'Undo':
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not messageJson['object']['type'] == 'Follow':
|
||||
if not messageJson['object']['type'] == 'Join':
|
||||
|
|
6
git.py
6
git.py
|
@ -9,8 +9,8 @@ __module_group__ = "Profile Metadata"
|
|||
|
||||
import os
|
||||
import html
|
||||
from utils import hasObjectDict
|
||||
from utils import acctDir
|
||||
from utils import hasObjectStringType
|
||||
|
||||
|
||||
def _gitFormatContent(content: str) -> str:
|
||||
|
@ -115,9 +115,7 @@ def convertPostToPatch(baseDir: str, nickname: str, domain: str,
|
|||
"""Detects whether the given post contains a patch
|
||||
and if so then converts it to a Patch ActivityPub type
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
return False
|
||||
if not postJsonObject['object'].get('type'):
|
||||
if not hasObjectStringType(postJsonObject, False):
|
||||
return False
|
||||
if postJsonObject['object']['type'] == 'Patch':
|
||||
return True
|
||||
|
|
47
inbox.py
47
inbox.py
|
@ -49,6 +49,7 @@ from utils import saveJson
|
|||
from utils import undoLikesCollectionEntry
|
||||
from utils import hasGroupType
|
||||
from utils import localActorUrl
|
||||
from utils import hasObjectStringType
|
||||
from categories import getHashtagCategories
|
||||
from categories import setHashtagCategory
|
||||
from httpsig import verifyPostHeaders
|
||||
|
@ -692,18 +693,7 @@ def _receiveUndo(session, baseDir: str, httpPrefix: str,
|
|||
if debug:
|
||||
print('DEBUG: "users" or "profile" missing from actor')
|
||||
return False
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: ' + messageJson['type'] + ' has no object')
|
||||
return False
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: ' + messageJson['type'] + ' has no object type')
|
||||
return False
|
||||
if not isinstance(messageJson['object']['type'], str):
|
||||
if debug:
|
||||
print('DEBUG: ' + messageJson['type'] +
|
||||
' type within object is not a string')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return False
|
||||
if not messageJson['object'].get('object'):
|
||||
if debug:
|
||||
|
@ -850,18 +840,7 @@ def _receiveUpdate(recentPostsCache: {}, session, baseDir: str,
|
|||
return False
|
||||
if not hasActor(messageJson, debug):
|
||||
return False
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: ' + messageJson['type'] + ' has no object')
|
||||
return False
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: ' + messageJson['type'] + ' object has no type')
|
||||
return False
|
||||
if not isinstance(messageJson['object']['type'], str):
|
||||
if debug:
|
||||
print('DEBUG: ' + messageJson['type'] +
|
||||
' object type is not string')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return False
|
||||
if not hasUsersPath(messageJson['actor']):
|
||||
if debug:
|
||||
|
@ -1031,9 +1010,7 @@ def _receiveUndoLike(recentPostsCache: {},
|
|||
return False
|
||||
if not hasActor(messageJson, debug):
|
||||
return False
|
||||
if not hasObjectDict(messageJson):
|
||||
return False
|
||||
if not messageJson['object'].get('type'):
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return False
|
||||
if messageJson['object']['type'] != 'Like':
|
||||
return False
|
||||
|
@ -1133,17 +1110,11 @@ def _receiveBookmark(recentPostsCache: {},
|
|||
return False
|
||||
if not hasActor(messageJson, debug):
|
||||
return False
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: no object in inbox bookmark Add')
|
||||
return False
|
||||
if not messageJson.get('target'):
|
||||
if debug:
|
||||
print('DEBUG: no target in inbox bookmark Add')
|
||||
return False
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: no object type in inbox bookmark Add')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return False
|
||||
if not isinstance(messageJson['target'], str):
|
||||
if debug:
|
||||
|
@ -1247,17 +1218,11 @@ def _receiveUndoBookmark(recentPostsCache: {},
|
|||
return False
|
||||
if not hasActor(messageJson, debug):
|
||||
return False
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: no object in inbox undo bookmark Remove')
|
||||
return False
|
||||
if not messageJson.get('target'):
|
||||
if debug:
|
||||
print('DEBUG: no target in inbox undo bookmark Remove')
|
||||
return False
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: no object type in inbox bookmark Remove')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return False
|
||||
if not isinstance(messageJson['target'], str):
|
||||
if debug:
|
||||
|
|
9
like.py
9
like.py
|
@ -9,6 +9,7 @@ __module_group__ = "ActivityPub"
|
|||
|
||||
import os
|
||||
from pprint import pprint
|
||||
from utils import hasObjectStringType
|
||||
from utils import removeDomainPort
|
||||
from utils import hasObjectDict
|
||||
from utils import hasUsersPath
|
||||
|
@ -380,13 +381,7 @@ def outboxUndoLike(recentPostsCache: {},
|
|||
return
|
||||
if not messageJson['type'] == 'Undo':
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: undo like object is not dict')
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: undo like - no type')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not messageJson['object']['type'] == 'Like':
|
||||
if debug:
|
||||
|
|
|
@ -16,6 +16,7 @@ from posts import outboxMessageCreateWrap
|
|||
from posts import savePostToBox
|
||||
from posts import sendToFollowersThread
|
||||
from posts import sendToNamedAddresses
|
||||
from utils import hasObjectStringType
|
||||
from utils import getBaseContentFromPost
|
||||
from utils import hasObjectDict
|
||||
from utils import getLocalNetworkAddresses
|
||||
|
@ -73,13 +74,7 @@ def _outboxPersonReceiveUpdate(recentPostsCache: {},
|
|||
return
|
||||
if messageJson['type'] != 'Update':
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
if debug:
|
||||
print('DEBUG: c2s actor update object is not dict')
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: c2s actor update - no type')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not isinstance(messageJson['object']['type'], str):
|
||||
if debug:
|
||||
|
|
22
posts.py
22
posts.py
|
@ -32,6 +32,7 @@ from webfinger import webfingerHandle
|
|||
from httpsig import createSignedHeader
|
||||
from siteactive import siteIsActive
|
||||
from languages import understoodPostLanguage
|
||||
from utils import hasObjectStringType
|
||||
from utils import removeIdEnding
|
||||
from utils import replaceUsersWithAt
|
||||
from utils import hasGroupType
|
||||
|
@ -2711,13 +2712,14 @@ def _isProfileUpdate(postJsonObject: {}) -> bool:
|
|||
"""Is the given post a profile update?
|
||||
for actor updates there is no 'to' within the object
|
||||
"""
|
||||
if postJsonObject['object'].get('type') and postJsonObject.get('type'):
|
||||
if (postJsonObject['type'] == 'Update' and
|
||||
(postJsonObject['object']['type'] == 'Person' or
|
||||
postJsonObject['object']['type'] == 'Application' or
|
||||
postJsonObject['object']['type'] == 'Group' or
|
||||
postJsonObject['object']['type'] == 'Service')):
|
||||
return True
|
||||
if postJsonObject.get('type'):
|
||||
if hasObjectStringType(postJsonObject, False):
|
||||
if (postJsonObject['type'] == 'Update' and
|
||||
(postJsonObject['object']['type'] == 'Person' or
|
||||
postJsonObject['object']['type'] == 'Application' or
|
||||
postJsonObject['object']['type'] == 'Group' or
|
||||
postJsonObject['object']['type'] == 'Service')):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
@ -2752,7 +2754,7 @@ def sendToNamedAddresses(session, baseDir: str,
|
|||
pprint(postJsonObject)
|
||||
print('DEBUG: ' +
|
||||
'no "to" field when sending to named addresses')
|
||||
if postJsonObject['object'].get('type'):
|
||||
if hasObjectStringType(postJsonObject, debug):
|
||||
if postJsonObject['object']['type'] == 'Follow' or \
|
||||
postJsonObject['object']['type'] == 'Join':
|
||||
if isinstance(postJsonObject['object']['object'], str):
|
||||
|
@ -2897,9 +2899,7 @@ def _sendingProfileUpdate(postJsonObject: {}) -> bool:
|
|||
"""
|
||||
if postJsonObject['type'] != 'Update':
|
||||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
return False
|
||||
if not postJsonObject['object'].get('type'):
|
||||
if not hasObjectStringType(postJsonObject, False):
|
||||
return False
|
||||
activityType = postJsonObject['object']['type']
|
||||
if activityType == 'Person' or \
|
||||
|
|
14
shares.py
14
shares.py
|
@ -22,6 +22,7 @@ from posts import getPersonBox
|
|||
from session import postJson
|
||||
from session import postImage
|
||||
from session import createSession
|
||||
from utils import hasObjectStringType
|
||||
from utils import dateStringToSeconds
|
||||
from utils import dateSecondsToString
|
||||
from utils import getConfigParam
|
||||
|
@ -30,7 +31,6 @@ from utils import validNickname
|
|||
from utils import loadJson
|
||||
from utils import saveJson
|
||||
from utils import getImageExtensions
|
||||
from utils import hasObjectDict
|
||||
from utils import removeDomainPort
|
||||
from utils import isAccountDir
|
||||
from utils import acctDir
|
||||
|
@ -1030,11 +1030,7 @@ def outboxShareUpload(baseDir: str, httpPrefix: str,
|
|||
return
|
||||
if not messageJson['type'] == 'Add':
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: undo block - no type')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not messageJson['object']['type'] == 'Offer':
|
||||
if debug:
|
||||
|
@ -1103,11 +1099,7 @@ def outboxUndoShareUpload(baseDir: str, httpPrefix: str,
|
|||
return
|
||||
if not messageJson['type'] == 'Remove':
|
||||
return
|
||||
if not hasObjectDict(messageJson):
|
||||
return
|
||||
if not messageJson['object'].get('type'):
|
||||
if debug:
|
||||
print('DEBUG: undo block - no type')
|
||||
if not hasObjectStringType(messageJson, debug):
|
||||
return
|
||||
if not messageJson['object']['type'] == 'Offer':
|
||||
if debug:
|
||||
|
|
21
utils.py
21
utils.py
|
@ -2037,7 +2037,7 @@ def isBlogPost(postJsonObject: {}) -> bool:
|
|||
return False
|
||||
if not hasObjectDict(postJsonObject):
|
||||
return False
|
||||
if not postJsonObject['object'].get('type'):
|
||||
if not hasObjectStringType(postJsonObject, False):
|
||||
return False
|
||||
if not postJsonObject['object'].get('content'):
|
||||
return False
|
||||
|
@ -3034,3 +3034,22 @@ def hasActor(postJsonObject: {}, debug: bool) -> bool:
|
|||
msg += ' ' + postJsonObject['id']
|
||||
print(msg)
|
||||
return False
|
||||
|
||||
|
||||
def hasObjectStringType(postJsonObject: {}, debug: bool) -> bool:
|
||||
"""Dies the given post have a type field within an object dict?
|
||||
"""
|
||||
if not hasObjectDict(postJsonObject):
|
||||
if debug:
|
||||
print('hasObjectStringType no object found')
|
||||
return False
|
||||
if postJsonObject['object'].get('type'):
|
||||
if isinstance(postJsonObject['object']['type'], str):
|
||||
return True
|
||||
elif debug:
|
||||
if postJsonObject.get('type'):
|
||||
print('DEBUG: ' + postJsonObject['type'] +
|
||||
' type within object is not a string')
|
||||
if debug:
|
||||
print('No type field within object ' + postJsonObject['id'])
|
||||
return False
|
||||
|
|
Loading…
Reference in New Issue