From 34e533f2898485377037702de43415a41c6bb27b Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 28 Dec 2021 17:20:43 +0000 Subject: [PATCH] Snake case --- daemon.py | 85 ++++++++++++++++++++++++----------------------- enigma.py | 4 +-- mastoapiv1.py | 28 ++++++++-------- metadata.py | 14 ++++---- webapp_profile.py | 6 ++-- webfinger.py | 20 +++++------ 6 files changed, 79 insertions(+), 78 deletions(-) diff --git a/daemon.py b/daemon.py index 488d72d98..a6d3d2e00 100644 --- a/daemon.py +++ b/daemon.py @@ -24,13 +24,13 @@ from shutil import copyfile from session import create_session from webfinger import webfinger_meta from webfinger import webfinger_node_info -from webfinger import webfingerLookup -from webfinger import webfingerUpdate -from mastoapiv1 import mastoApiV1Response -from metadata import metaDataNodeInfo -from metadata import metadataCustomEmoji -from enigma import getEnigmaPubKey -from enigma import setEnigmaPubKey +from webfinger import webfinger_lookup +from webfinger import webfinger_update +from mastoapiv1 import masto_api_v1_response +from metadata import meta_data_node_info +from metadata import metadata_custom_emoji +from enigma import get_enigma_pub_key +from enigma import set_enigma_pub_key from pgp import getEmailAddress from pgp import setEmailAddress from pgp import getPGPpubKey @@ -1062,23 +1062,24 @@ class PubServer(BaseHTTPRequestHandler): self._update_known_crawlers(uaStr) broch_mode = broch_modeIsActive(base_dir) - sendJson, sendJsonStr = mastoApiV1Response(path, - calling_domain, - uaStr, - authorized, - http_prefix, - base_dir, - nickname, domain, - domain_full, - onion_domain, - i2p_domain, - translate, - registration, - system_language, - project_version, - customEmoji, - show_node_info_accounts, - broch_mode) + sendJson, sendJsonStr = \ + masto_api_v1_response(path, + calling_domain, + uaStr, + authorized, + http_prefix, + base_dir, + nickname, domain, + domain_full, + onion_domain, + i2p_domain, + translate, + registration, + system_language, + project_version, + customEmoji, + show_node_info_accounts, + broch_mode) if sendJson is not None: msg = json.dumps(sendJson).encode('utf-8') @@ -1146,11 +1147,11 @@ class PubServer(BaseHTTPRequestHandler): instanceUrl = self._get_instance_url(calling_domain) aboutUrl = instanceUrl + '/about' termsOfServiceUrl = instanceUrl + '/terms' - info = metaDataNodeInfo(self.server.base_dir, - aboutUrl, termsOfServiceUrl, - self.server.registration, - nodeInfoVersion, - show_node_info_accounts) + info = meta_data_node_info(self.server.base_dir, + aboutUrl, termsOfServiceUrl, + self.server.registration, + nodeInfoVersion, + show_node_info_accounts) if info: msg = json.dumps(info).encode('utf-8') msglen = len(msg) @@ -1243,9 +1244,9 @@ class PubServer(BaseHTTPRequestHandler): print('DEBUG: WEBFINGER lookup ' + self.path + ' ' + str(self.server.base_dir)) wfResult = \ - webfingerLookup(self.path, self.server.base_dir, - self.server.domain, self.server.onion_domain, - self.server.port, self.server.debug) + webfinger_lookup(self.path, self.server.base_dir, + self.server.domain, self.server.onion_domain, + self.server.port, self.server.debug) if wfResult: msg = json.dumps(wfResult).encode('utf-8') msglen = len(msg) @@ -5382,15 +5383,15 @@ class PubServer(BaseHTTPRequestHandler): actorChanged = True # change Enigma public key - currentEnigmaPubKey = getEnigmaPubKey(actor_json) + currentEnigmaPubKey = get_enigma_pub_key(actor_json) if fields.get('enigmapubkey'): if fields['enigmapubkey'] != currentEnigmaPubKey: - setEnigmaPubKey(actor_json, - fields['enigmapubkey']) + set_enigma_pub_key(actor_json, + fields['enigmapubkey']) actorChanged = True else: if currentEnigmaPubKey: - setEnigmaPubKey(actor_json, '') + set_enigma_pub_key(actor_json, '') actorChanged = True # change PGP public key @@ -6488,10 +6489,10 @@ class PubServer(BaseHTTPRequestHandler): addActorUpdateTimestamp(actor_json) # save the actor save_json(actor_json, actorFilename) - webfingerUpdate(base_dir, - nickname, domain, - onion_domain, - self.server.cached_webfingers) + webfinger_update(base_dir, + nickname, domain, + onion_domain, + self.server.cached_webfingers) # also copy to the actors cache and # person_cache in memory storePersonInCache(base_dir, @@ -7121,7 +7122,7 @@ class PubServer(BaseHTTPRequestHandler): jamiAddress = getJamiAddress(actor_json) cwtchAddress = getCwtchAddress(actor_json) emailAddress = getEmailAddress(actor_json) - EnigmaPubKey = getEnigmaPubKey(actor_json) + EnigmaPubKey = get_enigma_pub_key(actor_json) PGPpubKey = getPGPpubKey(actor_json) PGPfingerprint = getPGPfingerprint(actor_json) if actor_json.get('alsoKnownAs'): @@ -18795,7 +18796,7 @@ def runDaemon(content_license_url: str, # get the list of custom emoji, for use by the mastodon api httpd.customEmoji = \ - metadataCustomEmoji(base_dir, http_prefix, httpd.domain_full) + metadata_custom_emoji(base_dir, http_prefix, httpd.domain_full) # whether to enable broch mode, which locks down the instance setBrochMode(base_dir, httpd.domain_full, broch_mode) diff --git a/enigma.py b/enigma.py index 8767d9f4f..e70d3ffd8 100644 --- a/enigma.py +++ b/enigma.py @@ -8,7 +8,7 @@ __status__ = "Production" __module_group__ = "Profile Metadata" -def getEnigmaPubKey(actor_json: {}) -> str: +def get_enigma_pub_key(actor_json: {}) -> str: """Returns Enigma public key for the given actor """ if not actor_json.get('attachment'): @@ -28,7 +28,7 @@ def getEnigmaPubKey(actor_json: {}) -> str: return '' -def setEnigmaPubKey(actor_json: {}, enigmaPubKey: str) -> None: +def set_enigma_pub_key(actor_json: {}, enigmaPubKey: str) -> None: """Sets a Enigma public key for the given actor """ removeKey = False diff --git a/mastoapiv1.py b/mastoapiv1.py index fdbeddcab..5191df508 100644 --- a/mastoapiv1.py +++ b/mastoapiv1.py @@ -81,20 +81,20 @@ def _getMastoApiV1Account(base_dir: str, nickname: str, domain: str) -> {}: return mastoAccountJson -def mastoApiV1Response(path: str, calling_domain: str, - uaStr: str, - authorized: bool, - http_prefix: str, - base_dir: str, nickname: str, domain: str, - domain_full: str, - onion_domain: str, i2p_domain: str, - translate: {}, - registration: bool, - system_language: str, - project_version: str, - customEmoji: [], - show_node_info_accounts: bool, - broch_mode: bool) -> ({}, str): +def masto_api_v1_response(path: str, calling_domain: str, + uaStr: str, + authorized: bool, + http_prefix: str, + base_dir: str, nickname: str, domain: str, + domain_full: str, + onion_domain: str, i2p_domain: str, + translate: {}, + registration: bool, + system_language: str, + project_version: str, + customEmoji: [], + show_node_info_accounts: bool, + broch_mode: bool) -> ({}, str): """This is a vestigil mastodon API for the purpose of returning an empty result to sites like https://mastopeek.app-dist.eu diff --git a/metadata.py b/metadata.py index ffe6373a6..0a77feb13 100644 --- a/metadata.py +++ b/metadata.py @@ -31,11 +31,11 @@ def _getStatusCount(base_dir: str) -> int: return statusCtr -def metaDataNodeInfo(base_dir: str, - aboutUrl: str, - termsOfServiceUrl: str, - registration: bool, version: str, - showAccounts: bool) -> {}: +def meta_data_node_info(base_dir: str, + aboutUrl: str, + termsOfServiceUrl: str, + registration: bool, version: str, + showAccounts: bool) -> {}: """ /nodeinfo/2.0 endpoint Also see https://socialhub.activitypub.rocks/t/ fep-f1d5-nodeinfo-in-fediverse-software/1190/4 @@ -207,8 +207,8 @@ def metaDataInstance(showAccounts: bool, return instance -def metadataCustomEmoji(base_dir: str, - http_prefix: str, domain_full: str) -> {}: +def metadata_custom_emoji(base_dir: str, + http_prefix: str, domain_full: str) -> {}: """Returns the custom emoji Endpoint /api/v1/custom_emojis See https://docs.joinmastodon.org/methods/instance/custom_emojis diff --git a/webapp_profile.py b/webapp_profile.py index f2d9223e8..e5e63a2d7 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -47,7 +47,7 @@ from ssb import getSSBAddress from pgp import getEmailAddress from pgp import getPGPfingerprint from pgp import getPGPpubKey -from enigma import getEnigmaPubKey +from enigma import get_enigma_pub_key from tox import getToxAddress from briar import getBriarAddress from jami import getJamiAddress @@ -635,7 +635,7 @@ def htmlProfile(signing_priv_key_pem: str, donateUrl = getDonationUrl(profile_json) websiteUrl = getWebsite(profile_json, translate) blogAddress = getBlogAddress(profile_json) - EnigmaPubKey = getEnigmaPubKey(profile_json) + EnigmaPubKey = get_enigma_pub_key(profile_json) PGPpubKey = getPGPpubKey(profile_json) PGPfingerprint = getPGPfingerprint(profile_json) emailAddress = getEmailAddress(profile_json) @@ -2141,7 +2141,7 @@ def htmlEditProfile(css_cache: {}, translate: {}, base_dir: str, path: str, jamiAddress = getJamiAddress(actor_json) cwtchAddress = getCwtchAddress(actor_json) emailAddress = getEmailAddress(actor_json) - EnigmaPubKey = getEnigmaPubKey(actor_json) + EnigmaPubKey = get_enigma_pub_key(actor_json) PGPpubKey = getPGPpubKey(actor_json) PGPfingerprint = getPGPfingerprint(actor_json) if actor_json.get('name'): diff --git a/webfinger.py b/webfinger.py index 1b649db71..89e252ae0 100644 --- a/webfinger.py +++ b/webfinger.py @@ -214,9 +214,9 @@ def webfinger_meta(http_prefix: str, domain_full: str) -> str: return metaStr -def webfingerLookup(path: str, base_dir: str, - domain: str, onion_domain: str, - port: int, debug: bool) -> {}: +def webfinger_lookup(path: str, base_dir: str, + domain: str, onion_domain: str, + port: int, debug: bool) -> {}: """Lookup the webfinger endpoint for an account """ if not path.startswith('/.well-known/webfinger?'): @@ -279,7 +279,7 @@ def webfingerLookup(path: str, base_dir: str, return wfJson -def _webfingerUpdateAvatar(wfJson: {}, actor_json: {}) -> bool: +def _webfinger_updateAvatar(wfJson: {}, actor_json: {}) -> bool: """Updates the avatar image link """ found = False @@ -337,7 +337,7 @@ def _webfingerAddBlogLink(wfJson: {}, actor_json: {}) -> bool: return True -def _webfingerUpdateFromProfile(wfJson: {}, actor_json: {}) -> bool: +def _webfinger_updateFromProfile(wfJson: {}, actor_json: {}) -> bool: """Updates webfinger Email/blog/xmpp links from profile Returns true if one or more tags has been changed """ @@ -411,7 +411,7 @@ def _webfingerUpdateFromProfile(wfJson: {}, actor_json: {}) -> bool: wfJson['aliases'].remove(fullAlias) changed = True - if _webfingerUpdateAvatar(wfJson, actor_json): + if _webfinger_updateAvatar(wfJson, actor_json): changed = True if _webfingerAddBlogLink(wfJson, actor_json): @@ -420,9 +420,9 @@ def _webfingerUpdateFromProfile(wfJson: {}, actor_json: {}) -> bool: return changed -def webfingerUpdate(base_dir: str, nickname: str, domain: str, - onion_domain: str, - cached_webfingers: {}) -> None: +def webfinger_update(base_dir: str, nickname: str, domain: str, + onion_domain: str, + cached_webfingers: {}) -> None: handle = nickname + '@' + domain wfSubdir = '/wfendpoints' if not os.path.isdir(base_dir + wfSubdir): @@ -446,6 +446,6 @@ def webfingerUpdate(base_dir: str, nickname: str, domain: str, if not actor_json: return - if _webfingerUpdateFromProfile(wfJson, actor_json): + if _webfinger_updateFromProfile(wfJson, actor_json): if save_json(wfJson, filename): storeWebfingerInCache(handle, wfJson, cached_webfingers)