Snake case

merge-requests/30/head
Bob Mottram 2021-12-26 17:53:07 +00:00
parent 6f18cec3a9
commit 821af94f59
12 changed files with 39 additions and 39 deletions

View File

@ -17,7 +17,7 @@ from utils import getNicknameFromActor
from utils import domainPermitted from utils import domainPermitted
from utils import followPerson from utils import followPerson
from utils import acct_dir from utils import acct_dir
from utils import hasGroupType from utils import has_group_type
from utils import local_actor_url from utils import local_actor_url
from utils import has_actor from utils import has_actor
from utils import has_object_stringType from utils import has_object_stringType
@ -163,7 +163,7 @@ def _accept_follow(base_dir: str, domain: str, message_json: {},
return return
# does the url path indicate that this is a group actor # does the url path indicate that this is a group actor
group_account = hasGroupType(base_dir, followed_actor, None, debug) group_account = has_group_type(base_dir, followed_actor, None, debug)
if debug: if debug:
print('Accepted follow is a group: ' + str(group_account) + print('Accepted follow is a group: ' + str(group_account) +
' ' + followed_actor + ' ' + base_dir) ' ' + followed_actor + ' ' + base_dir)

View File

@ -8,7 +8,7 @@ __status__ = "Production"
__module_group__ = "ActivityPub" __module_group__ = "ActivityPub"
from utils import has_object_string_object from utils import has_object_string_object
from utils import hasGroupType from utils import has_group_type
from utils import removeDomainPort from utils import removeDomainPort
from utils import removeIdEnding from utils import removeIdEnding
from utils import has_users_path from utils import has_users_path
@ -171,7 +171,7 @@ def createAnnounce(session, base_dir: str, federation_list: [],
announceActor = \ announceActor = \
objectUrl.split('/' + announceNickname + '/')[0] + \ objectUrl.split('/' + announceNickname + '/')[0] + \
'/' + announceNickname '/' + announceNickname
if hasGroupType(base_dir, announceActor, person_cache): if has_group_type(base_dir, announceActor, person_cache):
group_account = True group_account = True
if announceNickname and announceDomain: if announceNickname and announceDomain:

View File

@ -303,7 +303,7 @@ from utils import isSuspended
from utils import dangerousMarkup from utils import dangerousMarkup
from utils import refresh_newswire from utils import refresh_newswire
from utils import isImageFile from utils import isImageFile
from utils import hasGroupType from utils import has_group_type
from manualapprove import manualDenyFollowRequestThread from manualapprove import manualDenyFollowRequestThread
from manualapprove import manualApproveFollowRequestThread from manualapprove import manualApproveFollowRequestThread
from announce import createAnnounce from announce import createAnnounce
@ -2957,9 +2957,9 @@ class PubServer(BaseHTTPRequestHandler):
} }
pathUsersSection = path.split('/users/')[1] pathUsersSection = path.split('/users/')[1]
self.postToNickname = pathUsersSection.split('/')[0] self.postToNickname = pathUsersSection.split('/')[0]
group_account = hasGroupType(self.server.base_dir, group_account = has_group_type(self.server.base_dir,
followingActor, followingActor,
self.server.person_cache) self.server.person_cache)
unfollowAccount(self.server.base_dir, self.postToNickname, unfollowAccount(self.server.base_dir, self.postToNickname,
self.server.domain, self.server.domain,
followingNickname, followingDomainFull, followingNickname, followingDomainFull,

View File

@ -28,7 +28,7 @@ from utils import save_json
from utils import isAccountDir from utils import isAccountDir
from utils import get_user_paths from utils import get_user_paths
from utils import acct_dir from utils import acct_dir
from utils import hasGroupType from utils import has_group_type
from utils import local_actor_url from utils import local_actor_url
from acceptreject import createAccept from acceptreject import createAccept
from acceptreject import createReject from acceptreject import createReject
@ -763,7 +763,7 @@ def followedAccountAccepts(session, base_dir: str, http_prefix: str,
group_account = False group_account = False
if followJson: if followJson:
if followJson.get('actor'): if followJson.get('actor'):
if hasGroupType(base_dir, followJson['actor'], person_cache): if has_group_type(base_dir, followJson['actor'], person_cache):
group_account = True group_account = True
return sendSignedJson(acceptJson, session, base_dir, return sendSignedJson(acceptJson, session, base_dir,
@ -822,7 +822,7 @@ def followedAccountRejects(session, base_dir: str, http_prefix: str,
client_to_server = False client_to_server = False
denyHandle = get_full_domain(nickname + '@' + domain, fromPort) denyHandle = get_full_domain(nickname + '@' + domain, fromPort)
group_account = False group_account = False
if hasGroupType(base_dir, personUrl, person_cache): if has_group_type(base_dir, personUrl, person_cache):
group_account = True group_account = True
# remove from the follow requests file # remove from the follow requests file
removeFromFollowRequests(base_dir, nicknameToFollow, domainToFollow, removeFromFollowRequests(base_dir, nicknameToFollow, domainToFollow,
@ -874,7 +874,7 @@ def sendFollowRequest(session, base_dir: str,
if followNickname: if followNickname:
followedId = followedActor followedId = followedActor
followHandle = followNickname + '@' + requestDomain followHandle = followNickname + '@' + requestDomain
group_account = hasGroupType(base_dir, followedActor, person_cache) group_account = has_group_type(base_dir, followedActor, person_cache)
if group_account: if group_account:
followHandle = '!' + followHandle followHandle = '!' + followHandle
print('Follow request being sent to group account') print('Follow request being sent to group account')
@ -1416,7 +1416,7 @@ def outboxUndoFollow(base_dir: str, message_json: {}, debug: bool) -> None:
domainFollowingFull = get_full_domain(domainFollowing, portFollowing) domainFollowingFull = get_full_domain(domainFollowing, portFollowing)
group_account = \ group_account = \
hasGroupType(base_dir, message_json['object']['object'], None) has_group_type(base_dir, message_json['object']['object'], None)
if unfollowAccount(base_dir, nicknameFollower, domainFollowerFull, if unfollowAccount(base_dir, nicknameFollower, domainFollowerFull,
nicknameFollowing, domainFollowingFull, nicknameFollowing, domainFollowingFull,
debug, group_account): debug, group_account):

View File

@ -58,7 +58,7 @@ from utils import load_json
from utils import save_json from utils import save_json
from utils import undoLikesCollectionEntry from utils import undoLikesCollectionEntry
from utils import undoReactionCollectionEntry from utils import undoReactionCollectionEntry
from utils import hasGroupType from utils import has_group_type
from utils import local_actor_url from utils import local_actor_url
from utils import has_object_stringType from utils import has_object_stringType
from categories import getHashtagCategories from categories import getHashtagCategories
@ -777,7 +777,7 @@ def _receiveUndoFollow(session, base_dir: str, http_prefix: str,
domainFollowingFull = get_full_domain(domainFollowing, portFollowing) domainFollowingFull = get_full_domain(domainFollowing, portFollowing)
group_account = \ group_account = \
hasGroupType(base_dir, message_json['object']['actor'], None) has_group_type(base_dir, message_json['object']['actor'], None)
if unfollowerOfAccount(base_dir, if unfollowerOfAccount(base_dir,
nicknameFollowing, domainFollowingFull, nicknameFollowing, domainFollowingFull,
nicknameFollower, domainFollowerFull, nicknameFollower, domainFollowerFull,
@ -3985,7 +3985,7 @@ def _receiveFollowRequest(session, base_dir: str, http_prefix: str,
message_json['actor']) message_json['actor'])
group_account = \ group_account = \
hasGroupType(base_dir, message_json['actor'], person_cache) has_group_type(base_dir, message_json['actor'], person_cache)
if group_account and is_group_account(base_dir, nickname, domain): if group_account and is_group_account(base_dir, nickname, domain):
print('Group cannot follow a group') print('Group cannot follow a group')
return False return False
@ -4027,8 +4027,8 @@ def _receiveFollowRequest(session, base_dir: str, http_prefix: str,
if os.path.isfile(followersFilename): if os.path.isfile(followersFilename):
if approveHandle not in open(followersFilename).read(): if approveHandle not in open(followersFilename).read():
group_account = \ group_account = \
hasGroupType(base_dir, has_group_type(base_dir,
message_json['actor'], person_cache) message_json['actor'], person_cache)
if debug: if debug:
print(approveHandle + ' / ' + message_json['actor'] + print(approveHandle + ' / ' + message_json['actor'] +
' is Group: ' + str(group_account)) ' is Group: ' + str(group_account))

View File

@ -22,7 +22,7 @@ from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import locatePost from utils import locatePost
from utils import undoLikesCollectionEntry from utils import undoLikesCollectionEntry
from utils import hasGroupType from utils import has_group_type
from utils import local_actor_url from utils import local_actor_url
from utils import load_json from utils import load_json
from utils import save_json from utils import save_json
@ -106,7 +106,7 @@ def _like(recentPostsCache: {},
if actorLiked: if actorLiked:
likedPostNickname = getNicknameFromActor(actorLiked) likedPostNickname = getNicknameFromActor(actorLiked)
likedPostDomain, likedPostPort = getDomainFromActor(actorLiked) likedPostDomain, likedPostPort = getDomainFromActor(actorLiked)
group_account = hasGroupType(base_dir, actorLiked, person_cache) group_account = has_group_type(base_dir, actorLiked, person_cache)
else: else:
if has_users_path(objectUrl): if has_users_path(objectUrl):
likedPostNickname = getNicknameFromActor(objectUrl) likedPostNickname = getNicknameFromActor(objectUrl)
@ -116,7 +116,7 @@ def _like(recentPostsCache: {},
objectUrl.split('/' + likedPostNickname + '/')[0] + \ objectUrl.split('/' + likedPostNickname + '/')[0] + \
'/' + likedPostNickname '/' + likedPostNickname
group_account = \ group_account = \
hasGroupType(base_dir, actorLiked, person_cache) has_group_type(base_dir, actorLiked, person_cache)
if likedPostNickname: if likedPostNickname:
postFilename = locatePost(base_dir, nickname, domain, objectUrl) postFilename = locatePost(base_dir, nickname, domain, objectUrl)

View File

@ -12,7 +12,7 @@ from utils import isAccountDir
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import acct_dir from utils import acct_dir
from utils import hasGroupType from utils import has_group_type
from webfinger import webfingerHandle from webfinger import webfingerHandle
from blocking import isBlocked from blocking import isBlocked
from posts import getUserUrl from posts import getUserUrl
@ -106,7 +106,7 @@ def _updateMovedHandle(base_dir: str, nickname: str, domain: str,
if movedToPort: if movedToPort:
if movedToPort != 80 and movedToPort != 443: if movedToPort != 80 and movedToPort != 443:
movedToDomainFull = movedToDomain + ':' + str(movedToPort) movedToDomainFull = movedToDomain + ':' + str(movedToPort)
group_account = hasGroupType(base_dir, movedToUrl, None) group_account = has_group_type(base_dir, movedToUrl, None)
if isBlocked(base_dir, nickname, domain, if isBlocked(base_dir, nickname, domain,
movedToNickname, movedToDomain): movedToNickname, movedToDomain):
# someone that you follow has moved to a blocked domain # someone that you follow has moved to a blocked domain

View File

@ -57,7 +57,7 @@ from utils import get_image_extensions
from utils import isImageFile from utils import isImageFile
from utils import acct_dir from utils import acct_dir
from utils import get_user_paths from utils import get_user_paths
from utils import getGroupPaths from utils import get_group_paths
from utils import local_actor_url from utils import local_actor_url
from utils import dangerousSVG from utils import dangerousSVG
from session import createSession from session import createSession
@ -1445,7 +1445,7 @@ def getActorJson(hostDomain: str, handle: str, http: bool, gnunet: bool,
detectedUsersPath in handle or \ detectedUsersPath in handle or \
handle.startswith('http') or \ handle.startswith('http') or \
handle.startswith('hyper'): handle.startswith('hyper'):
groupPaths = getGroupPaths() groupPaths = get_group_paths()
if detectedUsersPath in groupPaths: if detectedUsersPath in groupPaths:
group_account = True group_account = True
# format: https://domain/@nick # format: https://domain/@nick

View File

@ -37,7 +37,7 @@ from utils import invalidCiphertext
from utils import has_object_stringType from utils import has_object_stringType
from utils import removeIdEnding from utils import removeIdEnding
from utils import replace_users_with_at from utils import replace_users_with_at
from utils import hasGroupType from utils import has_group_type
from utils import get_base_content_from_post from utils import get_base_content_from_post
from utils import removeDomainPort from utils import removeDomainPort
from utils import getPortFromDomain from utils import getPortFromDomain
@ -3000,7 +3000,7 @@ def _sendToNamedAddresses(session, base_dir: str,
if sharedItemFederationTokens.get(fromDomainFull): if sharedItemFederationTokens.get(fromDomainFull):
sharedItemsToken = sharedItemFederationTokens[fromDomainFull] sharedItemsToken = sharedItemFederationTokens[fromDomainFull]
group_account = hasGroupType(base_dir, address, person_cache) group_account = has_group_type(base_dir, address, person_cache)
sendSignedJson(post_json_object, session, base_dir, sendSignedJson(post_json_object, session, base_dir,
nickname, fromDomain, port, nickname, fromDomain, port,

View File

@ -24,7 +24,7 @@ from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import locatePost from utils import locatePost
from utils import undoReactionCollectionEntry from utils import undoReactionCollectionEntry
from utils import hasGroupType from utils import has_group_type
from utils import local_actor_url from utils import local_actor_url
from utils import load_json from utils import load_json
from utils import save_json from utils import save_json
@ -104,7 +104,7 @@ def _reaction(recentPostsCache: {},
reactionPostNickname = getNicknameFromActor(actorReaction) reactionPostNickname = getNicknameFromActor(actorReaction)
reactionPostDomain, reactionPostPort = \ reactionPostDomain, reactionPostPort = \
getDomainFromActor(actorReaction) getDomainFromActor(actorReaction)
group_account = hasGroupType(base_dir, actorReaction, person_cache) group_account = has_group_type(base_dir, actorReaction, person_cache)
else: else:
if has_users_path(objectUrl): if has_users_path(objectUrl):
reactionPostNickname = getNicknameFromActor(objectUrl) reactionPostNickname = getNicknameFromActor(objectUrl)
@ -115,7 +115,7 @@ def _reaction(recentPostsCache: {},
objectUrl.split('/' + reactionPostNickname + '/')[0] + \ objectUrl.split('/' + reactionPostNickname + '/')[0] + \
'/' + reactionPostNickname '/' + reactionPostNickname
group_account = \ group_account = \
hasGroupType(base_dir, actorReaction, person_cache) has_group_type(base_dir, actorReaction, person_cache)
if reactionPostNickname: if reactionPostNickname:
postFilename = locatePost(base_dir, nickname, domain, objectUrl) postFilename = locatePost(base_dir, nickname, domain, objectUrl)

View File

@ -1063,7 +1063,7 @@ def get_user_paths() -> []:
'/c/', '/video-channels/') '/c/', '/video-channels/')
def getGroupPaths() -> []: def get_group_paths() -> []:
"""Returns possible group paths """Returns possible group paths
e.g. https://lemmy/c/groupname e.g. https://lemmy/c/groupname
""" """
@ -2988,17 +2988,17 @@ def dateSecondsToString(dateSec: int) -> str:
return thisDate.strftime("%Y-%m-%dT%H:%M:%SZ") return thisDate.strftime("%Y-%m-%dT%H:%M:%SZ")
def hasGroupType(base_dir: str, actor: str, person_cache: {}, def has_group_type(base_dir: str, actor: str, person_cache: {},
debug: bool = False) -> bool: debug: bool = False) -> bool:
"""Does the given actor url have a group type? """Does the given actor url have a group type?
""" """
# does the actor path clearly indicate that this is a group? # does the actor path clearly indicate that this is a group?
# eg. https://lemmy/c/groupname # eg. https://lemmy/c/groupname
groupPaths = getGroupPaths() group_paths = get_group_paths()
for grpPath in groupPaths: for grp_path in group_paths:
if grpPath in actor: if grp_path in actor:
if debug: if debug:
print('grpPath ' + grpPath + ' in ' + actor) print('grpPath ' + grp_path + ' in ' + actor)
return True return True
# is there a cached actor which can be examined for Group type? # is there a cached actor which can be examined for Group type?
return is_group_actor(base_dir, actor, person_cache, debug) return is_group_actor(base_dir, actor, person_cache, debug)

View File

@ -19,7 +19,7 @@ from utils import save_json
from utils import getProtocolPrefixes from utils import getProtocolPrefixes
from utils import removeDomainPort from utils import removeDomainPort
from utils import get_user_paths from utils import get_user_paths
from utils import getGroupPaths from utils import get_group_paths
from utils import local_actor_url from utils import local_actor_url
@ -49,7 +49,7 @@ def _parseHandle(handle: str) -> (str, str, bool):
# try for different /users/ paths # try for different /users/ paths
usersPaths = get_user_paths() usersPaths = get_user_paths()
groupPaths = getGroupPaths() groupPaths = get_group_paths()
for possibleUsersPath in usersPaths: for possibleUsersPath in usersPaths:
if possibleUsersPath in handle: if possibleUsersPath in handle:
if possibleUsersPath in groupPaths: if possibleUsersPath in groupPaths: