From 8e67d4910fc02803a3404f7152a9effd9c913522 Mon Sep 17 00:00:00 2001
From: Bob Mottram
Date: Mon, 23 Dec 2024 18:23:47 +0000
Subject: [PATCH] Add list types
---
tests.py | 182 +++++++++++++++++++-------------------
theme.py | 2 +-
tox.py | 2 +-
utils.py | 32 +++----
webapp_column_left.py | 8 +-
webapp_column_right.py | 12 +--
webapp_confirm.py | 12 +--
webapp_conversation.py | 2 +-
webapp_create_post.py | 6 +-
webapp_frontscreen.py | 2 +-
webapp_hashtagswarm.py | 10 +--
webapp_likers.py | 2 +-
webapp_moderation.py | 10 +--
webapp_podcast.py | 4 +-
webapp_post.py | 14 +--
webapp_profile.py | 14 +--
webapp_search.py | 24 ++---
webapp_suspended.py | 2 +-
webapp_tos.py | 2 +-
webapp_utils.py | 32 +++----
webapp_welcome.py | 2 +-
webapp_welcome_final.py | 2 +-
webapp_welcome_profile.py | 2 +-
webfinger.py | 4 +-
website.py | 4 +-
xmpp.py | 2 +-
youtube.py | 2 +-
27 files changed, 196 insertions(+), 196 deletions(-)
diff --git a/tests.py b/tests.py
index ae714eaeb..497f81f8c 100644
--- a/tests.py
+++ b/tests.py
@@ -1089,7 +1089,7 @@ def create_server_bob(path: str, domain: str, port: int,
lists_enabled = ''
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
dyslexic_font = False
- crawlers_allowed = []
+ crawlers_allowed: list[str] = []
check_actor_timeout = 2
preferred_podcast_formats = None
clacks = None
@@ -1146,7 +1146,7 @@ def create_server_eve(path: str, domain: str, port: int, federation_list: [],
shutil.rmtree(path, ignore_errors=False)
os.mkdir(path)
os.chdir(path)
- shared_items_federated_domains = []
+ shared_items_federated_domains: list[str] = []
nickname = 'eve'
http_prefix = 'http'
proxy_type = None
@@ -1179,14 +1179,14 @@ def create_server_eve(path: str, domain: str, port: int, federation_list: [],
show_node_info_version = True
city = 'London, England'
log_login_failures = False
- user_agents_blocked = []
+ user_agents_blocked: list[str] = []
max_like_count = 10
low_bandwidth = True
default_reply_interval_hrs = 9999999999
lists_enabled = ''
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
dyslexic_font = False
- crawlers_allowed = []
+ crawlers_allowed: list[str] = []
check_actor_timeout = 2
preferred_podcast_formats = None
clacks = None
@@ -1268,7 +1268,7 @@ def create_server_group(path: str, domain: str, port: int,
shutil.rmtree(path, ignore_errors=False)
os.mkdir(path)
os.chdir(path)
- shared_items_federated_domains = []
+ shared_items_federated_domains: list[str] = []
# system_language = 'en'
nickname = 'testgroup'
http_prefix = 'http'
@@ -1304,14 +1304,14 @@ def create_server_group(path: str, domain: str, port: int,
show_node_info_version = True
city = 'London, England'
log_login_failures = False
- user_agents_blocked = []
+ user_agents_blocked: list[str] = []
max_like_count = 10
low_bandwidth = True
default_reply_interval_hrs = 9999999999
lists_enabled = ''
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
dyslexic_font = False
- crawlers_allowed = []
+ crawlers_allowed: list[str] = []
check_actor_timeout = 2
preferred_podcast_formats = None
clacks = None
@@ -1446,7 +1446,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
cc_url = None
alice_person_cache = {}
alice_cached_webfingers = {}
- alice_shared_items_federated_domains = []
+ alice_shared_items_federated_domains: list[str] = []
alice_shared_item_federation_tokens = {}
attached_image_filename = base_dir + '/img/logo.png'
test_image_width, test_image_height = \
@@ -1471,8 +1471,8 @@ def test_post_message_between_servers(base_dir: str) -> None:
buy_url = ''
chat_url = ''
auto_cw_cache = {}
- searchable_by = []
- mitm_servers = []
+ searchable_by: list[str] = []
+ mitm_servers: list[str] = []
send_result = \
send_post(signing_priv_key_pem, __version__,
session_alice, alice_dir, 'alice', alice_domain, alice_port,
@@ -1592,7 +1592,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
bob_post_log = []
bob_person_cache = {}
bob_cached_webfingers = {}
- sites_unavailable = []
+ sites_unavailable: list[str] = []
status_number = None
outbox_post_filename = None
outbox_path = data_dir(alice_dir) + '/alice@' + alice_domain + '/outbox'
@@ -1603,7 +1603,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
outbox_post_filename = outbox_path + '/' + name
assert status_number > 0
assert outbox_post_filename
- mitm_servers = []
+ mitm_servers: list[str] = []
assert like_post({}, session_bob, bob_dir, federation_list,
'bob', bob_domain, bob_port, http_prefix,
'alice', alice_domain, alice_port, [],
@@ -1627,8 +1627,8 @@ def test_post_message_between_servers(base_dir: str) -> None:
print('\n\n*******************************************************')
print("Bob reacts to Alice's post")
- sites_unavailable = []
- mitm_servers = []
+ sites_unavailable: list[str] = []
+ mitm_servers: list[str] = []
assert reaction_post({}, session_bob, bob_dir, federation_list,
'bob', bob_domain, bob_port, http_prefix,
'alice', alice_domain, alice_port, [],
@@ -1669,8 +1669,8 @@ def test_post_message_between_servers(base_dir: str) -> None:
print('outbox items before announce: ' + str(outbox_before_announce_count))
assert outbox_before_announce_count == 0
assert before_announce_count == 0
- sites_unavailable = []
- mitm_servers = []
+ sites_unavailable: list[str] = []
+ mitm_servers: list[str] = []
announce_public(session_bob, bob_dir, federation_list,
'bob', bob_domain, bob_port, http_prefix,
object_url,
@@ -1731,7 +1731,7 @@ def test_follow_between_servers(base_dir: str) -> None:
languages_understood = [system_language]
http_prefix = 'http'
proxy_type = None
- federation_list = []
+ federation_list: list[str] = []
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
media_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
media_creator = 'Penfold'
@@ -1814,10 +1814,10 @@ def test_follow_between_servers(base_dir: str) -> None:
alice_person_cache = {}
alice_cached_webfingers = {}
alice_post_log = []
- sites_unavailable = []
+ sites_unavailable: list[str] = []
bob_actor = http_prefix + '://' + bob_address + '/users/bob'
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
send_result = \
send_follow_request(session_alice, alice_dir,
'alice', alice_domain,
@@ -1863,7 +1863,7 @@ def test_follow_between_servers(base_dir: str) -> None:
alice_post_log = []
alice_person_cache = {}
alice_cached_webfingers = {}
- alice_shared_items_federated_domains = []
+ alice_shared_items_federated_domains: list[str] = []
alice_shared_item_federation_tokens = {}
alice_post_log = []
is_article = False
@@ -1875,8 +1875,8 @@ def test_follow_between_servers(base_dir: str) -> None:
chat_url = ''
video_transcript = None
auto_cw_cache = {}
- searchable_by = []
- mitm_servers = []
+ searchable_by: list[str] = []
+ mitm_servers: list[str] = []
send_result = \
send_post(signing_priv_key_pem, __version__,
session_alice, alice_dir, 'alice', alice_domain, alice_port,
@@ -1940,7 +1940,7 @@ def test_shared_items_federation(base_dir: str) -> None:
languages_understood = [system_language]
http_prefix = 'http'
proxy_type = None
- federation_list = []
+ federation_list: list[str] = []
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
media_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
media_creator = 'Dr Drokk'
@@ -2021,7 +2021,7 @@ def test_shared_items_federation(base_dir: str) -> None:
'host': bob_address,
'Accept': 'application/ld+json; profile="' + profile_str + '"'
}
- mitm_servers = []
+ mitm_servers: list[str] = []
bob_instance_actor_json = \
get_json(signing_priv_key_pem, session_client,
'http://' + bob_address + '/@actor', test_headers, {}, True,
@@ -2056,8 +2056,8 @@ def test_shared_items_federation(base_dir: str) -> None:
alice_person_cache = {}
alice_cached_webfingers = {}
alice_post_log = []
- sites_unavailable = []
- mitm_servers = []
+ sites_unavailable: list[str] = []
+ mitm_servers: list[str] = []
bob_actor = http_prefix + '://' + bob_address + '/users/bob'
send_result = \
send_follow_request(session_alice, alice_dir,
@@ -2133,7 +2133,7 @@ def test_shared_items_federation(base_dir: str) -> None:
shared_item_price = "1.30"
shared_item_currency = "EUR"
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
session_bob = create_session(proxy_type)
share_json = \
send_share_via_server(bob_dir, session_bob,
@@ -2226,7 +2226,7 @@ def test_shared_items_federation(base_dir: str) -> None:
print('\n\n*********************************************************')
print('Bob can read the shared items catalog on his own instance')
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
catalog_json = \
get_shared_items_catalog_via_server(session_bob,
'bob', bob_password,
@@ -2239,7 +2239,7 @@ def test_shared_items_federation(base_dir: str) -> None:
assert 'DFC:supplies' in catalog_json
assert len(catalog_json.get('DFC:supplies')) == 3
- mitm_servers = []
+ mitm_servers: list[str] = []
offers_json = \
get_offers_via_server(session_bob, 'bob', bob_password,
bob_domain, bob_port,
@@ -2252,7 +2252,7 @@ def test_shared_items_federation(base_dir: str) -> None:
assert isinstance(offers_json, dict)
assert len(offers_json['orderedItems']) >= 1
- mitm_servers = []
+ mitm_servers: list[str] = []
wanted_json = \
get_wanted_via_server(session_bob, 'bob', bob_password,
bob_domain, bob_port,
@@ -2290,8 +2290,8 @@ def test_shared_items_federation(base_dir: str) -> None:
chat_url = ''
video_transcript = None
auto_cw_cache = {}
- searchable_by = []
- mitm_servers = []
+ searchable_by: list[str] = []
+ mitm_servers: list[str] = []
send_result = \
send_post(signing_priv_key_pem, __version__,
session_alice, alice_dir, 'alice', alice_domain, alice_port,
@@ -2412,7 +2412,7 @@ def test_group_follow(base_dir: str) -> None:
# system_language = 'en'
http_prefix = 'http'
proxy_type = None
- federation_list = []
+ federation_list: list[str] = []
content_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
media_license_url = 'https://creativecommons.org/licenses/by-nc/4.0'
media_creator = 'Bumble'
@@ -2514,7 +2514,7 @@ def test_group_follow(base_dir: str) -> None:
'Accept': 'application/ld+json; profile="' + profile_str + '"'
}
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
outbox_json = get_json(signing_priv_key_pem, session, alice_outbox,
as_header, None, True, mitm_servers,
__version__, 'http', None)
@@ -2527,7 +2527,7 @@ def test_group_follow(base_dir: str) -> None:
print('Alice outbox totalItems: ' + str(outbox_json['totalItems']))
assert outbox_json['totalItems'] == 3
- mitm_servers = []
+ mitm_servers: list[str] = []
outbox_json = get_json(signing_priv_key_pem, session,
first_page, as_header,
None, True, mitm_servers, __version__, 'http', None)
@@ -2558,12 +2558,12 @@ def test_group_follow(base_dir: str) -> None:
alice_person_cache = {}
alice_cached_webfingers = {}
alice_post_log = []
- sites_unavailable = []
+ sites_unavailable: list[str] = []
# aliceActor = http_prefix + '://' + alice_address + '/users/alice'
testgroup_actor = \
http_prefix + '://' + testgroupAddress + '/users/testgroup'
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
send_result = \
send_follow_request(session_alice, alice_dir,
'alice', alice_domain,
@@ -2639,12 +2639,12 @@ def test_group_follow(base_dir: str) -> None:
bob_person_cache = {}
bob_cached_webfingers = {}
bob_post_log = []
- sites_unavailable = []
+ sites_unavailable: list[str] = []
# bob_actor = http_prefix + '://' + bob_address + '/users/bob'
testgroup_actor = \
http_prefix + '://' + testgroupAddress + '/users/testgroup'
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
send_result = \
send_follow_request(session_bob, bob_dir,
'bob', bob_domain,
@@ -2713,7 +2713,7 @@ def test_group_follow(base_dir: str) -> None:
alice_post_log = []
alice_person_cache = {}
alice_cached_webfingers = {}
- alice_shared_items_federated_domains = []
+ alice_shared_items_federated_domains: list[str] = []
alice_shared_item_federation_tokens = {}
alice_post_log = []
is_article = False
@@ -2740,8 +2740,8 @@ def test_group_follow(base_dir: str) -> None:
chat_url = ''
video_transcript = None
auto_cw_cache = {}
- searchable_by = []
- mitm_servers = []
+ searchable_by: list[str] = []
+ mitm_servers: list[str] = []
send_result = \
send_post(signing_priv_key_pem, __version__,
session_alice, alice_dir, 'alice', alice_domain, alice_port,
@@ -2844,7 +2844,7 @@ def _test_followers_of_person(base_dir: str) -> None:
password = 'birb'
port = 80
http_prefix = 'https'
- federation_list = []
+ federation_list: list[str] = []
base_dir = curr_dir + '/.tests_followersofperson'
if os.path.isdir(base_dir):
shutil.rmtree(base_dir, ignore_errors=False)
@@ -2894,7 +2894,7 @@ def _test_followers_on_domain(base_dir: str) -> None:
password = 'birb'
port = 80
http_prefix = 'https'
- federation_list = []
+ federation_list: list[str] = []
base_dir = curr_dir + '/.tests_nooffollowersOndomain'
if os.path.isdir(base_dir):
shutil.rmtree(base_dir, ignore_errors=False)
@@ -2961,7 +2961,7 @@ def _test_group_followers(base_dir: str) -> None:
password = 'somepass'
port = 80
http_prefix = 'https'
- federation_list = []
+ federation_list: list[str] = []
base_dir = curr_dir + '/.tests_testgroupfollowers'
if os.path.isdir(base_dir):
shutil.rmtree(base_dir, ignore_errors=False)
@@ -3141,7 +3141,7 @@ def _test_create_person_account(base_dir: str):
buy_url = ''
chat_url = ''
auto_cw_cache = {}
- searchable_by = []
+ searchable_by: list[str] = []
session = None
test_post_json = \
create_public_post(base_dir, nickname, domain, port, http_prefix,
@@ -3276,7 +3276,7 @@ def test_client_to_server(base_dir: str):
languages_understood = [system_language]
http_prefix = 'http'
proxy_type = None
- federation_list = []
+ federation_list: list[str] = []
low_bandwidth = False
if os.path.isdir(base_dir + '/.tests'):
@@ -3396,8 +3396,8 @@ def test_client_to_server(base_dir: str):
chat_url = ''
video_transcript = None
auto_cw_cache = {}
- searchable_by = []
- mitm_servers = []
+ searchable_by: list[str] = []
+ mitm_servers: list[str] = []
send_result = \
send_post_via_server(signing_priv_key_pem, __version__,
alice_dir, session_alice, 'alice', password,
@@ -3483,7 +3483,7 @@ def test_client_to_server(base_dir: str):
print('\n\nAlice follows Bob')
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
send_follow_request_via_server(alice_dir, session_alice,
'alice', password,
alice_domain, alice_port,
@@ -3526,7 +3526,7 @@ def test_client_to_server(base_dir: str):
alice_domain, alice_port)
print('\n\nEVENT: Bob follows Alice')
- mitm_servers = []
+ mitm_servers: list[str] = []
send_follow_request_via_server(alice_dir, session_alice,
'bob', 'bobpass',
bob_domain, bob_port,
@@ -3620,7 +3620,7 @@ def test_client_to_server(base_dir: str):
assert 'VEVENT' not in str(result)
print('\n\nEVENT: Bob likes the post')
- mitm_servers = []
+ mitm_servers: list[str] = []
send_like_via_server(bob_dir, session_bob,
'bob', 'bobpass',
bob_domain, bob_port,
@@ -3652,7 +3652,7 @@ def test_client_to_server(base_dir: str):
print('EVENT: Post liked')
print('\n\nEVENT: Bob reacts to the post')
- mitm_servers = []
+ mitm_servers: list[str] = []
send_reaction_via_server(bob_dir, session_bob,
'bob', 'bobpass',
bob_domain, bob_port,
@@ -3701,7 +3701,7 @@ def test_client_to_server(base_dir: str):
show_test_boxes('bob', bob_inbox_path, bob_outbox_path)
print('\n\nEVENT: Bob repeats the post')
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
send_announce_via_server(bob_dir, session_bob, 'bob', password,
bob_domain, bob_port,
http_prefix, outbox_post_id,
@@ -3744,7 +3744,7 @@ def test_client_to_server(base_dir: str):
print('\n\nEVENT: Alice deletes her post: ' + outbox_post_id + ' ' +
str(alice_posts_before))
password = 'alicepass'
- mitm_servers = []
+ mitm_servers: list[str] = []
send_delete_via_server(alice_dir, session_alice, 'alice', password,
alice_domain, alice_port,
http_prefix, outbox_post_id,
@@ -3775,7 +3775,7 @@ def test_client_to_server(base_dir: str):
print('\n\nEVENT: Alice unfollows Bob')
password = 'alicepass'
- mitm_servers = []
+ mitm_servers: list[str] = []
send_unfollow_request_via_server(base_dir, session_alice,
'alice', password,
alice_domain, alice_port,
@@ -4048,7 +4048,7 @@ def _test_addemoji(base_dir: str):
nickname = 'testuser'
domain = 'testdomain.net'
port = 3682
- recipients = []
+ recipients: list[str] = []
translate = {}
hashtags = {}
base_dir_original = base_dir
@@ -4080,7 +4080,7 @@ def _test_addemoji(base_dir: str):
assert ':lemon:' in content_modified
assert content_modified.startswith('')
assert content_modified.endswith('
')
- tags = []
+ tags: list[dict] = []
for _, tag in hashtags.items():
tags.append(tag)
content = content_modified
@@ -4307,7 +4307,7 @@ def _test_jsonld():
def _test_site_active():
print('test_site_is_active')
timeout = 10
- sites_unavailable = []
+ sites_unavailable: list[str] = []
# at least one site should resolve
if not site_is_active('https://archive.org', timeout, sites_unavailable):
if not site_is_active('https://wikipedia.org', timeout,
@@ -4393,7 +4393,7 @@ def _test_danger_svg(base_dir: str) -> None:
domain_full = domain
onion_domain = None
i2p_domain = None
- federation_list = []
+ federation_list: list[str] = []
debug = True
svg_image_filename = base_dir + '/.unit_test_safe.svg'
post_json_object = {
@@ -4801,7 +4801,7 @@ def _test_hashtag_rules():
conditions_str = \
'contains "Cat" or contains "Corvid" or ' + \
'contains "Dormouse" or contains "Buzzard"'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == str(['or', ['contains', ['"Cat"']],
@@ -4812,7 +4812,7 @@ def _test_hashtag_rules():
content = 'This is a test'
moderated = True
conditions_str = '#foo or #bar'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == str(['or', ['#foo'], ['#bar']])
@@ -4826,7 +4826,7 @@ def _test_hashtag_rules():
url = 'https://testsite.com/something'
moderated = True
conditions_str = '#foo and from "testsite.com"'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == str(['and', ['#foo'], ['from', ['"testsite.com"']]])
@@ -4839,7 +4839,7 @@ def _test_hashtag_rules():
content = 'This is a test'
moderated = True
conditions_str = 'contains "is a" and #foo or #bar'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == \
@@ -4853,7 +4853,7 @@ def _test_hashtag_rules():
moderated = False
conditions_str = 'not moderated and #foo or #bar'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == \
@@ -4866,7 +4866,7 @@ def _test_hashtag_rules():
moderated = True
conditions_str = 'moderated and #foo or #bar'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == \
@@ -4878,7 +4878,7 @@ def _test_hashtag_rules():
assert not hashtag_rule_resolve(tree, hashtags, moderated, content, url)
conditions_str = 'x'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert tree is None
@@ -4887,7 +4887,7 @@ def _test_hashtag_rules():
assert not hashtag_rule_resolve(tree, hashtags, moderated, content, url)
conditions_str = '#x'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == str(['#x'])
@@ -4898,7 +4898,7 @@ def _test_hashtag_rules():
assert not hashtag_rule_resolve(tree, hashtags, moderated, content, url)
conditions_str = 'not #b'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == str(['not', ['#b']])
@@ -4909,7 +4909,7 @@ def _test_hashtag_rules():
assert not hashtag_rule_resolve(tree, hashtags, moderated, content, url)
conditions_str = '#foo or #bar and #a'
- tags_in_conditions = []
+ tags_in_conditions: list[str] = []
tree = hashtag_rule_tree(operators, conditions_str,
tags_in_conditions, moderated)
assert str(tree) == str(['and', ['or', ['#foo'], ['#bar']], ['#a']])
@@ -5062,7 +5062,7 @@ def _test_reply_to_public_post(base_dir: str) -> None:
chat_url = ''
auto_cw_cache = {}
video_transcript = ''
- searchable_by = []
+ searchable_by: list[str] = []
session = None
reply = \
create_public_post(base_dir, nickname, domain, port, http_prefix,
@@ -5139,7 +5139,7 @@ def get_function_calls(name: str, lines: [], start_line_ctr: int,
"""Returns the functions called by the given one,
Starting with the given source code at the given line
"""
- calls_functions = []
+ calls_functions: list[str] = []
function_content_str = ''
for line_ctr in range(start_line_ctr + 1, len(lines)):
line_str = lines[line_ctr].strip()
@@ -5423,7 +5423,7 @@ def _test_checkbox_names():
def _test_post_field_names(source_file: str, fieldnames: []):
print('test_post_field_Names')
- fnames = []
+ fnames: list[str] = []
for field in fieldnames:
fnames.append(field + '.get')
@@ -5459,7 +5459,7 @@ def _test_post_field_names(source_file: str, fieldnames: []):
' should be camel case')
assert False
- fnames = []
+ fnames: list[str] = []
for field in fieldnames:
fnames.append(field + '[')
for fname in fnames:
@@ -5492,7 +5492,7 @@ def _test_post_field_names(source_file: str, fieldnames: []):
def _test_thread_functions():
print('test_thread_functions')
modules = {}
- threads_called_in_modules = []
+ threads_called_in_modules: list[str] = []
# get the source for each module
# Allow recursive walk
@@ -5565,7 +5565,7 @@ def _test_thread_functions():
ctr += 1
continue
arg_ctr = 0
- calling_function_args_list = []
+ calling_function_args_list: list[str] = []
for func_arg in thread_function_args:
if arg_ctr == 0:
arg_ctr += 1
@@ -5607,7 +5607,7 @@ def _check_self_variables(mod_name: str, method_name: str,
self_vars = line.split('self.server.')
ctr = 0
terminators = (' ', '.', ',', ')', '[', ' ', ':')
- func_args = []
+ func_args: list[str] = []
for arg_str in method_args:
arg_str = arg_str.strip().split(':')[0]
func_args.append(arg_str)
@@ -5631,7 +5631,7 @@ def _test_functions():
function_properties = {}
modules = {}
mod_groups = {}
- method_loc = []
+ method_loc: list[str] = []
for _, _, files in os.walk('.'):
for source_file in files:
@@ -5659,7 +5659,7 @@ def _test_functions():
line_count = 0
prev_line = 'start'
method_name = ''
- method_args = []
+ method_args: list[str] = []
module_line = 0
curr_return_types = ''
is_comment = False
@@ -5761,7 +5761,7 @@ def _test_functions():
not return_types.endswith(')'):
return_types += ')'
else:
- return_types = []
+ return_types: list[str] = []
curr_return_types = return_types
method_args = method_args.split(')', 1)[0]
method_args = method_args.replace(' ', '').split(',')
@@ -5807,7 +5807,7 @@ def _test_functions():
'get'
]
- bad_function_names = []
+ bad_function_names: list[str] = []
for name, properties in function_properties.items():
if '_' not in name:
if name.lower() != name:
@@ -6109,7 +6109,7 @@ def _test_links_within_post(base_dir: str) -> None:
chat_url = ''
auto_cw_cache = {}
video_transcript = ''
- searchable_by = []
+ searchable_by: list[str] = []
session = None
post_json_object = \
@@ -6464,7 +6464,7 @@ def _test_speaker_replace_link():
'not run more than one snowflake in the same ' + \
'network.https://support.torproject.org/censorship/' + \
'how-to-help-running-snowflake/'
- detected_links = []
+ detected_links: list[str] = []
result = \
speaker_replace_links(http_prefix, nickname, domain, domain_full,
text, {'Linked': 'Web link'}, detected_links)
@@ -6476,7 +6476,7 @@ def _test_speaker_replace_link():
remote_link = 'https://somedomain/tags/sometag'
text = 'Test with a hashtag ' + remote_link + ' link'
- detected_links = []
+ detected_links: list[str] = []
result = \
speaker_replace_links(http_prefix, nickname, domain, domain_full,
text, {'Linked': 'Web link'}, detected_links)
@@ -6550,7 +6550,7 @@ def test_update_actor(base_dir: str):
http_prefix = 'http'
proxy_type = None
- federation_list = []
+ federation_list: list[str] = []
system_language = 'en'
if os.path.isdir(base_dir + '/.tests'):
@@ -6627,7 +6627,7 @@ def test_update_actor(base_dir: str):
'=gv5G\n' + \
'-----END PGP PUBLIC KEY BLOCK-----'
signing_priv_key_pem = None
- mitm_servers = []
+ mitm_servers: list[str] = []
actor_update = \
pgp_public_key_upload(alice_dir, session_alice,
'alice', password,
@@ -6734,7 +6734,7 @@ def _test_spoofed_geolocation() -> None:
assert not point_in_nogo(test_square, 5, 11)
assert not point_in_nogo(test_square, -5, -5)
assert not point_in_nogo(test_square, -5, 5)
- nogo_list = []
+ nogo_list: list[str] = []
curr_time = date_utcnow()
decoy_seed = 7634681
city_radius = 0.1
@@ -6749,7 +6749,7 @@ def _test_spoofed_geolocation() -> None:
assert len(coords[4]) > 4
assert len(coords[5]) > 4
assert coords[6] > 0
- nogo_list = []
+ nogo_list: list[str] = []
coords = spoof_geolocation('', 'unknown', curr_time,
decoy_seed, cities_list, nogo_list)
assert coords[0] >= 51.8744 - city_radius
@@ -7232,7 +7232,7 @@ def _translate_ontology(base_dir: str) -> None:
if "rdfs:label" not in item:
continue
english_str = None
- languages_found = []
+ languages_found: list[str] = []
for label in item["rdfs:label"]:
if '@language' not in label:
continue
@@ -7302,7 +7302,7 @@ def _test_can_replyto(base_dir: str) -> None:
chat_url = ''
auto_cw_cache = {}
video_transcript = ''
- searchable_by = []
+ searchable_by: list[str] = []
session = None
post_json_object = \
@@ -8642,7 +8642,7 @@ def _test_book_link(base_dir: str):
'type': 'Edition'}],
'to': ['https://www.w3.org/ns/activitystreams#Public'],
'type': 'Note'}
- languages_understood = []
+ languages_understood: list[str] = []
translate = {}
book_dict = get_book_from_post(post_json_object, True)
diff --git a/theme.py b/theme.py
index d44057b8d..0b865e34c 100644
--- a/theme.py
+++ b/theme.py
@@ -141,7 +141,7 @@ def get_themes_list(base_dir: str) -> []:
also used to create the web interface dropdown list
and to lookup function names
"""
- themes = []
+ themes: list[str] = []
for _, dirs, _ in os.walk(base_dir + '/theme'):
for theme_name in dirs:
if '~' not in theme_name and \
diff --git a/tox.py b/tox.py
index fc2ee883c..7977b2c61 100644
--- a/tox.py
+++ b/tox.py
@@ -77,7 +77,7 @@ def set_tox_address(actor_json: {}, tox_address: str) -> None:
not_tox_address = True
if not actor_json.get('attachment'):
- actor_json['attachment'] = []
+ actor_json['attachment']: list[dict] = []
# remove any existing value
property_found = None
diff --git a/utils.py b/utils.py
index b891a04c0..2e5433cda 100644
--- a/utils.py
+++ b/utils.py
@@ -385,7 +385,7 @@ def get_actor_languages_list(actor_json: {}) -> []:
return lang_list
if isinstance(property_value[prop_value_name], str):
lang_str = property_value[prop_value_name]
- lang_list_temp = []
+ lang_list_temp: list[str] = []
if ',' in lang_str:
lang_list_temp = lang_str.split(',')
elif ';' in lang_str:
@@ -398,7 +398,7 @@ def get_actor_languages_list(actor_json: {}) -> []:
lang_list_temp = lang_str.split(' ')
else:
return [lang_str]
- lang_list = []
+ lang_list: list[str] = []
for lang in lang_list_temp:
lang = lang.strip()
if lang not in lang_list:
@@ -1083,7 +1083,7 @@ def get_followers_list(base_dir: str,
if not os.path.isfile(filename):
return []
- lines = []
+ lines: list[str] = []
try:
with open(filename, 'r', encoding='utf-8') as fp_foll:
lines = fp_foll.readlines()
@@ -1103,7 +1103,7 @@ def get_followers_of_person(base_dir: str,
"""Returns a list containing the followers of the given person
Used by the shared inbox to know who to send incoming mail to
"""
- followers = []
+ followers: list[str] = []
domain = remove_domain_port(domain)
handle = nickname + '@' + domain
handle_dir = acct_handle_dir(base_dir, handle)
@@ -2249,7 +2249,7 @@ def _remove_attachment(base_dir: str, http_prefix: str, domain: str,
except OSError:
print('EX: _remove_attachment unable to delete etag file ' +
str(etag_filename))
- post_json['attachment'] = []
+ post_json['attachment']: list[dict] = []
def remove_post_from_index(post_url: str, debug: bool,
@@ -2261,7 +2261,7 @@ def remove_post_from_index(post_url: str, debug: bool,
post_id = remove_id_ending(post_url)
if not text_in_file(post_id, index_file):
return
- lines = []
+ lines: list[str] = []
try:
with open(index_file, 'r', encoding='utf-8') as fp_mod1:
lines = fp_mod1.readlines()
@@ -3009,7 +3009,7 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str,
else:
search_words = [search_str]
- res = []
+ res: list[str] = []
try:
with open(index_filename, 'r', encoding='utf-8') as fp_index:
post_filename = 'start'
@@ -3051,7 +3051,7 @@ def _get_mutuals_of_person(base_dir: str,
get_followers_list(base_dir, nickname, domain, 'followers.txt')
following = \
get_followers_list(base_dir, nickname, domain, 'following.txt')
- mutuals = []
+ mutuals: list[str] = []
for handle in following:
if handle in followers:
mutuals.append(handle)
@@ -3101,8 +3101,8 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
else:
search_words = [search_str]
- following_list = []
- mutuals_list = []
+ following_list: list[str] = []
+ mutuals_list: list[str] = []
check_searchable_by = False
if box_name == 'inbox':
check_searchable_by = True
@@ -3114,7 +3114,7 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
# create a list containing all of the mutuals
mutuals_list = _get_mutuals_of_person(base_dir, nickname, domain)
- res = []
+ res: list[str] = []
for root, _, fnames in os.walk(path):
for fname in fnames:
file_path = os.path.join(root, fname)
@@ -3979,7 +3979,7 @@ def get_supported_languages(base_dir: str) -> []:
"""Returns a list of supported languages
"""
translations_dir = base_dir + '/translations'
- languages_str = []
+ languages_str: list[str] = []
for _, _, files in os.walk(translations_dir):
for fname in files:
if not fname.endswith('.json'):
@@ -3995,7 +3995,7 @@ def get_category_types(base_dir: str) -> []:
"""Returns the list of ontologies
"""
ontology_dir = base_dir + '/ontology'
- categories = []
+ categories: list[str] = []
for _, _, files in os.walk(ontology_dir):
for fname in files:
if not fname.endswith('.json'):
@@ -4511,7 +4511,7 @@ def load_min_images_for_accounts(base_dir: str) -> []:
"""Loads a list of nicknames for accounts where all images should
be minimized by default
"""
- min_images_for_accounts = []
+ min_images_for_accounts: list[str] = []
dir_str = data_dir(base_dir)
for subdir, dirs, _ in os.walk(dir_str):
for account in dirs:
@@ -4556,7 +4556,7 @@ def load_reverse_timeline(base_dir: str) -> []:
"""Loads flags for each user indicating whether they prefer to
see reversed timelines
"""
- reverse_sequence = []
+ reverse_sequence: list[str] = []
dir_str = data_dir(base_dir)
for _, dirs, _ in os.walk(dir_str):
for acct in dirs:
@@ -5368,7 +5368,7 @@ def load_mitm_servers(base_dir: str) -> []:
"""Loads a list of servers implementing insecure transport security
"""
mitm_servers_filename = data_dir(base_dir) + '/mitm_servers.txt'
- mitm_servers = []
+ mitm_servers: list[str] = []
if os.path.isfile(mitm_servers_filename):
try:
with open(mitm_servers_filename, 'r',
diff --git a/webapp_column_left.py b/webapp_column_left.py
index 8a1a49808..9da4c14bc 100644
--- a/webapp_column_left.py
+++ b/webapp_column_left.py
@@ -54,7 +54,7 @@ def _get_left_column_shares(base_dir: str,
if not shares_json:
return []
- links_list = []
+ links_list: list[str] = []
ctr = 0
for _, item in shares_json.items():
sharedesc = item['displayName']
@@ -97,7 +97,7 @@ def _get_left_column_wanted(base_dir: str,
if not shares_json:
return []
- links_list = []
+ links_list: list[str] = []
ctr = 0
for _, item in shares_json.items():
sharedesc = item['displayName']
@@ -404,7 +404,7 @@ def html_links_mobile(base_dir: str,
instance_title = \
get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
html_str = \
html_header_with_external_style(css_filename, instance_title, None,
preload_images)
@@ -478,7 +478,7 @@ def html_edit_links(translate: {}, base_dir: str, path: str,
instance_title = \
get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
edit_links_form = \
html_header_with_external_style(css_filename, instance_title, None,
preload_images)
diff --git a/webapp_column_right.py b/webapp_column_right.py
index 8b2bbfacf..66d9de77a 100644
--- a/webapp_column_right.py
+++ b/webapp_column_right.py
@@ -380,10 +380,10 @@ def html_citations(base_dir: str, nickname: str, domain: str,
# these can then be used to re-select checkboxes later
citations_filename = \
acct_dir(base_dir, nickname, domain) + '/.citations.txt'
- citations_selected = []
+ citations_selected: list[str] = []
if os.path.isfile(citations_filename):
citations_separator = '#####'
- citations = []
+ citations: list[str] = []
try:
with open(citations_filename, 'r', encoding='utf-8') as fp_cit:
citations = fp_cit.readlines()
@@ -406,7 +406,7 @@ def html_citations(base_dir: str, nickname: str, domain: str,
instance_title = \
get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
html_str = \
html_header_with_external_style(css_filename, instance_title, None,
preload_images)
@@ -527,7 +527,7 @@ def html_newswire_mobile(base_dir: str, nickname: str,
metadata = None
if text_mode_browser(ua_str):
metadata = '\n'
- preload_images = []
+ preload_images: list[str] = []
html_str = \
html_header_with_external_style(css_filename, instance_title, metadata,
preload_images)
@@ -603,7 +603,7 @@ def html_edit_newswire(translate: {}, base_dir: str, path: str,
instance_title = \
get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
edit_newswire_form = \
html_header_with_external_style(css_filename, instance_title, None,
preload_images)
@@ -761,7 +761,7 @@ def html_edit_news_post(translate: {}, base_dir: str, path: str,
instance_title = \
get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
edit_news_post_form = \
html_header_with_external_style(css_filename, instance_title, None,
preload_images)
diff --git a/webapp_confirm.py b/webapp_confirm.py
index 3957adb3f..4fe506ea9 100644
--- a/webapp_confirm.py
+++ b/webapp_confirm.py
@@ -74,7 +74,7 @@ def html_confirm_delete(server,
instance_title = \
get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
delete_post_str = \
html_header_with_external_style(css_filename, instance_title, None,
preload_images)
@@ -171,7 +171,7 @@ def html_confirm_remove_shared_item(translate: {},
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
shares_str = html_header_with_external_style(css_filename,
instance_title, None,
preload_images)
@@ -229,7 +229,7 @@ def html_confirm_follow(translate: {}, base_dir: str,
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
follow_str = html_header_with_external_style(css_filename,
instance_title, None,
preload_images)
@@ -290,7 +290,7 @@ def html_confirm_unfollow(translate: {}, base_dir: str,
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
follow_str = html_header_with_external_style(css_filename,
instance_title, None,
preload_images)
@@ -339,7 +339,7 @@ def html_confirm_unblock(translate: {}, base_dir: str,
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
block_str = html_header_with_external_style(css_filename,
instance_title, None,
preload_images)
@@ -388,7 +388,7 @@ def html_confirm_block(translate: {}, base_dir: str,
css_filename = base_dir + '/follow.css'
instance_title = get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
block_str = html_header_with_external_style(css_filename,
instance_title, None,
preload_images)
diff --git a/webapp_conversation.py b/webapp_conversation.py
index 65301ce7b..162297714 100644
--- a/webapp_conversation.py
+++ b/webapp_conversation.py
@@ -75,7 +75,7 @@ def html_conversation_view(authorized: bool, post_id: str,
instance_title = \
get_config_param(base_dir, 'instanceTitle')
- preload_images = []
+ preload_images: list[str] = []
metadata_str = ''
if post_id:
diff --git a/webapp_create_post.py b/webapp_create_post.py
index 13be4f86f..257a39aa3 100644
--- a/webapp_create_post.py
+++ b/webapp_create_post.py
@@ -791,7 +791,7 @@ def html_new_post(edit_post_params: {},
currencies = get_currencies()
extra_fields += '
\n'
citations_str += '