Snake case

merge-requests/30/head
Bob Mottram 2022-01-04 21:19:06 +00:00
parent 1e26c685b1
commit e6c64a5504
4 changed files with 362 additions and 359 deletions

View File

@ -786,7 +786,7 @@ def html_edit_blog(media_instance: bool, translate: {},
""" """
post_filename = locate_post(base_dir, nickname, domain, post_url) post_filename = locate_post(base_dir, nickname, domain, post_url)
if not post_filename: if not post_filename:
print('Edit blog: Filename not found for ' + post_url) print('Edit blog: filename not found for ' + post_url)
return None return None
post_json_object = load_json(post_filename) post_json_object = load_json(post_filename)

View File

@ -1381,17 +1381,17 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str,
post_json_object = {} post_json_object = {}
original_screen_reader = screenreader original_screen_reader = screenreader
sounds_dir = 'theme/default/sounds/' sounds_dir = 'theme/default/sounds/'
# prevSay = '' # prev_say = ''
# prevCalendar = False # prev_calendar = False
# prevFollow = False # prev_follow = False
# prevLike = '' # prev_like = ''
# prevShare = False # prev_share = False
dm_sound_filename = sounds_dir + 'dm.ogg' dm_sound_filename = sounds_dir + 'dm.ogg'
reply_sound_filename = sounds_dir + 'reply.ogg' reply_sound_filename = sounds_dir + 'reply.ogg'
# calendarSoundFilename = sounds_dir + 'calendar.ogg' # calendar_sound_filename = sounds_dir + 'calendar.ogg'
# followSoundFilename = sounds_dir + 'follow.ogg' # follow_sound_filename = sounds_dir + 'follow.ogg'
# likeSoundFilename = sounds_dir + 'like.ogg' # like_sound_filename = sounds_dir + 'like.ogg'
# shareSoundFilename = sounds_dir + 'share.ogg' # share_sound_filename = sounds_dir + 'share.ogg'
player = 'ffplay' player = 'ffplay'
name_str = None name_str = None
gender = None gender = None

View File

@ -701,10 +701,11 @@ if args.posts:
print('originDomain: ' + str(originDomain)) print('originDomain: ' + str(originDomain))
if '@' not in args.posts: if '@' not in args.posts:
if '/users/' in args.posts: if '/users/' in args.posts:
postsNickname = get_nickname_from_actor(args.posts) posts_nickname = get_nickname_from_actor(args.posts)
postsDomain, postsPort = get_domain_from_actor(args.posts) posts_domain, posts_port = get_domain_from_actor(args.posts)
args.posts = \ args.posts = \
get_full_domain(postsNickname + '@' + postsDomain, postsPort) get_full_domain(posts_nickname + '@' + posts_domain,
posts_port)
else: else:
print('Syntax: --posts nickname@domain') print('Syntax: --posts nickname@domain')
sys.exit() sys.exit()
@ -735,10 +736,11 @@ if args.posts:
if args.postDomains: if args.postDomains:
if '@' not in args.postDomains: if '@' not in args.postDomains:
if '/users/' in args.postDomains: if '/users/' in args.postDomains:
postsNickname = get_nickname_from_actor(args.postDomains) posts_nickname = get_nickname_from_actor(args.postDomains)
postsDomain, postsPort = get_domain_from_actor(args.postDomains) posts_domain, posts_port = get_domain_from_actor(args.postDomains)
args.postDomains = \ args.postDomains = \
get_full_domain(postsNickname + '@' + postsDomain, postsPort) get_full_domain(posts_nickname + '@' + posts_domain,
posts_port)
else: else:
print('Syntax: --postDomains nickname@domain') print('Syntax: --postDomains nickname@domain')
sys.exit() sys.exit()
@ -757,8 +759,8 @@ if args.postDomains:
args.port = 80 args.port = 80
elif args.gnunet: elif args.gnunet:
proxy_type = 'gnunet' proxy_type = 'gnunet'
wordFrequency = {} word_frequency = {}
domainList = [] domain_list = []
if not args.language: if not args.language:
args.language = 'en' args.language = 'en'
signing_priv_key_pem = None signing_priv_key_pem = None
@ -768,17 +770,17 @@ if args.postDomains:
originDomain = args.domain originDomain = args.domain
if args.secure_mode: if args.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, originDomain) signing_priv_key_pem = get_instance_actor_key(base_dir, originDomain)
domainList = \ domain_list = \
get_public_post_domains(None, get_public_post_domains(None,
base_dir, nickname, domain, base_dir, nickname, domain,
originDomain, originDomain,
proxy_type, args.port, proxy_type, args.port,
http_prefix, debug, http_prefix, debug,
__version__, __version__,
wordFrequency, domainList, word_frequency, domain_list,
args.language, args.language,
signing_priv_key_pem) signing_priv_key_pem)
for postDomain in domainList: for postDomain in domain_list:
print(postDomain) print(postDomain)
sys.exit() sys.exit()
@ -787,11 +789,12 @@ if args.postDomainsBlocked:
# given handle but which are globally blocked on this instance # given handle but which are globally blocked on this instance
if '@' not in args.postDomainsBlocked: if '@' not in args.postDomainsBlocked:
if '/users/' in args.postDomainsBlocked: if '/users/' in args.postDomainsBlocked:
postsNickname = get_nickname_from_actor(args.postDomainsBlocked) posts_nickname = get_nickname_from_actor(args.postDomainsBlocked)
postsDomain, postsPort = \ posts_domain, posts_port = \
get_domain_from_actor(args.postDomainsBlocked) get_domain_from_actor(args.postDomainsBlocked)
args.postDomainsBlocked = \ args.postDomainsBlocked = \
get_full_domain(postsNickname + '@' + postsDomain, postsPort) get_full_domain(posts_nickname + '@' + posts_domain,
posts_port)
else: else:
print('Syntax: --postDomainsBlocked nickname@domain') print('Syntax: --postDomainsBlocked nickname@domain')
sys.exit() sys.exit()
@ -810,23 +813,23 @@ if args.postDomainsBlocked:
args.port = 80 args.port = 80
elif args.gnunet: elif args.gnunet:
proxy_type = 'gnunet' proxy_type = 'gnunet'
wordFrequency = {} word_frequency = {}
domainList = [] domain_list = []
if not args.language: if not args.language:
args.language = 'en' args.language = 'en'
signing_priv_key_pem = None signing_priv_key_pem = None
if args.secure_mode: if args.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain) signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
domainList = \ domain_list = \
get_public_post_domains_blocked(None, get_public_post_domains_blocked(None,
base_dir, nickname, domain, base_dir, nickname, domain,
proxy_type, args.port, proxy_type, args.port,
http_prefix, debug, http_prefix, debug,
__version__, __version__,
wordFrequency, domainList, word_frequency, domain_list,
args.language, args.language,
signing_priv_key_pem) signing_priv_key_pem)
for postDomain in domainList: for postDomain in domain_list:
print(postDomain) print(postDomain)
sys.exit() sys.exit()
@ -835,10 +838,11 @@ if args.check_domains:
# given handle but which are globally blocked on this instance # given handle but which are globally blocked on this instance
if '@' not in args.check_domains: if '@' not in args.check_domains:
if '/users/' in args.check_domains: if '/users/' in args.check_domains:
postsNickname = get_nickname_from_actor(args.posts) posts_nickname = get_nickname_from_actor(args.posts)
postsDomain, postsPort = get_domain_from_actor(args.posts) posts_domain, posts_port = get_domain_from_actor(args.posts)
args.check_domains = \ args.check_domains = \
get_full_domain(postsNickname + '@' + postsDomain, postsPort) get_full_domain(posts_nickname + '@' + posts_domain,
posts_port)
else: else:
print('Syntax: --check_domains nickname@domain') print('Syntax: --check_domains nickname@domain')
sys.exit() sys.exit()
@ -857,7 +861,7 @@ if args.check_domains:
args.port = 80 args.port = 80
elif args.gnunet: elif args.gnunet:
proxy_type = 'gnunet' proxy_type = 'gnunet'
maxBlockedDomains = 0 max_blocked_domains = 0
if not args.language: if not args.language:
args.language = 'en' args.language = 'en'
signing_priv_key_pem = None signing_priv_key_pem = None
@ -868,7 +872,7 @@ if args.check_domains:
proxy_type, args.port, proxy_type, args.port,
http_prefix, debug, http_prefix, debug,
__version__, __version__,
maxBlockedDomains, False, args.language, max_blocked_domains, False, args.language,
signing_priv_key_pem) signing_priv_key_pem)
sys.exit() sys.exit()
@ -891,14 +895,14 @@ if args.socnet:
signing_priv_key_pem = None signing_priv_key_pem = None
if args.secure_mode: if args.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain) signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
dotGraph = instances_graph(base_dir, args.socnet, dot_graph = instances_graph(base_dir, args.socnet,
proxy_type, args.port, proxy_type, args.port,
http_prefix, debug, http_prefix, debug,
__version__, args.language, __version__, args.language,
signing_priv_key_pem) signing_priv_key_pem)
try: try:
with open('socnet.dot', 'w+') as fp: with open('socnet.dot', 'w+') as fp_soc:
fp.write(dotGraph) fp_soc.write(dot_graph)
print('Saved to socnet.dot') print('Saved to socnet.dot')
except OSError: except OSError:
print('EX: commandline unable to write socnet.dot') print('EX: commandline unable to write socnet.dot')
@ -936,9 +940,9 @@ if args.postsraw:
if args.json: if args.json:
session = create_session(None) session = create_session(None)
profileStr = 'https://www.w3.org/ns/activitystreams' profile_str = 'https://www.w3.org/ns/activitystreams'
asHeader = { as_header = {
'Accept': 'application/ld+json; profile="' + profileStr + '"' 'Accept': 'application/ld+json; profile="' + profile_str + '"'
} }
if not args.domain: if not args.domain:
args.domain = get_config_param(base_dir, 'domain') args.domain = get_config_param(base_dir, 'domain')
@ -952,17 +956,17 @@ if args.json:
print('Obtained instance actor signing key') print('Obtained instance actor signing key')
else: else:
print('Did not obtain instance actor key for ' + domain) print('Did not obtain instance actor key for ' + domain)
testJson = get_json(signing_priv_key_pem, session, args.json, asHeader, test_json = get_json(signing_priv_key_pem, session, args.json, as_header,
None, debug, __version__, http_prefix, domain) None, debug, __version__, http_prefix, domain)
if testJson: if test_json:
pprint(testJson) pprint(test_json)
sys.exit() sys.exit()
if args.htmlpost: if args.htmlpost:
session = create_session(None) session = create_session(None)
profileStr = 'https://www.w3.org/ns/activitystreams' profile_str = 'https://www.w3.org/ns/activitystreams'
asHeader = { as_header = {
'Accept': 'text/html; profile="' + profileStr + '"' 'Accept': 'text/html; profile="' + profile_str + '"'
} }
if not args.domain: if not args.domain:
args.domain = get_config_param(base_dir, 'domain') args.domain = get_config_param(base_dir, 'domain')
@ -977,7 +981,7 @@ if args.htmlpost:
else: else:
print('Did not obtain instance actor key for ' + domain) print('Did not obtain instance actor key for ' + domain)
testHtml = download_html(signing_priv_key_pem, session, args.htmlpost, testHtml = download_html(signing_priv_key_pem, session, args.htmlpost,
asHeader, None, debug, __version__, as_header, None, debug, __version__,
http_prefix, domain) http_prefix, domain)
if testHtml: if testHtml:
print(testHtml) print(testHtml)
@ -1237,15 +1241,15 @@ if args.followerspending:
print('Specify a nickname with the --nickname option') print('Specify a nickname with the --nickname option')
sys.exit() sys.exit()
accountsDir = acct_dir(base_dir, args.nickname, domain) accounts_dir = acct_dir(base_dir, args.nickname, domain)
approveFollowsFilename = accountsDir + '/followrequests.txt' approve_follows_filename = accounts_dir + '/followrequests.txt'
approveCtr = 0 approve_ctr = 0
if os.path.isfile(approveFollowsFilename): if os.path.isfile(approve_follows_filename):
with open(approveFollowsFilename, 'r') as approvefile: with open(approve_follows_filename, 'r') as approvefile:
for approve in approvefile: for approve in approvefile:
print(approve.replace('\n', '').replace('\r', '')) print(approve.replace('\n', '').replace('\r', ''))
approveCtr += 1 approve_ctr += 1
if approveCtr == 0: if approve_ctr == 0:
print('There are no follow requests pending approval.') print('There are no follow requests pending approval.')
sys.exit() sys.exit()
@ -1274,28 +1278,28 @@ if args.message:
print(' --sendto followers') print(' --sendto followers')
sys.exit() sys.exit()
if '@' in args.sendto: if '@' in args.sendto:
toNickname = args.sendto.split('@')[0] to_nickname = args.sendto.split('@')[0]
toDomain = args.sendto.split('@')[1] to_domain = args.sendto.split('@')[1]
toDomain = toDomain.replace('\n', '').replace('\r', '') to_domain = to_domain.replace('\n', '').replace('\r', '')
toPort = 443 to_port = 443
if ':' in toDomain: if ':' in to_domain:
toPort = get_port_from_domain(toDomain) to_port = get_port_from_domain(to_domain)
toDomain = remove_domain_port(toDomain) to_domain = remove_domain_port(to_domain)
else: else:
if args.sendto.endswith('followers'): if args.sendto.endswith('followers'):
toNickname = None to_nickname = None
toDomain = 'followers' to_domain = 'followers'
toPort = port to_port = port
else: else:
toNickname = None to_nickname = None
toDomain = 'public' to_domain = 'public'
toPort = port to_port = port
ccUrl = None cc_url = None
sendMessage = args.message sendMessage = args.message
followersOnly = args.followersonly followers_only = args.followersonly
client_to_server = args.client client_to_server = args.client
attachedImageDescription = args.imageDescription attached_image_description = args.imageDescription
city = 'London, England' city = 'London, England'
send_threads = [] send_threads = []
postLog = [] postLog = []
@ -1303,12 +1307,12 @@ if args.message:
cached_webfingers = {} cached_webfingers = {}
subject = args.subject subject = args.subject
attach = args.attach attach = args.attach
mediaType = None media_type = None
if attach: if attach:
mediaType = get_attachment_media_type(attach) media_type = get_attachment_media_type(attach)
replyTo = args.replyto reply_to = args.replyto
followersOnly = False followers_only = False
isArticle = False is_article = False
if not domain: if not domain:
domain = get_config_param(base_dir, 'domain') domain = get_config_param(base_dir, 'domain')
signing_priv_key_pem = None signing_priv_key_pem = None
@ -1319,14 +1323,14 @@ if args.message:
send_post_via_server(signing_priv_key_pem, __version__, send_post_via_server(signing_priv_key_pem, __version__,
base_dir, session, args.nickname, args.password, base_dir, session, args.nickname, args.password,
domain, port, domain, port,
toNickname, toDomain, toPort, ccUrl, to_nickname, to_domain, to_port, cc_url,
http_prefix, sendMessage, followersOnly, http_prefix, sendMessage, followers_only,
args.commentsEnabled, attach, mediaType, args.commentsEnabled, attach, media_type,
attachedImageDescription, city, attached_image_description, city,
cached_webfingers, person_cache, isArticle, cached_webfingers, person_cache, is_article,
args.language, args.low_bandwidth, args.language, args.low_bandwidth,
args.content_license_url, args.debug, args.content_license_url, args.debug,
replyTo, replyTo, args.conversationId, subject) reply_to, reply_to, args.conversationId, subject)
for i in range(10): for i in range(10):
# TODO detect send success/fail # TODO detect send success/fail
time.sleep(1) time.sleep(1)
@ -1398,13 +1402,13 @@ if args.box:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain) signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
session = create_session(proxy_type) session = create_session(proxy_type)
boxJson = c2s_box_json(base_dir, session, box_json = c2s_box_json(base_dir, session,
args.nickname, args.password, args.nickname, args.password,
domain, port, http_prefix, domain, port, http_prefix,
args.box, args.pageNumber, args.box, args.pageNumber,
args.debug, signing_priv_key_pem) args.debug, signing_priv_key_pem)
if boxJson: if box_json:
pprint(boxJson) pprint(box_json)
else: else:
print('Box not found: ' + args.box) print('Box not found: ' + args.box)
sys.exit() sys.exit()
@ -1880,18 +1884,18 @@ if args.follow:
sys.exit() sys.exit()
args.password = args.password.replace('\n', '') args.password = args.password.replace('\n', '')
followNickname = get_nickname_from_actor(args.follow) follow_nickname = get_nickname_from_actor(args.follow)
if not followNickname: if not follow_nickname:
print('Unable to find nickname in ' + args.follow) print('Unable to find nickname in ' + args.follow)
sys.exit() sys.exit()
followDomain, followPort = get_domain_from_actor(args.follow) follow_domain, follow_port = get_domain_from_actor(args.follow)
session = create_session(proxy_type) session = create_session(proxy_type)
person_cache = {} person_cache = {}
cached_webfingers = {} cached_webfingers = {}
followHttpPrefix = http_prefix follow_http_prefix = http_prefix
if args.follow.startswith('https'): if args.follow.startswith('https'):
followHttpPrefix = 'https' follow_http_prefix = 'https'
if not domain: if not domain:
domain = get_config_param(base_dir, 'domain') domain = get_config_param(base_dir, 'domain')
signing_priv_key_pem = None signing_priv_key_pem = None
@ -1901,8 +1905,8 @@ if args.follow:
send_follow_requestViaServer(base_dir, session, send_follow_requestViaServer(base_dir, session,
args.nickname, args.password, args.nickname, args.password,
domain, port, domain, port,
followNickname, followDomain, followPort, follow_nickname, follow_domain, follow_port,
http_prefix, follow_http_prefix,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, __version__, signing_priv_key_pem) debug, __version__, signing_priv_key_pem)
for t in range(20): for t in range(20):
@ -1926,18 +1930,18 @@ if args.unfollow:
sys.exit() sys.exit()
args.password = args.password.replace('\n', '') args.password = args.password.replace('\n', '')
followNickname = get_nickname_from_actor(args.unfollow) follow_nickname = get_nickname_from_actor(args.unfollow)
if not followNickname: if not follow_nickname:
print('WARN: unable to find nickname in ' + args.unfollow) print('WARN: unable to find nickname in ' + args.unfollow)
sys.exit() sys.exit()
followDomain, followPort = get_domain_from_actor(args.unfollow) follow_domain, follow_port = get_domain_from_actor(args.unfollow)
session = create_session(proxy_type) session = create_session(proxy_type)
person_cache = {} person_cache = {}
cached_webfingers = {} cached_webfingers = {}
followHttpPrefix = http_prefix follow_http_prefix = http_prefix
if args.follow.startswith('https'): if args.follow.startswith('https'):
followHttpPrefix = 'https' follow_http_prefix = 'https'
if not domain: if not domain:
domain = get_config_param(base_dir, 'domain') domain = get_config_param(base_dir, 'domain')
signing_priv_key_pem = None signing_priv_key_pem = None
@ -1947,8 +1951,8 @@ if args.unfollow:
send_unfollow_request_via_server(base_dir, session, send_unfollow_request_via_server(base_dir, session,
args.nickname, args.password, args.nickname, args.password,
domain, port, domain, port,
followNickname, followDomain, followPort, follow_nickname, follow_domain,
http_prefix, follow_port, follow_http_prefix,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, __version__, signing_priv_key_pem) debug, __version__, signing_priv_key_pem)
for t in range(20): for t in range(20):
@ -1972,22 +1976,22 @@ if args.followingList:
session = create_session(proxy_type) session = create_session(proxy_type)
person_cache = {} person_cache = {}
cached_webfingers = {} cached_webfingers = {}
followHttpPrefix = http_prefix follow_http_prefix = http_prefix
if not domain: if not domain:
domain = get_config_param(base_dir, 'domain') domain = get_config_param(base_dir, 'domain')
signing_priv_key_pem = None signing_priv_key_pem = None
if args.secure_mode: if args.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain) signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
followingJson = \ following_json = \
get_following_via_server(base_dir, session, get_following_via_server(base_dir, session,
args.nickname, args.password, args.nickname, args.password,
domain, port, domain, port,
http_prefix, args.pageNumber, follow_http_prefix, args.pageNumber,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, __version__, signing_priv_key_pem) debug, __version__, signing_priv_key_pem)
if followingJson: if following_json:
pprint(followingJson) pprint(following_json)
sys.exit() sys.exit()
if args.followersList: if args.followersList:
@ -2005,23 +2009,23 @@ if args.followersList:
session = create_session(proxy_type) session = create_session(proxy_type)
person_cache = {} person_cache = {}
cached_webfingers = {} cached_webfingers = {}
followHttpPrefix = http_prefix follow_http_prefix = http_prefix
if not domain: if not domain:
domain = get_config_param(base_dir, 'domain') domain = get_config_param(base_dir, 'domain')
signing_priv_key_pem = None signing_priv_key_pem = None
if args.secure_mode: if args.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain) signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
followersJson = \ followers_json = \
get_followers_via_server(base_dir, session, get_followers_via_server(base_dir, session,
args.nickname, args.password, args.nickname, args.password,
domain, port, domain, port,
http_prefix, args.pageNumber, follow_http_prefix, args.pageNumber,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, __version__, debug, __version__,
signing_priv_key_pem) signing_priv_key_pem)
if followersJson: if followers_json:
pprint(followersJson) pprint(followers_json)
sys.exit() sys.exit()
if args.followRequestsList: if args.followRequestsList:
@ -2039,23 +2043,23 @@ if args.followRequestsList:
session = create_session(proxy_type) session = create_session(proxy_type)
person_cache = {} person_cache = {}
cached_webfingers = {} cached_webfingers = {}
followHttpPrefix = http_prefix follow_http_prefix = http_prefix
if not domain: if not domain:
domain = get_config_param(base_dir, 'domain') domain = get_config_param(base_dir, 'domain')
signing_priv_key_pem = None signing_priv_key_pem = None
if args.secure_mode: if args.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain) signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
followRequestsJson = \ follow_requests_json = \
get_follow_requests_via_server(base_dir, session, get_follow_requests_via_server(base_dir, session,
args.nickname, args.password, args.nickname, args.password,
domain, port, domain, port,
http_prefix, args.pageNumber, follow_http_prefix, args.pageNumber,
cached_webfingers, person_cache, cached_webfingers, person_cache,
debug, __version__, debug, __version__,
signing_priv_key_pem) signing_priv_key_pem)
if followRequestsJson: if follow_requests_json:
pprint(followRequestsJson) pprint(follow_requests_json)
sys.exit() sys.exit()
nickname = 'admin' nickname = 'admin'
@ -2212,48 +2216,48 @@ if args.followers:
str(wf_request)) str(wf_request))
sys.exit() sys.exit()
personUrl = None person_url = None
if wf_request.get('errors'): if wf_request.get('errors'):
print('wf_request error: ' + str(wf_request['errors'])) print('wf_request error: ' + str(wf_request['errors']))
if has_users_path(args.followers): if has_users_path(args.followers):
personUrl = originalActor person_url = originalActor
else: else:
sys.exit() sys.exit()
profileStr = 'https://www.w3.org/ns/activitystreams' profile_str = 'https://www.w3.org/ns/activitystreams'
asHeader = { as_header = {
'Accept': 'application/activity+json; profile="' + profileStr + '"' 'Accept': 'application/activity+json; profile="' + profile_str + '"'
} }
if not personUrl: if not person_url:
personUrl = get_user_url(wf_request, 0, args.debug) person_url = get_user_url(wf_request, 0, args.debug)
if nickname == domain: if nickname == domain:
personUrl = personUrl.replace('/users/', '/actor/') person_url = person_url.replace('/users/', '/actor/')
personUrl = personUrl.replace('/accounts/', '/actor/') person_url = person_url.replace('/accounts/', '/actor/')
personUrl = personUrl.replace('/channel/', '/actor/') person_url = person_url.replace('/channel/', '/actor/')
personUrl = personUrl.replace('/profile/', '/actor/') person_url = person_url.replace('/profile/', '/actor/')
personUrl = personUrl.replace('/u/', '/actor/') person_url = person_url.replace('/u/', '/actor/')
personUrl = personUrl.replace('/c/', '/actor/') person_url = person_url.replace('/c/', '/actor/')
if not personUrl: if not person_url:
# try single user instance # try single user instance
personUrl = http_prefix + '://' + domain person_url = http_prefix + '://' + domain
profileStr = 'https://www.w3.org/ns/activitystreams' profile_str = 'https://www.w3.org/ns/activitystreams'
asHeader = { as_header = {
'Accept': 'application/ld+json; profile="' + profileStr + '"' 'Accept': 'application/ld+json; profile="' + profile_str + '"'
} }
if '/channel/' in personUrl or '/accounts/' in personUrl: if '/channel/' in person_url or '/accounts/' in person_url:
profileStr = 'https://www.w3.org/ns/activitystreams' profile_str = 'https://www.w3.org/ns/activitystreams'
asHeader = { as_header = {
'Accept': 'application/ld+json; profile="' + profileStr + '"' 'Accept': 'application/ld+json; profile="' + profile_str + '"'
} }
signing_priv_key_pem = None signing_priv_key_pem = None
if args.secure_mode: if args.secure_mode:
signing_priv_key_pem = get_instance_actor_key(base_dir, domain) signing_priv_key_pem = get_instance_actor_key(base_dir, domain)
followersList = \ followers_list = \
download_follow_collection(signing_priv_key_pem, download_follow_collection(signing_priv_key_pem,
'followers', session, 'followers', session,
http_prefix, personUrl, 1, 3, args.debug) http_prefix, person_url, 1, 3, args.debug)
if followersList: if followers_list:
for actor in followersList: for actor in followers_list:
print(actor) print(actor)
sys.exit() sys.exit()
@ -2267,10 +2271,10 @@ if args.addaccount:
print('Use the --domain option to set the domain name') print('Use the --domain option to set the domain name')
sys.exit() sys.exit()
configuredDomain = get_config_param(base_dir, 'domain') configured_domain = get_config_param(base_dir, 'domain')
if configuredDomain: if configured_domain:
if domain != configuredDomain: if domain != configured_domain:
print('The account domain is expected to be ' + configuredDomain) print('The account domain is expected to be ' + configured_domain)
sys.exit() sys.exit()
if not valid_nickname(domain, nickname): if not valid_nickname(domain, nickname):
@ -2286,8 +2290,8 @@ if args.addaccount:
if len(args.password.strip()) < 8: if len(args.password.strip()) < 8:
print('Password should be at least 8 characters') print('Password should be at least 8 characters')
sys.exit() sys.exit()
accountDir = acct_dir(base_dir, nickname, domain) account_dir = acct_dir(base_dir, nickname, domain)
if os.path.isdir(accountDir): if os.path.isdir(account_dir):
print('Account already exists') print('Account already exists')
sys.exit() sys.exit()
if os.path.isdir(base_dir + '/deactivated/' + nickname + '@' + domain): if os.path.isdir(base_dir + '/deactivated/' + nickname + '@' + domain):
@ -2299,7 +2303,7 @@ if args.addaccount:
http_prefix = 'http' http_prefix = 'http'
create_person(base_dir, nickname, domain, port, http_prefix, create_person(base_dir, nickname, domain, port, http_prefix,
True, not args.noapproval, args.password.strip()) True, not args.noapproval, args.password.strip())
if os.path.isdir(accountDir): if os.path.isdir(account_dir):
print('Account created for ' + nickname + '@' + domain) print('Account created for ' + nickname + '@' + domain)
else: else:
print('Account creation failed') print('Account creation failed')
@ -2329,13 +2333,13 @@ if args.addgroup:
if len(args.password.strip()) < 8: if len(args.password.strip()) < 8:
print('Password should be at least 8 characters') print('Password should be at least 8 characters')
sys.exit() sys.exit()
accountDir = acct_dir(base_dir, nickname, domain) account_dir = acct_dir(base_dir, nickname, domain)
if os.path.isdir(accountDir): if os.path.isdir(account_dir):
print('Group already exists') print('Group already exists')
sys.exit() sys.exit()
create_group(base_dir, nickname, domain, port, http_prefix, create_group(base_dir, nickname, domain, port, http_prefix,
True, args.password.strip()) True, args.password.strip())
if os.path.isdir(accountDir): if os.path.isdir(account_dir):
print('Group created for ' + nickname + '@' + domain) print('Group created for ' + nickname + '@' + domain)
else: else:
print('Group creation failed') print('Group creation failed')
@ -2361,10 +2365,10 @@ if args.rmaccount:
else: else:
domain = get_config_param(base_dir, 'domain') domain = get_config_param(base_dir, 'domain')
configuredDomain = get_config_param(base_dir, 'domain') configured_domain = get_config_param(base_dir, 'domain')
if configuredDomain: if configured_domain:
if domain != configuredDomain: if domain != configured_domain:
print('The account domain is expected to be ' + configuredDomain) print('The account domain is expected to be ' + configured_domain)
sys.exit() sys.exit()
if args.deactivate: if args.deactivate:
@ -2409,18 +2413,18 @@ if args.changepassword:
if not args.domain or not get_config_param(base_dir, 'domain'): if not args.domain or not get_config_param(base_dir, 'domain'):
print('Use the --domain option to set the domain name') print('Use the --domain option to set the domain name')
sys.exit() sys.exit()
newPassword = args.changepassword[1] new_password = args.changepassword[1]
if len(newPassword) < 8: if len(new_password) < 8:
print('Password should be at least 8 characters') print('Password should be at least 8 characters')
sys.exit() sys.exit()
accountDir = acct_dir(base_dir, nickname, domain) account_dir = acct_dir(base_dir, nickname, domain)
if not os.path.isdir(accountDir): if not os.path.isdir(account_dir):
print('Account ' + nickname + '@' + domain + ' not found') print('Account ' + nickname + '@' + domain + ' not found')
sys.exit() sys.exit()
passwordFile = base_dir + '/accounts/passwords' password_file = base_dir + '/accounts/passwords'
if os.path.isfile(passwordFile): if os.path.isfile(password_file):
if nickname + ':' in open(passwordFile).read(): if nickname + ':' in open(password_file).read():
store_basic_credentials(base_dir, nickname, newPassword) store_basic_credentials(base_dir, nickname, new_password)
print('Password for ' + nickname + ' was changed') print('Password for ' + nickname + ' was changed')
else: else:
print(nickname + ' is not in the passwords file') print(nickname + ' is not in the passwords file')
@ -2546,8 +2550,7 @@ if args.availability:
' as ' + args.availability) ' as ' + args.availability)
send_availability_via_server(base_dir, session, nickname, args.password, send_availability_via_server(base_dir, session, nickname, args.password,
domain, port, domain, port, http_prefix,
http_prefix,
args.availability, args.availability,
cached_webfingers, person_cache, cached_webfingers, person_cache,
True, __version__, signing_priv_key_pem) True, __version__, signing_priv_key_pem)
@ -2621,8 +2624,8 @@ else:
get_config_param(base_dir, 'sharedItemsFederatedDomains') get_config_param(base_dir, 'sharedItemsFederatedDomains')
if fed_domains_str: if fed_domains_str:
fed_domains_list = fed_domains_str.split(',') fed_domains_list = fed_domains_str.split(',')
for sharedFederatedDomain in fed_domains_list: for shared_federated_domain in fed_domains_list:
shared_items_federated_domains.append(sharedFederatedDomain.strip()) shared_items_federated_domains.append(shared_federated_domain.strip())
if args.block: if args.block:
if not nickname: if not nickname:
@ -2637,12 +2640,12 @@ if args.block:
args.password = args.password.replace('\n', '') args.password = args.password.replace('\n', '')
if '@' in args.block: if '@' in args.block:
blockedDomain = args.block.split('@')[1] blocked_domain = args.block.split('@')[1]
blockedDomain = blockedDomain.replace('\n', '').replace('\r', '') blocked_domain = blocked_domain.replace('\n', '').replace('\r', '')
blockedNickname = args.block.split('@')[0] blocked_nickname = args.block.split('@')[0]
blockedActor = http_prefix + '://' + blockedDomain + \ blocked_actor = http_prefix + '://' + blocked_domain + \
'/users/' + blockedNickname '/users/' + blocked_nickname
args.block = blockedActor args.block = blocked_actor
else: else:
if '/users/' not in args.block: if '/users/' not in args.block:
print(args.block + ' does not look like an actor url') print(args.block + ' does not look like an actor url')
@ -2745,12 +2748,12 @@ if args.unblock:
args.password = args.password.replace('\n', '') args.password = args.password.replace('\n', '')
if '@' in args.unblock: if '@' in args.unblock:
blockedDomain = args.unblock.split('@')[1] blocked_domain = args.unblock.split('@')[1]
blockedDomain = blockedDomain.replace('\n', '').replace('\r', '') blocked_domain = blocked_domain.replace('\n', '').replace('\r', '')
blockedNickname = args.unblock.split('@')[0] blocked_nickname = args.unblock.split('@')[0]
blockedActor = http_prefix + '://' + blockedDomain + \ blocked_actor = http_prefix + '://' + blocked_domain + \
'/users/' + blockedNickname '/users/' + blocked_nickname
args.unblock = blockedActor args.unblock = blocked_actor
else: else:
if '/users/' not in args.unblock: if '/users/' not in args.unblock:
print(args.unblock + ' does not look like an actor url') print(args.unblock + ' does not look like an actor url')
@ -2860,129 +2863,129 @@ if args.testdata:
delete_all_posts(base_dir, nickname, domain, 'inbox') delete_all_posts(base_dir, nickname, domain, 'inbox')
delete_all_posts(base_dir, nickname, domain, 'outbox') delete_all_posts(base_dir, nickname, domain, 'outbox')
testFollowersOnly = False test_followers_only = False
testSaveToFile = True test_save_to_file = True
testC2S = False test_c2s = False
testCommentsEnabled = True test_comments_enabled = True
testAttachImageFilename = None test_attach_image_filename = None
testMediaType = None test_media_type = None
testImageDescription = None test_image_description = None
testCity = 'London, England' test_city = 'London, England'
testInReplyTo = None test_in_reply_to = None
testInReplyToAtomUri = None test_in_reply_to_atom_uri = None
testSubject = None test_subject = None
testSchedulePost = False test_schedule_post = False
testEventDate = None test_event_date = None
testEventTime = None test_event_time = None
testLocation = None test_location = None
testIsArticle = False test_is_article = False
conversationId = None conversation_id = None
low_bandwidth = False low_bandwidth = False
create_public_post(base_dir, nickname, domain, port, http_prefix, create_public_post(base_dir, nickname, domain, port, http_prefix,
"like this is totally just a #test man", "like this is totally just a #test man",
testFollowersOnly, test_followers_only,
testSaveToFile, test_save_to_file,
testC2S, test_c2s,
testCommentsEnabled, test_comments_enabled,
testAttachImageFilename, test_attach_image_filename,
testMediaType, testImageDescription, testCity, test_media_type, test_image_description, test_city,
testInReplyTo, testInReplyToAtomUri, test_in_reply_to, test_in_reply_to_atom_uri,
testSubject, testSchedulePost, test_subject, test_schedule_post,
testEventDate, testEventTime, testLocation, test_event_date, test_event_time, test_location,
testIsArticle, args.language, conversationId, test_is_article, args.language, conversation_id,
low_bandwidth, args.content_license_url) low_bandwidth, args.content_license_url)
create_public_post(base_dir, nickname, domain, port, http_prefix, create_public_post(base_dir, nickname, domain, port, http_prefix,
"Zoiks!!!", "Zoiks!!!",
testFollowersOnly, test_followers_only,
testSaveToFile, test_save_to_file,
testC2S, test_c2s,
testCommentsEnabled, test_comments_enabled,
testAttachImageFilename, test_attach_image_filename,
testMediaType, testImageDescription, testCity, test_media_type, test_image_description, test_city,
testInReplyTo, testInReplyToAtomUri, test_in_reply_to, test_in_reply_to_atom_uri,
testSubject, testSchedulePost, test_subject, test_schedule_post,
testEventDate, testEventTime, testLocation, test_event_date, test_event_time, test_location,
testIsArticle, args.language, conversationId, test_is_article, args.language, conversation_id,
low_bandwidth, args.content_license_url) low_bandwidth, args.content_license_url)
create_public_post(base_dir, nickname, domain, port, http_prefix, create_public_post(base_dir, nickname, domain, port, http_prefix,
"Hey scoob we need like a hundred more #milkshakes", "Hey scoob we need like a hundred more #milkshakes",
testFollowersOnly, test_followers_only,
testSaveToFile, test_save_to_file,
testC2S, test_c2s,
testCommentsEnabled, test_comments_enabled,
testAttachImageFilename, test_attach_image_filename,
testMediaType, testImageDescription, testCity, test_media_type, test_image_description, test_city,
testInReplyTo, testInReplyToAtomUri, test_in_reply_to, test_in_reply_to_atom_uri,
testSubject, testSchedulePost, test_subject, test_schedule_post,
testEventDate, testEventTime, testLocation, test_event_date, test_event_time, test_location,
testIsArticle, args.language, conversationId, test_is_article, args.language, conversation_id,
low_bandwidth, args.content_license_url) low_bandwidth, args.content_license_url)
create_public_post(base_dir, nickname, domain, port, http_prefix, create_public_post(base_dir, nickname, domain, port, http_prefix,
"Getting kinda spooky around here", "Getting kinda spooky around here",
testFollowersOnly, test_followers_only,
testSaveToFile, test_save_to_file,
testC2S, test_c2s,
testCommentsEnabled, test_comments_enabled,
testAttachImageFilename, test_attach_image_filename,
testMediaType, testImageDescription, testCity, test_media_type, test_image_description, test_city,
'someone', testInReplyToAtomUri, 'someone', test_in_reply_to_atom_uri,
testSubject, testSchedulePost, test_subject, test_schedule_post,
testEventDate, testEventTime, testLocation, test_event_date, test_event_time, test_location,
testIsArticle, args.language, conversationId, test_is_article, args.language, conversation_id,
low_bandwidth, args.content_license_url) low_bandwidth, args.content_license_url)
create_public_post(base_dir, nickname, domain, port, http_prefix, create_public_post(base_dir, nickname, domain, port, http_prefix,
"And they would have gotten away with it too" + "And they would have gotten away with it too" +
"if it wasn't for those pesky hackers", "if it wasn't for those pesky hackers",
testFollowersOnly, test_followers_only,
testSaveToFile, test_save_to_file,
testC2S, test_c2s,
testCommentsEnabled, test_comments_enabled,
'img/logo.png', 'image/png', 'img/logo.png', 'image/png',
'Description of image', testCity, 'Description of image', test_city,
testInReplyTo, testInReplyToAtomUri, test_in_reply_to, test_in_reply_to_atom_uri,
testSubject, testSchedulePost, test_subject, test_schedule_post,
testEventDate, testEventTime, testLocation, test_event_date, test_event_time, test_location,
testIsArticle, args.language, conversationId, test_is_article, args.language, conversation_id,
low_bandwidth, args.content_license_url) low_bandwidth, args.content_license_url)
create_public_post(base_dir, nickname, domain, port, http_prefix, create_public_post(base_dir, nickname, domain, port, http_prefix,
"man these centralized sites are like the worst!", "man these centralized sites are like the worst!",
testFollowersOnly, test_followers_only,
testSaveToFile, test_save_to_file,
testC2S, test_c2s,
testCommentsEnabled, test_comments_enabled,
testAttachImageFilename, test_attach_image_filename,
testMediaType, testImageDescription, testCity, test_media_type, test_image_description, test_city,
testInReplyTo, testInReplyToAtomUri, test_in_reply_to, test_in_reply_to_atom_uri,
testSubject, testSchedulePost, test_subject, test_schedule_post,
testEventDate, testEventTime, testLocation, test_event_date, test_event_time, test_location,
testIsArticle, args.language, conversationId, test_is_article, args.language, conversation_id,
low_bandwidth, args.content_license_url) low_bandwidth, args.content_license_url)
create_public_post(base_dir, nickname, domain, port, http_prefix, create_public_post(base_dir, nickname, domain, port, http_prefix,
"another mystery solved #test", "another mystery solved #test",
testFollowersOnly, test_followers_only,
testSaveToFile, test_save_to_file,
testC2S, test_c2s,
testCommentsEnabled, test_comments_enabled,
testAttachImageFilename, test_attach_image_filename,
testMediaType, testImageDescription, testCity, test_media_type, test_image_description, test_city,
testInReplyTo, testInReplyToAtomUri, test_in_reply_to, test_in_reply_to_atom_uri,
testSubject, testSchedulePost, test_subject, test_schedule_post,
testEventDate, testEventTime, testLocation, test_event_date, test_event_time, test_location,
testIsArticle, args.language, conversationId, test_is_article, args.language, conversation_id,
low_bandwidth, args.content_license_url) low_bandwidth, args.content_license_url)
create_public_post(base_dir, nickname, domain, port, http_prefix, create_public_post(base_dir, nickname, domain, port, http_prefix,
"let's go bowling", "let's go bowling",
testFollowersOnly, test_followers_only,
testSaveToFile, test_save_to_file,
testC2S, test_c2s,
testCommentsEnabled, test_comments_enabled,
testAttachImageFilename, test_attach_image_filename,
testMediaType, testImageDescription, testCity, test_media_type, test_image_description, test_city,
testInReplyTo, testInReplyToAtomUri, test_in_reply_to, test_in_reply_to_atom_uri,
testSubject, testSchedulePost, test_subject, test_schedule_post,
testEventDate, testEventTime, testLocation, test_event_date, test_event_time, test_location,
testIsArticle, args.language, conversationId, test_is_article, args.language, conversation_id,
low_bandwidth, args.content_license_url) low_bandwidth, args.content_license_url)
domain_full = domain + ':' + str(port) domain_full = domain + ':' + str(port)
clear_follows(base_dir, nickname, domain) clear_follows(base_dir, nickname, domain)
@ -3144,14 +3147,14 @@ if low_bandwidth is not None:
user_agents_blocked = [] user_agents_blocked = []
if args.userAgentBlocks: if args.userAgentBlocks:
user_agents_blockedStr = args.userAgentBlocks user_agents_blocked_str = args.userAgentBlocks
set_config_param(base_dir, 'userAgentsBlocked', user_agents_blockedStr) set_config_param(base_dir, 'userAgentsBlocked', user_agents_blocked_str)
else: else:
user_agents_blockedStr = \ user_agents_blocked_str = \
get_config_param(base_dir, 'userAgentsBlocked') get_config_param(base_dir, 'userAgentsBlocked')
if user_agents_blockedStr: if user_agents_blocked_str:
agentBlocksList = user_agents_blockedStr.split(',') agent_blocks_list = user_agents_blocked_str.split(',')
for agentBlockStr in agentBlocksList: for agentBlockStr in agent_blocks_list:
user_agents_blocked.append(agentBlockStr.strip()) user_agents_blocked.append(agentBlockStr.strip())
lists_enabled = '' lists_enabled = ''
@ -3166,23 +3169,23 @@ city = \
if city is not None: if city is not None:
args.city = city args.city = city
YTDomain = get_config_param(base_dir, 'youtubedomain') yt_domain = get_config_param(base_dir, 'youtubedomain')
if YTDomain: if yt_domain:
if '://' in YTDomain: if '://' in yt_domain:
YTDomain = YTDomain.split('://')[1] yt_domain = yt_domain.split('://')[1]
if '/' in YTDomain: if '/' in yt_domain:
YTDomain = YTDomain.split('/')[0] yt_domain = yt_domain.split('/')[0]
if '.' in YTDomain: if '.' in yt_domain:
args.yt_replace_domain = YTDomain args.yt_replace_domain = yt_domain
twitterDomain = get_config_param(base_dir, 'twitterdomain') twitter_domain = get_config_param(base_dir, 'twitterdomain')
if twitterDomain: if twitter_domain:
if '://' in twitterDomain: if '://' in twitter_domain:
twitterDomain = twitterDomain.split('://')[1] twitter_domain = twitter_domain.split('://')[1]
if '/' in twitterDomain: if '/' in twitter_domain:
twitterDomain = twitterDomain.split('/')[0] twitter_domain = twitter_domain.split('/')[0]
if '.' in twitterDomain: if '.' in twitter_domain:
args.twitter_replacement_domain = twitterDomain args.twitter_replacement_domain = twitter_domain
if set_theme(base_dir, theme_name, domain, if set_theme(base_dir, theme_name, domain,
args.allow_local_network_access, args.language): args.allow_local_network_access, args.language):
@ -3205,8 +3208,8 @@ if args.registration:
set_config_param(base_dir, 'registration', 'closed') set_config_param(base_dir, 'registration', 'closed')
print('New registrations closed') print('New registrations closed')
defaultCurrency = get_config_param(base_dir, 'defaultCurrency') default_currency = get_config_param(base_dir, 'defaultCurrency')
if not defaultCurrency: if not default_currency:
set_config_param(base_dir, 'defaultCurrency', 'EUR') set_config_param(base_dir, 'defaultCurrency', 'EUR')
if args.defaultCurrency: if args.defaultCurrency:
if args.defaultCurrency == args.defaultCurrency.upper(): if args.defaultCurrency == args.defaultCurrency.upper():

