From f15fed2145ea66a5d101cf1e616e9d2e292e3ffd Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Mon, 27 Dec 2021 17:42:35 +0000 Subject: [PATCH] Snake case --- announce.py | 8 ++++---- daemon.py | 6 +++--- follow.py | 8 ++++---- inbox.py | 4 ++-- newsdaemon.py | 4 ++-- person.py | 8 ++++---- pgp.py | 4 ++-- posts.py | 8 ++++---- roles.py | 4 ++-- schedule.py | 4 ++-- tests.py | 4 ++-- utils.py | 26 +++++++++++++------------- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/announce.py b/announce.py index 6df65d954..9f8b240ba 100644 --- a/announce.py +++ b/announce.py @@ -13,7 +13,7 @@ from utils import remove_domain_port from utils import remove_id_ending from utils import has_users_path from utils import get_full_domain -from utils import getStatusNumber +from utils import get_status_number from utils import createOutboxDir from utils import urlPermitted from utils import getNicknameFromActor @@ -137,7 +137,7 @@ def createAnnounce(session, base_dir: str, federation_list: [], domain = remove_domain_port(domain) fullDomain = get_full_domain(domain, port) - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() newAnnounceId = http_prefix + '://' + fullDomain + \ '/users/' + nickname + '/statuses/' + statusNumber atomUriStr = local_actor_url(http_prefix, nickname, fullDomain) + \ @@ -229,7 +229,7 @@ def sendAnnounceViaServer(base_dir: str, session, actorStr = local_actor_url(http_prefix, fromNickname, fromDomainFull) ccUrl = actorStr + '/followers' - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() newAnnounceId = actorStr + '/statuses/' + statusNumber newAnnounceJson = { "@context": "https://www.w3.org/ns/activitystreams", @@ -321,7 +321,7 @@ def sendUndoAnnounceViaServer(base_dir: str, session, actor = local_actor_url(http_prefix, nickname, domain_full) handle = replace_users_with_at(actor) - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() unAnnounceJson = { '@context': 'https://www.w3.org/ns/activitystreams', 'id': actor + '/statuses/' + str(statusNumber) + '/undo', diff --git a/daemon.py b/daemon.py index a3c52c862..9d5f2960e 100644 --- a/daemon.py +++ b/daemon.py @@ -295,7 +295,7 @@ from utils import get_cached_post_filename from utils import remove_post_from_cache from utils import getNicknameFromActor from utils import getDomainFromActor -from utils import getStatusNumber +from utils import get_status_number from utils import urlPermitted from utils import load_json from utils import save_json @@ -2941,7 +2941,7 @@ class PubServer(BaseHTTPRequestHandler): followingActor) followActor = \ local_actor_url(http_prefix, followerNickname, domain_full) - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() followId = followActor + '/statuses/' + str(statusNumber) unfollowJson = { '@context': 'https://www.w3.org/ns/activitystreams', @@ -6518,7 +6518,7 @@ class PubServer(BaseHTTPRequestHandler): actor_json['id'].replace('/', '#') + '.json' save_json(actor_json, actorCacheFilename) # send profile update to followers - pubNumber, pubDate = getStatusNumber() + pubNumber, pubDate = get_status_number() updateActorJson = getActorUpdateJson(actor_json) print('Sending actor update: ' + str(updateActorJson)) self._postToOutbox(updateActorJson, diff --git a/follow.py b/follow.py index 373c1530e..6c1f1e286 100644 --- a/follow.py +++ b/follow.py @@ -19,7 +19,7 @@ from utils import validNickname from utils import domainPermitted from utils import getDomainFromActor from utils import getNicknameFromActor -from utils import getStatusNumber +from utils import get_status_number from utils import follow_person from posts import sendSignedJson from posts import getPersonBox @@ -869,7 +869,7 @@ def sendFollowRequest(session, base_dir: str, requestDomain = get_full_domain(followDomain, followPort) - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() group_account = False if followNickname: @@ -962,7 +962,7 @@ def sendFollowRequestViaServer(base_dir: str, session, followedId = \ http_prefix + '://' + followDomainFull + '/@' + followNickname - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() newFollowJson = { '@context': 'https://www.w3.org/ns/activitystreams', 'id': followActor + '/statuses/' + str(statusNumber), @@ -1050,7 +1050,7 @@ def sendUnfollowRequestViaServer(base_dir: str, session, followActor = local_actor_url(http_prefix, fromNickname, fromDomainFull) followedId = \ http_prefix + '://' + followDomainFull + '/@' + followNickname - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() unfollowJson = { '@context': 'https://www.w3.org/ns/activitystreams', diff --git a/inbox.py b/inbox.py index b03d581d6..f7091f549 100644 --- a/inbox.py +++ b/inbox.py @@ -48,7 +48,7 @@ from utils import get_cached_post_filename from utils import remove_post_from_cache from utils import urlPermitted from utils import createInboxQueueDir -from utils import getStatusNumber +from utils import get_status_number from utils import getDomainFromActor from utils import getNicknameFromActor from utils import locate_post @@ -540,7 +540,7 @@ def savePostToInboxQueue(base_dir: str, http_prefix: str, post_id = remove_id_ending(post_json_object['id']) published = curr_time.strftime("%Y-%m-%dT%H:%M:%SZ") if not post_id: - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() if actor: post_id = actor + '/statuses/' + statusNumber else: diff --git a/newsdaemon.py b/newsdaemon.py index 0fa7ac612..647c33625 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -30,7 +30,7 @@ from utils import remove_html from utils import get_full_domain from utils import load_json from utils import save_json -from utils import getStatusNumber +from utils import get_status_number from utils import clearFromPostCaches from utils import dangerousMarkup from utils import local_actor_url @@ -581,7 +581,7 @@ def _convertRSStoActivityPub(base_dir: str, http_prefix: str, str(dateStrWithOffset)) continue - statusNumber, published = getStatusNumber(dateStr) + statusNumber, published = get_status_number(dateStr) newPostId = \ local_actor_url(http_prefix, 'news', domain) + \ '/statuses/' + statusNumber diff --git a/person.py b/person.py index 988255434..5e84e294a 100644 --- a/person.py +++ b/person.py @@ -43,7 +43,7 @@ from utils import containsInvalidChars from utils import replace_users_with_at from utils import remove_line_endings from utils import remove_domain_port -from utils import getStatusNumber +from utils import get_status_number from utils import get_full_domain from utils import validNickname from utils import load_json @@ -199,7 +199,7 @@ def randomizeActorImages(personJson: {}) -> None: def getActorUpdateJson(actor_json: {}) -> {}: """Returns the json for an Person Update """ - pubNumber, _ = getStatusNumber() + pubNumber, _ = get_status_number() manuallyApprovesFollowers = actor_json['manuallyApprovesFollowers'] return { '@context': [ @@ -403,7 +403,7 @@ def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int, personId + '/avatar' + \ str(randint(10000000000000, 99999999999999)) + '.png' # nosec - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() newPerson = { '@context': [ 'https://www.w3.org/ns/activitystreams', @@ -740,7 +740,7 @@ def personUpgradeActor(base_dir: str, personJson: {}, updateActor = True if not personJson.get('published'): - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() personJson['published'] = published updateActor = True diff --git a/pgp.py b/pgp.py index 4c3727b73..83a894010 100644 --- a/pgp.py +++ b/pgp.py @@ -14,7 +14,7 @@ from person import getActorJson from utils import contains_pgp_public_key from utils import is_pgp_encrypted from utils import get_full_domain -from utils import getStatusNumber +from utils import get_status_number from utils import local_actor_url from utils import replace_users_with_at from webfinger import webfingerHandle @@ -542,7 +542,7 @@ def pgpPublicKeyUpload(base_dir: str, session, setPGPpubKey(actor_json, PGPpubKey) # create an actor update - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() actorUpdate = { '@context': 'https://www.w3.org/ns/activitystreams', 'id': actor + '#updates/' + statusNumber, diff --git a/posts.py b/posts.py index 00a3c2756..3169f6033 100644 --- a/posts.py +++ b/posts.py @@ -51,7 +51,7 @@ from utils import valid_post_date from utils import get_full_domain from utils import get_followers_list from utils import isEvil -from utils import getStatusNumber +from utils import get_status_number from utils import createPersonDir from utils import urlPermitted from utils import getNicknameFromActor @@ -919,7 +919,7 @@ def savePostToBox(base_dir: str, http_prefix: str, post_id: str, domain = remove_domain_port(domain) if not post_id: - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() post_id = \ local_actor_url(http_prefix, nickname, originalDomain) + \ '/statuses/' + statusNumber @@ -1426,7 +1426,7 @@ def _createPostBase(base_dir: str, if tag['name'] not in content: del hashtagsDict[tagName] - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() newPostId = \ local_actor_url(http_prefix, nickname, domain) + \ '/statuses/' + statusNumber @@ -1570,7 +1570,7 @@ def outboxMessageCreateWrap(http_prefix: str, """ domain = get_full_domain(domain, port) - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() if message_json.get('published'): published = message_json['published'] newPostId = \ diff --git a/roles.py b/roles.py index 06b79452c..843b5e1aa 100644 --- a/roles.py +++ b/roles.py @@ -10,7 +10,7 @@ __module_group__ = "Profile Metadata" import os from utils import load_json from utils import save_json -from utils import getStatusNumber +from utils import get_status_number from utils import remove_domain_port from utils import acct_dir @@ -153,7 +153,7 @@ def _setActorRole(actor_json: {}, roleName: str) -> bool: continue if occupationItem['hasOccupation']['name'] == roleName: return True - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() newRole = { "@type": "Role", "hasOccupation": { diff --git a/schedule.py b/schedule.py index 767a8d8c9..5234398f4 100644 --- a/schedule.py +++ b/schedule.py @@ -11,7 +11,7 @@ import os import time import datetime from utils import has_object_dict -from utils import getStatusNumber +from utils import get_status_number from utils import load_json from utils import is_account_dir from utils import acct_dir @@ -82,7 +82,7 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd, # set the published time # If this is not recent then http checks on the receiving side # will reject it - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() if post_json_object.get('published'): post_json_object['published'] = published if has_object_dict(post_json_object): diff --git a/tests.py b/tests.py index f702938cb..9a2d3f560 100644 --- a/tests.py +++ b/tests.py @@ -80,7 +80,7 @@ from utils import getDomainFromActor from utils import copytree from utils import load_json from utils import save_json -from utils import getStatusNumber +from utils import get_status_number from utils import get_followers_of_person from utils import remove_html from utils import dangerousMarkup @@ -3459,7 +3459,7 @@ def _testGetStatusNumber(): print('testGetStatusNumber') prevStatusNumber = None for i in range(1, 20): - statusNumber, published = getStatusNumber() + statusNumber, published = get_status_number() if prevStatusNumber: assert len(statusNumber) == 18 assert int(statusNumber) > prevStatusNumber diff --git a/utils.py b/utils.py index 146fe2bb0..969e1fd46 100644 --- a/utils.py +++ b/utils.py @@ -657,8 +657,8 @@ def save_json(json_object: {}, filename: str) -> bool: tries = 0 while tries < 5: try: - with open(filename, 'w+') as fp: - fp.write(json.dumps(json_object)) + with open(filename, 'w+') as json_file: + json_file.write(json.dumps(json_object)) return True except OSError: print('EX: save_json ' + str(tries)) @@ -670,20 +670,20 @@ def save_json(json_object: {}, filename: str) -> bool: def load_json(filename: str, delay_sec: int = 2, max_tries: int = 5) -> {}: """Makes a few attempts to load a json formatted file """ - jsonObject = None + json_object = None tries = 0 while tries < max_tries: try: - with open(filename, 'r') as fp: - data = fp.read() - jsonObject = json.loads(data) + with open(filename, 'r') as json_file: + data = json_file.read() + json_object = json.loads(data) break except BaseException: print('EX: load_json exception ' + str(filename)) if delay_sec > 0: time.sleep(delay_sec) tries += 1 - return jsonObject + return json_object def load_json_onionify(filename: str, domain: str, onion_domain: str, @@ -691,27 +691,27 @@ def load_json_onionify(filename: str, domain: str, onion_domain: str, """Makes a few attempts to load a json formatted file This also converts the domain name to the onion domain """ - jsonObject = None + json_object = None tries = 0 while tries < 5: try: - with open(filename, 'r') as fp: - data = fp.read() + with open(filename, 'r') as json_file: + data = json_file.read() if data: data = data.replace(domain, onion_domain) data = data.replace('https:', 'http:') print('*****data: ' + data) - jsonObject = json.loads(data) + json_object = json.loads(data) break except BaseException: print('EX: load_json_onionify exception ' + str(filename)) if delay_sec > 0: time.sleep(delay_sec) tries += 1 - return jsonObject + return json_object -def getStatusNumber(publishedStr: str = None) -> (str, str): +def get_status_number(publishedStr: str = None) -> (str, str): """Returns the status number and published date """ if not publishedStr: