diff --git a/announce.py b/announce.py index c3c9a98ef..865aab407 100644 --- a/announce.py +++ b/announce.py @@ -51,7 +51,7 @@ def no_of_announces(post_json_object: {}) -> int: if not isinstance(obj['shares'], dict): return 0 if not obj['shares'].get('items'): - obj['shares']['items'] = [] + obj['shares']['items']: list[dict] = [] obj['shares']['totalItems'] = 0 return len(obj['shares']['items']) diff --git a/art.py b/art.py index 6a51f1ee2..5dbcc7373 100644 --- a/art.py +++ b/art.py @@ -81,7 +81,7 @@ def set_art_site_url(actor_json: {}, art_site_url: str) -> None: return if not actor_json.get('attachment'): - actor_json['attachment'] = [] + actor_json['attachment']: list[dict] = [] # remove any existing value property_found = None diff --git a/blocking.py b/blocking.py index 997e1c667..84aabfe6a 100644 --- a/blocking.py +++ b/blocking.py @@ -123,7 +123,7 @@ def blocked_timeline_json(actor: str, page_number: int, items_per_page: int, """ blocked_accounts_textarea = \ get_account_blocks(base_dir, nickname, domain) - blocked_list = [] + blocked_list: list[str] = [] if blocked_accounts_textarea: blocked_list = blocked_accounts_textarea.split('\n') start_index = (page_number - 1) * items_per_page @@ -846,7 +846,7 @@ def is_blocked(base_dir: str, nickname: str, domain: str, federated_blocks_filename = \ data_dir(base_dir) + '/block_api.txt' if os.path.isfile(federated_blocks_filename): - block_federated = [] + block_federated: list[str] = [] try: with open(federated_blocks_filename, 'r', encoding='utf-8') as fp_fed: @@ -1268,7 +1268,7 @@ def mute_post(base_dir: str, nickname: str, domain: str, port: int, post_json_obj['ignores'] = ignores_json else: if not post_json_obj['ignores'].get('items'): - post_json_obj['ignores']['items'] = [] + post_json_obj['ignores']['items']: list[dict] = [] items_list = post_json_obj['ignores']['items'] for ignores_item in items_list: if ignores_item.get('actor'): @@ -1737,7 +1737,7 @@ def import_blocking_file(base_dir: str, nickname: str, domain: str, blocking_reasons_filename = \ account_directory + '/blocking_reasons.txt' - existing_lines = [] + existing_lines: list[str] = [] if os.path.isfile(blocking_filename): try: with open(blocking_filename, 'r', encoding='utf-8') as fp_blocks: @@ -1746,7 +1746,7 @@ def import_blocking_file(base_dir: str, nickname: str, domain: str, print('EX: ' + 'unable to import existing blocked instances from file ' + blocking_filename) - existing_reasons = [] + existing_reasons: list[str] = [] if os.path.isfile(blocking_reasons_filename): try: with open(blocking_reasons_filename, @@ -1758,8 +1758,8 @@ def import_blocking_file(base_dir: str, nickname: str, domain: str, 'blocked instance reasons from file ' + blocking_reasons_filename) - append_blocks = [] - append_reasons = [] + append_blocks: list[str] = [] + append_reasons: list[str] = [] for line_str in lines: if line_str.startswith('#'): continue @@ -1829,7 +1829,7 @@ def export_blocking_file(base_dir: str, nickname: str, domain: str) -> str: if not os.path.isfile(blocking_filename): return blocks_header - blocking_lines = [] + blocking_lines: list[str] = [] if os.path.isfile(blocking_filename): try: with open(blocking_filename, 'r', encoding='utf-8') as fp_block: @@ -1837,7 +1837,7 @@ def export_blocking_file(base_dir: str, nickname: str, domain: str) -> str: except OSError: print('EX: export_blocks failed to read ' + blocking_filename) - blocking_reasons = [] + blocking_reasons: list[str] = [] if os.path.isfile(blocking_reasons_filename): try: with open(blocking_reasons_filename, 'r', @@ -1906,7 +1906,7 @@ def load_blocked_military(base_dir: str) -> {}: """Loads a list of nicknames for accounts which block military instances """ block_military_filename = data_dir(base_dir) + '/block_military.txt' - nicknames_list = [] + nicknames_list: list[str] = [] if os.path.isfile(block_military_filename): try: with open(block_military_filename, 'r', @@ -1927,7 +1927,7 @@ def load_blocked_government(base_dir: str) -> {}: """Loads a list of nicknames for accounts which block government instances """ block_government_filename = data_dir(base_dir) + '/block_government.txt' - nicknames_list = [] + nicknames_list: list[str] = [] if os.path.isfile(block_government_filename): try: with open(block_government_filename, 'r', @@ -1948,7 +1948,7 @@ def load_blocked_bluesky(base_dir: str) -> {}: """Loads a list of nicknames for accounts which block bluesky bridges """ block_bluesky_filename = data_dir(base_dir) + '/block_bluesky.txt' - nicknames_list = [] + nicknames_list: list[str] = [] if os.path.isfile(block_bluesky_filename): try: with open(block_bluesky_filename, 'r', @@ -2076,11 +2076,11 @@ def contains_bluesky_domain(message_str: str) -> bool: def load_federated_blocks_endpoints(base_dir: str) -> []: """Loads endpoint urls for federated blocklists """ - block_federated_endpoints = [] + block_federated_endpoints: list[str] = [] block_api_endpoints_filename = \ data_dir(base_dir) + '/block_api_endpoints.txt' if os.path.isfile(block_api_endpoints_filename): - new_block_federated_endpoints = [] + new_block_federated_endpoints: list[str] = [] try: with open(block_api_endpoints_filename, 'r', encoding='utf-8') as fp_ep: @@ -2120,7 +2120,7 @@ def _update_federated_blocks(session, base_dir: str, mitm_servers: []) -> []: """Creates block_api.txt """ - block_federated = [] + block_federated: list[str] = [] debug = True if not session: @@ -2217,7 +2217,7 @@ def save_block_federated_endpoints(base_dir: str, """ block_api_endpoints_filename = \ data_dir(base_dir) + '/block_api_endpoints.txt' - result = [] + result: list[str] = [] block_federated_endpoints_str = '' for endpoint in block_federated_endpoints: if not endpoint: diff --git a/blog.py b/blog.py index dea7defc7..d8309697f 100644 --- a/blog.py +++ b/blog.py @@ -77,9 +77,9 @@ def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {}, return 1 return 0 - removals = [] + removals: list[str] = [] replies = 0 - lines = [] + lines: list[str] = [] try: with open(post_filename, 'r', encoding='utf-8') as fp_post: lines = fp_post.readlines() @@ -154,7 +154,7 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {}, print('EX: unable to read blog 3 ' + post_filename) return '' - lines = [] + lines: list[str] = [] try: with open(post_filename, 'r', encoding='utf-8') as fp_post: lines = fp_post.readlines() @@ -275,7 +275,7 @@ def _html_blog_post_content(debug: bool, session, authorized: bool, person_url = local_actor_url(http_prefix, nickname, domain_full) actor_json = \ get_person_from_cache(base_dir, person_url, person_cache) - languages_understood = [] + languages_understood: list[str] = [] if actor_json: languages_understood = get_actor_languages_list(actor_json) json_content = get_content_from_post(post_json_object, system_language, diff --git a/bookmarks.py b/bookmarks.py index be9062c8b..a03df664f 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -159,7 +159,7 @@ def _no_of_bookmarks(post_json_object: {}) -> int: if not isinstance(post_json_object['object']['bookmarks'], dict): return 0 if not post_json_object['object']['bookmarks'].get('items'): - post_json_object['object']['bookmarks']['items'] = [] + post_json_object['object']['bookmarks']['items']: list[dict] = [] post_json_object['object']['bookmarks']['totalItems'] = 0 return len(post_json_object['object']['bookmarks']['items']) @@ -220,7 +220,7 @@ def update_bookmarks_collection(recent_posts_cache: {}, post_json_object['object']['bookmarks'] = bookmarks_json else: if not post_json_object['object']['bookmarks'].get('items'): - post_json_object['object']['bookmarks']['items'] = [] + post_json_object['object']['bookmarks']['items']: list[dict] = [] bm_items = post_json_object['object']['bookmarks']['items'] for bookmark_item in bm_items: if bookmark_item.get('actor'): diff --git a/briar.py b/briar.py index 56ef8bf26..0aa5b6a85 100644 --- a/briar.py +++ b/briar.py @@ -80,7 +80,7 @@ def set_briar_address(actor_json: {}, briar_address: str) -> None: not_briar_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/cache.py b/cache.py index b4569c60a..fdbc11467 100644 --- a/cache.py +++ b/cache.py @@ -147,7 +147,7 @@ def expire_person_cache(person_cache: {}): """Expires old entries from the cache in memory """ curr_time = date_utcnow() - removals = [] + removals: list[str] = [] for person_url, cache_json in person_cache.items(): cache_time = date_from_string_format(cache_json['timestamp'], ["%Y-%m-%dT%H:%M:%S%z"]) diff --git a/categories.py b/categories.py index bcf4a2c88..842eb3141 100644 --- a/categories.py +++ b/categories.py @@ -67,7 +67,7 @@ def load_city_hashtags(base_dir: str, translate: {}) -> None: cities_filename = base_dir + '/data/cities/' + cities_file if not os.path.isfile(cities_filename): continue - cities = [] + cities: list[str] = [] try: with open(cities_filename, 'r', encoding='utf-8') as fp_cities: cities = fp_cities.read().split('\n') @@ -202,7 +202,7 @@ def update_hashtag_categories(base_dir: str) -> None: category_list_filename) return - category_list = [] + category_list: list[str] = [] for category_str, _ in hashtag_categories.items(): category_list.append(category_str) category_list.sort() diff --git a/city.py b/city.py index e1b423f01..4028bdfa6 100644 --- a/city.py +++ b/city.py @@ -168,7 +168,7 @@ def parse_nogo_string(nogo_line: str) -> []: pts = polygon_str.split(',') if len(pts) <= 4: return [] - polygon = [] + polygon: list[list] = [] for index in range(int(len(pts)/2)): if index*2 + 1 >= len(pts): break @@ -224,7 +224,7 @@ def spoof_geolocation(base_dir: str, return (default_latitude, default_longitude, default_latdirection, default_longdirection, "", "", 0) - cities = [] + cities: list[str] = [] try: with open(locations_filename, 'r', encoding='utf-8') as fp_loc: cities = fp_loc.readlines() @@ -236,7 +236,7 @@ def spoof_geolocation(base_dir: str, nogo = nogo_list else: if os.path.isfile(nogo_filename): - nogo_list = [] + nogo_list: list[str] = [] try: with open(nogo_filename, 'r', encoding='utf-8') as fp_nogo: nogo_list = fp_nogo.readlines() diff --git a/content.py b/content.py index ed3beea39..34529e04f 100644 --- a/content.py +++ b/content.py @@ -295,7 +295,7 @@ def dangerous_css(filename: str, allow_local_network_access: bool) -> bool: def switch_words(base_dir: str, nickname: str, domain: str, content: str, - rules: [] = []) -> str: + rules: list[str] = []) -> str: """Performs word replacements. eg. Trump -> The Orange Menace """ if is_pgp_encrypted(content) or contains_pgp_public_key(content): @@ -409,7 +409,7 @@ def _update_common_emoji(base_dir: str, emoji_content: str) -> None: except OSError: print('EX: unable to load common emoji file') if common_emoji: - new_common_emoji = [] + new_common_emoji: list[str] = [] emoji_found = False for line in common_emoji: if ' ' + emoji_content in line: @@ -1115,7 +1115,7 @@ def remove_long_words(content: str, max_word_length: int, content = content.replace('