106
tests.py
View File

@ -3739,7 +3739,7 @@ def _test_danger_css(base_dir: str) -> None:
def _test_danger_svg(base_dir: str) -> None: def _test_danger_svg(base_dir: str) -> None:
print('testDangerousSVG') print('test_dangerous_svg')
svg_content = \ svg_content = \
' <svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">' + \ ' <svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg">' + \
' <circle cx="5" cy="5" r="4" />' + \ ' <circle cx="5" cy="5" r="4" />' + \
@ -3770,7 +3770,7 @@ def _test_danger_svg(base_dir: str) -> None:
def _test_danger_markup(): def _test_danger_markup():
print('testDangerousMarkup') print('test_dangerous_markup')
allow_local_network_access = False allow_local_network_access = False
content = '<p>This is a valid message</p>' content = '<p>This is a valid message</p>'
assert not dangerous_markup(content, allow_local_network_access) assert not dangerous_markup(content, allow_local_network_access)
@ -3851,7 +3851,7 @@ def _run_html_replace_quote_marks():
def _test_json_post_allows_comment(): def _test_json_post_allows_comment():
print('test_jsonPostAllowsComments') print('test_json_post_allows_comments')
post_json_object = { post_json_object = {
"id": "123" "id": "123"
} }
@ -3893,7 +3893,7 @@ def _test_json_post_allows_comment():
def _test_remove_id_ending(): def _test_remove_id_ending():
print('testRemoveIdEnding') print('test_remove_id_ending')
test_str = 'https://activitypub.somedomain.net' test_str = 'https://activitypub.somedomain.net'
result_str = remove_id_ending(test_str) result_str = remove_id_ending(test_str)
assert result_str == 'https://activitypub.somedomain.net' assert result_str == 'https://activitypub.somedomain.net'
@ -3919,7 +3919,7 @@ def _test_remove_id_ending():
def _test_valid_content_warning(): def _test_valid_content_warning():
print('testValidContentWarning') print('test_valid_content_warning')
result_str = valid_content_warning('Valid content warning') result_str = valid_content_warning('Valid content warning')
assert result_str == 'Valid content warning' assert result_str == 'Valid content warning'
@ -3932,7 +3932,7 @@ def _test_valid_content_warning():
def _test_translations(base_dir: str) -> None: def _test_translations(base_dir: str) -> None:
print('testTranslations') print('test_translations')
languages_str = get_supported_languages(base_dir) languages_str = get_supported_languages(base_dir)
assert languages_str assert languages_str
@ -3958,7 +3958,7 @@ def _test_translations(base_dir: str) -> None:
def _test_constant_time_string(): def _test_constant_time_string():
print('testConstantTimeStringCheck') print('test_constant_time_string_check')
assert constant_time_string_check('testing', 'testing') assert constant_time_string_check('testing', 'testing')
assert not constant_time_string_check('testing', '1234') assert not constant_time_string_check('testing', '1234')
assert not constant_time_string_check('testing', '1234567') assert not constant_time_string_check('testing', '1234567')
@ -3995,7 +3995,7 @@ def _test_constant_time_string():
def _test_replace_email_quote(): def _test_replace_email_quote():
print('testReplaceEmailQuote') print('test_replace_email_quote')
test_str = '<p>This content has no quote.</p>' test_str = '<p>This content has no quote.</p>'
assert html_replace_email_quote(test_str) == test_str assert html_replace_email_quote(test_str) == test_str
@ -4053,7 +4053,7 @@ def _test_replace_email_quote():
def _test_strip_html_tag(): def _test_strip_html_tag():
print('testRemoveHtmlTag') print('test_remove_html_tag')
test_str = "<p><img width=\"864\" height=\"486\" " + \ test_str = "<p><img width=\"864\" height=\"486\" " + \
"src=\"https://somesiteorother.com/image.jpg\"></p>" "src=\"https://somesiteorother.com/image.jpg\"></p>"
result_str = remove_html_tag(test_str, 'width') result_str = remove_html_tag(test_str, 'width')
@ -4062,7 +4062,7 @@ def _test_strip_html_tag():
def _test_hashtag_rules(): def _test_hashtag_rules():
print('testHashtagRuleTree') print('test_hashtag_rule_tree')
operators = ('not', 'and', 'or', 'xor', 'from', 'contains') operators = ('not', 'and', 'or', 'xor', 'from', 'contains')
url = 'testsite.com' url = 'testsite.com'
@ -4194,7 +4194,7 @@ def _test_hashtag_rules():
def _test_newswire_tags(): def _test_newswire_tags():
print('testNewswireTags') print('test_newswire_tags')
rss_description = '<img src="https://somesite/someimage.jpg" ' + \ rss_description = '<img src="https://somesite/someimage.jpg" ' + \
'class="misc-stuff" alt="#ExcitingHashtag" ' + \ 'class="misc-stuff" alt="#ExcitingHashtag" ' + \
'srcset="https://somesite/someimage.jpg" ' + \ 'srcset="https://somesite/someimage.jpg" ' + \
@ -4208,7 +4208,7 @@ def _test_newswire_tags():
def _test_first_paragraph_from_string(): def _test_first_paragraph_from_string():
print('testFirstParagraphFromString') print('test_first_paragraph_from_string')
test_str = \ test_str = \
'<p><a href="https://somesite.com/somepath">This is a test</a></p>' + \ '<p><a href="https://somesite.com/somepath">This is a test</a></p>' + \
'<p>This is another paragraph</p>' '<p>This is another paragraph</p>'
@ -4223,7 +4223,7 @@ def _test_first_paragraph_from_string():
def _test_parse_feed_date(): def _test_parse_feed_date():
print('testParseFeedDate') print('test_parse_feed_date')
pub_date = "2020-12-14T00:08:06+00:00" pub_date = "2020-12-14T00:08:06+00:00"
published_date = parse_feed_date(pub_date) published_date = parse_feed_date(pub_date)
@ -4243,7 +4243,7 @@ def _test_parse_feed_date():
def _test_valid_nick(): def _test_valid_nick():
print('testValidNickname') print('test_valid_nickname')
domain = 'somedomain.net' domain = 'somedomain.net'
nickname = 'myvalidnick' nickname = 'myvalidnick'
@ -4260,7 +4260,7 @@ def _test_valid_nick():
def _test_guess_tag_category() -> None: def _test_guess_tag_category() -> None:
print('testGuessHashtagCategory') print('test_guess_hashtag_category')
hashtag_categories = { hashtag_categories = {
"foo": ["swan", "goose"], "foo": ["swan", "goose"],
"bar": ["cats", "mouse"] "bar": ["cats", "mouse"]
@ -4273,11 +4273,10 @@ def _test_guess_tag_category() -> None:
def _test_mentioned_people(base_dir: str) -> None: def _test_mentioned_people(base_dir: str) -> None:
print('testGetMentionedPeople') print('test_get_mentioned_people')
content = "@dragon@cave.site @bat@cave.site This is a test." content = "@dragon@cave.site @bat@cave.site This is a test."
actors = get_mentioned_people(base_dir, 'https', actors = \
content, get_mentioned_people(base_dir, 'https', content, 'mydomain', False)
'mydomain', False)
assert actors assert actors
assert len(actors) == 2 assert len(actors) == 2
assert actors[0] == "https://cave.site/users/dragon" assert actors[0] == "https://cave.site/users/dragon"
@ -4503,7 +4502,7 @@ def _diagram_groups(include_groups: [],
def _test_post_variable_names(): def _test_post_variable_names():
print('testPostVariableNames') print('test_post_variable_names')
for _, _, files in os.walk('.'): for _, _, files in os.walk('.'):
for source_file in files: for source_file in files:
@ -4537,7 +4536,7 @@ def _test_post_variable_names():
def _test_config_param_names(): def _test_config_param_names():
print('testConfigParamNames') print('test_config_param_names')
fnames = ('get_config_param', 'set_config_param') fnames = ('get_config_param', 'set_config_param')
for _, _, files in os.walk('.'): for _, _, files in os.walk('.'):
@ -4586,7 +4585,7 @@ def _test_config_param_names():
def _test_source_contains_no_tabs(): def _test_source_contains_no_tabs():
print('testSourceContainsNoTabs') print('test_source_contains_no_tabs')
for _, _, files in os.walk('.'): for _, _, files in os.walk('.'):
for source_file in files: for source_file in files:
@ -4608,7 +4607,7 @@ def _test_source_contains_no_tabs():
def _test_checkbox_names(): def _test_checkbox_names():
print('testCheckboxNames') print('test_checkbox_names')
fnames = ['edit_text_field', 'edit_check_box', 'edit_text_area'] fnames = ['edit_text_field', 'edit_check_box', 'edit_text_area']
for _, _, files in os.walk('.'): for _, _, files in os.walk('.'):
@ -4653,7 +4652,7 @@ def _test_checkbox_names():
def _test_post_field_names(source_file: str, fieldnames: []): def _test_post_field_names(source_file: str, fieldnames: []):
print('test_POST_field_Names') print('test_post_field_Names')
fnames = [] fnames = []
for field in fieldnames: for field in fieldnames:
@ -4722,7 +4721,7 @@ def _test_post_field_names(source_file: str, fieldnames: []):
def _test_functions(): def _test_functions():
print('test_Functions') print('test_functions')
function = {} function = {}
function_properties = {} function_properties = {}
modules = {} modules = {}
@ -5087,6 +5086,7 @@ def _test_functions():
def _test_links_within_post(base_dir: str) -> None: def _test_links_within_post(base_dir: str) -> None:
print('test_links_within_post')
system_language = 'en' system_language = 'en'
nickname = 'test27636' nickname = 'test27636'
domain = 'rando.site' domain = 'rando.site'
@ -5167,7 +5167,7 @@ def _test_links_within_post(base_dir: str) -> None:
def _test_mastoapi(): def _test_mastoapi():
print('testMastoApi') print('test_masto_api')
nickname = 'ThisIsATestNickname' nickname = 'ThisIsATestNickname'
masto_id = get_masto_api_v1id_from_nickname(nickname) masto_id = get_masto_api_v1id_from_nickname(nickname)
assert masto_id assert masto_id
@ -5178,7 +5178,7 @@ def _test_mastoapi():
def _test_domain_handling(): def _test_domain_handling():
print('testDomainHandling') print('test_domain_handling')
test_domain = 'localhost' test_domain = 'localhost'
assert decoded_host(test_domain) == test_domain assert decoded_host(test_domain) == test_domain
test_domain = '127.0.0.1:60' test_domain = '127.0.0.1:60'
@ -5190,7 +5190,7 @@ def _test_domain_handling():
def _test_prepare_html_post_nick(): def _test_prepare_html_post_nick():
print('testPrepareHtmlPostNickname') print('test_prepare_html_post_nickname')
post_html = '<a class="imageAnchor" href="/users/bob?replyfollowers=' post_html = '<a class="imageAnchor" href="/users/bob?replyfollowers='
post_html += '<a class="imageAnchor" href="/users/bob?repeatprivate=' post_html += '<a class="imageAnchor" href="/users/bob?repeatprivate='
result = prepare_html_post_nickname('alice', post_html) result = prepare_html_post_nickname('alice', post_html)
@ -5205,7 +5205,7 @@ def _test_prepare_html_post_nick():
def _test_valid_hash_tag(): def _test_valid_hash_tag():
print('testValidHashTag') print('test_valid_hash_tag')
assert valid_hash_tag('ThisIsValid') assert valid_hash_tag('ThisIsValid')
assert valid_hash_tag('ThisIsValid12345') assert valid_hash_tag('ThisIsValid12345')
assert valid_hash_tag('ThisIsVälid') assert valid_hash_tag('ThisIsVälid')
@ -5220,7 +5220,7 @@ def _test_valid_hash_tag():
def _test_markdown_to_html(): def _test_markdown_to_html():
print('testMarkdownToHtml') print('test_markdown_to_html')
markdown = 'This is just plain text' markdown = 'This is just plain text'
assert markdown_to_html(markdown) == markdown assert markdown_to_html(markdown) == markdown
@ -5267,7 +5267,7 @@ def _test_markdown_to_html():
def _test_extract_text_fields_from_post(): def _test_extract_text_fields_from_post():
print('testExtractTextFieldsInPOST') print('test_extract_text_fields_in_post')
boundary = '-----------------------------116202748023898664511855843036' boundary = '-----------------------------116202748023898664511855843036'
form_data = '-----------------------------116202748023898664511855' + \ form_data = '-----------------------------116202748023898664511855' + \
'843036\r\nContent-Disposition: form-data; name="submitPost"' + \ '843036\r\nContent-Disposition: form-data; name="submitPost"' + \
@ -5323,7 +5323,7 @@ def _test_speaker_replace_link():
def _test_camel_case_split(): def _test_camel_case_split():
print('testCamelCaseSplit') print('test_camel_case_split')
test_str = 'ThisIsCamelCase' test_str = 'ThisIsCamelCase'
assert camel_case_split(test_str) == 'This Is Camel Case' assert camel_case_split(test_str) == 'This Is Camel Case'
@ -5332,7 +5332,7 @@ def _test_camel_case_split():
def _test_emoji_images(): def _test_emoji_images():
print('testEmojiImages') print('test_emoji_images')
emoji_filename = 'emoji/default_emoji.json' emoji_filename = 'emoji/default_emoji.json'
assert os.path.isfile(emoji_filename) assert os.path.isfile(emoji_filename)
emoji_json = load_json(emoji_filename) emoji_json = load_json(emoji_filename)
@ -5496,7 +5496,7 @@ def test_update_actor(base_dir: str):
def _test_remove_interactions() -> None: def _test_remove_interactions() -> None:
print('testRemovePostInteractions') print('test_remove_post_interactions')
post_json_object = { post_json_object = {
"type": "Create", "type": "Create",
"object": { "object": {
@ -5529,7 +5529,7 @@ def _test_remove_interactions() -> None:
def _test_spoofed_geolocation() -> None: def _test_spoofed_geolocation() -> None:
print('testSpoofGeolocation') print('test_spoof_geolocation')
nogo_line = \ nogo_line = \
'NEW YORK, USA: 73.951W,40.879, 73.974W,40.83, ' + \ 'NEW YORK, USA: 73.951W,40.879, 73.974W,40.83, ' + \
'74.029W,40.756, 74.038W,40.713, 74.056W,40.713, ' + \ '74.029W,40.756, 74.038W,40.713, 74.056W,40.713, ' + \
@ -5772,7 +5772,7 @@ def _test_spoofed_geolocation() -> None:
def _test_skills() -> None: def _test_skills() -> None:
print('testSkills') print('test_skills')
actor_json = { actor_json = {
'hasOccupation': [ 'hasOccupation': [
{ {
@ -5798,7 +5798,7 @@ def _test_skills() -> None:
def _test_roles() -> None: def _test_roles() -> None:
print('testRoles') print('test_roles')
actor_json = { actor_json = {
'hasOccupation': [ 'hasOccupation': [
{ {
@ -5822,7 +5822,7 @@ def _test_roles() -> None:
def _test_useragent_domain() -> None: def _test_useragent_domain() -> None:
print('testUserAgentDomain') print('test_user_agent_domain')
user_agent = \ user_agent = \
'http.rb/4.4.1 (Mastodon/9.10.11; +https://mastodon.something/)' 'http.rb/4.4.1 (Mastodon/9.10.11; +https://mastodon.something/)'
assert user_agent_domain(user_agent, False) == 'mastodon.something' assert user_agent_domain(user_agent, False) == 'mastodon.something'
@ -5832,7 +5832,7 @@ def _test_useragent_domain() -> None:
def _test_switch_word(base_dir: str) -> None: def _test_switch_word(base_dir: str) -> None:
print('testSwitchWords') print('test_switch_words')
rules = [ rules = [
"rock -> hamster", "rock -> hamster",
"orange -> lemon" "orange -> lemon"
@ -5854,7 +5854,7 @@ def _test_switch_word(base_dir: str) -> None:
def _test_word_lengths_limit() -> None: def _test_word_lengths_limit() -> None:
print('testLimitWordLengths') print('test_limit_word_lengths')
max_word_length = 13 max_word_length = 13
text = "This is a test" text = "This is a test"
result = limit_word_lengths(text, max_word_length) result = limit_word_lengths(text, max_word_length)
@ -5866,7 +5866,7 @@ def _test_word_lengths_limit() -> None:
def _test_limit_repeted_words() -> None: def _test_limit_repeted_words() -> None:
print('limit_repeated_words') print('test_limit_repeated_words')
text = \ text = \
"This is a preamble.\n\n" + \ "This is a preamble.\n\n" + \
"Same Same Same Same Same Same Same Same Same Same " + \ "Same Same Same Same Same Same Same Same Same Same " + \
@ -5903,7 +5903,7 @@ def _test_limit_repeted_words() -> None:
def _test_set_actor_language(): def _test_set_actor_language():
print('testSetActorLanguages') print('test_set_actor_languages')
actor_json = { actor_json = {
"attachment": [] "attachment": []
} }
@ -5922,7 +5922,7 @@ def _test_set_actor_language():
def _test_get_links_from_content(): def _test_get_links_from_content():
print('testGetLinksFromContent') print('test_get_links_from_content')
content = 'This text has no links' content = 'This text has no links'
links = get_links_from_content(content) links = get_links_from_content(content)
assert not links assert not links
@ -5946,7 +5946,7 @@ def _test_get_links_from_content():
def _test_authorized_shared_items(): def _test_authorized_shared_items():
print('testAuthorizeSharedItems') print('test_authorize_shared_items')
shared_items_fed_domains = \ shared_items_fed_domains = \
['dog.domain', 'cat.domain', 'birb.domain'] ['dog.domain', 'cat.domain', 'birb.domain']
tokens_json = \ tokens_json = \
@ -5992,7 +5992,7 @@ def _test_authorized_shared_items():
def _test_date_conversions() -> None: def _test_date_conversions() -> None:
print('testDateConversions') print('test_date_conversions')
date_str = "2021-05-16T14:37:41Z" date_str = "2021-05-16T14:37:41Z"
date_sec = date_string_to_seconds(date_str) date_sec = date_string_to_seconds(date_str)
date_str2 = date_seconds_to_string(date_sec) date_str2 = date_seconds_to_string(date_sec)
@ -6000,7 +6000,7 @@ def _test_date_conversions() -> None:
def _test_valid_password(): def _test_valid_password():
print('testValidPassword') print('test_valid_password')
assert not valid_password('123') assert not valid_password('123')
assert not valid_password('') assert not valid_password('')
assert valid_password('パスワード12345') assert valid_password('パスワード12345')
@ -6009,7 +6009,7 @@ def _test_valid_password():
def _test_get_price_from_string() -> None: def _test_get_price_from_string() -> None:
print('testGetPriceFromString') print('test_get_price_from_string')
price, curr = get_price_from_string("5.23") price, curr = get_price_from_string("5.23")
assert price == "5.23" assert price == "5.23"
assert curr == "EUR" assert curr == "EUR"
@ -6080,7 +6080,7 @@ def _translate_ontology(base_dir: str) -> None:
def _test_can_replyto(base_dir: str) -> None: def _test_can_replyto(base_dir: str) -> None:
print('testCanReplyTo') print('test_can_reply_to')
system_language = 'en' system_language = 'en'
nickname = 'test27637' nickname = 'test27637'
domain = 'rando.site' domain = 'rando.site'
@ -6142,7 +6142,7 @@ def _test_can_replyto(base_dir: str) -> None:
def _test_seconds_between_publish() -> None: def _test_seconds_between_publish() -> None:
print('testSecondsBetweenPublished') print('test_seconds_between_published')
published1 = "2021-10-14T09:39:27Z" published1 = "2021-10-14T09:39:27Z"
published2 = "2021-10-14T09:41:28Z" published2 = "2021-10-14T09:41:28Z"
@ -6155,7 +6155,7 @@ def _test_seconds_between_publish() -> None:
def _test_word_similarity() -> None: def _test_word_similarity() -> None:
print('testWordsSimilarity') print('test_words_similarity')
min_words = 10 min_words = 10
content1 = "This is the same" content1 = "This is the same"
content2 = "This is the same" content2 = "This is the same"
@ -6179,7 +6179,7 @@ def _test_word_similarity() -> None:
def _test_add_cw_lists(base_dir: str) -> None: def _test_add_cw_lists(base_dir: str) -> None:
print('testAddCWfromLists') print('test_add_CW_from_lists')
translate = {} translate = {}
cw_lists = load_cw_lists(base_dir, True) cw_lists = load_cw_lists(base_dir, True)
assert cw_lists assert cw_lists
@ -6220,7 +6220,7 @@ def _test_add_cw_lists(base_dir: str) -> None:
def _test_valid_emoji_content() -> None: def _test_valid_emoji_content() -> None:
print('testValidEmojiContent') print('test_valid_emoji_content')
assert not valid_emoji_content(None) assert not valid_emoji_content(None)
assert not valid_emoji_content(' ') assert not valid_emoji_content(' ')
assert not valid_emoji_content('j') assert not valid_emoji_content('j')
@ -6231,7 +6231,7 @@ def _test_valid_emoji_content() -> None:
def _test_httpsig_base_new(with_digest: bool, base_dir: str, def _test_httpsig_base_new(with_digest: bool, base_dir: str,
algorithm: str, digest_algorithm: str) -> None: algorithm: str, digest_algorithm: str) -> None:
print('testHttpsigNew(' + str(with_digest) + ')') print('test_httpsig_new(' + str(with_digest) + ')')
debug = True debug = True
path = base_dir + '/.testHttpsigBaseNew' path = base_dir + '/.testHttpsigBaseNew'