Snake case

merge-requests/30/head
Bob Mottram 2021-12-27 17:42:35 +00:00
parent 218ea067c0
commit f15fed2145
12 changed files with 44 additions and 44 deletions

View File

@ -13,7 +13,7 @@ from utils import remove_domain_port
from utils import remove_id_ending from utils import remove_id_ending
from utils import has_users_path from utils import has_users_path
from utils import get_full_domain from utils import get_full_domain
from utils import getStatusNumber from utils import get_status_number
from utils import createOutboxDir from utils import createOutboxDir
from utils import urlPermitted from utils import urlPermitted
from utils import getNicknameFromActor from utils import getNicknameFromActor
@ -137,7 +137,7 @@ def createAnnounce(session, base_dir: str, federation_list: [],
domain = remove_domain_port(domain) domain = remove_domain_port(domain)
fullDomain = get_full_domain(domain, port) fullDomain = get_full_domain(domain, port)
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
newAnnounceId = http_prefix + '://' + fullDomain + \ newAnnounceId = http_prefix + '://' + fullDomain + \
'/users/' + nickname + '/statuses/' + statusNumber '/users/' + nickname + '/statuses/' + statusNumber
atomUriStr = local_actor_url(http_prefix, nickname, fullDomain) + \ 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) actorStr = local_actor_url(http_prefix, fromNickname, fromDomainFull)
ccUrl = actorStr + '/followers' ccUrl = actorStr + '/followers'
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
newAnnounceId = actorStr + '/statuses/' + statusNumber newAnnounceId = actorStr + '/statuses/' + statusNumber
newAnnounceJson = { newAnnounceJson = {
"@context": "https://www.w3.org/ns/activitystreams", "@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) actor = local_actor_url(http_prefix, nickname, domain_full)
handle = replace_users_with_at(actor) handle = replace_users_with_at(actor)
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
unAnnounceJson = { unAnnounceJson = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
'id': actor + '/statuses/' + str(statusNumber) + '/undo', 'id': actor + '/statuses/' + str(statusNumber) + '/undo',

View File

@ -295,7 +295,7 @@ from utils import get_cached_post_filename
from utils import remove_post_from_cache from utils import remove_post_from_cache
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import getStatusNumber from utils import get_status_number
from utils import urlPermitted from utils import urlPermitted
from utils import load_json from utils import load_json
from utils import save_json from utils import save_json
@ -2941,7 +2941,7 @@ class PubServer(BaseHTTPRequestHandler):
followingActor) followingActor)
followActor = \ followActor = \
local_actor_url(http_prefix, followerNickname, domain_full) local_actor_url(http_prefix, followerNickname, domain_full)
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
followId = followActor + '/statuses/' + str(statusNumber) followId = followActor + '/statuses/' + str(statusNumber)
unfollowJson = { unfollowJson = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
@ -6518,7 +6518,7 @@ class PubServer(BaseHTTPRequestHandler):
actor_json['id'].replace('/', '#') + '.json' actor_json['id'].replace('/', '#') + '.json'
save_json(actor_json, actorCacheFilename) save_json(actor_json, actorCacheFilename)
# send profile update to followers # send profile update to followers
pubNumber, pubDate = getStatusNumber() pubNumber, pubDate = get_status_number()
updateActorJson = getActorUpdateJson(actor_json) updateActorJson = getActorUpdateJson(actor_json)
print('Sending actor update: ' + str(updateActorJson)) print('Sending actor update: ' + str(updateActorJson))
self._postToOutbox(updateActorJson, self._postToOutbox(updateActorJson,

View File

@ -19,7 +19,7 @@ from utils import validNickname
from utils import domainPermitted from utils import domainPermitted
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import getStatusNumber from utils import get_status_number
from utils import follow_person from utils import follow_person
from posts import sendSignedJson from posts import sendSignedJson
from posts import getPersonBox from posts import getPersonBox
@ -869,7 +869,7 @@ def sendFollowRequest(session, base_dir: str,
requestDomain = get_full_domain(followDomain, followPort) requestDomain = get_full_domain(followDomain, followPort)
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
group_account = False group_account = False
if followNickname: if followNickname:
@ -962,7 +962,7 @@ def sendFollowRequestViaServer(base_dir: str, session,
followedId = \ followedId = \
http_prefix + '://' + followDomainFull + '/@' + followNickname http_prefix + '://' + followDomainFull + '/@' + followNickname
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
newFollowJson = { newFollowJson = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
'id': followActor + '/statuses/' + str(statusNumber), 'id': followActor + '/statuses/' + str(statusNumber),
@ -1050,7 +1050,7 @@ def sendUnfollowRequestViaServer(base_dir: str, session,
followActor = local_actor_url(http_prefix, fromNickname, fromDomainFull) followActor = local_actor_url(http_prefix, fromNickname, fromDomainFull)
followedId = \ followedId = \
http_prefix + '://' + followDomainFull + '/@' + followNickname http_prefix + '://' + followDomainFull + '/@' + followNickname
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
unfollowJson = { unfollowJson = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',

View File

@ -48,7 +48,7 @@ from utils import get_cached_post_filename
from utils import remove_post_from_cache from utils import remove_post_from_cache
from utils import urlPermitted from utils import urlPermitted
from utils import createInboxQueueDir from utils import createInboxQueueDir
from utils import getStatusNumber from utils import get_status_number
from utils import getDomainFromActor from utils import getDomainFromActor
from utils import getNicknameFromActor from utils import getNicknameFromActor
from utils import locate_post 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']) post_id = remove_id_ending(post_json_object['id'])
published = curr_time.strftime("%Y-%m-%dT%H:%M:%SZ") published = curr_time.strftime("%Y-%m-%dT%H:%M:%SZ")
if not post_id: if not post_id:
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
if actor: if actor:
post_id = actor + '/statuses/' + statusNumber post_id = actor + '/statuses/' + statusNumber
else: else:

View File

@ -30,7 +30,7 @@ from utils import remove_html
from utils import get_full_domain from utils import get_full_domain
from utils import load_json from utils import load_json
from utils import save_json from utils import save_json
from utils import getStatusNumber from utils import get_status_number
from utils import clearFromPostCaches from utils import clearFromPostCaches
from utils import dangerousMarkup from utils import dangerousMarkup
from utils import local_actor_url from utils import local_actor_url
@ -581,7 +581,7 @@ def _convertRSStoActivityPub(base_dir: str, http_prefix: str,
str(dateStrWithOffset)) str(dateStrWithOffset))
continue continue
statusNumber, published = getStatusNumber(dateStr) statusNumber, published = get_status_number(dateStr)
newPostId = \ newPostId = \
local_actor_url(http_prefix, 'news', domain) + \ local_actor_url(http_prefix, 'news', domain) + \
'/statuses/' + statusNumber '/statuses/' + statusNumber

View File

@ -43,7 +43,7 @@ from utils import containsInvalidChars
from utils import replace_users_with_at from utils import replace_users_with_at
from utils import remove_line_endings from utils import remove_line_endings
from utils import remove_domain_port 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 get_full_domain
from utils import validNickname from utils import validNickname
from utils import load_json from utils import load_json
@ -199,7 +199,7 @@ def randomizeActorImages(personJson: {}) -> None:
def getActorUpdateJson(actor_json: {}) -> {}: def getActorUpdateJson(actor_json: {}) -> {}:
"""Returns the json for an Person Update """Returns the json for an Person Update
""" """
pubNumber, _ = getStatusNumber() pubNumber, _ = get_status_number()
manuallyApprovesFollowers = actor_json['manuallyApprovesFollowers'] manuallyApprovesFollowers = actor_json['manuallyApprovesFollowers']
return { return {
'@context': [ '@context': [
@ -403,7 +403,7 @@ def _createPersonBase(base_dir: str, nickname: str, domain: str, port: int,
personId + '/avatar' + \ personId + '/avatar' + \
str(randint(10000000000000, 99999999999999)) + '.png' # nosec str(randint(10000000000000, 99999999999999)) + '.png' # nosec
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
newPerson = { newPerson = {
'@context': [ '@context': [
'https://www.w3.org/ns/activitystreams', 'https://www.w3.org/ns/activitystreams',
@ -740,7 +740,7 @@ def personUpgradeActor(base_dir: str, personJson: {},
updateActor = True updateActor = True
if not personJson.get('published'): if not personJson.get('published'):
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
personJson['published'] = published personJson['published'] = published
updateActor = True updateActor = True

4
pgp.py
View File

@ -14,7 +14,7 @@ from person import getActorJson
from utils import contains_pgp_public_key from utils import contains_pgp_public_key
from utils import is_pgp_encrypted from utils import is_pgp_encrypted
from utils import get_full_domain 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 local_actor_url
from utils import replace_users_with_at from utils import replace_users_with_at
from webfinger import webfingerHandle from webfinger import webfingerHandle
@ -542,7 +542,7 @@ def pgpPublicKeyUpload(base_dir: str, session,
setPGPpubKey(actor_json, PGPpubKey) setPGPpubKey(actor_json, PGPpubKey)
# create an actor update # create an actor update
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
actorUpdate = { actorUpdate = {
'@context': 'https://www.w3.org/ns/activitystreams', '@context': 'https://www.w3.org/ns/activitystreams',
'id': actor + '#updates/' + statusNumber, 'id': actor + '#updates/' + statusNumber,

View File

@ -51,7 +51,7 @@ from utils import valid_post_date
from utils import get_full_domain from utils import get_full_domain
from utils import get_followers_list from utils import get_followers_list
from utils import isEvil from utils import isEvil
from utils import getStatusNumber from utils import get_status_number
from utils import createPersonDir from utils import createPersonDir
from utils import urlPermitted from utils import urlPermitted
from utils import getNicknameFromActor from utils import getNicknameFromActor
@ -919,7 +919,7 @@ def savePostToBox(base_dir: str, http_prefix: str, post_id: str,
domain = remove_domain_port(domain) domain = remove_domain_port(domain)
if not post_id: if not post_id:
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
post_id = \ post_id = \
local_actor_url(http_prefix, nickname, originalDomain) + \ local_actor_url(http_prefix, nickname, originalDomain) + \
'/statuses/' + statusNumber '/statuses/' + statusNumber
@ -1426,7 +1426,7 @@ def _createPostBase(base_dir: str,
if tag['name'] not in content: if tag['name'] not in content:
del hashtagsDict[tagName] del hashtagsDict[tagName]
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
newPostId = \ newPostId = \
local_actor_url(http_prefix, nickname, domain) + \ local_actor_url(http_prefix, nickname, domain) + \
'/statuses/' + statusNumber '/statuses/' + statusNumber
@ -1570,7 +1570,7 @@ def outboxMessageCreateWrap(http_prefix: str,
""" """
domain = get_full_domain(domain, port) domain = get_full_domain(domain, port)
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
if message_json.get('published'): if message_json.get('published'):
published = message_json['published'] published = message_json['published']
newPostId = \ newPostId = \

View File

@ -10,7 +10,7 @@ __module_group__ = "Profile Metadata"
import os import os
from utils import load_json from utils import load_json
from utils import save_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 remove_domain_port
from utils import acct_dir from utils import acct_dir
@ -153,7 +153,7 @@ def _setActorRole(actor_json: {}, roleName: str) -> bool:
continue continue
if occupationItem['hasOccupation']['name'] == roleName: if occupationItem['hasOccupation']['name'] == roleName:
return True return True
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
newRole = { newRole = {
"@type": "Role", "@type": "Role",
"hasOccupation": { "hasOccupation": {

View File

@ -11,7 +11,7 @@ import os
import time import time
import datetime import datetime
from utils import has_object_dict from utils import has_object_dict
from utils import getStatusNumber from utils import get_status_number
from utils import load_json from utils import load_json
from utils import is_account_dir from utils import is_account_dir
from utils import acct_dir from utils import acct_dir
@ -82,7 +82,7 @@ def _updatePostSchedule(base_dir: str, handle: str, httpd,
# set the published time # set the published time
# If this is not recent then http checks on the receiving side # If this is not recent then http checks on the receiving side
# will reject it # will reject it
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
if post_json_object.get('published'): if post_json_object.get('published'):
post_json_object['published'] = published post_json_object['published'] = published
if has_object_dict(post_json_object): if has_object_dict(post_json_object):

View File

@ -80,7 +80,7 @@ from utils import getDomainFromActor
from utils import copytree from utils import copytree
from utils import load_json from utils import load_json
from utils import save_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 get_followers_of_person
from utils import remove_html from utils import remove_html
from utils import dangerousMarkup from utils import dangerousMarkup
@ -3459,7 +3459,7 @@ def _testGetStatusNumber():
print('testGetStatusNumber') print('testGetStatusNumber')
prevStatusNumber = None prevStatusNumber = None
for i in range(1, 20): for i in range(1, 20):
statusNumber, published = getStatusNumber() statusNumber, published = get_status_number()
if prevStatusNumber: if prevStatusNumber:
assert len(statusNumber) == 18 assert len(statusNumber) == 18
assert int(statusNumber) > prevStatusNumber assert int(statusNumber) > prevStatusNumber

View File

@ -657,8 +657,8 @@ def save_json(json_object: {}, filename: str) -> bool:
tries = 0 tries = 0
while tries < 5: while tries < 5:
try: try:
with open(filename, 'w+') as fp: with open(filename, 'w+') as json_file:
fp.write(json.dumps(json_object)) json_file.write(json.dumps(json_object))
return True return True
except OSError: except OSError:
print('EX: save_json ' + str(tries)) 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) -> {}: def load_json(filename: str, delay_sec: int = 2, max_tries: int = 5) -> {}:
"""Makes a few attempts to load a json formatted file """Makes a few attempts to load a json formatted file
""" """
jsonObject = None json_object = None
tries = 0 tries = 0
while tries < max_tries: while tries < max_tries:
try: try:
with open(filename, 'r') as fp: with open(filename, 'r') as json_file:
data = fp.read() data = json_file.read()
jsonObject = json.loads(data) json_object = json.loads(data)
break break
except BaseException: except BaseException:
print('EX: load_json exception ' + str(filename)) print('EX: load_json exception ' + str(filename))
if delay_sec > 0: if delay_sec > 0:
time.sleep(delay_sec) time.sleep(delay_sec)
tries += 1 tries += 1
return jsonObject return json_object
def load_json_onionify(filename: str, domain: str, onion_domain: str, 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 """Makes a few attempts to load a json formatted file
This also converts the domain name to the onion domain This also converts the domain name to the onion domain
""" """
jsonObject = None json_object = None
tries = 0 tries = 0
while tries < 5: while tries < 5:
try: try:
with open(filename, 'r') as fp: with open(filename, 'r') as json_file:
data = fp.read() data = json_file.read()
if data: if data:
data = data.replace(domain, onion_domain) data = data.replace(domain, onion_domain)
data = data.replace('https:', 'http:') data = data.replace('https:', 'http:')
print('*****data: ' + data) print('*****data: ' + data)
jsonObject = json.loads(data) json_object = json.loads(data)
break break
except BaseException: except BaseException:
print('EX: load_json_onionify exception ' + str(filename)) print('EX: load_json_onionify exception ' + str(filename))
if delay_sec > 0: if delay_sec > 0:
time.sleep(delay_sec) time.sleep(delay_sec)
tries += 1 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 """Returns the status number and published date
""" """
if not publishedStr: if not publishedStr: