From 6326203952ed224d8edeb97426ee7575fe04d481 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sun, 2 Jan 2022 14:51:02 +0000 Subject: [PATCH] Snake case --- epicyon.py | 20 +- follow.py | 1033 +++++++++++++++++++++--------------------- like.py | 46 +- migrate.py | 20 +- person.py | 28 +- pgp.py | 10 +- shares.py | 40 +- skills.py | 10 +- socnet.py | 10 +- webapp_moderation.py | 4 +- 10 files changed, 614 insertions(+), 607 deletions(-) diff --git a/epicyon.py b/epicyon.py index bf8097275..1d38c3b94 100644 --- a/epicyon.py +++ b/epicyon.py @@ -2200,21 +2200,21 @@ if args.followers: signing_priv_key_pem = None if args.secure_mode: signing_priv_key_pem = get_instance_actor_key(base_dir, domain) - wfRequest = webfinger_handle(session, handle, - http_prefix, cached_webfingers, - hostDomain, __version__, debug, False, - signing_priv_key_pem) - if not wfRequest: + wf_request = webfinger_handle(session, handle, + http_prefix, cached_webfingers, + hostDomain, __version__, debug, False, + signing_priv_key_pem) + if not wf_request: print('Unable to webfinger ' + handle) sys.exit() - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('Webfinger for ' + handle + ' did not return a dict. ' + - str(wfRequest)) + str(wf_request)) sys.exit() personUrl = None - if wfRequest.get('errors'): - print('wfRequest error: ' + str(wfRequest['errors'])) + if wf_request.get('errors'): + print('wf_request error: ' + str(wf_request['errors'])) if has_users_path(args.followers): personUrl = originalActor else: @@ -2225,7 +2225,7 @@ if args.followers: 'Accept': 'application/activity+json; profile="' + profileStr + '"' } if not personUrl: - personUrl = get_user_url(wfRequest, 0, args.debug) + personUrl = get_user_url(wf_request, 0, args.debug) if nickname == domain: personUrl = personUrl.replace('/users/', '/actor/') personUrl = personUrl.replace('/accounts/', '/actor/') diff --git a/follow.py b/follow.py index 4193d66ae..70e7c0b71 100644 --- a/follow.py +++ b/follow.py @@ -43,24 +43,24 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None: The lastseen files are used to generate the Zzz icons on follows/following lists on the profile screen. """ - for subdir, dirs, files in os.walk(base_dir + '/accounts'): + for _, dirs, _ in os.walk(base_dir + '/accounts'): for acct in dirs: if not is_account_dir(acct): continue - accountDir = os.path.join(base_dir + '/accounts', acct) - followingFilename = accountDir + '/following.txt' - if not os.path.isfile(followingFilename): + account_dir = os.path.join(base_dir + '/accounts', acct) + following_filename = account_dir + '/following.txt' + if not os.path.isfile(following_filename): continue - lastSeenDir = accountDir + '/lastseen' - if not os.path.isdir(lastSeenDir): - os.mkdir(lastSeenDir) - followingHandles = [] + last_seen_dir = account_dir + '/lastseen' + if not os.path.isdir(last_seen_dir): + os.mkdir(last_seen_dir) + following_handles = [] try: - with open(followingFilename, 'r') as fp: - followingHandles = fp.readlines() + with open(following_filename, 'r') as fp_foll: + following_handles = fp_foll.readlines() except OSError: - print('EX: create_initial_last_seen ' + followingFilename) - for handle in followingHandles: + print('EX: create_initial_last_seen ' + following_filename) + for handle in following_handles: if '#' in handle: continue if '@' not in handle: @@ -71,97 +71,98 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None: if nickname.startswith('!'): nickname = nickname[1:] actor = local_actor_url(http_prefix, nickname, domain) - lastSeenFilename = \ - lastSeenDir + '/' + actor.replace('/', '#') + '.txt' - if not os.path.isfile(lastSeenFilename): + last_seen_filename = \ + last_seen_dir + '/' + actor.replace('/', '#') + '.txt' + if not os.path.isfile(last_seen_filename): try: - with open(lastSeenFilename, 'w+') as fp: - fp.write(str(100)) + with open(last_seen_filename, 'w+') as fp_last: + fp_last.write(str(100)) except OSError: print('EX: create_initial_last_seen 2 ' + - lastSeenFilename) + last_seen_filename) break def _pre_approved_follower(base_dir: str, nickname: str, domain: str, - approveHandle: str) -> bool: + approve_handle: str) -> bool: """Is the given handle an already manually approved follower? """ handle = nickname + '@' + domain - accountDir = base_dir + '/accounts/' + handle - approvedFilename = accountDir + '/approved.txt' - if os.path.isfile(approvedFilename): - if approveHandle in open(approvedFilename).read(): + account_dir = base_dir + '/accounts/' + handle + approved_filename = account_dir + '/approved.txt' + if os.path.isfile(approved_filename): + if approve_handle in open(approved_filename).read(): return True return False def _remove_from_follow_base(base_dir: str, nickname: str, domain: str, - acceptOrDenyHandle: str, followFile: str, + accept_or_deny_handle: str, follow_file: str, debug: bool) -> None: """Removes a handle/actor from follow requests or rejects file """ handle = nickname + '@' + domain - accountsDir = base_dir + '/accounts/' + handle - approveFollowsFilename = accountsDir + '/' + followFile + '.txt' - if not os.path.isfile(approveFollowsFilename): + accounts_dir = base_dir + '/accounts/' + handle + approve_follows_filename = accounts_dir + '/' + follow_file + '.txt' + if not os.path.isfile(approve_follows_filename): if debug: print('WARN: Approve follow requests file ' + - approveFollowsFilename + ' not found') + approve_follows_filename + ' not found') return - acceptDenyActor = None - if acceptOrDenyHandle not in open(approveFollowsFilename).read(): + accept_deny_actor = None + if accept_or_deny_handle not in open(approve_follows_filename).read(): # is this stored in the file as an actor rather than a handle? - acceptDenyNickname = acceptOrDenyHandle.split('@')[0] - acceptDenyDomain = acceptOrDenyHandle.split('@')[1] + accept_deny_nickname = accept_or_deny_handle.split('@')[0] + accept_deny_domain = accept_or_deny_handle.split('@')[1] # for each possible users path construct an actor and # check if it exists in teh file - usersPaths = get_user_paths() - actorFound = False - for usersName in usersPaths: - acceptDenyActor = \ - '://' + acceptDenyDomain + usersName + acceptDenyNickname - if acceptDenyActor in open(approveFollowsFilename).read(): - actorFound = True + users_paths = get_user_paths() + actor_found = False + for users_name in users_paths: + accept_deny_actor = \ + '://' + accept_deny_domain + users_name + accept_deny_nickname + if accept_deny_actor in open(approve_follows_filename).read(): + actor_found = True break - if not actorFound: + if not actor_found: return try: - with open(approveFollowsFilename + '.new', 'w+') as approvefilenew: - with open(approveFollowsFilename, 'r') as approvefile: - if not acceptDenyActor: - for approveHandle in approvefile: - if not approveHandle.startswith(acceptOrDenyHandle): - approvefilenew.write(approveHandle) + with open(approve_follows_filename + '.new', 'w+') as approvefilenew: + with open(approve_follows_filename, 'r') as approvefile: + if not accept_deny_actor: + for approve_handle in approvefile: + accept_deny_handle = accept_or_deny_handle + if not approve_handle.startswith(accept_deny_handle): + approvefilenew.write(approve_handle) else: - for approveHandle in approvefile: - if acceptDenyActor not in approveHandle: - approvefilenew.write(approveHandle) + for approve_handle in approvefile: + if accept_deny_actor not in approve_handle: + approvefilenew.write(approve_handle) except OSError as ex: print('EX: _remove_from_follow_base ' + - approveFollowsFilename + ' ' + str(ex)) + approve_follows_filename + ' ' + str(ex)) - os.rename(approveFollowsFilename + '.new', approveFollowsFilename) + os.rename(approve_follows_filename + '.new', approve_follows_filename) def remove_from_follow_requests(base_dir: str, nickname: str, domain: str, - denyHandle: str, debug: bool) -> None: + deny_handle: str, debug: bool) -> None: """Removes a handle from follow requests """ _remove_from_follow_base(base_dir, nickname, domain, - denyHandle, 'followrequests', debug) + deny_handle, 'followrequests', debug) def _remove_from_follow_rejects(base_dir: str, nickname: str, domain: str, - acceptHandle: str, debug: bool) -> None: + accept_handle: str, debug: bool) -> None: """Removes a handle from follow rejects """ _remove_from_follow_base(base_dir, nickname, domain, - acceptHandle, 'followrejects', debug) + accept_handle, 'followrejects', debug) def is_following_actor(base_dir: str, @@ -173,20 +174,20 @@ def is_following_actor(base_dir: str, handle = nickname + '@' + domain if not os.path.isdir(base_dir + '/accounts/' + handle): return False - followingFile = base_dir + '/accounts/' + handle + '/following.txt' - if not os.path.isfile(followingFile): + following_file = base_dir + '/accounts/' + handle + '/following.txt' + if not os.path.isfile(following_file): return False - if actor.lower() in open(followingFile).read().lower(): + if actor.lower() in open(following_file).read().lower(): return True - followingNickname = get_nickname_from_actor(actor) - if not followingNickname: + following_nickname = get_nickname_from_actor(actor) + if not following_nickname: print('WARN: unable to find nickname in ' + actor) return False - followingDomain, followingPort = get_domain_from_actor(actor) - followingHandle = \ - get_full_domain(followingNickname + '@' + followingDomain, - followingPort) - if followingHandle.lower() in open(followingFile).read().lower(): + following_domain, following_port = get_domain_from_actor(actor) + following_handle = \ + get_full_domain(following_nickname + '@' + following_domain, + following_port) + if following_handle.lower() in open(following_file).read().lower(): return True return False @@ -208,13 +209,13 @@ def get_mutuals_of_person(base_dir: str, def add_follower_of_person(base_dir: str, nickname: str, domain: str, - followerNickname: str, followerDomain: str, + follower_nickname: str, follower_domain: str, federation_list: [], debug: bool, group_account: bool) -> bool: """Adds a follower of the given person """ return follow_person(base_dir, nickname, domain, - followerNickname, followerDomain, + follower_nickname, follower_domain, federation_list, debug, group_account, 'followers.txt') @@ -223,143 +224,144 @@ def get_follower_domains(base_dir: str, nickname: str, domain: str) -> []: """Returns a list of domains for followers """ domain = remove_domain_port(domain) - followersFile = acct_dir(base_dir, nickname, domain) + '/followers.txt' - if not os.path.isfile(followersFile): + followers_file = acct_dir(base_dir, nickname, domain) + '/followers.txt' + if not os.path.isfile(followers_file): return [] lines = [] try: - with open(followersFile, 'r') as fpFollowers: - lines = fpFollowers.readlines() + with open(followers_file, 'r') as fp_foll: + lines = fp_foll.readlines() except OSError: - print('EX: get_follower_domains ' + followersFile) + print('EX: get_follower_domains ' + followers_file) - domainsList = [] + domains_list = [] for handle in lines: handle = handle.replace('\n', '') - followerDomain, _ = get_domain_from_actor(handle) - if not followerDomain: + follower_domain, _ = get_domain_from_actor(handle) + if not follower_domain: continue - if followerDomain not in domainsList: - domainsList.append(followerDomain) - return domainsList + if follower_domain not in domains_list: + domains_list.append(follower_domain) + return domains_list def is_follower_of_person(base_dir: str, nickname: str, domain: str, - followerNickname: str, followerDomain: str) -> bool: - """is the given nickname a follower of followerNickname? + follower_nickname: str, + follower_domain: str) -> bool: + """is the given nickname a follower of follower_nickname? """ - if not followerDomain: - print('No followerDomain') + if not follower_domain: + print('No follower_domain') return False - if not followerNickname: - print('No followerNickname for ' + followerDomain) + if not follower_nickname: + print('No follower_nickname for ' + follower_domain) return False domain = remove_domain_port(domain) - followersFile = acct_dir(base_dir, nickname, domain) + '/followers.txt' - if not os.path.isfile(followersFile): + followers_file = acct_dir(base_dir, nickname, domain) + '/followers.txt' + if not os.path.isfile(followers_file): return False - handle = followerNickname + '@' + followerDomain + handle = follower_nickname + '@' + follower_domain - alreadyFollowing = False + already_following = False - followersStr = '' + followers_str = '' try: - with open(followersFile, 'r') as fpFollowers: - followersStr = fpFollowers.read() + with open(followers_file, 'r') as fp_foll: + followers_str = fp_foll.read() except OSError: - print('EX: is_follower_of_person ' + followersFile) + print('EX: is_follower_of_person ' + followers_file) - if handle in followersStr: - alreadyFollowing = True + if handle in followers_str: + already_following = True else: paths = get_user_paths() - for userPath in paths: - url = '://' + followerDomain + userPath + followerNickname - if url in followersStr: - alreadyFollowing = True + for user_path in paths: + url = '://' + follower_domain + user_path + follower_nickname + if url in followers_str: + already_following = True break - return alreadyFollowing + return already_following def unfollow_account(base_dir: str, nickname: str, domain: str, - followNickname: str, followDomain: str, + follow_nickname: str, follow_domain: str, debug: bool, group_account: bool, - followFile: str = 'following.txt') -> bool: + follow_file: str = 'following.txt') -> bool: """Removes a person to the follow list """ domain = remove_domain_port(domain) handle = nickname + '@' + domain - handleToUnfollow = followNickname + '@' + followDomain + handle_to_unfollow = follow_nickname + '@' + follow_domain if group_account: - handleToUnfollow = '!' + handleToUnfollow + handle_to_unfollow = '!' + handle_to_unfollow if not os.path.isdir(base_dir + '/accounts'): os.mkdir(base_dir + '/accounts') if not os.path.isdir(base_dir + '/accounts/' + handle): os.mkdir(base_dir + '/accounts/' + handle) - filename = base_dir + '/accounts/' + handle + '/' + followFile + filename = base_dir + '/accounts/' + handle + '/' + follow_file if not os.path.isfile(filename): if debug: print('DEBUG: follow file ' + filename + ' was not found') return False - handleToUnfollowLower = handleToUnfollow.lower() - if handleToUnfollowLower not in open(filename).read().lower(): + handle_to_unfollow_lower = handle_to_unfollow.lower() + if handle_to_unfollow_lower not in open(filename).read().lower(): if debug: - print('DEBUG: handle to unfollow ' + handleToUnfollow + + print('DEBUG: handle to unfollow ' + handle_to_unfollow + ' is not in ' + filename) return lines = [] try: - with open(filename, 'r') as f: - lines = f.readlines() + with open(filename, 'r') as fp_unfoll: + lines = fp_unfoll.readlines() except OSError: print('EX: unfollow_account ' + filename) if lines: try: - with open(filename, 'w+') as f: + with open(filename, 'w+') as fp_unfoll: for line in lines: - checkHandle = line.strip("\n").strip("\r").lower() - if checkHandle != handleToUnfollowLower and \ - checkHandle != '!' + handleToUnfollowLower: - f.write(line) + check_handle = line.strip("\n").strip("\r").lower() + if check_handle not in (handle_to_unfollow_lower, + '!' + handle_to_unfollow_lower): + fp_unfoll.write(line) except OSError as ex: print('EX: unable to write ' + filename + ' ' + str(ex)) # write to an unfollowed file so that if a follow accept # later arrives then it can be ignored - unfollowedFilename = base_dir + '/accounts/' + handle + '/unfollowed.txt' - if os.path.isfile(unfollowedFilename): - if handleToUnfollowLower not in \ - open(unfollowedFilename).read().lower(): + unfollowed_filename = base_dir + '/accounts/' + handle + '/unfollowed.txt' + if os.path.isfile(unfollowed_filename): + if handle_to_unfollow_lower not in \ + open(unfollowed_filename).read().lower(): try: - with open(unfollowedFilename, 'a+') as f: - f.write(handleToUnfollow + '\n') + with open(unfollowed_filename, 'a+') as fp_unfoll: + fp_unfoll.write(handle_to_unfollow + '\n') except OSError: - print('EX: unable to append ' + unfollowedFilename) + print('EX: unable to append ' + unfollowed_filename) else: try: - with open(unfollowedFilename, 'w+') as f: - f.write(handleToUnfollow + '\n') + with open(unfollowed_filename, 'w+') as fp_unfoll: + fp_unfoll.write(handle_to_unfollow + '\n') except OSError: - print('EX: unable to write ' + unfollowedFilename) + print('EX: unable to write ' + unfollowed_filename) return True def unfollower_of_account(base_dir: str, nickname: str, domain: str, - followerNickname: str, followerDomain: str, + follower_nickname: str, follower_domain: str, debug: bool, group_account: bool) -> bool: """Remove a follower of a person """ return unfollow_account(base_dir, nickname, domain, - followerNickname, followerDomain, + follower_nickname, follower_domain, debug, group_account, 'followers.txt') def clear_follows(base_dir: str, nickname: str, domain: str, - followFile: str = 'following.txt') -> None: + follow_file: str = 'following.txt') -> None: """Removes all follows """ handle = nickname + '@' + domain @@ -367,7 +369,7 @@ def clear_follows(base_dir: str, nickname: str, domain: str, os.mkdir(base_dir + '/accounts') if not os.path.isdir(base_dir + '/accounts/' + handle): os.mkdir(base_dir + '/accounts/' + handle) - filename = base_dir + '/accounts/' + handle + '/' + followFile + filename = base_dir + '/accounts/' + handle + '/' + follow_file if os.path.isfile(filename): try: os.remove(filename) @@ -383,7 +385,7 @@ def clear_followers(base_dir: str, nickname: str, domain: str) -> None: def _get_no_of_follows(base_dir: str, nickname: str, domain: str, authenticated: bool, - followFile='following.txt') -> int: + follow_file='following.txt') -> int: """Returns the number of follows or followers """ # only show number of followers to authenticated @@ -391,14 +393,14 @@ def _get_no_of_follows(base_dir: str, nickname: str, domain: str, # if not authenticated: # return 9999 handle = nickname + '@' + domain - filename = base_dir + '/accounts/' + handle + '/' + followFile + filename = base_dir + '/accounts/' + handle + '/' + follow_file if not os.path.isfile(filename): return 0 ctr = 0 lines = [] try: - with open(filename, 'r') as f: - lines = f.readlines() + with open(filename, 'r') as fp_foll: + lines = fp_foll.readlines() except OSError: print('EX: _get_no_of_follows ' + filename) if lines: @@ -428,7 +430,7 @@ def get_no_of_followers(base_dir: str, def get_following_feed(base_dir: str, domain: str, port: int, path: str, http_prefix: str, authorized: bool, follows_per_page=12, - followFile='following') -> {}: + follow_file='following') -> {}: """Returns the following and followers feeds from GET requests. This accesses the following.txt or followers.txt and builds a collection. """ @@ -436,32 +438,32 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str, if not authorized: follows_per_page = 6 - if '/' + followFile not in path: + if '/' + follow_file not in path: return None # handle page numbers - headerOnly = True - pageNumber = None + header_only = True + page_number = None if '?page=' in path: - pageNumber = path.split('?page=')[1] - if pageNumber == 'true' or not authorized: - pageNumber = 1 + page_number = path.split('?page=')[1] + if page_number == 'true' or not authorized: + page_number = 1 else: try: - pageNumber = int(pageNumber) + page_number = int(page_number) except BaseException: print('EX: get_following_feed unable to convert to int ' + - str(pageNumber)) - pass + str(page_number)) path = path.split('?page=')[0] - headerOnly = False + header_only = False - if not path.endswith('/' + followFile): + if not path.endswith('/' + follow_file): return None nickname = None if path.startswith('/users/'): - nickname = path.replace('/users/', '', 1).replace('/' + followFile, '') + nickname = \ + path.replace('/users/', '', 1).replace('/' + follow_file, '') if path.startswith('/@'): - nickname = path.replace('/@', '', 1).replace('/' + followFile, '') + nickname = path.replace('/@', '', 1).replace('/' + follow_file, '') if not nickname: return None if not valid_nickname(domain, nickname): @@ -469,63 +471,63 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str, domain = get_full_domain(domain, port) - if headerOnly: - firstStr = \ + if header_only: + first_str = \ local_actor_url(http_prefix, nickname, domain) + \ - '/' + followFile + '?page=1' - idStr = \ - local_actor_url(http_prefix, nickname, domain) + '/' + followFile - totalStr = \ + '/' + follow_file + '?page=1' + id_str = \ + local_actor_url(http_prefix, nickname, domain) + '/' + follow_file + total_str = \ _get_no_of_follows(base_dir, nickname, domain, authorized) following = { '@context': 'https://www.w3.org/ns/activitystreams', - 'first': firstStr, - 'id': idStr, - 'totalItems': totalStr, + 'first': first_str, + 'id': id_str, + 'totalItems': total_str, 'type': 'OrderedCollection' } return following - if not pageNumber: - pageNumber = 1 + if not page_number: + page_number = 1 - nextPageNumber = int(pageNumber + 1) - idStr = \ + next_page_number = int(page_number + 1) + id_str = \ local_actor_url(http_prefix, nickname, domain) + \ - '/' + followFile + '?page=' + str(pageNumber) - partOfStr = \ - local_actor_url(http_prefix, nickname, domain) + '/' + followFile + '/' + follow_file + '?page=' + str(page_number) + part_of_str = \ + local_actor_url(http_prefix, nickname, domain) + '/' + follow_file following = { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': idStr, + 'id': id_str, 'orderedItems': [], - 'partOf': partOfStr, + 'partOf': part_of_str, 'totalItems': 0, 'type': 'OrderedCollectionPage' } - handleDomain = domain - handleDomain = remove_domain_port(handleDomain) - handle = nickname + '@' + handleDomain - filename = base_dir + '/accounts/' + handle + '/' + followFile + '.txt' + handle_domain = domain + handle_domain = remove_domain_port(handle_domain) + handle = nickname + '@' + handle_domain + filename = base_dir + '/accounts/' + handle + '/' + follow_file + '.txt' if not os.path.isfile(filename): return following - currPage = 1 - pageCtr = 0 - totalCtr = 0 + curr_page = 1 + page_ctr = 0 + total_ctr = 0 lines = [] try: - with open(filename, 'r') as f: - lines = f.readlines() + with open(filename, 'r') as fp_foll: + lines = fp_foll.readlines() except OSError: print('EX: get_following_feed ' + filename) for line in lines: if '#' not in line: if '@' in line and not line.startswith('http'): # nickname@domain - pageCtr += 1 - totalCtr += 1 - if currPage == pageNumber: + page_ctr += 1 + total_ctr += 1 + if curr_page == page_number: line2 = \ line.lower().replace('\n', '').replace('\r', '') nick = line2.split('@')[0] @@ -541,81 +543,81 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str, line.startswith('hyper')) and has_users_path(line)): # https://domain/users/nickname - pageCtr += 1 - totalCtr += 1 - if currPage == pageNumber: - appendStr = \ + page_ctr += 1 + total_ctr += 1 + if curr_page == page_number: + append_str = \ line.lower().replace('\n', '').replace('\r', '') - following['orderedItems'].append(appendStr) - if pageCtr >= follows_per_page: - pageCtr = 0 - currPage += 1 - following['totalItems'] = totalCtr - lastPage = int(totalCtr / follows_per_page) - if lastPage < 1: - lastPage = 1 - if nextPageNumber > lastPage: + following['orderedItems'].append(append_str) + if page_ctr >= follows_per_page: + page_ctr = 0 + curr_page += 1 + following['totalItems'] = total_ctr + last_page = int(total_ctr / follows_per_page) + if last_page < 1: + last_page = 1 + if next_page_number > last_page: following['next'] = \ local_actor_url(http_prefix, nickname, domain) + \ - '/' + followFile + '?page=' + str(lastPage) + '/' + follow_file + '?page=' + str(last_page) return following -def follow_approval_required(base_dir: str, nicknameToFollow: str, - domainToFollow: str, debug: bool, - followRequestHandle: str) -> bool: +def follow_approval_required(base_dir: str, nickname_to_follow: str, + domain_to_follow: str, debug: bool, + follow_request_handle: str) -> bool: """ Returns the policy for follower approvals """ # has this handle already been manually approved? - if _pre_approved_follower(base_dir, nicknameToFollow, domainToFollow, - followRequestHandle): + if _pre_approved_follower(base_dir, nickname_to_follow, domain_to_follow, + follow_request_handle): return False - manuallyApproveFollows = False - domainToFollow = remove_domain_port(domainToFollow) - actorFilename = base_dir + '/accounts/' + \ - nicknameToFollow + '@' + domainToFollow + '.json' - if os.path.isfile(actorFilename): - actor = load_json(actorFilename) + manually_approve_follows = False + domain_to_follow = remove_domain_port(domain_to_follow) + actor_filename = base_dir + '/accounts/' + \ + nickname_to_follow + '@' + domain_to_follow + '.json' + if os.path.isfile(actor_filename): + actor = load_json(actor_filename) if actor: - if actor.get('manuallyApprovesFollowers'): - manuallyApproveFollows = actor['manuallyApprovesFollowers'] + if actor.get('manually_approves_followers'): + manually_approve_follows = actor['manuallyApprovesFollowers'] else: if debug: - print(nicknameToFollow + '@' + domainToFollow + + print(nickname_to_follow + '@' + domain_to_follow + ' automatically approves followers') else: if debug: - print('DEBUG: Actor file not found: ' + actorFilename) - return manuallyApproveFollows + print('DEBUG: Actor file not found: ' + actor_filename) + return manually_approve_follows def no_of_follow_requests(base_dir: str, - nicknameToFollow: str, domainToFollow: str, - nickname: str, domain: str, fromPort: int, - followType: str) -> int: + nickname_to_follow: str, domain_to_follow: str, + nickname: str, domain: str, from_port: int, + follow_type: str) -> int: """Returns the current number of follow requests """ - accountsDir = base_dir + '/accounts/' + \ - nicknameToFollow + '@' + domainToFollow - approveFollowsFilename = accountsDir + '/followrequests.txt' - if not os.path.isfile(approveFollowsFilename): + accounts_dir = base_dir + '/accounts/' + \ + nickname_to_follow + '@' + domain_to_follow + approve_follows_filename = accounts_dir + '/followrequests.txt' + if not os.path.isfile(approve_follows_filename): return 0 ctr = 0 lines = [] try: - with open(approveFollowsFilename, 'r') as f: - lines = f.readlines() + with open(approve_follows_filename, 'r') as fp_approve: + lines = fp_approve.readlines() except OSError: - print('EX: no_of_follow_requests ' + approveFollowsFilename) + print('EX: no_of_follow_requests ' + approve_follows_filename) if lines: - if followType == "onion": - for fileLine in lines: - if '.onion' in fileLine: + if follow_type == "onion": + for file_line in lines: + if '.onion' in file_line: ctr += 1 - elif followType == "i2p": - for fileLine in lines: - if '.i2p' in fileLine: + elif follow_type == "i2p": + for file_line in lines: + if '.i2p' in file_line: ctr += 1 else: return len(lines) @@ -623,105 +625,107 @@ def no_of_follow_requests(base_dir: str, def store_follow_request(base_dir: str, - nicknameToFollow: str, domainToFollow: str, port: int, - nickname: str, domain: str, fromPort: int, - followJson: {}, - debug: bool, personUrl: str, + nickname_to_follow: str, + domain_to_follow: str, port: int, + nickname: str, domain: str, from_port: int, + follow_json: {}, + debug: bool, person_url: str, group_account: bool) -> bool: """Stores the follow request for later use """ - accountsDir = base_dir + '/accounts/' + \ - nicknameToFollow + '@' + domainToFollow - if not os.path.isdir(accountsDir): + accounts_dir = base_dir + '/accounts/' + \ + nickname_to_follow + '@' + domain_to_follow + if not os.path.isdir(accounts_dir): return False - domain_full = get_full_domain(domain, fromPort) - approveHandle = get_full_domain(nickname + '@' + domain, fromPort) + domain_full = get_full_domain(domain, from_port) + approve_handle = get_full_domain(nickname + '@' + domain, from_port) if group_account: - approveHandle = '!' + approveHandle + approve_handle = '!' + approve_handle - followersFilename = accountsDir + '/followers.txt' - if os.path.isfile(followersFilename): - alreadyFollowing = False + followers_filename = accounts_dir + '/followers.txt' + if os.path.isfile(followers_filename): + already_following = False - followersStr = '' + followers_str = '' try: - with open(followersFilename, 'r') as fpFollowers: - followersStr = fpFollowers.read() + with open(followers_filename, 'r') as fp_foll: + followers_str = fp_foll.read() except OSError: - print('EX: store_follow_request ' + followersFilename) + print('EX: store_follow_request ' + followers_filename) - if approveHandle in followersStr: - alreadyFollowing = True + if approve_handle in followers_str: + already_following = True else: - usersPaths = get_user_paths() - for possibleUsersPath in usersPaths: - url = '://' + domain_full + possibleUsersPath + nickname - if url in followersStr: - alreadyFollowing = True + users_paths = get_user_paths() + for possible_users_path in users_paths: + url = '://' + domain_full + possible_users_path + nickname + if url in followers_str: + already_following = True break - if alreadyFollowing: + if already_following: if debug: print('DEBUG: ' + - nicknameToFollow + '@' + domainToFollow + - ' already following ' + approveHandle) + nickname_to_follow + '@' + domain_to_follow + + ' already following ' + approve_handle) return True # should this follow be denied? - denyFollowsFilename = accountsDir + '/followrejects.txt' - if os.path.isfile(denyFollowsFilename): - if approveHandle in open(denyFollowsFilename).read(): - remove_from_follow_requests(base_dir, nicknameToFollow, - domainToFollow, approveHandle, debug) - print(approveHandle + ' was already denied as a follower of ' + - nicknameToFollow) + deny_follows_filename = accounts_dir + '/followrejects.txt' + if os.path.isfile(deny_follows_filename): + if approve_handle in open(deny_follows_filename).read(): + remove_from_follow_requests(base_dir, nickname_to_follow, + domain_to_follow, approve_handle, + debug) + print(approve_handle + ' was already denied as a follower of ' + + nickname_to_follow) return True # add to a file which contains a list of requests - approveFollowsFilename = accountsDir + '/followrequests.txt' + approve_follows_filename = accounts_dir + '/followrequests.txt' # store either nick@domain or the full person/actor url - approveHandleStored = approveHandle - if '/users/' not in personUrl: - approveHandleStored = personUrl + approve_handle_stored = approve_handle + if '/users/' not in person_url: + approve_handle_stored = person_url if group_account: - approveHandle = '!' + approveHandle + approve_handle = '!' + approve_handle - if os.path.isfile(approveFollowsFilename): - if approveHandle not in open(approveFollowsFilename).read(): + if os.path.isfile(approve_follows_filename): + if approve_handle not in open(approve_follows_filename).read(): try: - with open(approveFollowsFilename, 'a+') as fp: - fp.write(approveHandleStored + '\n') + with open(approve_follows_filename, 'a+') as fp_approve: + fp_approve.write(approve_handle_stored + '\n') except OSError: - print('EX: store_follow_request 2 ' + approveFollowsFilename) + print('EX: store_follow_request 2 ' + approve_follows_filename) else: if debug: - print('DEBUG: ' + approveHandleStored + + print('DEBUG: ' + approve_handle_stored + ' is already awaiting approval') else: try: - with open(approveFollowsFilename, 'w+') as fp: - fp.write(approveHandleStored + '\n') + with open(approve_follows_filename, 'w+') as fp_approve: + fp_approve.write(approve_handle_stored + '\n') except OSError: - print('EX: store_follow_request 3 ' + approveFollowsFilename) + print('EX: store_follow_request 3 ' + approve_follows_filename) # store the follow request in its own directory # We don't rely upon the inbox because items in there could expire - requestsDir = accountsDir + '/requests' - if not os.path.isdir(requestsDir): - os.mkdir(requestsDir) - followActivityfilename = requestsDir + '/' + approveHandle + '.follow' - return save_json(followJson, followActivityfilename) + requests_dir = accounts_dir + '/requests' + if not os.path.isdir(requests_dir): + os.mkdir(requests_dir) + follow_activity_filename = requests_dir + '/' + approve_handle + '.follow' + return save_json(follow_json, follow_activity_filename) def followed_account_accepts(session, base_dir: str, http_prefix: str, - nicknameToFollow: str, domainToFollow: str, + nickname_to_follow: str, domain_to_follow: str, port: int, - nickname: str, domain: str, fromPort: int, - personUrl: str, federation_list: [], - followJson: {}, send_threads: [], postLog: [], + nickname: str, domain: str, from_port: int, + person_url: str, federation_list: [], + follow_json: {}, send_threads: [], postLog: [], cached_webfingers: {}, person_cache: {}, debug: bool, project_version: str, removeFollowActivity: bool, @@ -729,48 +733,48 @@ def followed_account_accepts(session, base_dir: str, http_prefix: str, """The person receiving a follow request accepts the new follower and sends back an Accept activity """ - acceptHandle = nickname + '@' + domain + accept_handle = nickname + '@' + domain # send accept back if debug: print('DEBUG: sending Accept activity for ' + 'follow request which arrived at ' + - nicknameToFollow + '@' + domainToFollow + - ' back to ' + acceptHandle) - acceptJson = create_accept(base_dir, federation_list, - nicknameToFollow, domainToFollow, port, - personUrl, '', http_prefix, - followJson) + nickname_to_follow + '@' + domain_to_follow + + ' back to ' + accept_handle) + accept_json = create_accept(base_dir, federation_list, + nickname_to_follow, domain_to_follow, port, + person_url, '', http_prefix, + follow_json) if debug: - pprint(acceptJson) + pprint(accept_json) print('DEBUG: sending follow Accept from ' + - nicknameToFollow + '@' + domainToFollow + + nickname_to_follow + '@' + domain_to_follow + ' port ' + str(port) + ' to ' + - acceptHandle + ' port ' + str(fromPort)) + accept_handle + ' port ' + str(from_port)) client_to_server = False if removeFollowActivity: # remove the follow request json - followActivityfilename = \ - acct_dir(base_dir, nicknameToFollow, domainToFollow) + \ + follow_activity_filename = \ + acct_dir(base_dir, nickname_to_follow, domain_to_follow) + \ '/requests/' + \ nickname + '@' + domain + '.follow' - if os.path.isfile(followActivityfilename): + if os.path.isfile(follow_activity_filename): try: - os.remove(followActivityfilename) + os.remove(follow_activity_filename) except OSError: print('EX: followed_account_accepts unable to delete ' + - followActivityfilename) + follow_activity_filename) group_account = False - if followJson: - if followJson.get('actor'): - if has_group_type(base_dir, followJson['actor'], person_cache): + if follow_json: + if follow_json.get('actor'): + if has_group_type(base_dir, follow_json['actor'], person_cache): group_account = True - return send_signed_json(acceptJson, session, base_dir, - nicknameToFollow, domainToFollow, port, - nickname, domain, fromPort, '', + return send_signed_json(accept_json, session, base_dir, + nickname_to_follow, domain_to_follow, port, + nickname, domain, from_port, '', http_prefix, True, client_to_server, federation_list, send_threads, postLog, cached_webfingers, @@ -780,9 +784,9 @@ def followed_account_accepts(session, base_dir: str, http_prefix: str, def followed_account_rejects(session, base_dir: str, http_prefix: str, - nicknameToFollow: str, domainToFollow: str, + nickname_to_follow: str, domain_to_follow: str, port: int, - nickname: str, domain: str, fromPort: int, + nickname: str, domain: str, from_port: int, federation_list: [], send_threads: [], postLog: [], cached_webfingers: {}, person_cache: {}, @@ -795,50 +799,50 @@ def followed_account_rejects(session, base_dir: str, http_prefix: str, if debug: print('DEBUG: sending Reject activity for ' + 'follow request which arrived at ' + - nicknameToFollow + '@' + domainToFollow + + nickname_to_follow + '@' + domain_to_follow + ' back to ' + nickname + '@' + domain) # get the json for the original follow request - followActivityfilename = \ - acct_dir(base_dir, nicknameToFollow, domainToFollow) + '/requests/' + \ - nickname + '@' + domain + '.follow' - followJson = load_json(followActivityfilename) - if not followJson: + follow_activity_filename = \ + acct_dir(base_dir, nickname_to_follow, domain_to_follow) + \ + '/requests/' + nickname + '@' + domain + '.follow' + follow_json = load_json(follow_activity_filename) + if not follow_json: print('No follow request json was found for ' + - followActivityfilename) + follow_activity_filename) return None # actor who made the follow request - personUrl = followJson['actor'] + person_url = follow_json['actor'] # create the reject activity - rejectJson = \ + reject_json = \ create_reject(base_dir, federation_list, - nicknameToFollow, domainToFollow, port, - personUrl, '', http_prefix, followJson) + nickname_to_follow, domain_to_follow, port, + person_url, '', http_prefix, follow_json) if debug: - pprint(rejectJson) + pprint(reject_json) print('DEBUG: sending follow Reject from ' + - nicknameToFollow + '@' + domainToFollow + + nickname_to_follow + '@' + domain_to_follow + ' port ' + str(port) + ' to ' + - nickname + '@' + domain + ' port ' + str(fromPort)) + nickname + '@' + domain + ' port ' + str(from_port)) client_to_server = False - denyHandle = get_full_domain(nickname + '@' + domain, fromPort) + deny_handle = get_full_domain(nickname + '@' + domain, from_port) group_account = False - if has_group_type(base_dir, personUrl, person_cache): + if has_group_type(base_dir, person_url, person_cache): group_account = True # remove from the follow requests file - remove_from_follow_requests(base_dir, nicknameToFollow, domainToFollow, - denyHandle, debug) + remove_from_follow_requests(base_dir, nickname_to_follow, domain_to_follow, + deny_handle, debug) # remove the follow request json try: - os.remove(followActivityfilename) + os.remove(follow_activity_filename) except OSError: print('EX: followed_account_rejects unable to delete ' + - followActivityfilename) + follow_activity_filename) # send the reject activity - return send_signed_json(rejectJson, session, base_dir, - nicknameToFollow, domainToFollow, port, - nickname, domain, fromPort, '', + return send_signed_json(reject_json, session, base_dir, + nickname_to_follow, domain_to_follow, port, + nickname, domain, from_port, '', http_prefix, True, client_to_server, federation_list, send_threads, postLog, cached_webfingers, @@ -850,7 +854,7 @@ def followed_account_rejects(session, base_dir: str, http_prefix: str, def send_follow_request(session, base_dir: str, nickname: str, domain: str, port: int, http_prefix: str, - followNickname: str, followDomain: str, + follow_nickname: str, follow_domain: str, followedActor: str, followPort: int, followHttpPrefix: str, client_to_server: bool, federation_list: [], @@ -862,75 +866,76 @@ def send_follow_request(session, base_dir: str, if not signing_priv_key_pem: print('WARN: follow request without signing key') - if not domain_permitted(followDomain, federation_list): - print('You are not permitted to follow the domain ' + followDomain) + if not domain_permitted(follow_domain, federation_list): + print('You are not permitted to follow the domain ' + follow_domain) return None - fullDomain = get_full_domain(domain, port) - followActor = local_actor_url(http_prefix, nickname, fullDomain) + full_domain = get_full_domain(domain, port) + follow_actor = local_actor_url(http_prefix, nickname, full_domain) - requestDomain = get_full_domain(followDomain, followPort) + request_domain = get_full_domain(follow_domain, followPort) - statusNumber, published = get_status_number() + status_number, _ = get_status_number() group_account = False - if followNickname: - followedId = followedActor - followHandle = followNickname + '@' + requestDomain + if follow_nickname: + followed_id = followedActor + follow_handle = follow_nickname + '@' + request_domain group_account = has_group_type(base_dir, followedActor, person_cache) if group_account: - followHandle = '!' + followHandle + follow_handle = '!' + follow_handle print('Follow request being sent to group account') else: if debug: print('DEBUG: send_follow_request - assuming single user instance') - followedId = followHttpPrefix + '://' + requestDomain - singleUserNickname = 'dev' - followHandle = singleUserNickname + '@' + requestDomain + followed_id = followHttpPrefix + '://' + request_domain + single_user_nickname = 'dev' + follow_handle = single_user_nickname + '@' + request_domain # remove follow handle from unfollowed.txt - unfollowedFilename = \ + unfollowed_filename = \ acct_dir(base_dir, nickname, domain) + '/unfollowed.txt' - if os.path.isfile(unfollowedFilename): - if followHandle in open(unfollowedFilename).read(): - unfollowedFile = None + if os.path.isfile(unfollowed_filename): + if follow_handle in open(unfollowed_filename).read(): + unfollowed_file = None try: - with open(unfollowedFilename, 'r') as fp: - unfollowedFile = fp.read() + with open(unfollowed_filename, 'r') as fp_unfoll: + unfollowed_file = fp_unfoll.read() except OSError: - print('EX: send_follow_request ' + unfollowedFilename) - if unfollowedFile: - unfollowedFile = \ - unfollowedFile.replace(followHandle + '\n', '') + print('EX: send_follow_request ' + unfollowed_filename) + if unfollowed_file: + unfollowed_file = \ + unfollowed_file.replace(follow_handle + '\n', '') try: - with open(unfollowedFilename, 'w+') as fp: - fp.write(unfollowedFile) + with open(unfollowed_filename, 'w+') as fp_unfoll: + fp_unfoll.write(unfollowed_file) except OSError: - print('EX: unable to write ' + unfollowedFilename) + print('EX: unable to write ' + unfollowed_filename) - newFollowJson = { + new_follow_json = { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': followActor + '/statuses/' + str(statusNumber), + 'id': follow_actor + '/statuses/' + str(status_number), 'type': 'Follow', - 'actor': followActor, - 'object': followedId + 'actor': follow_actor, + 'object': followed_id } if group_account: - newFollowJson['to'] = followedId - print('Follow request: ' + str(newFollowJson)) + new_follow_json['to'] = followed_id + print('Follow request: ' + str(new_follow_json)) if follow_approval_required(base_dir, nickname, domain, debug, - followHandle): + follow_handle): # Remove any follow requests rejected for the account being followed. # It's assumed that if you are following someone then you are # ok with them following back. If this isn't the case then a rejected # follow request will block them again. _remove_from_follow_rejects(base_dir, nickname, domain, - followHandle, debug) + follow_handle, debug) - send_signed_json(newFollowJson, session, base_dir, nickname, domain, port, - followNickname, followDomain, followPort, + send_signed_json(new_follow_json, session, base_dir, + nickname, domain, port, + follow_nickname, follow_domain, followPort, 'https://www.w3.org/ns/activitystreams#Public', http_prefix, True, client_to_server, federation_list, @@ -938,13 +943,13 @@ def send_follow_request(session, base_dir: str, debug, project_version, None, group_account, signing_priv_key_pem, 8234389) - return newFollowJson + return new_follow_json def send_follow_requestViaServer(base_dir: str, session, - fromNickname: str, password: str, - fromDomain: str, fromPort: int, - followNickname: str, followDomain: str, + from_nickname: str, password: str, + from_domain: str, from_port: int, + follow_nickname: str, follow_domain: str, followPort: int, http_prefix: str, cached_webfingers: {}, person_cache: {}, @@ -956,55 +961,55 @@ def send_follow_requestViaServer(base_dir: str, session, print('WARN: No session for send_follow_requestViaServer') return 6 - fromDomainFull = get_full_domain(fromDomain, fromPort) + from_domain_full = get_full_domain(from_domain, from_port) - followDomainFull = get_full_domain(followDomain, followPort) + follow_domain_full = get_full_domain(follow_domain, followPort) - followActor = local_actor_url(http_prefix, fromNickname, fromDomainFull) - followedId = \ - http_prefix + '://' + followDomainFull + '/@' + followNickname + follow_actor = \ + local_actor_url(http_prefix, from_nickname, from_domain_full) + followed_id = \ + http_prefix + '://' + follow_domain_full + '/@' + follow_nickname - statusNumber, published = get_status_number() - newFollowJson = { + status_number, published = get_status_number() + new_follow_json = { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': followActor + '/statuses/' + str(statusNumber), + 'id': follow_actor + '/statuses/' + str(status_number), 'type': 'Follow', - 'actor': followActor, - 'object': followedId + 'actor': follow_actor, + 'object': followed_id } - handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname + handle = http_prefix + '://' + from_domain_full + '/@' + from_nickname # lookup the inbox for the To handle - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, - fromDomain, project_version, debug, False, + from_domain, project_version, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: if debug: print('DEBUG: follow request webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('WARN: follow request Webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 - postToBox = 'outbox' + post_to_box = 'outbox' # get the actor inbox for the To handle - originDomain = fromDomain - (inboxUrl, pubKeyId, pubKey, - fromPersonId, sharedInbox, avatarUrl, - displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + origin_domain = from_domain + (inboxUrl, _, _, fromPersonId, sharedInbox, avatarUrl, + displayName, _) = get_person_box(signing_priv_key_pem, origin_domain, + base_dir, session, wf_request, person_cache, project_version, http_prefix, - fromNickname, - fromDomain, postToBox, 52025) + from_nickname, + from_domain, post_to_box, 52025) if not inboxUrl: if debug: - print('DEBUG: follow request no ' + postToBox + + print('DEBUG: follow request no ' + post_to_box + ' was found for ' + handle) return 3 if not fromPersonId: @@ -1012,17 +1017,17 @@ def send_follow_requestViaServer(base_dir: str, session, print('DEBUG: follow request no actor was found for ' + handle) return 4 - authHeader = create_basic_auth_header(fromNickname, password) + auth_header = create_basic_auth_header(from_nickname, password) headers = { - 'host': fromDomain, + 'host': from_domain, 'Content-type': 'application/json', - 'Authorization': authHeader + 'Authorization': auth_header } - postResult = \ - post_json(http_prefix, fromDomainFull, - session, newFollowJson, [], inboxUrl, headers, 3, True) - if not postResult: + post_result = \ + post_json(http_prefix, from_domain_full, + session, new_follow_json, [], inboxUrl, headers, 3, True) + if not post_result: if debug: print('DEBUG: POST follow request failed for c2s to ' + inboxUrl) return 5 @@ -1030,13 +1035,13 @@ def send_follow_requestViaServer(base_dir: str, session, if debug: print('DEBUG: c2s POST follow request success') - return newFollowJson + return new_follow_json def send_unfollow_request_via_server(base_dir: str, session, - fromNickname: str, password: str, - fromDomain: str, fromPort: int, - followNickname: str, followDomain: str, + from_nickname: str, password: str, + from_domain: str, from_port: int, + follow_nickname: str, follow_domain: str, followPort: int, http_prefix: str, cached_webfingers: {}, person_cache: {}, @@ -1048,60 +1053,61 @@ def send_unfollow_request_via_server(base_dir: str, session, print('WARN: No session for send_unfollow_request_via_server') return 6 - fromDomainFull = get_full_domain(fromDomain, fromPort) - followDomainFull = get_full_domain(followDomain, followPort) + from_domain_full = get_full_domain(from_domain, from_port) + follow_domain_full = get_full_domain(follow_domain, followPort) - followActor = local_actor_url(http_prefix, fromNickname, fromDomainFull) - followedId = \ - http_prefix + '://' + followDomainFull + '/@' + followNickname - statusNumber, published = get_status_number() + follow_actor = \ + local_actor_url(http_prefix, from_nickname, from_domain_full) + followed_id = \ + http_prefix + '://' + follow_domain_full + '/@' + follow_nickname + status_number, published = get_status_number() - unfollowJson = { + unfollow_json = { '@context': 'https://www.w3.org/ns/activitystreams', - 'id': followActor + '/statuses/' + str(statusNumber) + '/undo', + 'id': follow_actor + '/statuses/' + str(status_number) + '/undo', 'type': 'Undo', - 'actor': followActor, + 'actor': follow_actor, 'object': { - 'id': followActor + '/statuses/' + str(statusNumber), + 'id': follow_actor + '/statuses/' + str(status_number), 'type': 'Follow', - 'actor': followActor, - 'object': followedId + 'actor': follow_actor, + 'object': followed_id } } - handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname + handle = http_prefix + '://' + from_domain_full + '/@' + from_nickname # lookup the inbox for the To handle - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, - fromDomain, project_version, debug, False, + from_domain, project_version, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: if debug: print('DEBUG: unfollow webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('WARN: unfollow webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 - postToBox = 'outbox' + post_to_box = 'outbox' # get the actor inbox for the To handle - originDomain = fromDomain + origin_domain = from_domain (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, - originDomain, + origin_domain, base_dir, session, - wfRequest, person_cache, + wf_request, person_cache, project_version, http_prefix, - fromNickname, - fromDomain, postToBox, + from_nickname, + from_domain, post_to_box, 76536) if not inboxUrl: if debug: - print('DEBUG: unfollow no ' + postToBox + + print('DEBUG: unfollow no ' + post_to_box + ' was found for ' + handle) return 3 if not fromPersonId: @@ -1109,17 +1115,17 @@ def send_unfollow_request_via_server(base_dir: str, session, print('DEBUG: unfollow no actor was found for ' + handle) return 4 - authHeader = create_basic_auth_header(fromNickname, password) + auth_header = create_basic_auth_header(from_nickname, password) headers = { - 'host': fromDomain, + 'host': from_domain, 'Content-type': 'application/json', - 'Authorization': authHeader + 'Authorization': auth_header } - postResult = \ - post_json(http_prefix, fromDomainFull, - session, unfollowJson, [], inboxUrl, headers, 3, True) - if not postResult: + post_result = \ + post_json(http_prefix, from_domain_full, + session, unfollow_json, [], inboxUrl, headers, 3, True) + if not post_result: if debug: print('DEBUG: POST unfollow failed for c2s to ' + inboxUrl) return 5 @@ -1127,13 +1133,13 @@ def send_unfollow_request_via_server(base_dir: str, session, if debug: print('DEBUG: c2s POST unfollow success') - return unfollowJson + return unfollow_json def get_following_via_server(base_dir: str, session, nickname: str, password: str, domain: str, port: int, - http_prefix: str, pageNumber: int, + http_prefix: str, page_number: int, cached_webfingers: {}, person_cache: {}, debug: bool, project_version: str, signing_priv_key_pem: str) -> {}: @@ -1144,19 +1150,19 @@ def get_following_via_server(base_dir: str, session, return 6 domain_full = get_full_domain(domain, port) - followActor = local_actor_url(http_prefix, nickname, domain_full) + follow_actor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = create_basic_auth_header(nickname, password) + auth_header = create_basic_auth_header(nickname, password) headers = { 'host': domain, 'Content-type': 'application/json', - 'Authorization': authHeader + 'Authorization': auth_header } - if pageNumber < 1: - pageNumber = 1 - url = followActor + '/following?page=' + str(pageNumber) + if page_number < 1: + page_number = 1 + url = follow_actor + '/following?page=' + str(page_number) followingJson = \ get_json(signing_priv_key_pem, session, url, headers, {}, debug, __version__, http_prefix, domain, 10, True) @@ -1174,7 +1180,7 @@ def get_following_via_server(base_dir: str, session, def get_followers_via_server(base_dir: str, session, nickname: str, password: str, domain: str, port: int, - http_prefix: str, pageNumber: int, + http_prefix: str, page_number: int, cached_webfingers: {}, person_cache: {}, debug: bool, project_version: str, signing_priv_key_pem: str) -> {}: @@ -1185,23 +1191,23 @@ def get_followers_via_server(base_dir: str, session, return 6 domain_full = get_full_domain(domain, port) - followActor = local_actor_url(http_prefix, nickname, domain_full) + follow_actor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = create_basic_auth_header(nickname, password) + auth_header = create_basic_auth_header(nickname, password) headers = { 'host': domain, 'Content-type': 'application/json', - 'Authorization': authHeader + 'Authorization': auth_header } - if pageNumber < 1: - pageNumber = 1 - url = followActor + '/followers?page=' + str(pageNumber) - followersJson = \ + if page_number < 1: + page_number = 1 + url = follow_actor + '/followers?page=' + str(page_number) + followers_json = \ get_json(signing_priv_key_pem, session, url, headers, {}, debug, __version__, http_prefix, domain, 10, True) - if not followersJson: + if not followers_json: if debug: print('DEBUG: GET followers list failed for c2s to ' + url) return 5 @@ -1209,13 +1215,13 @@ def get_followers_via_server(base_dir: str, session, if debug: print('DEBUG: c2s GET followers list request success') - return followersJson + return followers_json def get_follow_requests_via_server(base_dir: str, session, nickname: str, password: str, domain: str, port: int, - http_prefix: str, pageNumber: int, + http_prefix: str, page_number: int, cached_webfingers: {}, person_cache: {}, debug: bool, project_version: str, signing_priv_key_pem: str) -> {}: @@ -1227,22 +1233,22 @@ def get_follow_requests_via_server(base_dir: str, session, domain_full = get_full_domain(domain, port) - followActor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = create_basic_auth_header(nickname, password) + follow_actor = local_actor_url(http_prefix, nickname, domain_full) + auth_header = create_basic_auth_header(nickname, password) headers = { 'host': domain, 'Content-type': 'application/json', - 'Authorization': authHeader + 'Authorization': auth_header } - if pageNumber < 1: - pageNumber = 1 - url = followActor + '/followrequests?page=' + str(pageNumber) - followersJson = \ + if page_number < 1: + page_number = 1 + url = follow_actor + '/followrequests?page=' + str(page_number) + followers_json = \ get_json(signing_priv_key_pem, session, url, headers, {}, debug, __version__, http_prefix, domain, 10, True) - if not followersJson: + if not followers_json: if debug: print('DEBUG: GET follow requests list failed for c2s to ' + url) return 5 @@ -1250,13 +1256,13 @@ def get_follow_requests_via_server(base_dir: str, session, if debug: print('DEBUG: c2s GET follow requests list request success') - return followersJson + return followers_json def approve_follow_request_via_server(base_dir: str, session, nickname: str, password: str, domain: str, port: int, - http_prefix: str, approveHandle: int, + http_prefix: str, approve_handle: int, cached_webfingers: {}, person_cache: {}, debug: bool, project_version: str, signing_priv_key_pem: str) -> str: @@ -1271,19 +1277,19 @@ def approve_follow_request_via_server(base_dir: str, session, domain_full = get_full_domain(domain, port) actor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = create_basic_auth_header(nickname, password) + auth_header = create_basic_auth_header(nickname, password) headers = { 'host': domain, 'Content-type': 'text/html; charset=utf-8', - 'Authorization': authHeader + 'Authorization': auth_header } - url = actor + '/followapprove=' + approveHandle - approveHtml = \ + url = actor + '/followapprove=' + approve_handle + approve_html = \ get_json(signing_priv_key_pem, session, url, headers, {}, debug, __version__, http_prefix, domain, 10, True) - if not approveHtml: + if not approve_html: if debug: print('DEBUG: GET approve follow request failed for c2s to ' + url) return 5 @@ -1291,13 +1297,13 @@ def approve_follow_request_via_server(base_dir: str, session, if debug: print('DEBUG: c2s GET approve follow request request success') - return approveHtml + return approve_html def deny_follow_request_via_server(base_dir: str, session, nickname: str, password: str, domain: str, port: int, - http_prefix: str, denyHandle: int, + http_prefix: str, deny_handle: int, cached_webfingers: {}, person_cache: {}, debug: bool, project_version: str, signing_priv_key_pem: str) -> str: @@ -1312,19 +1318,19 @@ def deny_follow_request_via_server(base_dir: str, session, domain_full = get_full_domain(domain, port) actor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = create_basic_auth_header(nickname, password) + auth_header = create_basic_auth_header(nickname, password) headers = { 'host': domain, 'Content-type': 'text/html; charset=utf-8', - 'Authorization': authHeader + 'Authorization': auth_header } - url = actor + '/followdeny=' + denyHandle - denyHtml = \ + url = actor + '/followdeny=' + deny_handle + deny_html = \ get_json(signing_priv_key_pem, session, url, headers, {}, debug, __version__, http_prefix, domain, 10, True) - if not denyHtml: + if not deny_html: if debug: print('DEBUG: GET deny follow request failed for c2s to ' + url) return 5 @@ -1332,7 +1338,7 @@ def deny_follow_request_via_server(base_dir: str, session, if debug: print('DEBUG: c2s GET deny follow request request success') - return denyHtml + return deny_html def get_followers_of_actor(base_dir: str, actor: str, debug: bool) -> {}: @@ -1342,43 +1348,43 @@ def get_followers_of_actor(base_dir: str, actor: str, debug: bool) -> {}: """ if debug: print('DEBUG: getting followers of ' + actor) - recipientsDict = {} + recipients_dict = {} if ':' not in actor: - return recipientsDict + return recipients_dict nickname = get_nickname_from_actor(actor) if not nickname: if debug: print('DEBUG: no nickname found in ' + actor) - return recipientsDict - domain, port = get_domain_from_actor(actor) + return recipients_dict + domain, _ = get_domain_from_actor(actor) if not domain: if debug: print('DEBUG: no domain found in ' + actor) - return recipientsDict - actorHandle = nickname + '@' + domain + return recipients_dict + actor_handle = nickname + '@' + domain if debug: - print('DEBUG: searching for handle ' + actorHandle) + print('DEBUG: searching for handle ' + actor_handle) # for each of the accounts - for subdir, dirs, files in os.walk(base_dir + '/accounts'): + for subdir, dirs, _ in os.walk(base_dir + '/accounts'): for account in dirs: if '@' in account and not account.startswith('inbox@'): - followingFilename = \ + following_filename = \ os.path.join(subdir, account) + '/following.txt' if debug: print('DEBUG: examining follows of ' + account) - print(followingFilename) - if os.path.isfile(followingFilename): + print(following_filename) + if os.path.isfile(following_filename): # does this account follow the given actor? if debug: - print('DEBUG: checking if ' + actorHandle + - ' in ' + followingFilename) - if actorHandle in open(followingFilename).read(): + print('DEBUG: checking if ' + actor_handle + + ' in ' + following_filename) + if actor_handle in open(following_filename).read(): if debug: print('DEBUG: ' + account + - ' follows ' + actorHandle) - recipientsDict[account] = None + ' follows ' + actor_handle) + recipients_dict[account] = None break - return recipientsDict + return recipients_dict def outbox_undo_follow(base_dir: str, message_json: {}, debug: bool) -> None: @@ -1402,49 +1408,50 @@ def outbox_undo_follow(base_dir: str, message_json: {}, debug: bool) -> None: if debug: print('DEBUG: undo follow arrived in outbox') - nicknameFollower = get_nickname_from_actor(message_json['object']['actor']) - if not nicknameFollower: + nickname_follower = \ + get_nickname_from_actor(message_json['object']['actor']) + if not nickname_follower: print('WARN: unable to find nickname in ' + message_json['object']['actor']) return - domainFollower, portFollower = \ + domain_follower, port_follower = \ get_domain_from_actor(message_json['object']['actor']) - domainFollowerFull = get_full_domain(domainFollower, portFollower) + domain_follower_full = get_full_domain(domain_follower, port_follower) - nicknameFollowing = \ + nickname_following = \ get_nickname_from_actor(message_json['object']['object']) - if not nicknameFollowing: + if not nickname_following: print('WARN: unable to find nickname in ' + message_json['object']['object']) return - domainFollowing, portFollowing = \ + domain_following, port_following = \ get_domain_from_actor(message_json['object']['object']) - domainFollowingFull = get_full_domain(domainFollowing, portFollowing) + domain_following_full = get_full_domain(domain_following, port_following) group_account = \ has_group_type(base_dir, message_json['object']['object'], None) - if unfollow_account(base_dir, nicknameFollower, domainFollowerFull, - nicknameFollowing, domainFollowingFull, + if unfollow_account(base_dir, nickname_follower, domain_follower_full, + nickname_following, domain_following_full, debug, group_account): if debug: - print('DEBUG: ' + nicknameFollower + ' unfollowed ' + - nicknameFollowing + '@' + domainFollowingFull) + print('DEBUG: ' + nickname_follower + ' unfollowed ' + + nickname_following + '@' + domain_following_full) else: if debug: - print('WARN: ' + nicknameFollower + ' could not unfollow ' + - nicknameFollowing + '@' + domainFollowingFull) + print('WARN: ' + nickname_follower + ' could not unfollow ' + + nickname_following + '@' + domain_following_full) def follower_approval_active(base_dir: str, nickname: str, domain: str) -> bool: """Returns true if the given account requires follower approval """ - manuallyApprovesFollowers = False - actorFilename = acct_dir(base_dir, nickname, domain) + '.json' - if os.path.isfile(actorFilename): - actor_json = load_json(actorFilename) + manually_approves_followers = False + actor_filename = acct_dir(base_dir, nickname, domain) + '.json' + if os.path.isfile(actor_filename): + actor_json = load_json(actor_filename) if actor_json: if actor_json.get('manuallyApprovesFollowers'): - manuallyApprovesFollowers = \ + manually_approves_followers = \ actor_json['manuallyApprovesFollowers'] - return manuallyApprovesFollowers + return manually_approves_followers diff --git a/like.py b/like.py index c4571b4b5..23eb1373a 100644 --- a/like.py +++ b/like.py @@ -198,31 +198,31 @@ def send_like_via_server(base_dir: str, session, handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname # lookup the inbox for the To handle - wfRequest = webfinger_handle(session, handle, http_prefix, - cached_webfingers, - fromDomain, project_version, debug, False, - signing_priv_key_pem) - if not wfRequest: + wf_request = webfinger_handle(session, handle, http_prefix, + cached_webfingers, + fromDomain, project_version, debug, False, + signing_priv_key_pem) + if not wf_request: if debug: print('DEBUG: like webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('WARN: like webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 postToBox = 'outbox' # get the actor inbox for the To handle originDomain = fromDomain - (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, - displayName, _) = get_person_box(signing_priv_key_pem, - originDomain, - base_dir, session, wfRequest, - person_cache, - project_version, http_prefix, - fromNickname, fromDomain, - postToBox, 72873) + (inboxUrl, _, _, fromPersonId, _, _, + _, _) = get_person_box(signing_priv_key_pem, + originDomain, + base_dir, session, wf_request, + person_cache, + project_version, http_prefix, + fromNickname, fromDomain, + postToBox, 72873) if not inboxUrl: if debug: @@ -285,18 +285,18 @@ def send_undo_like_via_server(base_dir: str, session, handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname # lookup the inbox for the To handle - wfRequest = webfinger_handle(session, handle, http_prefix, - cached_webfingers, - fromDomain, project_version, debug, False, - signing_priv_key_pem) - if not wfRequest: + wf_request = webfinger_handle(session, handle, http_prefix, + cached_webfingers, + fromDomain, project_version, debug, False, + signing_priv_key_pem) + if not wf_request: if debug: print('DEBUG: unlike webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): if debug: print('WARN: unlike webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 postToBox = 'outbox' @@ -306,7 +306,7 @@ def send_undo_like_via_server(base_dir: str, session, (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + base_dir, session, wf_request, person_cache, project_version, http_prefix, fromNickname, fromDomain, postToBox, diff --git a/migrate.py b/migrate.py index c179868fc..5e041bd6a 100644 --- a/migrate.py +++ b/migrate.py @@ -60,26 +60,26 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str, return ctr if handle.startswith('@'): handle = handle[1:] - wfRequest = webfinger_handle(session, handle, - http_prefix, cached_webfingers, - domain, __version__, debug, False, - signing_priv_key_pem) - if not wfRequest: + wf_request = webfinger_handle(session, handle, + http_prefix, cached_webfingers, + domain, __version__, debug, False, + signing_priv_key_pem) + if not wf_request: print('updateMovedHandle unable to webfinger ' + handle) return ctr - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('updateMovedHandle webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return ctr personUrl = None - if wfRequest.get('errors'): - print('wfRequest error: ' + str(wfRequest['errors'])) + if wf_request.get('errors'): + print('wf_request error: ' + str(wf_request['errors'])) return ctr if not personUrl: - personUrl = get_user_url(wfRequest, 0, debug) + personUrl = get_user_url(wf_request, 0, debug) if not personUrl: return ctr diff --git a/person.py b/person.py index 8f815eb64..d26891689 100644 --- a/person.py +++ b/person.py @@ -1523,7 +1523,7 @@ def get_actor_json(hostDomain: str, handle: str, http: bool, gnunet: bool, nickname = domain personUrl = None - wfRequest = None + wf_request = None if '://' in originalActor and \ originalActor.lower().endswith('/actor'): @@ -1536,27 +1536,27 @@ def get_actor_json(hostDomain: str, handle: str, http: bool, gnunet: bool, personUrl = originalActor else: handle = nickname + '@' + domain - wfRequest = webfinger_handle(session, handle, - http_prefix, cached_webfingers, - hostDomain, __version__, debug, - group_account, signing_priv_key_pem) - if not wfRequest: + wf_request = webfinger_handle(session, handle, + http_prefix, cached_webfingers, + hostDomain, __version__, debug, + group_account, signing_priv_key_pem) + if not wf_request: if not quiet: print('get_actor_json Unable to webfinger ' + handle) return None, None - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): if not quiet: print('get_actor_json Webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return None, None if not quiet: - pprint(wfRequest) + pprint(wf_request) - if wfRequest.get('errors'): + if wf_request.get('errors'): if not quiet or debug: - print('get_actor_json wfRequest error: ' + - str(wfRequest['errors'])) + print('get_actor_json wf_request error: ' + + str(wf_request['errors'])) if has_users_path(handle): personUrl = originalActor else: @@ -1568,8 +1568,8 @@ def get_actor_json(hostDomain: str, handle: str, http: bool, gnunet: bool, headersList = ( "activity+json", "ld+json", "jrd+json" ) - if not personUrl and wfRequest: - personUrl = get_user_url(wfRequest, 0, debug) + if not personUrl and wf_request: + personUrl = get_user_url(wf_request, 0, debug) if nickname == domain: paths = get_user_paths() for userPath in paths: diff --git a/pgp.py b/pgp.py index 81a2239e2..fa65d5105 100644 --- a/pgp.py +++ b/pgp.py @@ -556,19 +556,19 @@ def pgp_public_key_upload(base_dir: str, session, print('actor update is ' + str(actorUpdate)) # lookup the inbox for the To handle - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, domain, __version__, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: if debug: print('DEBUG: pgp actor update webfinger failed for ' + handle) return None - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): if debug: print('WARN: Webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return None postToBox = 'outbox' @@ -577,7 +577,7 @@ def pgp_public_key_upload(base_dir: str, session, originDomain = domain (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + base_dir, session, wf_request, person_cache, __version__, http_prefix, nickname, domain, postToBox, 35725) diff --git a/shares.py b/shares.py index 067ca1c01..086914eff 100644 --- a/shares.py +++ b/shares.py @@ -609,18 +609,18 @@ def send_share_via_server(base_dir, session, handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname # lookup the inbox for the To handle - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, fromDomain, project_version, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: if debug: print('DEBUG: share webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('WARN: share webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 postToBox = 'outbox' @@ -630,7 +630,7 @@ def send_share_via_server(base_dir, session, (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + base_dir, session, wf_request, person_cache, project_version, http_prefix, fromNickname, fromDomain, postToBox, @@ -714,17 +714,17 @@ def send_undo_share_via_server(base_dir: str, session, handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname # lookup the inbox for the To handle - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, fromDomain, project_version, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: if debug: print('DEBUG: unshare webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('WARN: unshare webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 postToBox = 'outbox' @@ -734,7 +734,7 @@ def send_undo_share_via_server(base_dir: str, session, (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + base_dir, session, wf_request, person_cache, project_version, http_prefix, fromNickname, fromDomain, postToBox, @@ -829,18 +829,18 @@ def send_wanted_via_server(base_dir, session, handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname # lookup the inbox for the To handle - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, fromDomain, project_version, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: if debug: print('DEBUG: share webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('WARN: wanted webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 postToBox = 'outbox' @@ -850,7 +850,7 @@ def send_wanted_via_server(base_dir, session, (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + base_dir, session, wf_request, person_cache, project_version, http_prefix, fromNickname, fromDomain, postToBox, @@ -934,17 +934,17 @@ def send_undo_wanted_via_server(base_dir: str, session, handle = http_prefix + '://' + fromDomainFull + '/@' + fromNickname # lookup the inbox for the To handle - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, fromDomain, project_version, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: if debug: print('DEBUG: unwant webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('WARN: unwant webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 postToBox = 'outbox' @@ -954,7 +954,7 @@ def send_undo_wanted_via_server(base_dir: str, session, (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + base_dir, session, wf_request, person_cache, project_version, http_prefix, fromNickname, fromDomain, postToBox, diff --git a/skills.py b/skills.py index 2918837ea..508efe278 100644 --- a/skills.py +++ b/skills.py @@ -207,18 +207,18 @@ def send_skill_via_server(base_dir: str, session, nickname: str, password: str, handle = http_prefix + '://' + domain_full + '/@' + nickname # lookup the inbox for the To handle - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, domain, project_version, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: if debug: print('DEBUG: skill webfinger failed for ' + handle) return 1 - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('WARN: skill webfinger for ' + handle + - ' did not return a dict. ' + str(wfRequest)) + ' did not return a dict. ' + str(wf_request)) return 1 postToBox = 'outbox' @@ -228,7 +228,7 @@ def send_skill_via_server(base_dir: str, session, nickname: str, password: str, (inboxUrl, pubKeyId, pubKey, fromPersonId, sharedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + base_dir, session, wf_request, person_cache, project_version, http_prefix, nickname, domain, postToBox, 76121) diff --git a/socnet.py b/socnet.py index a33e2cb1f..1a5fd4bfd 100644 --- a/socnet.py +++ b/socnet.py @@ -51,23 +51,23 @@ def instances_graph(base_dir: str, handles: str, domain_full = get_full_domain(domain, port) handle = http_prefix + "://" + domain_full + "/@" + nickname - wfRequest = \ + wf_request = \ webfinger_handle(session, handle, http_prefix, cached_webfingers, domain, project_version, debug, False, signing_priv_key_pem) - if not wfRequest: + if not wf_request: return dotGraphStr + '}\n' - if not isinstance(wfRequest, dict): + if not isinstance(wf_request, dict): print('Webfinger for ' + handle + ' did not return a dict. ' + - str(wfRequest)) + str(wf_request)) return dotGraphStr + '}\n' originDomain = None (personUrl, pubKeyId, pubKey, personId, shaedInbox, avatarUrl, displayName, _) = get_person_box(signing_priv_key_pem, originDomain, - base_dir, session, wfRequest, + base_dir, session, wf_request, person_cache, project_version, http_prefix, nickname, domain, 'outbox', diff --git a/webapp_moderation.py b/webapp_moderation.py index 998d598d3..d106dd33a 100644 --- a/webapp_moderation.py +++ b/webapp_moderation.py @@ -33,7 +33,7 @@ from session import create_session def html_moderation(css_cache: {}, default_timeline: str, recent_posts_cache: {}, max_recent_posts: int, translate: {}, pageNumber: int, itemsPerPage: int, - session, base_dir: str, wfRequest: {}, person_cache: {}, + session, base_dir: str, wf_request: {}, person_cache: {}, nickname: str, domain: str, port: int, inboxJson: {}, allow_deletion: bool, http_prefix: str, project_version: str, @@ -63,7 +63,7 @@ def html_moderation(css_cache: {}, default_timeline: str, recent_posts_cache, max_recent_posts, translate, pageNumber, itemsPerPage, session, base_dir, - wfRequest, person_cache, + wf_request, person_cache, nickname, domain, port, inboxJson, 'moderation', allow_deletion, http_prefix, project_version, True, False,