', '

') words = content.split(' ') if not long_words_list: - long_words_list = [] + long_words_list: list[str] = [] for word_str in words: if len(word_str) > max_word_length: if word_str not in long_words_list: @@ -1341,7 +1341,7 @@ def load_dogwhistles(filename: str) -> {}: """ if not os.path.isfile(filename): return {} - dogwhistle_lines = [] + dogwhistle_lines: list[str] = [] try: with open(filename, 'r', encoding='utf-8') as fp_dogwhistles: dogwhistle_lines = fp_dogwhistles.readlines() @@ -1398,7 +1398,7 @@ def add_html_tags(base_dir: str, http_prefix: str, words = _get_simplified_content(content).split(' ') # remove . for words which are not mentions - new_words = [] + new_words: list[str] = [] for _, word_str in enumerate(words): if word_str.endswith('.'): if not word_str.startswith('@'): @@ -1423,7 +1423,7 @@ def add_html_tags(base_dir: str, http_prefix: str, petnames = None if '@' in words: if os.path.isfile(following_filename): - following = [] + following: list[str] = [] try: with open(following_filename, 'r', encoding='utf-8') as fp_foll: @@ -1437,7 +1437,7 @@ def add_html_tags(base_dir: str, http_prefix: str, petnames.append(pet + '\n') # extract mentions and tags from words - long_words_list = [] + long_words_list: list[str] = [] prev_word_str = '' auto_tags_list = _load_auto_tags(base_dir, nickname, domain) append_tags = [] @@ -1539,7 +1539,7 @@ def _string_starts_with_url_prefix(text: str) -> bool: def get_mentions_from_html(html_text: str, match_str: str) -> []: """Extracts mentioned actors from the given html content string """ - mentions = [] + mentions: list[str] = [] if match_str not in html_text: return mentions mentions_list = html_text.split(match_str) @@ -2080,14 +2080,14 @@ def content_diff(content: str, prev_content: str) -> str: """ cdiff = difflib.Differ() text1_lines = content.splitlines() - text1_sentences = [] + text1_sentences: list[str] = [] for line in text1_lines: sentences = line.split('.') for sentence in sentences: text1_sentences.append(sentence.strip()) text2_lines = prev_content.splitlines() - text2_sentences = [] + text2_sentences: list[str] = [] for line in text2_lines: sentences = line.split('.') for sentence in sentences: @@ -2128,7 +2128,7 @@ def create_edits_html(edits_json: {}, post_json_object: {}, if 'content' not in post_json_object['object']: if 'contentMap' not in post_json_object['object']: return '' - edit_dates_list = [] + edit_dates_list: list[str] = [] for modified, _ in edits_json.items(): edit_dates_list.append(modified) edit_dates_list.sort(reverse=True) @@ -2243,7 +2243,7 @@ def add_name_emojis_to_tags(base_dir: str, http_prefix: str, # get emojis from the actor name words = name.split(' ') - emojis = [] + emojis: list[str] = [] for wrd in words: if wrd.startswith(':') and wrd.endswith(':'): if wrd not in emojis: @@ -2251,7 +2251,7 @@ def add_name_emojis_to_tags(base_dir: str, http_prefix: str, if not emojis: return - actor_tags = [] + actor_tags: list[dict] = [] if actor_json.get('tag'): actor_tags = actor_json['tag'] diff --git a/conversation.py b/conversation.py index 70a2bd65f..893085361 100644 --- a/conversation.py +++ b/conversation.py @@ -135,7 +135,7 @@ def _get_replies_to_post(post_json_object: {}, mitm_servers: []) -> []: """Returns a list of reply posts to the given post as json """ - result = [] + result: list[dict] = [] post_obj = post_json_object if has_object_dict(post_json_object): post_obj = post_json_object['object'] @@ -174,7 +174,7 @@ def _get_replies_to_post(post_json_object: {}, if not replies_collection['first'].get('next'): return result - items_list = [] + items_list: list[dict] = [] if replies_collection['first'].get('items'): items_list = replies_collection['first']['items'] if not items_list: @@ -303,7 +303,7 @@ def download_conversation_posts(authorized: bool, session, as_header = { 'Accept': 'application/ld+json; profile="' + profile_str + '"' } - conversation_view = [] + conversation_view: list[dict] = [] signing_priv_key_pem = get_instance_actor_key(base_dir, domain) post_id = remove_id_ending(post_id) post_filename = \ @@ -326,7 +326,7 @@ def download_conversation_posts(authorized: bool, session, post_json_object) # get any replies - replies_to_post = [] + replies_to_post: list[dict] = [] if get_json_valid(post_json_object): replies_to_post = \ _get_replies_to_post(post_json_object, @@ -335,7 +335,7 @@ def download_conversation_posts(authorized: bool, session, http_prefix, base_dir, nickname, domain, 0, [], mitm_servers) - ids = [] + ids: list[str] = [] while get_json_valid(post_json_object): if not isinstance(post_json_object, dict): break diff --git a/crawlers.py b/crawlers.py index 8747d789c..79486ee81 100644 --- a/crawlers.py +++ b/crawlers.py @@ -45,7 +45,7 @@ def update_known_crawlers(ua_str: str, if curr_time - last_known_crawler >= 30: # remove any old observations - remove_crawlers = [] + remove_crawlers: list[str] = [] for uagent, item in known_crawlers.items(): if curr_time - item['lastseen'] >= 60 * 60 * 24 * 30: remove_crawlers.append(uagent) @@ -72,7 +72,7 @@ def load_known_web_bots(base_dir: str) -> []: known_bots_filename) if not crawlers_str: return [] - known_bots = [] + known_bots: list[str] = [] crawlers_list = crawlers_str.split('\n') for crawler in crawlers_list: if not crawler: diff --git a/cwlists.py b/cwlists.py index 0c08fabb0..d7e3cbbb4 100644 --- a/cwlists.py +++ b/cwlists.py @@ -124,7 +124,7 @@ def add_cw_from_lists(post_json_object: {}, cw_lists: {}, translate: {}, if not content: return - post_tags = [] + post_tags: list[dict] = [] if post_json_object['object'].get('tag'): if isinstance(post_json_object['object']['tag'], list): post_tags = post_json_object['object']['tag'] diff --git a/cwtch.py b/cwtch.py index 311e3672c..8cadc61b5 100644 --- a/cwtch.py +++ b/cwtch.py @@ -66,7 +66,7 @@ def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None: not_cwtch_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/daemon.py b/daemon.py index 2a11dd603..56e8f8a27 100644 --- a/daemon.py +++ b/daemon.py @@ -321,7 +321,7 @@ class EpicyonServer(ThreadingHTTPServer): clacks = None public_replies_unlisted = False dogwhistles = {} - preferred_podcast_formats = [] + preferred_podcast_formats: list[str] = [] bold_reading = {} hide_follows = {} account_timezone = None @@ -404,8 +404,8 @@ class EpicyonServer(ThreadingHTTPServer): domain_full = '' http_prefix = 'https' debug = False - federation_list = [] - shared_items_federated_domains = [] + federation_list: list[str] = [] + shared_items_federated_domains: list[str] = [] base_dir = '' instance_id = '' person_cache = {} @@ -420,7 +420,7 @@ class EpicyonServer(ThreadingHTTPServer): getreq_busy = False postreq_busy = False received_message = False - inbox_queue = [] + inbox_queue: list[dict] = [] send_threads = None postLog = [] max_queue_length = 64 diff --git a/webapp_profile.py b/webapp_profile.py index 8b933b956..a7b67e55b 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -3680,7 +3680,7 @@ def _individual_follow_as_html(signing_priv_key_pem: str, debug: bool, system_language: str, mitm_servers: [], - buttons: list = []) -> str: + buttons: list[str] = []) -> str: """An individual follow entry on the profile screen """ follow_url_nickname = get_nickname_from_actor(follow_url)