From f96495a356c6fd9e96380691b5a1ac3736cdf8cf Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 28 Dec 2021 21:36:27 +0000 Subject: [PATCH] Snake case --- announce.py | 6 +- auth.py | 13 +-- availability.py | 4 +- bookmarks.py | 6 +- daemon.py | 270 +++++++++++++++++++++++------------------------ delete.py | 4 +- epicyon.py | 8 +- follow.py | 16 +-- inbox.py | 10 +- like.py | 6 +- manualapprove.py | 46 ++++---- media.py | 48 ++++----- outbox.py | 14 +-- person.py | 12 +-- pgp.py | 4 +- posts.py | 124 +++++++++++----------- reaction.py | 6 +- shares.py | 38 +++---- skills.py | 4 +- tests.py | 190 ++++++++++++++++----------------- threads.py | 14 +-- webapp_post.py | 4 +- 22 files changed, 424 insertions(+), 423 deletions(-) diff --git a/announce.py b/announce.py index d75ed096c..668fb9f94 100644 --- a/announce.py +++ b/announce.py @@ -30,7 +30,7 @@ from posts import sendSignedJson from posts import getPersonBox from session import postJson from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header def isSelfAnnounce(post_json_object: {}) -> bool: @@ -283,7 +283,7 @@ def sendAnnounceViaServer(base_dir: str, session, print('DEBUG: announce no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -368,7 +368,7 @@ def sendUndoAnnounceViaServer(base_dir: str, session, print('DEBUG: undo announce no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, diff --git a/auth.py b/auth.py index d94ddeeab..b0f19b1a4 100644 --- a/auth.py +++ b/auth.py @@ -73,7 +73,7 @@ def _verifyPassword(storedPassword: str, providedPassword: str) -> bool: return constantTimeStringCheck(pwHash, storedPassword) -def createBasicAuthHeader(nickname: str, password: str) -> str: +def create_basic_auth_header(nickname: str, password: str) -> str: """This is only used by tests """ authStr = \ @@ -83,8 +83,8 @@ def createBasicAuthHeader(nickname: str, password: str) -> str: return 'Basic ' + base64.b64encode(authStr.encode('utf-8')).decode('utf-8') -def authorizeBasic(base_dir: str, path: str, authHeader: str, - debug: bool) -> bool: +def authorize_basic(base_dir: str, path: str, authHeader: str, + debug: bool) -> bool: """HTTP basic auth """ if ' ' not in authHeader: @@ -152,7 +152,8 @@ def authorizeBasic(base_dir: str, path: str, authHeader: str, return False -def storeBasicCredentials(base_dir: str, nickname: str, password: str) -> bool: +def store_basic_credentials(base_dir: str, + nickname: str, password: str) -> bool: """Stores login credentials to a file """ if ':' in nickname or ':' in password: @@ -230,11 +231,11 @@ def authorize(base_dir: str, path: str, authHeader: str, debug: bool) -> bool: """Authorize using http header """ if authHeader.lower().startswith('basic '): - return authorizeBasic(base_dir, path, authHeader, debug) + return authorize_basic(base_dir, path, authHeader, debug) return False -def createPassword(length: int): +def create_password(length: int): validChars = 'abcdefghijklmnopqrstuvwxyz' + \ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' return ''.join((secrets.choice(validChars) for i in range(length))) diff --git a/availability.py b/availability.py index 7508d2915..c2e0c9e20 100644 --- a/availability.py +++ b/availability.py @@ -9,7 +9,7 @@ __module_group__ = "Profile Metadata" import os from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from posts import getPersonBox from session import postJson from utils import has_object_string @@ -141,7 +141,7 @@ def sendAvailabilityViaServer(base_dir: str, session, print('DEBUG: availability no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, diff --git a/bookmarks.py b/bookmarks.py index 43a99a60f..de42f4aa8 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -10,7 +10,7 @@ __module_group__ = "Timeline" import os from pprint import pprint from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from utils import remove_domain_port from utils import has_users_path from utils import get_full_domain @@ -443,7 +443,7 @@ def sendBookmarkViaServer(base_dir: str, session, print('DEBUG: bookmark no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, @@ -533,7 +533,7 @@ def sendUndoBookmarkViaServer(base_dir: str, session, print('DEBUG: unbookmark no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, diff --git a/daemon.py b/daemon.py index bd5bcf790..44613251c 100644 --- a/daemon.py +++ b/daemon.py @@ -115,19 +115,19 @@ from skills import actor_skill_value from skills import set_actor_skill_level from auth import record_login_failure from auth import authorize -from auth import createPassword -from auth import createBasicAuthHeader -from auth import authorizeBasic -from auth import storeBasicCredentials -from threads import threadWithTrace -from threads import removeDormantThreads -from media import processMetaData -from media import convertImageToLowBandwidth -from media import replaceYouTube -from media import replaceTwitter -from media import attachMedia -from media import pathIsVideo -from media import pathIsAudio +from auth import create_password +from auth import create_basic_auth_header +from auth import authorize_basic +from auth import store_basic_credentials +from threads import thread_with_trace +from threads import remove_dormant_threads +from media import process_meta_data +from media import convert_image_to_low_bandwidth +from media import replace_you_tube +from media import replace_twitter +from media import attach_media +from media import path_is_video +from media import path_is_audio from blocking import getCWlistVariable from blocking import loadCWLists from blocking import updateBlockedCache @@ -228,7 +228,7 @@ from shares import runFederatedSharesDaemon from shares import runFederatedSharesWatchdog from shares import updateSharedItemFederationToken from shares import createSharedItemFederationToken -from shares import authorizeSharedItems +from shares import authorize_shared_items from shares import generateSharedItemFederationTokens from shares import getSharesFeedForPerson from shares import addShare @@ -1355,10 +1355,10 @@ class PubServer(BaseHTTPRequestHandler): accountOutboxThreadName + '/' + str(self.server.outbox_thread_index[accountOutboxThreadName])) self.server.outboxThread[accountOutboxThreadName][index] = \ - threadWithTrace(target=self._postToOutbox, - args=(message_json.copy(), - self.server.project_version, None), - daemon=True) + thread_with_trace(target=self._postToOutbox, + args=(message_json.copy(), + self.server.project_version, None), + daemon=True) print('Starting outbox thread') self.server.outboxThread[accountOutboxThreadName][index].start() return True @@ -1722,7 +1722,7 @@ class PubServer(BaseHTTPRequestHandler): cookie, calling_domain) return authHeader = \ - createBasicAuthHeader(loginNickname, loginPassword) + create_basic_auth_header(loginNickname, loginPassword) if self.headers.get('X-Forward-For'): ipAddress = self.headers['X-Forward-For'] elif self.headers.get('X-Forwarded-For'): @@ -1732,9 +1732,9 @@ class PubServer(BaseHTTPRequestHandler): if not domain.endswith('.onion'): if not is_local_network_address(ipAddress): print('Login attempt from IP: ' + str(ipAddress)) - if not authorizeBasic(base_dir, '/users/' + - loginNickname + '/outbox', - authHeader, False): + if not authorize_basic(base_dir, '/users/' + + loginNickname + '/outbox', + authHeader, False): print('Login failed: ' + loginNickname) self._clearLoginDetails(loginNickname, calling_domain) failTime = int(time.time()) @@ -1768,7 +1768,7 @@ class PubServer(BaseHTTPRequestHandler): # on nick+password+salt saltFilename = \ acct_dir(base_dir, loginNickname, domain) + '/.salt' - salt = createPassword(32) + salt = create_password(32) if os.path.isfile(saltFilename): try: with open(saltFilename, 'r') as fp: @@ -4827,10 +4827,10 @@ class PubServer(BaseHTTPRequestHandler): base_dir, nickname, domain) if self.server.low_bandwidth: - convertImageToLowBandwidth(filename) - processMetaData(base_dir, nickname, domain, - filename, postImageFilename, city, - content_license_url) + convert_image_to_low_bandwidth(filename) + process_meta_data(base_dir, nickname, domain, + filename, postImageFilename, city, + content_license_url) if os.path.isfile(postImageFilename): print('profile update POST ' + mType + ' image, zip or font saved to ' + @@ -4976,8 +4976,8 @@ class PubServer(BaseHTTPRequestHandler): if valid_password(fields['password']) and \ fields['password'] == fields['passwordconfirm']: # set password - storeBasicCredentials(base_dir, nickname, - fields['password']) + store_basic_credentials(base_dir, nickname, + fields['password']) # reply interval in hours if fields.get('replyhours'): @@ -7199,8 +7199,8 @@ class PubServer(BaseHTTPRequestHandler): """Returns a media file """ if is_image_file(path) or \ - pathIsVideo(path) or \ - pathIsAudio(path): + path_is_video(path) or \ + path_is_audio(path): mediaStr = path.split('/media/')[1] mediaFilename = base_dir + '/media/' + mediaStr if os.path.isfile(mediaFilename): @@ -13527,13 +13527,13 @@ class PubServer(BaseHTTPRequestHandler): permittedDomains = \ self.server.shared_items_federated_domains sharedItemTokens = self.server.sharedItemFederationTokens - if authorizeSharedItems(permittedDomains, - self.server.base_dir, - self.headers['Origin'], - calling_domain, - self.headers['Authorization'], - self.server.debug, - sharedItemTokens): + if authorize_shared_items(permittedDomains, + self.server.base_dir, + self.headers['Origin'], + calling_domain, + self.headers['Authorization'], + self.server.debug, + sharedItemTokens): catalogAuthorized = True elif self.server.debug: print('Authorization token refused for ' + @@ -13619,13 +13619,13 @@ class PubServer(BaseHTTPRequestHandler): permittedDomains = \ self.server.shared_items_federated_domains sharedItemTokens = self.server.sharedItemFederationTokens - if authorizeSharedItems(permittedDomains, - self.server.base_dir, - self.headers['Origin'], - calling_domain, - self.headers['Authorization'], - self.server.debug, - sharedItemTokens): + if authorize_shared_items(permittedDomains, + self.server.base_dir, + self.headers['Origin'], + calling_domain, + self.headers['Authorization'], + self.server.debug, + sharedItemTokens): catalogAuthorized = True elif self.server.debug: print('Authorization token refused for ' + @@ -16397,8 +16397,8 @@ class PubServer(BaseHTTPRequestHandler): if '/media/' in self.path: if is_image_file(self.path) or \ - pathIsVideo(self.path) or \ - pathIsAudio(self.path): + path_is_video(self.path) or \ + path_is_audio(self.path): mediaStr = self.path.split('/media/')[1] mediaFilename = \ self.server.base_dir + '/media/' + mediaStr @@ -16512,11 +16512,11 @@ class PubServer(BaseHTTPRequestHandler): self.server.base_dir, nickname, self.server.domain) if self.server.low_bandwidth: - convertImageToLowBandwidth(filename) - processMetaData(self.server.base_dir, - nickname, self.server.domain, - filename, postImageFilename, city, - content_license_url) + convert_image_to_low_bandwidth(filename) + process_meta_data(self.server.base_dir, + nickname, self.server.domain, + filename, postImageFilename, city, + content_license_url) if os.path.isfile(postImageFilename): print('POST media saved to ' + postImageFilename) else: @@ -16814,25 +16814,25 @@ class PubServer(BaseHTTPRequestHandler): nickname, self.server.domain) post_json_object['object'] = \ - attachMedia(self.server.base_dir, - self.server.http_prefix, - nickname, - self.server.domain, - self.server.port, - post_json_object['object'], - filename, - attachmentMediaType, - imgDescription, - city, - self.server.low_bandwidth, - self.server.content_license_url) + attach_media(self.server.base_dir, + self.server.http_prefix, + nickname, + self.server.domain, + self.server.port, + post_json_object['object'], + filename, + attachmentMediaType, + imgDescription, + city, + self.server.low_bandwidth, + self.server.content_license_url) - replaceYouTube(post_json_object, - self.server.yt_replace_domain, - self.server.system_language) - replaceTwitter(post_json_object, - self.server.twitter_replacement_domain, - self.server.system_language) + replace_you_tube(post_json_object, + self.server.yt_replace_domain, + self.server.system_language) + replace_twitter(post_json_object, + self.server.twitter_replacement_domain, + self.server.system_language) save_json(post_json_object, post_filename) # also save to the news actor if nickname != 'news': @@ -18384,7 +18384,7 @@ def runPostsQueue(base_dir: str, send_threads: [], debug: bool, """ while True: time.sleep(1) - removeDormantThreads(base_dir, send_threads, debug, timeoutMins) + remove_dormant_threads(base_dir, send_threads, debug, timeoutMins) def runSharesExpire(versionNumber: str, base_dir: str) -> None: @@ -18875,17 +18875,17 @@ def runDaemon(content_license_url: str, print('Creating fitness thread') httpd.thrFitness = \ - threadWithTrace(target=fitnessThread, - args=(base_dir, httpd.fitness), daemon=True) + thread_with_trace(target=fitnessThread, + args=(base_dir, httpd.fitness), daemon=True) httpd.thrFitness.start() print('Creating cache expiry thread') httpd.thrCache = \ - threadWithTrace(target=expire_cache, - args=(base_dir, httpd.person_cache, - httpd.http_prefix, - archive_dir, - httpd.maxPostsInBox), daemon=True) + thread_with_trace(target=expire_cache, + args=(base_dir, httpd.person_cache, + httpd.http_prefix, + archive_dir, + httpd.maxPostsInBox), daemon=True) httpd.thrCache.start() # number of mins after which sending posts or updates will expire @@ -18893,25 +18893,25 @@ def runDaemon(content_license_url: str, print('Creating posts queue') httpd.thrPostsQueue = \ - threadWithTrace(target=runPostsQueue, - args=(base_dir, httpd.send_threads, debug, - httpd.send_threads_timeout_mins), daemon=True) + thread_with_trace(target=runPostsQueue, + args=(base_dir, httpd.send_threads, debug, + httpd.send_threads_timeout_mins), daemon=True) if not unit_test: httpd.thrPostsWatchdog = \ - threadWithTrace(target=runPostsWatchdog, - args=(project_version, httpd), daemon=True) + thread_with_trace(target=runPostsWatchdog, + args=(project_version, httpd), daemon=True) httpd.thrPostsWatchdog.start() else: httpd.thrPostsQueue.start() print('Creating expire thread for shared items') httpd.thrSharesExpire = \ - threadWithTrace(target=runSharesExpire, - args=(project_version, base_dir), daemon=True) + thread_with_trace(target=runSharesExpire, + args=(project_version, base_dir), daemon=True) if not unit_test: httpd.thrSharesExpireWatchdog = \ - threadWithTrace(target=runSharesExpireWatchdog, - args=(project_version, httpd), daemon=True) + thread_with_trace(target=runSharesExpireWatchdog, + args=(project_version, httpd), daemon=True) httpd.thrSharesExpireWatchdog.start() else: httpd.thrSharesExpire.start() @@ -18938,55 +18938,55 @@ def runDaemon(content_license_url: str, print('Creating inbox queue') httpd.thrInboxQueue = \ - threadWithTrace(target=run_inbox_queue, - args=(httpd.recent_posts_cache, - httpd.max_recent_posts, - project_version, - base_dir, http_prefix, httpd.send_threads, - httpd.postLog, httpd.cached_webfingers, - httpd.person_cache, httpd.inbox_queue, - domain, onion_domain, i2p_domain, - port, proxy_type, - httpd.federation_list, - max_replies, - domain_max_posts_per_day, - account_max_posts_per_day, - allow_deletion, debug, - max_mentions, max_emoji, - httpd.translate, unit_test, - httpd.yt_replace_domain, - httpd.twitter_replacement_domain, - httpd.show_published_date_only, - httpd.max_followers, - httpd.allow_local_network_access, - httpd.peertube_instances, - verify_all_signatures, - httpd.theme_name, - httpd.system_language, - httpd.max_like_count, - httpd.signing_priv_key_pem, - httpd.default_reply_interval_hrs, - httpd.cw_lists), daemon=True) + thread_with_trace(target=run_inbox_queue, + args=(httpd.recent_posts_cache, + httpd.max_recent_posts, + project_version, + base_dir, http_prefix, httpd.send_threads, + httpd.postLog, httpd.cached_webfingers, + httpd.person_cache, httpd.inbox_queue, + domain, onion_domain, i2p_domain, + port, proxy_type, + httpd.federation_list, + max_replies, + domain_max_posts_per_day, + account_max_posts_per_day, + allow_deletion, debug, + max_mentions, max_emoji, + httpd.translate, unit_test, + httpd.yt_replace_domain, + httpd.twitter_replacement_domain, + httpd.show_published_date_only, + httpd.max_followers, + httpd.allow_local_network_access, + httpd.peertube_instances, + verify_all_signatures, + httpd.theme_name, + httpd.system_language, + httpd.max_like_count, + httpd.signing_priv_key_pem, + httpd.default_reply_interval_hrs, + httpd.cw_lists), daemon=True) print('Creating scheduled post thread') httpd.thrPostSchedule = \ - threadWithTrace(target=runPostSchedule, - args=(base_dir, httpd, 20), daemon=True) + thread_with_trace(target=runPostSchedule, + args=(base_dir, httpd, 20), daemon=True) print('Creating newswire thread') httpd.thrNewswireDaemon = \ - threadWithTrace(target=runNewswireDaemon, - args=(base_dir, httpd, - http_prefix, domain, port, - httpd.translate), daemon=True) + thread_with_trace(target=runNewswireDaemon, + args=(base_dir, httpd, + http_prefix, domain, port, + httpd.translate), daemon=True) print('Creating federated shares thread') httpd.thrFederatedSharesDaemon = \ - threadWithTrace(target=runFederatedSharesDaemon, - args=(base_dir, httpd, - http_prefix, httpd.domain_full, - proxy_type, debug, - httpd.system_language), daemon=True) + thread_with_trace(target=runFederatedSharesDaemon, + args=(base_dir, httpd, + http_prefix, httpd.domain_full, + proxy_type, debug, + httpd.system_language), daemon=True) # flags used when restarting the inbox queue httpd.restartInboxQueueInProgress = False @@ -19004,26 +19004,26 @@ def runDaemon(content_license_url: str, if not unit_test: print('Creating inbox queue watchdog') httpd.thrWatchdog = \ - threadWithTrace(target=run_inbox_queue_watchdog, - args=(project_version, httpd), daemon=True) + thread_with_trace(target=run_inbox_queue_watchdog, + args=(project_version, httpd), daemon=True) httpd.thrWatchdog.start() print('Creating scheduled post watchdog') httpd.thrWatchdogSchedule = \ - threadWithTrace(target=runPostScheduleWatchdog, - args=(project_version, httpd), daemon=True) + thread_with_trace(target=runPostScheduleWatchdog, + args=(project_version, httpd), daemon=True) httpd.thrWatchdogSchedule.start() print('Creating newswire watchdog') httpd.thrNewswireWatchdog = \ - threadWithTrace(target=runNewswireWatchdog, - args=(project_version, httpd), daemon=True) + thread_with_trace(target=runNewswireWatchdog, + args=(project_version, httpd), daemon=True) httpd.thrNewswireWatchdog.start() print('Creating federated shares watchdog') httpd.thrFederatedSharesWatchdog = \ - threadWithTrace(target=runFederatedSharesWatchdog, - args=(project_version, httpd), daemon=True) + thread_with_trace(target=runFederatedSharesWatchdog, + args=(project_version, httpd), daemon=True) httpd.thrFederatedSharesWatchdog.start() else: print('Starting inbox queue') diff --git a/delete.py b/delete.py index 464ba5f7c..039025437 100644 --- a/delete.py +++ b/delete.py @@ -22,7 +22,7 @@ from utils import remove_moderation_post_from_index from utils import local_actor_url from session import postJson from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from posts import getPersonBox @@ -91,7 +91,7 @@ def sendDeleteViaServer(base_dir: str, session, print('DEBUG: delete no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, diff --git a/epicyon.py b/epicyon.py index 2a414ad11..70c290f7d 100644 --- a/epicyon.py +++ b/epicyon.py @@ -63,8 +63,8 @@ from tests import testFollowBetweenServers from tests import testClientToServer from tests import testUpdateActor from tests import runAllTests -from auth import storeBasicCredentials -from auth import createPassword +from auth import store_basic_credentials +from auth import create_password from utils import remove_domain_port from utils import get_port_from_domain from utils import has_users_path @@ -1103,7 +1103,7 @@ if args.resetregistrations: # unique ID for the instance instance_id = get_config_param(base_dir, 'instance_id') if not instance_id: - instance_id = createPassword(32) + instance_id = create_password(32) set_config_param(base_dir, 'instance_id', instance_id) print('Instance ID: ' + instance_id) @@ -2418,7 +2418,7 @@ if args.changepassword: passwordFile = base_dir + '/accounts/passwords' if os.path.isfile(passwordFile): if nickname + ':' in open(passwordFile).read(): - storeBasicCredentials(base_dir, nickname, newPassword) + store_basic_credentials(base_dir, nickname, newPassword) print('Password for ' + nickname + ' was changed') else: print(nickname + ' is not in the passwords file') diff --git a/follow.py b/follow.py index e620e78d4..00a47e6da 100644 --- a/follow.py +++ b/follow.py @@ -33,7 +33,7 @@ from utils import local_actor_url from acceptreject import createAccept from acceptreject import createReject from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from session import getJson from session import postJson @@ -1009,7 +1009,7 @@ def send_follow_requestViaServer(base_dir: str, session, print('DEBUG: follow request no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -1106,7 +1106,7 @@ def sendUnfollowRequestViaServer(base_dir: str, session, print('DEBUG: unfollow no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -1143,7 +1143,7 @@ def getFollowingViaServer(base_dir: str, session, domain_full = get_full_domain(domain, port) followActor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, @@ -1184,7 +1184,7 @@ def getFollowersViaServer(base_dir: str, session, domain_full = get_full_domain(domain, port) followActor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, @@ -1225,7 +1225,7 @@ def getFollowRequestsViaServer(base_dir: str, session, domain_full = get_full_domain(domain, port) followActor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, @@ -1268,7 +1268,7 @@ def approveFollowRequestViaServer(base_dir: str, session, domain_full = get_full_domain(domain, port) actor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, @@ -1309,7 +1309,7 @@ def denyFollowRequestViaServer(base_dir: str, session, domain_full = get_full_domain(domain, port) actor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, diff --git a/inbox.py b/inbox.py index 3cfd50ece..5dec6020b 100644 --- a/inbox.py +++ b/inbox.py @@ -105,8 +105,8 @@ from posts import sendSignedJson from posts import sendToFollowersThread from webapp_post import individualPostAsHtml from question import questionUpdateVotes -from media import replaceYouTube -from media import replaceTwitter +from media import replace_you_tube +from media import replace_twitter from git import isGitPatch from git import receiveGitPatch from followingCalendar import receivingCalendarEvents @@ -3454,11 +3454,11 @@ def _inboxAfterInitial(recent_posts_cache: {}, max_recent_posts: int, return False # replace YouTube links, so they get less tracking data - replaceYouTube(post_json_object, yt_replace_domain, system_language) + replace_you_tube(post_json_object, yt_replace_domain, system_language) # replace twitter link domains, so that you can view twitter posts # without having an account - replaceTwitter(post_json_object, twitter_replacement_domain, - system_language) + replace_twitter(post_json_object, twitter_replacement_domain, + system_language) # list of indexes to be updated updateIndexList = ['inbox'] diff --git a/like.py b/like.py index 7c889142d..a966a51c3 100644 --- a/like.py +++ b/like.py @@ -31,7 +31,7 @@ from utils import get_cached_post_filename from posts import sendSignedJson from session import postJson from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from posts import getPersonBox @@ -230,7 +230,7 @@ def sendLikeViaServer(base_dir: str, session, print('DEBUG: like no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -318,7 +318,7 @@ def sendUndoLikeViaServer(base_dir: str, session, print('DEBUG: unlike no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, diff --git a/manualapprove.py b/manualapprove.py index 362fd2e82..41b18b4bf 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -16,7 +16,7 @@ from utils import remove_domain_port from utils import get_port_from_domain from utils import get_user_paths from utils import acct_dir -from threads import threadWithTrace +from threads import thread_with_trace def manualDenyFollowRequest(session, base_dir: str, @@ -85,17 +85,17 @@ def manualDenyFollowRequestThread(session, base_dir: str, user interface doesn't lag """ thr = \ - threadWithTrace(target=manualDenyFollowRequest, - args=(session, base_dir, - http_prefix, - nickname, domain, port, - denyHandle, - federation_list, - send_threads, postLog, - cached_webfingers, person_cache, - debug, - project_version, - signing_priv_key_pem), daemon=True) + thread_with_trace(target=manualDenyFollowRequest, + args=(session, base_dir, + http_prefix, + nickname, domain, port, + denyHandle, + federation_list, + send_threads, postLog, + cached_webfingers, person_cache, + debug, + project_version, + signing_priv_key_pem), daemon=True) thr.start() send_threads.append(thr) @@ -293,16 +293,16 @@ def manualApproveFollowRequestThread(session, base_dir: str, the UI to lag """ thr = \ - threadWithTrace(target=manualApproveFollowRequest, - args=(session, base_dir, - http_prefix, - nickname, domain, port, - approveHandle, - federation_list, - send_threads, postLog, - cached_webfingers, person_cache, - debug, - project_version, - signing_priv_key_pem), daemon=True) + thread_with_trace(target=manualApproveFollowRequest, + args=(session, base_dir, + http_prefix, + nickname, domain, port, + approveHandle, + federation_list, + send_threads, postLog, + cached_webfingers, person_cache, + debug, + project_version, + signing_priv_key_pem), daemon=True) thr.start() send_threads.append(thr) diff --git a/media.py b/media.py index 514320f2e..ce8b1c8e5 100644 --- a/media.py +++ b/media.py @@ -14,7 +14,7 @@ import subprocess import random from random import randint from hashlib import sha1 -from auth import createPassword +from auth import create_password from utils import get_base_content_from_post from utils import get_full_domain from utils import get_image_extensions @@ -72,8 +72,8 @@ def _replaceSiloDomain(post_json_object: {}, post_json_object['object']['contentMap'][system_language] = contentStr -def replaceYouTube(post_json_object: {}, replacementDomain: str, - system_language: str) -> None: +def replace_you_tube(post_json_object: {}, replacementDomain: str, + system_language: str) -> None: """Replace YouTube with a replacement domain This denies Google some, but not all, tracking data """ @@ -81,8 +81,8 @@ def replaceYouTube(post_json_object: {}, replacementDomain: str, replacementDomain, system_language) -def replaceTwitter(post_json_object: {}, replacementDomain: str, - system_language: str) -> None: +def replace_twitter(post_json_object: {}, replacementDomain: str, + system_language: str) -> None: """Replace Twitter with a replacement domain This allows you to view twitter posts without having a twitter account """ @@ -160,7 +160,7 @@ def _spoofMetaData(base_dir: str, nickname: str, domain: str, return -def convertImageToLowBandwidth(image_filename: str) -> None: +def convert_image_to_low_bandwidth(image_filename: str) -> None: """Converts an image to a low bandwidth version """ low_bandwidthFilename = image_filename + '.low' @@ -168,7 +168,7 @@ def convertImageToLowBandwidth(image_filename: str) -> None: try: os.remove(low_bandwidthFilename) except OSError: - print('EX: convertImageToLowBandwidth unable to delete ' + + print('EX: convert_image_to_low_bandwidth unable to delete ' + low_bandwidthFilename) cmd = \ @@ -190,7 +190,7 @@ def convertImageToLowBandwidth(image_filename: str) -> None: try: os.remove(image_filename) except OSError: - print('EX: convertImageToLowBandwidth unable to delete ' + + print('EX: convert_image_to_low_bandwidth unable to delete ' + image_filename) os.rename(low_bandwidthFilename, image_filename) if os.path.isfile(image_filename): @@ -200,9 +200,9 @@ def convertImageToLowBandwidth(image_filename: str) -> None: low_bandwidthFilename) -def processMetaData(base_dir: str, nickname: str, domain: str, - image_filename: str, outputFilename: str, - city: str, content_license_url: str) -> None: +def process_meta_data(base_dir: str, nickname: str, domain: str, + image_filename: str, outputFilename: str, + city: str, content_license_url: str) -> None: """Handles image metadata. This tries to spoof the metadata if possible, but otherwise just removes it """ @@ -293,12 +293,12 @@ def _updateEtag(mediaFilename: str) -> None: str(mediaFilename) + '.etag') -def attachMedia(base_dir: str, http_prefix: str, - nickname: str, domain: str, port: int, - postJson: {}, image_filename: str, - mediaType: str, description: str, - city: str, low_bandwidth: bool, - content_license_url: str) -> {}: +def attach_media(base_dir: str, http_prefix: str, + nickname: str, domain: str, port: int, + postJson: {}, image_filename: str, + mediaType: str, description: str, + city: str, low_bandwidth: bool, + content_license_url: str) -> {}: """Attaches media to a json object post The description can be None """ @@ -327,7 +327,7 @@ def attachMedia(base_dir: str, http_prefix: str, domain = get_full_domain(domain, port) mPath = getMediaPath() - mediaPath = mPath + '/' + createPassword(32) + '.' + fileExtension + mediaPath = mPath + '/' + create_password(32) + '.' + fileExtension if base_dir: createMediaDirs(base_dir, mPath) mediaFilename = base_dir + '/' + mediaPath @@ -354,10 +354,10 @@ def attachMedia(base_dir: str, http_prefix: str, if base_dir: if mediaType.startswith('image/'): if low_bandwidth: - convertImageToLowBandwidth(image_filename) - processMetaData(base_dir, nickname, domain, - image_filename, mediaFilename, city, - content_license_url) + convert_image_to_low_bandwidth(image_filename) + process_meta_data(base_dir, nickname, domain, + image_filename, mediaFilename, city, + content_license_url) else: copyfile(image_filename, mediaFilename) _updateEtag(mediaFilename) @@ -394,14 +394,14 @@ def archiveMedia(base_dir: str, archive_directory: str, maxWeeks: int) -> None: break -def pathIsVideo(path: str) -> bool: +def path_is_video(path: str) -> bool: if path.endswith('.ogv') or \ path.endswith('.mp4'): return True return False -def pathIsAudio(path: str) -> bool: +def path_is_audio(path: str) -> bool: if path.endswith('.ogg') or \ path.endswith('.mp3'): return True diff --git a/outbox.py b/outbox.py index 8d94dc8b6..1c671f07a 100644 --- a/outbox.py +++ b/outbox.py @@ -10,7 +10,7 @@ __module_group__ = "Timeline" import os from shutil import copyfile from session import create_session -from auth import createPassword +from auth import create_password from posts import isImageMedia from posts import outbox_message_create_wrap from posts import save_post_to_box @@ -35,8 +35,8 @@ from blocking import outboxBlock from blocking import outboxUndoBlock from blocking import outboxMute from blocking import outboxUndoMute -from media import replaceYouTube -from media import replaceTwitter +from media import replace_you_tube +from media import replace_twitter from media import getMediaPath from media import createMediaDirs from inbox import inboxUpdateIndex @@ -286,11 +286,11 @@ def postMessageToOutbox(session, translate: {}, print('DEBUG: domain is blocked: ' + message_json['actor']) return False # replace youtube, so that google gets less tracking data - replaceYouTube(message_json, yt_replace_domain, system_language) + replace_you_tube(message_json, yt_replace_domain, system_language) # replace twitter, so that twitter posts can be shown without # having a twitter account - replaceTwitter(message_json, twitter_replacement_domain, - system_language) + replace_twitter(message_json, twitter_replacement_domain, + system_language) # https://www.w3.org/TR/activitypub/#create-activity-outbox message_json['object']['attributedTo'] = message_json['actor'] if message_json['object'].get('attachment'): @@ -328,7 +328,7 @@ def postMessageToOutbox(session, translate: {}, # generate a path for the uploaded image mPath = getMediaPath() mediaPath = mPath + '/' + \ - createPassword(16).lower() + '.' + fileExtension + create_password(16).lower() + '.' + fileExtension createMediaDirs(base_dir, mPath) mediaFilename = base_dir + '/' + mediaPath # move the uploaded image to its new path diff --git a/person.py b/person.py index 2acf24b15..a8c8fe6e6 100644 --- a/person.py +++ b/person.py @@ -32,12 +32,12 @@ from posts import createBookmarksTimeline from posts import createInbox from posts import createOutbox from posts import createModeration -from auth import storeBasicCredentials +from auth import store_basic_credentials from auth import removePassword from roles import setRole from roles import setRolesFromList from roles import getActorRolesList -from media import processMetaData +from media import process_meta_data from utils import remove_html from utils import contains_invalid_chars from utils import replace_users_with_at @@ -157,9 +157,9 @@ def setProfileImage(base_dir: str, http_prefix: str, '/usr/bin/convert ' + image_filename + ' -size ' + \ resolution + ' -quality 50 ' + profileFilename subprocess.call(cmd, shell=True) - processMetaData(base_dir, nickname, domain, - profileFilename, profileFilename, city, - content_license_url) + process_meta_data(base_dir, nickname, domain, + profileFilename, profileFilename, city, + content_license_url) return True return False @@ -534,7 +534,7 @@ def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int, if password: password = remove_line_endings(password) - storeBasicCredentials(base_dir, nickname, password) + store_basic_credentials(base_dir, nickname, password) return privateKeyPem, publicKeyPem, newPerson, webfingerEndpoint diff --git a/pgp.py b/pgp.py index 8b9e03764..0424166ba 100644 --- a/pgp.py +++ b/pgp.py @@ -19,7 +19,7 @@ from utils import local_actor_url from utils import replace_users_with_at from webfinger import webfingerHandle from posts import getPersonBox -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from session import postJson @@ -590,7 +590,7 @@ def pgpPublicKeyUpload(base_dir: str, session, print('DEBUG: No actor was found for ' + handle) return None - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, diff --git a/posts.py b/posts.py index 1e44e5acd..b1b0d6eda 100644 --- a/posts.py +++ b/posts.py @@ -18,7 +18,7 @@ import random from socket import error as SocketError from time import gmtime, strftime from collections import OrderedDict -from threads import threadWithTrace +from threads import thread_with_trace from cache import storePersonInCache from cache import getPersonFromCache from cache import expirePersonCache @@ -69,9 +69,9 @@ from utils import remove_html from utils import dangerous_markup from utils import acct_dir from utils import local_actor_url -from media import attachMedia -from media import replaceYouTube -from media import replaceTwitter +from media import attach_media +from media import replace_you_tube +from media import replace_twitter from content import wordsSimilarity from content import limitRepeatedWords from content import tagExists @@ -79,7 +79,7 @@ from content import removeLongWords from content import addHtmlTags from content import replaceEmojiFromTags from content import removeTextFormatting -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from blocking import isBlocked from blocking import isBlockedDomain from filters import isFiltered @@ -1131,10 +1131,10 @@ def _createPostS2S(base_dir: str, nickname: str, domain: str, port: int, } if attachImageFilename: newPost['object'] = \ - attachMedia(base_dir, http_prefix, nickname, domain, port, - newPost['object'], attachImageFilename, - mediaType, imageDescription, city, low_bandwidth, - content_license_url) + attach_media(base_dir, http_prefix, nickname, domain, port, + newPost['object'], attachImageFilename, + mediaType, imageDescription, city, low_bandwidth, + content_license_url) return newPost @@ -1196,10 +1196,10 @@ def _createPostC2S(base_dir: str, nickname: str, domain: str, port: int, } if attachImageFilename: newPost = \ - attachMedia(base_dir, http_prefix, nickname, domain, port, - newPost, attachImageFilename, - mediaType, imageDescription, city, low_bandwidth, - content_license_url) + attach_media(base_dir, http_prefix, nickname, domain, port, + newPost, attachImageFilename, + mediaType, imageDescription, city, low_bandwidth, + content_license_url) return newPost @@ -2405,14 +2405,14 @@ def sendPost(signing_priv_key_pem: str, project_version: str, send_threads.pop(0) print('WARN: thread killed') thr = \ - threadWithTrace(target=threadSendPost, - args=(session, - postJsonStr, - federation_list, - inboxUrl, base_dir, - signatureHeaderJson.copy(), - postLog, - debug), daemon=True) + thread_with_trace(target=threadSendPost, + args=(session, + postJsonStr, + federation_list, + inboxUrl, base_dir, + signatureHeaderJson.copy(), + postLog, + debug), daemon=True) send_threads.append(thr) thr.start() return 0 @@ -2518,7 +2518,7 @@ def sendPostViaServer(signing_priv_key_pem: str, project_version: str, conversationId, low_bandwidth, content_license_url) - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) if attachImageFilename: headers = { @@ -2770,14 +2770,14 @@ def sendSignedJson(post_json_object: {}, session, base_dir: str, print('DEBUG: starting thread to send post') pprint(post_json_object) thr = \ - threadWithTrace(target=threadSendPost, - args=(session, - postJsonStr, - federation_list, - inboxUrl, base_dir, - signatureHeaderJson.copy(), - postLog, - debug), daemon=True) + thread_with_trace(target=threadSendPost, + args=(session, + postJsonStr, + federation_list, + inboxUrl, base_dir, + signatureHeaderJson.copy(), + postLog, + debug), daemon=True) send_threads.append(thr) # thr.start() return 0 @@ -3029,18 +3029,18 @@ def sendToNamedAddressesThread(session, base_dir: str, """Returns a thread used to send a post to named addresses """ sendThread = \ - threadWithTrace(target=_sendToNamedAddresses, - args=(session, base_dir, - nickname, domain, - onion_domain, i2p_domain, port, - http_prefix, federation_list, - send_threads, postLog, - cached_webfingers, person_cache, - post_json_object, debug, - project_version, - shared_items_federated_domains, - sharedItemFederationTokens, - signing_priv_key_pem), daemon=True) + thread_with_trace(target=_sendToNamedAddresses, + args=(session, base_dir, + nickname, domain, + onion_domain, i2p_domain, port, + http_prefix, federation_list, + send_threads, postLog, + cached_webfingers, person_cache, + post_json_object, debug, + project_version, + shared_items_federated_domains, + sharedItemFederationTokens, + signing_priv_key_pem), daemon=True) try: sendThread.start() except SocketError as ex: @@ -3278,18 +3278,18 @@ def sendToFollowersThread(session, base_dir: str, """Returns a thread used to send a post to followers """ sendThread = \ - threadWithTrace(target=sendToFollowers, - args=(session, base_dir, - nickname, domain, - onion_domain, i2p_domain, port, - http_prefix, federation_list, - send_threads, postLog, - cached_webfingers, person_cache, - post_json_object.copy(), debug, - project_version, - shared_items_federated_domains, - sharedItemFederationTokens, - signing_priv_key_pem), daemon=True) + thread_with_trace(target=sendToFollowers, + args=(session, base_dir, + nickname, domain, + onion_domain, i2p_domain, port, + http_prefix, federation_list, + send_threads, postLog, + cached_webfingers, person_cache, + post_json_object.copy(), debug, + project_version, + shared_items_federated_domains, + sharedItemFederationTokens, + signing_priv_key_pem), daemon=True) try: sendThread.start() except SocketError as ex: @@ -4739,9 +4739,9 @@ def downloadAnnounce(session, base_dir: str, http_prefix: str, recent_posts_cache) return None post_json_object = announcedJson - replaceYouTube(post_json_object, yt_replace_domain, system_language) - replaceTwitter(post_json_object, twitter_replacement_domain, - system_language) + replace_you_tube(post_json_object, yt_replace_domain, system_language) + replace_twitter(post_json_object, twitter_replacement_domain, + system_language) if save_json(post_json_object, announceFilename): return post_json_object return None @@ -4830,7 +4830,7 @@ def sendBlockViaServer(base_dir: str, session, print('DEBUG: block no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -4910,7 +4910,7 @@ def sendMuteViaServer(base_dir: str, session, print('DEBUG: mute no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -4996,7 +4996,7 @@ def sendUndoMuteViaServer(base_dir: str, session, print('DEBUG: undo mute no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -5084,7 +5084,7 @@ def sendUndoBlockViaServer(base_dir: str, session, print('DEBUG: unblock no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -5148,7 +5148,7 @@ def c2sBoxJson(base_dir: str, session, domain_full = get_full_domain(domain, port) actor = local_actor_url(http_prefix, nickname, domain_full) - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) profileStr = 'https://www.w3.org/ns/activitystreams' headers = { diff --git a/reaction.py b/reaction.py index c1993fdad..83050caac 100644 --- a/reaction.py +++ b/reaction.py @@ -34,7 +34,7 @@ from utils import contains_invalid_chars from posts import sendSignedJson from session import postJson from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from posts import getPersonBox # the maximum number of reactions from individual actors which can be @@ -242,7 +242,7 @@ def sendReactionViaServer(base_dir: str, session, print('DEBUG: reaction no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -333,7 +333,7 @@ def sendUndoReactionViaServer(base_dir: str, session, print('DEBUG: unreaction no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, diff --git a/shares.py b/shares.py index 3d45c4d3e..136e3b556 100644 --- a/shares.py +++ b/shares.py @@ -16,7 +16,7 @@ from random import randint from pprint import pprint from session import getJson from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from auth import constantTimeStringCheck from posts import getPersonBox from session import postJson @@ -38,8 +38,8 @@ from utils import is_float from utils import get_category_types from utils import get_shares_files_list from utils import local_actor_url -from media import processMetaData -from media import convertImageToLowBandwidth +from media import process_meta_data +from media import convert_image_to_low_bandwidth from filters import isFilteredGlobally from siteactive import siteIsActive from content import getPriceFromString @@ -360,10 +360,10 @@ def addShare(base_dir: str, if not image_filename.endswith('.' + ext): continue if low_bandwidth: - convertImageToLowBandwidth(image_filename) - processMetaData(base_dir, nickname, domain, - image_filename, itemIDfile + '.' + ext, - city, content_license_url) + convert_image_to_low_bandwidth(image_filename) + process_meta_data(base_dir, nickname, domain, + image_filename, itemIDfile + '.' + ext, + city, content_license_url) if moveImage: try: os.remove(image_filename) @@ -645,7 +645,7 @@ def sendShareViaServer(base_dir, session, print('DEBUG: share no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) if image_filename: headers = { @@ -749,7 +749,7 @@ def sendUndoShareViaServer(base_dir: str, session, print('DEBUG: unshare no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -865,7 +865,7 @@ def sendWantedViaServer(base_dir, session, print('DEBUG: wanted no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) if image_filename: headers = { @@ -969,7 +969,7 @@ def sendUndoWantedViaServer(base_dir: str, session, print('DEBUG: unwant no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(fromNickname, password) + authHeader = create_basic_auth_header(fromNickname, password) headers = { 'host': fromDomain, @@ -1002,7 +1002,7 @@ def getSharedItemsCatalogViaServer(base_dir, session, print('WARN: No session for getSharedItemsCatalogViaServer') return 6 - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, @@ -1482,13 +1482,13 @@ def createSharedItemFederationToken(base_dir: str, return tokensJson -def authorizeSharedItems(shared_items_federated_domains: [], - base_dir: str, - originDomainFull: str, - calling_domainFull: str, - authHeader: str, - debug: bool, - tokensJson: {} = None) -> bool: +def authorize_shared_items(shared_items_federated_domains: [], + base_dir: str, + originDomainFull: str, + calling_domainFull: str, + authHeader: str, + debug: bool, + tokensJson: {} = None) -> bool: """HTTP simple token check for shared item federation """ if not shared_items_federated_domains: diff --git a/skills.py b/skills.py index d88612cea..43f650e3f 100644 --- a/skills.py +++ b/skills.py @@ -9,7 +9,7 @@ __module_group__ = "Profile Metadata" import os from webfinger import webfingerHandle -from auth import createBasicAuthHeader +from auth import create_basic_auth_header from posts import getPersonBox from session import postJson from utils import has_object_string @@ -243,7 +243,7 @@ def sendSkillViaServer(base_dir: str, session, nickname: str, password: str, print('DEBUG: skill no actor was found for ' + handle) return 4 - authHeader = createBasicAuthHeader(nickname, password) + authHeader = create_basic_auth_header(nickname, password) headers = { 'host': domain, diff --git a/tests.py b/tests.py index 23030e34c..f70bf1e8d 100644 --- a/tests.py +++ b/tests.py @@ -32,7 +32,7 @@ from httpsig import verifyPostHeaders from httpsig import messageContentDigest from cache import storePersonInCache from cache import getPersonFromCache -from threads import threadWithTrace +from threads import thread_with_trace from daemon import runDaemon from session import create_session from session import getJson @@ -105,9 +105,9 @@ from roles import setRolesFromList from roles import setRole from roles import actorHasRole from auth import constantTimeStringCheck -from auth import createBasicAuthHeader -from auth import authorizeBasic -from auth import storeBasicCredentials +from auth import create_basic_auth_header +from auth import authorize_basic +from auth import store_basic_credentials from like import likePost from like import sendLikeViaServer from reaction import reactionPost @@ -163,7 +163,7 @@ from languages import getLinksFromContent from languages import addLinksToContent from languages import libretranslate from languages import libretranslateLanguages -from shares import authorizeSharedItems +from shares import authorize_shared_items from shares import generateSharedItemFederationTokens from shares import createSharedItemFederationToken from shares import updateSharedItemFederationToken @@ -667,9 +667,9 @@ def _testThreadsFunction(param: str): def _testThreads(): print('testThreads') thr = \ - threadWithTrace(target=_testThreadsFunction, - args=('test',), - daemon=True) + thread_with_trace(target=_testThreadsFunction, + args=('test',), + daemon=True) thr.start() assert thr.is_alive() is True time.sleep(1) @@ -1145,11 +1145,11 @@ def testPostMessageBetweenServers(base_dir: str) -> None: thrAlice.kill() thrAlice = \ - threadWithTrace(target=createServerAlice, - args=(aliceDir, aliceDomain, alicePort, bobAddress, - federation_list, False, False, - aliceSendThreads), - daemon=True) + thread_with_trace(target=createServerAlice, + args=(aliceDir, aliceDomain, alicePort, bobAddress, + federation_list, False, False, + aliceSendThreads), + daemon=True) global thrBob if thrBob: @@ -1159,11 +1159,11 @@ def testPostMessageBetweenServers(base_dir: str) -> None: thrBob.kill() thrBob = \ - threadWithTrace(target=createServerBob, - args=(bobDir, bobDomain, bobPort, aliceAddress, - federation_list, False, False, - bobSendThreads), - daemon=True) + thread_with_trace(target=createServerBob, + args=(bobDir, bobDomain, bobPort, aliceAddress, + federation_list, False, False, + bobSendThreads), + daemon=True) thrAlice.start() thrBob.start() @@ -1469,11 +1469,11 @@ def testFollowBetweenServers(base_dir: str) -> None: thrAlice.kill() thrAlice = \ - threadWithTrace(target=createServerAlice, - args=(aliceDir, aliceDomain, alicePort, bobAddress, - federation_list, False, False, - aliceSendThreads), - daemon=True) + thread_with_trace(target=createServerAlice, + args=(aliceDir, aliceDomain, alicePort, bobAddress, + federation_list, False, False, + aliceSendThreads), + daemon=True) global thrBob if thrBob: @@ -1483,11 +1483,11 @@ def testFollowBetweenServers(base_dir: str) -> None: thrBob.kill() thrBob = \ - threadWithTrace(target=createServerBob, - args=(bobDir, bobDomain, bobPort, aliceAddress, - federation_list, False, False, - bobSendThreads), - daemon=True) + thread_with_trace(target=createServerBob, + args=(bobDir, bobDomain, bobPort, aliceAddress, + federation_list, False, False, + bobSendThreads), + daemon=True) thrAlice.start() thrBob.start() @@ -1661,11 +1661,11 @@ def testSharedItemsFederation(base_dir: str) -> None: thrAlice.kill() thrAlice = \ - threadWithTrace(target=createServerAlice, - args=(aliceDir, aliceDomain, alicePort, bobAddress, - federation_list, False, False, - aliceSendThreads), - daemon=True) + thread_with_trace(target=createServerAlice, + args=(aliceDir, aliceDomain, alicePort, bobAddress, + federation_list, False, False, + aliceSendThreads), + daemon=True) global thrBob if thrBob: @@ -1675,11 +1675,11 @@ def testSharedItemsFederation(base_dir: str) -> None: thrBob.kill() thrBob = \ - threadWithTrace(target=createServerBob, - args=(bobDir, bobDomain, bobPort, aliceAddress, - federation_list, False, False, - bobSendThreads), - daemon=True) + thread_with_trace(target=createServerBob, + args=(bobDir, bobDomain, bobPort, aliceAddress, + federation_list, False, False, + bobSendThreads), + daemon=True) thrAlice.start() thrBob.start() @@ -2070,12 +2070,12 @@ def testGroupFollow(base_dir: str) -> None: thrAlice.kill() thrAlice = \ - threadWithTrace(target=createServerAlice, - args=(aliceDir, aliceDomain, alicePort, - testgroupAddress, - federation_list, False, True, - aliceSendThreads), - daemon=True) + thread_with_trace(target=createServerAlice, + args=(aliceDir, aliceDomain, alicePort, + testgroupAddress, + federation_list, False, True, + aliceSendThreads), + daemon=True) global thrBob if thrBob: @@ -2085,11 +2085,11 @@ def testGroupFollow(base_dir: str) -> None: thrBob.kill() thrBob = \ - threadWithTrace(target=createServerBob, - args=(bobDir, bobDomain, bobPort, None, - federation_list, False, False, - bobSendThreads), - daemon=True) + thread_with_trace(target=createServerBob, + args=(bobDir, bobDomain, bobPort, None, + federation_list, False, False, + bobSendThreads), + daemon=True) global thrGroup if thrGroup: @@ -2099,11 +2099,11 @@ def testGroupFollow(base_dir: str) -> None: thrGroup.kill() thrGroup = \ - threadWithTrace(target=createServerGroup, - args=(testgroupDir, testgroupDomain, testgroupPort, - federation_list, False, False, - testgroupSendThreads), - daemon=True) + thread_with_trace(target=createServerGroup, + args=(testgroupDir, testgroupDomain, testgroupPort, + federation_list, False, False, + testgroupSendThreads), + daemon=True) thrAlice.start() thrBob.start() @@ -2748,29 +2748,29 @@ def _testAuthentication(base_dir: str) -> None: os.mkdir(base_dir) os.chdir(base_dir) - assert storeBasicCredentials(base_dir, 'othernick', 'otherpass') - assert storeBasicCredentials(base_dir, 'bad:nick', 'otherpass') is False - assert storeBasicCredentials(base_dir, 'badnick', 'otherpa:ss') is False - assert storeBasicCredentials(base_dir, nickname, password) + assert store_basic_credentials(base_dir, 'othernick', 'otherpass') + assert store_basic_credentials(base_dir, 'bad:nick', 'otherpass') is False + assert store_basic_credentials(base_dir, 'badnick', 'otherpa:ss') is False + assert store_basic_credentials(base_dir, nickname, password) - authHeader = createBasicAuthHeader(nickname, password) - assert authorizeBasic(base_dir, '/users/' + nickname + '/inbox', - authHeader, False) - assert authorizeBasic(base_dir, '/users/' + nickname, - authHeader, False) is False - assert authorizeBasic(base_dir, '/users/othernick/inbox', - authHeader, False) is False + authHeader = create_basic_auth_header(nickname, password) + assert authorize_basic(base_dir, '/users/' + nickname + '/inbox', + authHeader, False) + assert authorize_basic(base_dir, '/users/' + nickname, + authHeader, False) is False + assert authorize_basic(base_dir, '/users/othernick/inbox', + authHeader, False) is False - authHeader = createBasicAuthHeader(nickname, password + '1') - assert authorizeBasic(base_dir, '/users/' + nickname + '/inbox', - authHeader, False) is False + authHeader = create_basic_auth_header(nickname, password + '1') + assert authorize_basic(base_dir, '/users/' + nickname + '/inbox', + authHeader, False) is False password = 'someOtherPassword' - assert storeBasicCredentials(base_dir, nickname, password) + assert store_basic_credentials(base_dir, nickname, password) - authHeader = createBasicAuthHeader(nickname, password) - assert authorizeBasic(base_dir, '/users/' + nickname + '/inbox', - authHeader, False) + authHeader = create_basic_auth_header(nickname, password) + assert authorize_basic(base_dir, '/users/' + nickname + '/inbox', + authHeader, False) os.chdir(currDir) shutil.rmtree(base_dir, ignore_errors=False, onerror=None) @@ -2816,11 +2816,11 @@ def testClientToServer(base_dir: str): thrAlice.kill() thrAlice = \ - threadWithTrace(target=createServerAlice, - args=(aliceDir, aliceDomain, alicePort, bobAddress, - federation_list, False, False, - aliceSendThreads), - daemon=True) + thread_with_trace(target=createServerAlice, + args=(aliceDir, aliceDomain, alicePort, bobAddress, + federation_list, False, False, + aliceSendThreads), + daemon=True) global thrBob if thrBob: @@ -2830,11 +2830,11 @@ def testClientToServer(base_dir: str): thrBob.kill() thrBob = \ - threadWithTrace(target=createServerBob, - args=(bobDir, bobDomain, bobPort, aliceAddress, - federation_list, False, False, - bobSendThreads), - daemon=True) + thread_with_trace(target=createServerBob, + args=(bobDir, bobDomain, bobPort, aliceAddress, + federation_list, False, False, + bobSendThreads), + daemon=True) thrAlice.start() thrBob.start() @@ -5091,11 +5091,11 @@ def testUpdateActor(base_dir: str): thrAlice.kill() thrAlice = \ - threadWithTrace(target=createServerAlice, - args=(aliceDir, aliceDomain, alicePort, bobAddress, - federation_list, False, False, - aliceSendThreads), - daemon=True) + thread_with_trace(target=createServerAlice, + args=(aliceDir, aliceDomain, alicePort, bobAddress, + federation_list, False, False, + aliceSendThreads), + daemon=True) thrAlice.start() assert thrAlice.is_alive() is True @@ -5643,14 +5643,14 @@ def _testAuthorizeSharedItems(): assert len(tokensJson['dog.domain']) == 0 assert len(tokensJson['cat.domain']) >= 64 assert len(tokensJson['birb.domain']) == 0 - assert not authorizeSharedItems(shared_items_fed_domains, None, - 'birb.domain', - 'cat.domain', 'M' * 86, - False, tokensJson) - assert authorizeSharedItems(shared_items_fed_domains, None, - 'birb.domain', - 'cat.domain', tokensJson['cat.domain'], - False, tokensJson) + assert not authorize_shared_items(shared_items_fed_domains, None, + 'birb.domain', + 'cat.domain', 'M' * 86, + False, tokensJson) + assert authorize_shared_items(shared_items_fed_domains, None, + 'birb.domain', + 'cat.domain', tokensJson['cat.domain'], + False, tokensJson) tokensJson = \ updateSharedItemFederationToken(None, 'dog.domain', 'testToken', diff --git a/threads.py b/threads.py index fede4f3d5..61a92bc05 100644 --- a/threads.py +++ b/threads.py @@ -13,7 +13,7 @@ import time import datetime -class threadWithTrace(threading.Thread): +class thread_with_trace(threading.Thread): def __init__(self, *args, **keywords): self.startTime = datetime.datetime.utcnow() self.isStarted = False @@ -69,13 +69,13 @@ class threadWithTrace(threading.Thread): self.killed = True def clone(self, fn): - return threadWithTrace(target=fn, - args=self._args, - daemon=True) + return thread_with_trace(target=fn, + args=self._args, + daemon=True) -def removeDormantThreads(base_dir: str, threadsList: [], debug: bool, - timeoutMins: int) -> None: +def remove_dormant_threads(base_dir: str, threadsList: [], debug: bool, + timeoutMins: int) -> None: """Removes threads whose execution has completed """ if len(threadsList) == 0: @@ -150,5 +150,5 @@ def removeDormantThreads(base_dir: str, threadsList: [], debug: bool, ',' + str(noOfActiveThreads) + ',' + str(len(threadsList)) + '\n') except OSError: - print('EX: removeDormantThreads unable to write ' + + print('EX: remove_dormant_threads unable to write ' + sendLogFilename) diff --git a/webapp_post.py b/webapp_post.py index 0a1fb204d..7fde18c1f 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -11,7 +11,7 @@ import os import time import urllib.parse from dateutil.parser import parse -from auth import createPassword +from auth import create_password from git import isGitPatch from datetime import datetime from cache import getPersonFromCache @@ -1902,7 +1902,7 @@ def individualPostAsHtml(signing_priv_key_pem: str, contentStr, post_json_object, pageNumber) else: - postID = 'post' + str(createPassword(8)) + postID = 'post' + str(create_password(8)) contentStr = '' if post_json_object['object'].get('summary'): cwStr = str(post_json_object['object']['summary'])