diff --git a/acceptreject.py b/acceptreject.py index 14b280e2c..93293a851 100644 --- a/acceptreject.py +++ b/acceptreject.py @@ -250,7 +250,7 @@ def _reject_quote_request(message_json: {}, domain_full: str, print('Domain switched from ' + domain + ' to ' + curr_domain) - client_to_server = False + client_to_server: bool = False send_signed_json(reject_json, curr_session, base_dir, nickname_to_follow, domain_to_follow, port, nickname, domain, curr_port, @@ -320,8 +320,8 @@ def _accept_follow(base_dir: str, message_json: {}, print('DEBUG: unrecognized actor ' + this_actor) return else: - actor_found = False - users_list = get_user_paths() + actor_found: bool = False + users_list: list = get_user_paths() for users_str in users_list: if '/' + accepted_domain + users_str + nickname in this_actor: actor_found = True diff --git a/announce.py b/announce.py index 1dd9fa9b1..3f52cb528 100644 --- a/announce.py +++ b/announce.py @@ -224,7 +224,7 @@ def create_announce(session, base_dir: str, federation_list: [], announce_nickname = None announce_domain = None announce_port = None - group_account = False + group_account: bool = False if has_users_path(object_url): announce_nickname = get_nickname_from_actor(object_url) announce_domain, announce_port = get_domain_from_actor(object_url) @@ -614,10 +614,10 @@ def undo_announce_collection_entry(recent_posts_cache: {}, return if not post_json_object['object']['shares'].get('items'): return - total_items = 0 + total_items: int = 0 if post_json_object['object']['shares'].get('totalItems'): total_items = post_json_object['object']['shares']['totalItems'] - item_found = False + item_found: bool = False for announce_item in post_json_object['object']['shares']['items']: if not isinstance(announce_item, dict): continue diff --git a/auth.py b/auth.py index f933389bd..124d688a8 100644 --- a/auth.py +++ b/auth.py @@ -55,8 +55,8 @@ def constant_time_string_check(string1: str, string2: str) -> bool: # strings must be of equal length if len(string1) != len(string2): return False - ctr = 0 - matched = True + ctr: int = 0 + matched: bool = True for char in string1: if char != string2[ctr]: matched = False @@ -303,7 +303,7 @@ def record_login_failure(base_dir: str, ip_address: str, """ if not count_dict.get(ip_address): while len(count_dict.items()) > 100: - oldest_time = 0 + oldest_time: int = 0 oldest_ip = None for ip_addr, ip_item in count_dict.items(): if oldest_time == 0 or ip_item['time'] < oldest_time: diff --git a/availability.py b/availability.py index c013d20aa..d54ae8331 100644 --- a/availability.py +++ b/availability.py @@ -31,7 +31,7 @@ def set_availability(base_dir: str, nickname: str, domain: str, # avoid giant strings if len(status) > 128: return False - actor_exists = False + actor_exists: bool = False if actor_json: actor_exists = isinstance(actor_json, dict) actor_filename = acct_dir(base_dir, nickname, domain) + '.json' @@ -49,7 +49,7 @@ def get_availability(base_dir: str, nickname: str, domain: str, actor_json: {}) -> str: """Returns the availability for a given person """ - actor_exists = False + actor_exists: bool = False if actor_json: actor_exists = isinstance(actor_json, dict) if not actor_exists: diff --git a/blocking.py b/blocking.py index 44c282dcd..37a35e116 100644 --- a/blocking.py +++ b/blocking.py @@ -135,7 +135,7 @@ def blocked_timeline_json(actor: str, page_number: int, items_per_page: int, blocked_list = blocked_accounts_textarea.split('\n') start_index = (page_number - 1) * items_per_page if start_index >= len(blocked_list): - start_index = 0 + start_index: int = 0 last_page_number = (len(blocked_list) / items_per_page) + 1 result_json = { @@ -599,7 +599,7 @@ def update_blocked_cache(base_dir: str, curr_time = get_current_time_int() if blocked_cache_last_updated > curr_time: print('WARN: Cache updated in the future') - blocked_cache_last_updated = 0 + blocked_cache_last_updated: int = 0 seconds_since_last_update = curr_time - blocked_cache_last_updated if seconds_since_last_update < blocked_cache_update_secs: return blocked_cache_last_updated @@ -1347,7 +1347,7 @@ def unmute_post(base_dir: str, nickname: str, domain: str, port: int, if post_json_obj.get('ignores'): domain_full = get_full_domain(domain, port) actor = local_actor_url(http_prefix, nickname, domain_full) - total_items = 0 + total_items: int = 0 if post_json_obj['ignores'].get('totalItems'): total_items = post_json_obj['ignores']['totalItems'] items_list = post_json_obj['ignores']['items'] @@ -1440,7 +1440,7 @@ def outbox_mute(base_dir: str, http_prefix: str, domain_full = get_full_domain(domain, port) actor_url = get_actor_from_post(message_json) - actor_found = False + actor_found: bool = False users_paths = get_user_paths() for possible_path in users_paths: if actor_url.endswith(domain_full + possible_path + nickname): @@ -1500,7 +1500,7 @@ def outbox_undo_mute(base_dir: str, http_prefix: str, domain_full = get_full_domain(domain, port) actor_url = get_actor_from_post(message_json) - actor_found = False + actor_found: bool = False users_paths = get_user_paths() for possible_path in users_paths: if actor_url.endswith(domain_full + possible_path + nickname): @@ -1644,7 +1644,7 @@ def broch_modeLapses(base_dir: str, lapse_days: int) -> bool: curr_time = date_utcnow() days_since_broch = (curr_time - modified_date).days if days_since_broch >= lapse_days: - removed = False + removed: bool = False try: os.remove(allow_filename) removed = True @@ -1670,7 +1670,7 @@ def import_blocking_file(base_dir: str, nickname: str, domain: str, 'comment' not in lines[0]: return False fieldnames = lines[0].split(',') - comment_field_index = 0 + comment_field_index: int = 0 for field_str in fieldnames: if 'comment' in field_str: break @@ -2268,7 +2268,7 @@ def sending_is_blocked2(base_dir: str, nickname: str, domain: str, if not os.path.isfile(send_block_filename): return False - send_blocked = False + send_blocked: bool = False if text_in_file(to_actor, send_block_filename, False): send_blocked = True elif text_in_file('://' + to_domain + '\n', send_block_filename, False): diff --git a/blog.py b/blog.py index 7f62c9527..637b839c6 100644 --- a/blog.py +++ b/blog.py @@ -63,7 +63,7 @@ def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {}, return 0 try_post_box = ('tlblogs', 'inbox', 'outbox') - box_found = False + box_found: bool = False for post_box in try_post_box: post_filename = \ acct_dir(base_dir, nickname, domain) + '/' + post_box + '/' + \ @@ -82,7 +82,7 @@ def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {}, return 0 removals: list[str] = [] - replies = 0 + replies: int = 0 lines: list[str] = \ load_list(post_filename, 'EX: failed to read blog ' + post_filename) @@ -130,7 +130,7 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {}, return '' try_post_box = ('tlblogs', 'inbox', 'outbox') - box_found = False + box_found: bool = False for post_box in try_post_box: post_filename = \ acct_dir(base_dir, nickname, domain) + '/' + post_box + '/' + \ @@ -189,7 +189,7 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {}, # indicate the reply indentation level indent_str: str = '>' - indent_level = 0 + indent_level: int = 0 while indent_level < depth: indent_str += ' >' indent_level += 1 @@ -204,7 +204,7 @@ def html_blog_post_gemini_links(content: str) -> str: """ if '=> ' not in content: return content - ctr = 0 + ctr: int = 0 sections = content.split('=> ') new_content: str = '' for section in sections: @@ -277,7 +277,7 @@ def html_blog_post_markdown(content: str) -> str: if markdown_text not in new_content: continue sections = new_content.split(markdown_text) - ctr = 0 + ctr: int = 0 new_content2: str = '' for section in sections: if ctr == 0: @@ -321,7 +321,7 @@ def _html_blog_post_content(debug: bool, session, authorized: bool, blog_separator: str) -> str: """Returns the html content for a single blog post """ - linked_author = False + linked_author: bool = False actor: str = '' blog_str: str = '' message_link: str = '' @@ -329,7 +329,7 @@ def _html_blog_post_content(debug: bool, session, authorized: bool, message_link = \ post_json_object['object']['id'].replace('/statuses/', '/') title_str: str = '' - article_added = False + article_added: bool = False if post_json_object['object'].get('summary'): title_str = post_json_object['object']['summary'] blog_str += '

' + \ @@ -392,7 +392,7 @@ def _html_blog_post_content(debug: bool, session, authorized: bool, languages_understood = get_actor_languages_list(actor_json) json_content = get_content_from_post(post_json_object, system_language, languages_understood, "content") - minimize_all_images = False + minimize_all_images: bool = False attachment_str, _ = \ get_post_attachments_as_html(base_dir, nickname, domain, domain_full, post_json_object, @@ -832,7 +832,7 @@ def html_blog_page_rss3(base_dir: str, http_prefix: str, def _no_of_blog_accounts(base_dir: str) -> int: """Returns the number of blog accounts """ - ctr = 0 + ctr: int = 0 dir_str = data_dir(base_dir) for _, dirs, _ in os.walk(dir_str): for acct in dirs: diff --git a/bookmarks.py b/bookmarks.py index 1c97f12cc..cb9ad3944 100644 --- a/bookmarks.py +++ b/bookmarks.py @@ -106,10 +106,10 @@ def undo_bookmarks_collection_entry(recent_posts_cache: {}, return if not post_json_object['object']['bookmarks'].get('items'): return - total_items = 0 + total_items: int = 0 if post_json_object['object']['bookmarks'].get('totalItems'): total_items = post_json_object['object']['bookmarks']['totalItems'] - item_found = False + item_found: bool = False for bookmark_item in post_json_object['object']['bookmarks']['items']: if bookmark_item.get('actor'): if bookmark_item['actor'] == actor: diff --git a/briar.py b/briar.py index c5c9a7df7..b99f86dcb 100644 --- a/briar.py +++ b/briar.py @@ -63,7 +63,7 @@ def get_briar_address(actor_json: {}) -> str: def set_briar_address(actor_json: {}, briar_address: str) -> None: """Sets an briar address for the given actor """ - not_briar_address = False + not_briar_address: bool = False if len(briar_address) < 50: not_briar_address = True diff --git a/cache.py b/cache.py index 04a70fa49..61d055283 100644 --- a/cache.py +++ b/cache.py @@ -125,7 +125,7 @@ def get_person_from_cache(base_dir: str, person_url: str, """Get an actor from the cache """ # if the actor is not in memory then try to load it from file - loaded_from_file = False + loaded_from_file: bool = False if not person_cache.get(person_url): # does the person exist as a cached file? cache_filename = base_dir + '/cache/actors/' + \ @@ -293,7 +293,7 @@ def cache_svg_images(session, base_dir: str, http_prefix: str, post_attachments = get_post_attachments(obj) if not post_attachments: return False - cached = False + cached: bool = False post_id = remove_id_ending(obj['id']).replace('/', '--') actor: str = 'unknown' if post_attachments and obj.get('attributedTo'): diff --git a/categories.py b/categories.py index 8ad2278bb..27ce8d9fa 100644 --- a/categories.py +++ b/categories.py @@ -262,7 +262,7 @@ def set_hashtag_category(base_dir: str, hashtag: str, category: str, if os.path.isfile(category_filename): return False - category_written = False + category_written: bool = False try: with open(category_filename, 'w+', encoding='utf-8') as fp_category: fp_category.write(category) @@ -291,8 +291,8 @@ def guess_hashtag_category(tag_name: str, hashtag_categories: {}, return '' category_matched: str = '' - tag_matched_len = 0 - finished = False + tag_matched_len: int = 0 + finished: bool = False for category_str, hashtag_list in hashtag_categories.items(): if finished: diff --git a/city.py b/city.py index 5ba54c321..10d92951b 100644 --- a/city.py +++ b/city.py @@ -211,10 +211,10 @@ def spoof_geolocation(base_dir: str, if not os.path.isfile(nogo_filename): nogo_filename = base_dir + '/locations_nogo.txt' - man_city_radius = 0.1 - variance_at_location = 0.0004 - default_latitude = 51.8744 - default_longitude = 0.368333 + man_city_radius: float = 0.1 + variance_at_location: float = 0.0004 + default_latitude: float = 51.8744 + default_longitude: float = 0.368333 default_latdirection: str = 'N' default_longdirection: str = 'W' @@ -261,7 +261,7 @@ def spoof_geolocation(base_dir: str, city_fields = city_name.split(':') latitude = city_fields[1] longitude = city_fields[2] - area_km2 = 0 + area_km2: int = 0 if len(city_fields) > 3: area_km2 = int(city_fields[3]) latdirection: str = 'N' @@ -282,8 +282,8 @@ def spoof_geolocation(base_dir: str, datetime.timedelta(hours=approx_time_zone) cam_make, cam_model, cam_serial_number = \ _get_decoy_camera(decoy_seed) - valid_coord = False - seed_offset = 0 + valid_coord: bool = False + seed_offset: int = 0 while not valid_coord: # patterns of activity change in the city over time (distance_from_city_center, angle_radians) = \ @@ -351,11 +351,11 @@ def get_spoofed_city(city: str, base_dir: str, def _point_in_polygon(poly: [], x_coord: float, y_coord: float) -> bool: """Returns true if the given point is inside the given polygon """ - num = len(poly) - inside = False - p2x = 0.0 - p2y = 0.0 - xints = 0.0 + num: int = len(poly) + inside: bool = False + p2x: float = 0.0 + p2y: float = 0.0 + xints: float = 0.0 p1x, p1y = poly[0] for i in range(num + 1): p2x, p2y = poly[i % num] diff --git a/content.py b/content.py index 7c5309ff7..2fcea394c 100644 --- a/content.py +++ b/content.py @@ -85,8 +85,8 @@ def valid_url_lengths(content: str, max_url_length: int) -> bool: """ if '://' not in content: return True - sections = content.split('://') - ctr = 0 + sections: list = content.split('://') + ctr: int = 0 for text in sections: if ctr == 0: ctr += 1 @@ -103,7 +103,7 @@ def valid_url_lengths(content: str, max_url_length: int) -> bool: def remove_html_tag(html_str: str, tag: str) -> str: """Removes a given tag from a html string """ - tag_found = True + tag_found: bool = True while tag_found: match_str: str = ' ' + tag + '="' if match_str not in html_str: @@ -125,7 +125,7 @@ def _remove_quotes_within_quotes(content: str) -> str: if '' not in content: return content ctr = 1 - found = True + found: bool = True while found: prefix = content.split('
', ctr)[0] + '
' quoted_str = content.split('
', ctr)[1] @@ -202,7 +202,7 @@ def html_replace_inline_quotes(content: str) -> str: if '

' not in content: return content sections = content.split('

') - ctr = 0 + ctr: int = 0 new_content = '' for section in sections: if ctr == 0: @@ -238,8 +238,8 @@ def html_replace_quote_marks(content: str) -> str: sections = content.split('"') if len(sections) > 1: new_content: str = '' - open_quote = True - markup = False + open_quote: bool = True + markup: bool = False for char in content: curr_char = char if char == '<': @@ -255,11 +255,11 @@ def html_replace_quote_marks(content: str) -> str: new_content += curr_char if '"' in new_content: - open_quote = True + open_quote: bool = True content = new_content new_content: str = '' - ctr = 0 - sections = content.split('"') + ctr: int = 0 + sections: list = content.split('"') no_of_sections = len(sections) for sec in sections: new_content += sec @@ -300,8 +300,8 @@ def dangerous_css(filename: str, allow_local_network_access: bool) -> bool: # search for non-local web links if 'url(' in content: - url_list = content.split('url(') - ctr = 0 + url_list: list = content.split('url(') + ctr: int = 0 for url_str in url_list: if ctr == 0: ctr = 1 @@ -434,7 +434,7 @@ def _update_common_emoji(base_dir: str, emoji_content: str) -> None: common_emoji = common_emoji_str.split('\n') if common_emoji: new_common_emoji: list[str] = [] - emoji_found = False + emoji_found: bool = False for line in common_emoji: if ' ' + emoji_content in line: if not emoji_found: @@ -502,7 +502,7 @@ def replace_emoji_from_tags(session, base_dir: str, # emoji/charts/full-emoji-list.html if '-' not in icon_name: # a single code - replaced = False + replaced: bool = False try: replace_char = chr(int("0x" + icon_name, 16)) if not screen_readable: @@ -533,7 +533,7 @@ def replace_emoji_from_tags(session, base_dir: str, icon_codes = icon_name.split('-') icon_code_sequence: str = '' for icode in icon_codes: - replaced = False + replaced: bool = False try: icon_code_sequence += chr(int("0x" + icode, 16)) @@ -592,7 +592,7 @@ def _add_music_tag(content: str, tag: str) -> str: tag = '#' + tag if tag in content: return content - music_site_found = False + music_site_found: bool = False for site in MUSIC_SITES: if site + '/' in content: music_site_found = True @@ -612,8 +612,8 @@ def _shorten_linked_urls(content: str) -> str: return content if '<' not in content: return content - sections = content.split('>') - ctr = 0 + sections: list = content.split('>') + ctr: int = 0 for section_text in sections: if ctr == 0: ctr += 1 @@ -701,8 +701,8 @@ def remove_link_trackers_from_content(content: str) -> str: """ if '?utm_' not in content: return content - sections = content.split('?utm_') - ctr = 0 + sections: list = content.split('?utm_') + ctr: int = 0 new_content: str = '' for section_str in sections: if ctr == 0: @@ -728,7 +728,7 @@ def add_web_links(content: str) -> str: prefixes = get_link_prefixes() # do any of these prefixes exist within the content? - prefix_found = False + prefix_found: bool = False for prefix in prefixes: if prefix in content: prefix_found = True @@ -752,7 +752,7 @@ def add_web_links(content: str) -> str: if _contains_doi_reference(wrd, replace_dict): continue # does the word begin with a link prefix? - prefix_found = False + prefix_found: bool = False for prefix in prefixes: if wrd.startswith(prefix): prefix_found = True @@ -862,9 +862,9 @@ def replace_remote_hashtags(content: str, if ' href="' not in content: return content - sections = content.split(' href="') - ctr = 0 - replacements = {} + sections: list = content.split(' href="') + ctr: int = 0 + replacements: dict = {} for section in sections: if ctr == 0: ctr += 1 @@ -1008,7 +1008,7 @@ def _add_mention(base_dir: str, word_str: str, http_prefix: str, possible_nickname + "" return True # try replacing petnames with mentions - follow_ctr = 0 + follow_ctr: int = 0 if petnames: for follow in following: if '@' not in follow: @@ -1132,9 +1132,9 @@ def _remove_truncated_link(content: str) -> str: """ if '' not in content: content = '

' + content.replace('\n\n', '

') + '

' non_html_list = True - non_html_list2 = False + non_html_list2: bool = False if '\n' in content and '

' not in content: content = '

' + content.replace('\n', '

') + '

' non_html_list2 = True @@ -1319,13 +1319,13 @@ def detect_dogwhistles(content: str, dogwhistles: {}) -> {}: """Returns a dict containing any detected dogwhistle words """ content = remove_html(content).lower() - result = {} + result: dict = {} words = _get_simplified_content(content).split(' ') for whistle, category in dogwhistles.items(): if not category: continue - ending = False - starting = False + ending: bool = False + starting: bool = False whistle = whistle.lower() if whistle.startswith('x-'): @@ -1937,9 +1937,9 @@ def limit_repeated_words(text: str, max_repeats: int) -> str: """Removes words which are repeated many times """ words = text.replace('\n', ' ').split(' ') - repeat_ctr = 0 + repeat_ctr: int = 0 repeated_text: str = '' - replacements = {} + replacements: dict = {} prev_word: str = '' for word in words: if word == prev_word: @@ -1952,7 +1952,7 @@ def limit_repeated_words(text: str, max_repeats: int) -> str: if repeat_ctr > max_repeats: new_text = ((prev_word + ' ') * max_repeats).strip() replacements[prev_word] = [repeated_text, new_text] - repeat_ctr = 0 + repeat_ctr: int = 0 repeated_text: str = '' prev_word = word @@ -2024,7 +2024,7 @@ def words_similarity(content1: str, content2: str, min_words: int) -> int: histogram1 = _words_similarity_histogram(words1) histogram2 = _words_similarity_histogram(words2) - diff = 0 + diff: int = 0 for combined_words, histogram1_value in histogram1.items(): if not histogram2.get(combined_words): diff += 1 @@ -2045,7 +2045,7 @@ def contains_invalid_local_links(domain_full: str, if match_str not in content: continue # extract the urls and check whether they are for the local domain - ctr = 0 + ctr: int = 0 sections = content.split(match_str) final_section_index = len(sections) - 1 for section_str in sections: @@ -2072,17 +2072,17 @@ def bold_reading_string(text: str) -> str: """Returns bold reading formatted text """ text = html.unescape(text) - add_paragraph_markup = False + add_paragraph_markup: bool = False if '

' in text: text = text.replace('

', '\n').replace('

', '') add_paragraph_markup = True - paragraphs = text.split('\n') - parag_ctr = 0 + paragraphs: list = text.split('\n') + parag_ctr: int = 0 new_text: str = '' for parag in paragraphs: - words = parag.split(' ') + words: list = parag.split(' ') new_parag: str = '' - reading_markup = False + reading_markup: bool = False for wrd in words: if '<' in wrd: reading_markup = True @@ -2133,8 +2133,8 @@ def import_emoji(base_dir: str, import_filename: str, session) -> None: """ if not os.path.isfile(import_filename): return - emoji_dict = load_json(base_dir + '/emoji/default_emoji.json') - added = 0 + emoji_dict: dict = load_json(base_dir + '/emoji/default_emoji.json') + added: int = 0 lines_str = load_string(import_filename, 'EX: import_emoji failed ' + import_filename) if lines_str: @@ -2264,7 +2264,7 @@ def remove_script(content: str, log_filename: str, if prefix not in content: continue sections = content.split(prefix) - ctr = 0 + ctr: int = 0 for text in sections: if ctr == 0: ctr += 1 @@ -2393,8 +2393,8 @@ def format_mixed_right_to_left(content: str, if language_right_to_left(language): return content result: str = '' - changed = False - paragraphs = content.split('

') + changed: bool = False + paragraphs: list = content.split('

') for text_html in paragraphs: if '

' not in text_html: continue @@ -2413,7 +2413,7 @@ def format_mixed_right_to_left(content: str, prev_distilled = distilled distilled = distilled.replace('


', '

') paragraphs = distilled.split('

') - ctr = 0 + ctr: int = 0 for text_html in paragraphs: ctr += 1 if ctr < len(paragraphs): diff --git a/context.py b/context.py index ea4a78dec..9b8078532 100644 --- a/context.py +++ b/context.py @@ -62,7 +62,7 @@ def _has_valid_context_str(url: str) -> bool: """is the @context string of a post recognised? """ if url not in VALID_CONTEXTS: - wildcard_found = False + wildcard_found: bool = False for cont in VALID_CONTEXTS: if cont.startswith('*'): cont = cont.replace('*', '', 1) diff --git a/crawlers.py b/crawlers.py index 3a9644fe0..0e3da9770 100644 --- a/crawlers.py +++ b/crawlers.py @@ -126,8 +126,8 @@ def blocked_user_agent(calling_domain: str, agent_str: str, agent_domain = None if agent_str: - contains_bot_string = False - llm = False + contains_bot_string: bool = False + llm: bool = False # is this an LLM crawler? # https://github.com/ai-robots-txt/ai.robots.txt/blob/main/robots.txt @@ -222,7 +222,7 @@ def blocked_user_agent(calling_domain: str, agent_str: str, # is the User-Agent type blocked? eg. "Mastodon" if user_agents_blocked: - blocked_ua = False + blocked_ua: bool = False for agent_name in user_agents_blocked: if agent_name in agent_str: blocked_ua = True @@ -234,7 +234,7 @@ def blocked_user_agent(calling_domain: str, agent_str: str, return False, blocked_cache_last_updated, False # is the User-Agent domain blocked - blocked_ua = False + blocked_ua: bool = False if not agent_domain.startswith(calling_domain): blocked_cache_last_updated = \ update_blocked_cache(base_dir, blocked_cache, diff --git a/cwlists.py b/cwlists.py index f9367f2ce..a0aa51ec7 100644 --- a/cwlists.py +++ b/cwlists.py @@ -49,7 +49,7 @@ def _add_cw_match_tags(item: {}, post_tags: {}, cw_text: str, """Updates content warning text using hashtags from within the post content """ - matched = False + matched: bool = False for tag in item['hashtags']: tag = tag.strip() if not tag: @@ -81,7 +81,7 @@ def _add_cw_match_domains(item: {}, content: str, cw_text: str, """Updates content warning text using domains from within the post content """ - matched = False + matched: bool = False for domain in item['domains']: if '.' in domain or is_yggdrasil_address(domain): @@ -158,7 +158,7 @@ def add_cw_from_lists(post_json_object: {}, cw_lists: {}, translate: {}, if warning in cw_text: continue - matched = False + matched: bool = False # match hashtags within the post if post_tags and item.get('hashtags'): diff --git a/cwtch.py b/cwtch.py index c69e78901..6994d5470 100644 --- a/cwtch.py +++ b/cwtch.py @@ -59,7 +59,7 @@ def get_cwtch_address(actor_json: {}) -> str: def set_cwtch_address(actor_json: {}, cwtch_address: str) -> None: """Sets an cwtch address for the given actor """ - not_cwtch_address = False + not_cwtch_address: bool = False if len(cwtch_address) < 56: not_cwtch_address = True diff --git a/daemon.py b/daemon.py index a0c878a33..b01ed2506 100644 --- a/daemon.py +++ b/daemon.py @@ -305,35 +305,35 @@ class PubServerUnitTest(PubServer): class EpicyonServer(ThreadingHTTPServer): starting_daemon: bool = True - hide_announces = {} - no_of_books = 0 - max_api_blocks = 32000 + hide_announces: dict = {} + no_of_books: int = 0 + max_api_blocks: int = 32000 block_federated_endpoints = None - block_federated = [] - books_cache = {} - max_recent_books = 1000 - max_cached_readers = 24 - auto_cw_cache = {} + block_federated: list = [] + books_cache: dict = {} + max_recent_books: int = 1000 + max_cached_readers: int = 24 + auto_cw_cache: dict = {} sites_unavailable = None - max_shares_on_profile = 0 - block_military = {} - block_government = {} - block_bluesky = {} - block_nostr = {} + max_shares_on_profile: int = 0 + block_military: dict = {} + block_government: dict = {} + block_bluesky: dict = {} + block_nostr: dict = {} followers_synchronization: bool = False - followers_sync_cache = {} + followers_sync_cache: dict = {} buy_sites = None - min_images_for_accounts = 0 + min_images_for_accounts: int = 0 default_post_language = None - css_cache = {} + css_cache: dict = {} reverse_sequence = None clacks = None public_replies_unlisted: bool = False - dogwhistles = {} + dogwhistles: dict = {} preferred_podcast_formats: list[str] = [] - bold_reading = {} - hide_follows = {} - hide_recent_posts = {} + bold_reading: dict = {} + hide_follows: dict = {} + hide_recent_posts: dict = {} account_timezone = None post_to_nickname = None nodeinfo_is_active: bool = False @@ -344,17 +344,17 @@ class EpicyonServer(ThreadingHTTPServer): dyslexic_font: bool = False content_license_url: str = '' dm_license_url: str = '' - fitness = {} + fitness: dict = {} signing_priv_key_pem = None show_node_info_accounts: bool = False show_node_info_version: bool = False text_mode_banner: str = '' - access_keys = {} - rss_timeout_sec = 20 - check_actor_timeout = 2 - default_reply_interval_hrs = 9999999 - recent_dav_etags = {} - key_shortcuts = {} + access_keys: dict = {} + rss_timeout_sec: int = 20 + check_actor_timeout: int = 2 + default_reply_interval_hrs: int = 9999999 + recent_dav_etags: dict = {} + key_shortcuts: dict = {} low_bandwidth: bool = False user_agents_blocked = None crawlers_allowed = None @@ -363,52 +363,52 @@ class EpicyonServer(ThreadingHTTPServer): allow_local_network_access: bool = False yt_replace_domain: str = '' twitter_replacement_domain: str = '' - newswire = {} - max_newswire_posts = 0 + newswire: dict = {} + max_newswire_posts: int = 0 verify_all_signatures: bool = False - blocklistUpdateCtr = 0 - manual_follower_approval = True + blocklistUpdateCtr: int = 0 + manual_follower_approval: bool = True onion_domain = None i2p_domain = None yggdrasil_domain = None media_instance: bool = False blogs_instance: bool = False - translate = {} + translate: dict = {} system_language: str = 'en' city: str = '' - voting_time_mins = 30 + voting_time_mins: int = 30 positive_voting: bool = False - newswire_votes_threshold = 1 - max_newswire_feed_size_kb = 1 - max_newswire_posts_per_source = 1 + newswire_votes_threshold: int = 1 + max_newswire_feed_size_kb: int = 1 + max_newswire_posts_per_source: int = 1 show_published_date_only: bool = False - max_mirrored_articles = 0 - max_news_posts = 0 - maxTags = 32 - max_followers = 2000 + max_mirrored_articles: int = 0 + max_news_posts: int = 0 + maxTags: int = 32 + max_followers: int = 2000 show_publish_as_icon: bool = False full_width_tl_button_header: bool = False rss_icon_at_top: bool = True publish_button_at_top: bool = False max_feed_item_size_kb = 100 - maxCategoriesFeedItemSizeKb = 1024 - dormant_months = 6 - max_like_count = 10 - followingItemsPerPage = 12 + maxCategoriesFeedItemSizeKb: int = 1024 + dormant_months: int = 6 + max_like_count: int = 10 + followingItemsPerPage: int = 12 registration: bool = False enable_shared_inbox: bool = True - outboxThread = {} - outbox_thread_index = {} - new_post_thread = {} - project_version = __version__ + outboxThread: dict = {} + outbox_thread_index: dict = {} + new_post_thread: dict = {} + project_version: str = __version__ secure_mode: bool = True - max_post_length = 0 - maxMediaSize = 0 - maxMessageLength = 64000 - maxPostsInBox = 32000 - maxCacheAgeDays = 30 + max_post_length: int = 0 + maxMediaSize: int = 0 + maxMessageLength: int = 64000 + maxPostsInBox: int = 32000 + maxCacheAgeDays: int = 30 domain: str = '' - port = 43 + port: int = 43 domain_full: str = '' http_prefix: str = 'https' debug: bool = False @@ -416,62 +416,62 @@ class EpicyonServer(ThreadingHTTPServer): shared_items_federated_domains: list[str] = [] base_dir: str = '' instance_id: str = '' - person_cache = {} - cached_webfingers = {} - favicons_cache = {} + person_cache: dict = {} + cached_webfingers: dict = {} + favicons_cache: dict = {} proxy_type = None session = None session_onion = None session_i2p = None session_yggdrasil = None - last_getreq = 0 - last_postreq = 0 + last_getreq: int = 0 + last_postreq: int = 0 getreq_busy: bool = False postreq_busy: bool = False received_message: bool = False inbox_queue: list[dict] = [] send_threads = None post_log: list[str] = [] - max_queue_length = 64 + max_queue_length: int = 64 allow_deletion: bool = True - last_login_time = 0 - last_login_failure = 0 - login_failure_count = {} + last_login_time: int = 0 + last_login_failure: int = 0 + login_failure_count: dict = {} log_login_failures: bool = True - max_replies = 10 - tokens = {} - tokens_lookup = {} + max_replies: int = 10 + tokens: dict = {} + tokens_lookup: dict = {} instance_only_skills_search: bool = True followers_threads = [] blocked_cache: list[str] = [] - blocked_cache_last_updated = 0 - blocked_cache_update_secs = 120 - blocked_cache_last_updated = 0 - custom_emoji = {} - known_crawlers = {} - last_known_crawler = 0 + blocked_cache_last_updated: int = 0 + blocked_cache_update_secs: int = 120 + blocked_cache_last_updated: int = 0 + custom_emoji: dict = {} + known_crawlers: dict = {} + last_known_crawler: int = 0 lists_enabled = None - cw_lists = {} + cw_lists: dict = {} theme_name: str = '' news_instance: bool = False default_timeline: str = 'inbox' thrFitness = None - recent_posts_cache = {} + recent_posts_cache: dict = {} thrCache = None - send_threads_timeout_mins = 3 + send_threads_timeout_mins: int = 3 thrPostsQueue = None thrPostsWatchdog = None thrSharesExpire = None thrSharesExpireWatchdog = None - max_recent_posts = 1 - iconsCache = {} - fontsCache = {} + max_recent_posts: int = 1 + iconsCache: dict = {} + fontsCache: dict = {} shared_item_federation_tokens = None shared_item_federation_tokens = None peertube_instances: list[str] = [] - max_mentions = 10 - max_emoji = 10 - max_hashtags = 10 + max_mentions: int = 10 + max_emoji: int = 10 + max_hashtags: int = 10 thrInboxQueue = None thrPostSchedule = None thrNewswireDaemon = None @@ -479,27 +479,27 @@ class EpicyonServer(ThreadingHTTPServer): restart_inbox_queue_in_progress: bool = False restart_inbox_queue: bool = False signing_priv_key_pem: str = '' - thrCheckActor = {} + thrCheckActor: dict = {} thrImportFollowing = None thrWatchdog = None thrWatchdogSchedule = None thrNewswireWatchdog = None thrFederatedSharesWatchdog = None thrFederatedBlocksDaemon = None - qrcode_scale = 6 + qrcode_scale: int = 6 instance_description: str = '' instance_description_short: str = 'Epicyon' robots_txt = None last_llm_time = None mitm_servers: list[str] = [] log_unknown_requests: bool = False - watermark_width_percent = 0 - watermark_position = 0 - watermark_opacity = 0 - headers_catalog = {} + watermark_width_percent: int = 0 + watermark_position: int = 0 + watermark_opacity: int = 0 + headers_catalog: dict = {} dictionary: list[str] = [] - twograms = {} - searchable_by_default = {} + twograms: dict = {} + searchable_by_default: dict = {} known_epicyon_instances: list[str] = [] def handle_error(self, request, client_address): diff --git a/daemon_get.py b/daemon_get.py index 420e44e79..7f80d33dc 100644 --- a/daemon_get.py +++ b/daemon_get.py @@ -670,7 +670,7 @@ def daemon_http_get(self) -> None: return # turn off dropdowns on new post screen - no_drop_down = False + no_drop_down: bool = False if self.path.endswith('?nodropdown'): no_drop_down = True self.path = self.path.replace('?nodropdown', '') @@ -1508,10 +1508,10 @@ def daemon_http_get(self) -> None: self.server.debug) # is this a html/ssml/icalendar request? - html_getreq = False - csv_getreq = False - ssml_getreq = False - icalendar_getreq = False + html_getreq: bool = False + csv_getreq: bool = False + ssml_getreq: bool = False + icalendar_getreq: bool = False if has_accept(self, calling_domain): if request_http(self.headers, self.server.debug): html_getreq = True @@ -1683,7 +1683,7 @@ def daemon_http_get(self) -> None: self.server.fitness) return - users_in_path = False + users_in_path: bool = False if '/users/' in self.path: users_in_path = True @@ -2271,8 +2271,8 @@ def daemon_http_get(self) -> None: http_404(self, 125) return if self.path.endswith('/followingaccounts.csv'): - html_getreq = False - csv_getreq = True + html_getreq: bool = False + csv_getreq: bool = True if html_getreq: msg = html_following_list(self.server.base_dir, following_filename) @@ -2640,7 +2640,7 @@ def daemon_http_get(self) -> None: http_304(self) return - tries = 0 + tries: int = 0 media_binary = None while tries < 5: exc_str = 'EX: manifest logo ' + str(tries) + ' [ex]' @@ -2678,7 +2678,7 @@ def daemon_http_get(self) -> None: http_304(self) return - tries = 0 + tries: int = 0 media_binary = None while tries < 5: exc_str = 'EX: manifest screenshot ' + str(tries) + ' [ex]' @@ -2716,7 +2716,7 @@ def daemon_http_get(self) -> None: http_304(self) return - tries = 0 + tries: int = 0 media_binary = None while tries < 5: exc_str = 'EX: login screen image ' + str(tries) + ' [ex]' @@ -3555,7 +3555,7 @@ def daemon_http_get(self) -> None: '_GET', 'emoji search shown done', self.server.debug) - repeat_private = False + repeat_private: bool = False if html_getreq and '?repeatprivate=' in self.path: repeat_private = True self.path = self.path.replace('?repeatprivate=', '?repeat=') @@ -4371,7 +4371,7 @@ def daemon_http_get(self) -> None: # replying as a direct message, # for moderation posts or the dm timeline - reply_is_chat = False + reply_is_chat: bool = False if '?replydm=' in self.path or '?replychat=' in self.path: reply_type = 'replydm' if '?replychat=' in self.path: diff --git a/daemon_get_buttons_announce.py b/daemon_get_buttons_announce.py index 890762e51..235dc937c 100644 --- a/daemon_get_buttons_announce.py +++ b/daemon_get_buttons_announce.py @@ -233,10 +233,10 @@ def announce_button(self, calling_domain: str, path: str, announce_filename.replace('.json', '') + '.mitm' if os.path.isfile(mitm_filename): mitm = True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(self.post_to_nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if self.post_to_nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/daemon_get_buttons_bookmark.py b/daemon_get_buttons_bookmark.py index 149c12ee4..1e1ba5616 100644 --- a/daemon_get_buttons_bookmark.py +++ b/daemon_get_buttons_bookmark.py @@ -185,10 +185,10 @@ def bookmark_button(self, calling_domain: str, path: str, bookmark_filename.replace('.json', '') + '.mitm' if os.path.isfile(mitm_filename): mitm = True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(self.post_to_nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if self.post_to_nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -412,10 +412,10 @@ def bookmark_button_undo(self, calling_domain: str, path: str, bookmark_filename.replace('.json', '') + '.mitm' if os.path.isfile(mitm_filename): mitm = True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(self.post_to_nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if self.post_to_nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/daemon_get_buttons_like.py b/daemon_get_buttons_like.py index b1ce92ce1..cf625b20d 100644 --- a/daemon_get_buttons_like.py +++ b/daemon_get_buttons_like.py @@ -232,10 +232,10 @@ def like_button(self, calling_domain: str, path: str, liked_post_filename.replace('.json', '') + '.mitm' if os.path.isfile(mitm_filename): mitm = True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(self.post_to_nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if self.post_to_nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -503,10 +503,10 @@ def like_button_undo(self, calling_domain: str, path: str, liked_post_filename.replace('.json', '') + '.mitm' if os.path.isfile(mitm_filename): mitm = True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(self.post_to_nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if self.post_to_nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/daemon_get_buttons_mute.py b/daemon_get_buttons_mute.py index 0b11e24a4..9b63e2a10 100644 --- a/daemon_get_buttons_mute.py +++ b/daemon_get_buttons_mute.py @@ -121,16 +121,16 @@ def mute_button(self, calling_domain: str, path: str, nickname + ' ' + domain) print('mute_post: Muted post cache: ' + str(cached_post_filename)) - show_individual_post_icons = True - manually_approve_followers = \ + show_individual_post_icons: bool = True + manually_approve_followers: bool = \ follower_approval_active(base_dir, nickname, domain) - show_repeats = not is_dm(mute_post_json) - show_public_only = False - store_to_cache = True - use_cache_only = False - allow_downloads = False - show_avatar_options = True + show_repeats: bool = not is_dm(mute_post_json) + show_public_only: bool = False + store_to_cache: bool = True + use_cache_only: bool = False + allow_downloads: bool = False + show_avatar_options: bool = True avatar_url = None timezone = None if account_timezone.get(nickname): @@ -144,7 +144,7 @@ def mute_button(self, calling_domain: str, path: str, bold_reading = False if bold_reading_nicknames.get(nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -312,15 +312,15 @@ def mute_button_undo(self, calling_domain: str, path: str, nickname + ' ' + domain) print('unmute_post: Unmuted post cache: ' + str(cached_post_filename)) - show_individual_post_icons = True - manually_approve_followers = \ + show_individual_post_icons: bool = True + manually_approve_followers: bool = \ follower_approval_active(base_dir, nickname, domain) - show_repeats = not is_dm(mute_post_json) - show_public_only = False - store_to_cache = True - use_cache_only = False - allow_downloads = False - show_avatar_options = True + show_repeats: bool = not is_dm(mute_post_json) + show_public_only: bool = False + store_to_cache: bool = True + use_cache_only: bool = False + allow_downloads: bool = False + show_avatar_options: bool = True avatar_url = None timezone = None if account_timezone.get(nickname): @@ -334,7 +334,7 @@ def mute_button_undo(self, calling_domain: str, path: str, bold_reading = False if bold_reading_nicknames.get(nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/daemon_get_buttons_reaction.py b/daemon_get_buttons_reaction.py index 72934c2d0..ba1b8497d 100644 --- a/daemon_get_buttons_reaction.py +++ b/daemon_get_buttons_reaction.py @@ -262,10 +262,10 @@ def reaction_button(self, calling_domain: str, path: str, reaction_post_filename.replace('.json', '') + '.mitm' if os.path.isfile(mitm_filename): mitm = True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(self.post_to_nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if self.post_to_nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -556,10 +556,10 @@ def reaction_button_undo(self, calling_domain: str, path: str, reaction_post_filename.replace('.json', '') + '.mitm' if os.path.isfile(mitm_filename): mitm = True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(self.post_to_nickname): bold_reading = True - minimize_all_images = False + minimize_all_images: bool = False if self.post_to_nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/daemon_get_css.py b/daemon_get_css.py index 4e01c5f60..1c069d2ce 100644 --- a/daemon_get_css.py +++ b/daemon_get_css.py @@ -36,7 +36,7 @@ def get_style_sheet(self, base_dir: str, calling_domain: str, path: str, if css_cache.get(path): css = css_cache[path] elif os.path.isfile(path): - tries = 0 + tries: int = 0 while tries < 5: try: css = get_css(path) diff --git a/daemon_get_feeds.py b/daemon_get_feeds.py index af60a1413..850136a1d 100644 --- a/daemon_get_feeds.py +++ b/daemon_get_feeds.py @@ -125,7 +125,7 @@ def show_shares_feed(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True known_epicyon_instances = \ @@ -321,7 +321,7 @@ def show_following_feed(self, authorized: bool, if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True if not authorized and hide_follows.get(nickname): @@ -523,7 +523,7 @@ def show_moved_feed(self, authorized: bool, if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True @@ -719,7 +719,7 @@ def show_inactive_feed(self, authorized: bool, city = get_spoofed_city(city, base_dir, nickname, domain) if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True known_epicyon_instances = \ @@ -915,7 +915,7 @@ def show_followers_feed(self, authorized: bool, city = get_spoofed_city(city, base_dir, nickname, domain) if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True known_epicyon_instances = \ diff --git a/daemon_get_hashtag.py b/daemon_get_hashtag.py index 554231d78..59d7c9d09 100644 --- a/daemon_get_hashtag.py +++ b/daemon_get_hashtag.py @@ -216,7 +216,7 @@ def hashtag_search2(self, calling_domain: str, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True hashtag_str = \ diff --git a/daemon_get_images.py b/daemon_get_images.py index 7ff015957..718672b2b 100644 --- a/daemon_get_images.py +++ b/daemon_get_images.py @@ -83,7 +83,7 @@ def show_avatar_or_banner(self, referer_domain: str, path: str, original_ext = avatar_file_ext original_avatar_file = avatar_file alt_ext = get_image_extensions() - alt_found = False + alt_found: bool = False for alt in alt_ext: if alt == original_ext: continue @@ -494,7 +494,7 @@ def show_qrcode(self, calling_domain: str, path: str, http_304(self) return True - tries = 0 + tries: int = 0 media_binary = None while tries < 5: exc_str = 'EX: _show_qrcode ' + str(tries) + ' [ex]' @@ -541,7 +541,7 @@ def search_screen_banner(self, path: str, http_304(self) return True - tries = 0 + tries: int = 0 media_binary = None while tries < 5: exc_str = 'EX: _search_screen_banner ' + str(tries) + ' [ex]' @@ -583,7 +583,7 @@ def column_image(self, side: str, path: str, base_dir: str, domain: str, http_304(self) return True - tries = 0 + tries: int = 0 media_binary = None while tries < 5: exc_str = 'EX: _column_image ' + str(tries) + ' [ex]' @@ -624,7 +624,7 @@ def show_default_profile_background(self, base_dir: str, theme_name: str, http_304(self) return True - tries = 0 + tries: int = 0 bg_binary = None while tries < 5: exc_str = 'EX: _show_default_profile_background ' + \ @@ -674,7 +674,7 @@ def show_background_image(self, path: str, http_304(self) return True - tries = 0 + tries: int = 0 bg_binary = None while tries < 5: exc_str = 'EX: _show_background_image ' + \ diff --git a/daemon_get_login.py b/daemon_get_login.py index 14a396d52..5bc60a166 100644 --- a/daemon_get_login.py +++ b/daemon_get_login.py @@ -29,13 +29,13 @@ def redirect_to_login_screen(self, calling_domain: str, path: str, if authorized: return False - divert_to_login_screen = False + divert_to_login_screen: bool = False non_login_paths = ('/media/', '/ontologies/', '/data/', '/sharefiles/', '/statuses/', '/emoji/', '/tags/', '/tagmaps/', '/avatars/', '/favicons/', '/headers/', '/fonts/', '/icons/') if not string_contains(path, non_login_paths): - divert_to_login_screen = True + divert_to_login_screen: bool = True if path.startswith('/users/'): nick_str = path.split('/users/')[1] if '/' not in nick_str and '?' not in nick_str: diff --git a/daemon_get_post.py b/daemon_get_post.py index 08bd298c5..74181b917 100644 --- a/daemon_get_post.py +++ b/daemon_get_post.py @@ -135,7 +135,7 @@ def _show_post_from_file(self, post_filename: str, liked_by: str, if os.path.isfile(mitm_filename): mitm = True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True @@ -322,12 +322,12 @@ def show_individual_post(self, ssml_getreq: bool, authorized: bool, http_404(self, 75) return True - post_filename = \ + post_filename: str = \ acct_dir(base_dir, nickname, domain) + '/outbox/' + \ http_prefix + ':##' + domain_full + '#users#' + nickname + \ '#statuses#' + status_number + '.json' - include_create_wrapper = False + include_create_wrapper: bool = False if post_sections[-1] == 'activity': include_create_wrapper = True @@ -423,8 +423,8 @@ def show_new_post(self, edit_post_params: {}, ua_str: str) -> bool: """Shows the new post screen """ - searchable_by_default = 'yourself' - is_new_post_endpoint = False + searchable_by_default: str = 'yourself' + is_new_post_endpoint: bool = False new_post_month = None new_post_year = None if '/users/' in path and '/new' in path: @@ -488,7 +488,7 @@ def show_new_post(self, edit_post_params: {}, if reply_language: default_post_language2 = reply_language - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True @@ -677,7 +677,7 @@ def show_individual_at_post(self, ssml_getreq: bool, authorized: bool, http_prefix + ':##' + domain_full + '#users#' + nickname + \ '#statuses#' + status_number + '.json' - include_create_wrapper = False + include_create_wrapper: bool = False if post_sections[-1] == 'activity': include_create_wrapper = True @@ -777,7 +777,7 @@ def show_likers_of_post(self, authorized: bool, post_url = post_url.split('?')[0] post_url = post_url.replace('--', '/') - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True @@ -880,7 +880,7 @@ def show_announcers_of_post(self, authorized: bool, post_url = post_url.split('?')[0] post_url = post_url.replace('--', '/') - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True @@ -1036,7 +1036,7 @@ def show_replies_to_post(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True # get the list of mutuals for the current account @@ -1158,7 +1158,7 @@ def show_replies_to_post(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True # get the list of mutuals for the current account @@ -1284,14 +1284,14 @@ def show_notify_post(self, authorized: bool, nickname = path.split('/users/')[1] if '/' in nickname: return False - replies = False + replies: bool = False post_filename = locate_post(base_dir, nickname, domain, post_id, replies) if not post_filename: return False - include_create_wrapper = False + include_create_wrapper: bool = False if path.endswith('/activity'): include_create_wrapper = True @@ -1423,7 +1423,7 @@ def show_conversation_thread(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True conv_str = \ diff --git a/daemon_get_profile.py b/daemon_get_profile.py index d6b163301..af5691c1f 100644 --- a/daemon_get_profile.py +++ b/daemon_get_profile.py @@ -112,7 +112,7 @@ def show_person_profile(self, authorized: bool, city = get_spoofed_city(city, base_dir, nickname, domain) if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True known_epicyon_instances = \ @@ -286,7 +286,7 @@ def show_roles(self, calling_domain: str, referer_domain: str, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True known_epicyon_instances = \ @@ -447,7 +447,7 @@ def show_skills(self, calling_domain: str, referer_domain: str, nick = nickname if account_timezone.get(nick): timezone = account_timezone.get(nick) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nick): bold_reading = True known_epicyon_instances = \ diff --git a/daemon_get_reactions.py b/daemon_get_reactions.py index dcbef94aa..83728bf3d 100644 --- a/daemon_get_reactions.py +++ b/daemon_get_reactions.py @@ -122,7 +122,7 @@ def reaction_picker2(self, calling_domain: str, path: str, if account_timezone.get(self.post_to_nickname): timezone = account_timezone.get(self.post_to_nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(self.post_to_nickname): bold_reading = True diff --git a/daemon_get_timeline.py b/daemon_get_timeline.py index 61eed2d24..397218c82 100644 --- a/daemon_get_timeline.py +++ b/daemon_get_timeline.py @@ -141,10 +141,10 @@ def show_media_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True last_post_id = None @@ -152,7 +152,7 @@ def show_media_timeline(self, authorized: bool, last_post_id = path.split(';lastpost=')[1] if ';' in last_post_id: last_post_id = last_post_id.split(';')[0] - show_announces = True + show_announces: bool = True if hide_announces.get(nickname): show_announces = False known_epicyon_instances = \ @@ -362,10 +362,10 @@ def show_blogs_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True last_post_id = None @@ -589,10 +589,10 @@ def show_news_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True known_epicyon_instances = \ @@ -807,10 +807,10 @@ def show_features_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True known_epicyon_instances = \ @@ -987,10 +987,10 @@ def show_shares_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True known_epicyon_instances = \ @@ -1138,10 +1138,10 @@ def show_wanted_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True known_epicyon_instances = \ @@ -1323,10 +1323,10 @@ def show_bookmarks_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True known_epicyon_instances = \ @@ -1506,7 +1506,7 @@ def show_outbox_timeline(self, authorized: bool, positive_voting, voting_time_mins) if outbox_feed: - page_number = 0 + page_number: int = 0 if '?page=' in nickname: page_number = nickname.split('?page=')[1] if ';' in page_number: @@ -1546,13 +1546,13 @@ def show_outbox_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True - show_announces = True + show_announces: bool = True if hide_announces.get(nickname): show_announces = False known_epicyon_instances = \ @@ -1747,10 +1747,10 @@ def show_mod_timeline(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True known_epicyon_instances = \ @@ -1956,10 +1956,10 @@ def show_dms(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True last_post_id = None @@ -2172,10 +2172,10 @@ def show_replies(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True last_post_id = None @@ -2397,10 +2397,10 @@ def show_inbox(self, authorized: bool, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True - reverse_sequence = False + reverse_sequence: bool = False if nickname in reverse_sequence_nicknames: reverse_sequence = True last_post_id = None @@ -2408,7 +2408,7 @@ def show_inbox(self, authorized: bool, last_post_id = path.split(';lastpost=')[1] if ';' in last_post_id: last_post_id = last_post_id.split(';')[0] - show_announces = True + show_announces: bool = True if hide_announces.get(nickname): show_announces = False known_epicyon_instances = \ diff --git a/daemon_post.py b/daemon_post.py index 83322913f..5d997ee21 100644 --- a/daemon_post.py +++ b/daemon_post.py @@ -498,7 +498,7 @@ def daemon_http_post(self) -> None: '_POST', '_news_post_edit', self.server.debug) - users_in_path = False + users_in_path: bool = False if '/users/' in self.path: users_in_path = True @@ -533,7 +533,7 @@ def daemon_http_post(self) -> None: '_POST', '_moderator_actions', self.server.debug) - search_for_emoji = False + search_for_emoji: bool = False if self.path.endswith('/searchhandleemoji'): search_for_emoji = True self.path = self.path.replace('/searchhandleemoji', @@ -1135,7 +1135,7 @@ def daemon_http_post(self) -> None: self.server.postreq_busy = False return - is_media_content = False + is_media_content: bool = False if string_starts_with(self.headers['Content-type'], ('image/', 'video/', 'audio/')): is_media_content = True @@ -1223,7 +1223,7 @@ def daemon_http_post(self) -> None: # check content length before reading bytes if self.path in ('/sharedInbox', '/inbox'): - length = 0 + length: int = 0 if self.headers.get('Content-length'): length = int(self.headers['Content-length']) elif self.headers.get('Content-Length'): diff --git a/daemon_post_keys.py b/daemon_post_keys.py index 299dcb7ca..82d9d1f23 100644 --- a/daemon_post_keys.py +++ b/daemon_post_keys.py @@ -73,7 +73,7 @@ def keyboard_shortcuts(self, calling_domain: str, cookie: str, self.server.postreq_busy = False return - save_keys = False + save_keys: bool = False access_keys_template = access_keys for variable_name, _ in access_keys_template.items(): if not access_keys2.get(variable_name): diff --git a/daemon_post_login.py b/daemon_post_login.py index 168da8098..76642cd88 100644 --- a/daemon_post_login.py +++ b/daemon_post_login.py @@ -228,9 +228,9 @@ def post_login_screen(self, calling_domain: str, cookie: str, # be careful to avoid logging the password login_str = login_params if '=' in login_params: - login_params_list = login_params.split('=') + login_params_list: list = login_params.split('=') login_str: str = '' - skip_param = False + skip_param: bool = False for login_prm in login_params_list: if not skip_param: login_str += login_prm + '=' diff --git a/daemon_post_person_options.py b/daemon_post_person_options.py index 54672e440..3cccc2de8 100644 --- a/daemon_post_person_options.py +++ b/daemon_post_person_options.py @@ -293,7 +293,7 @@ def _person_options_view(self, options_confirm_params: str, self.server.postreq_busy = False return True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(chooser_nickname): bold_reading = True @@ -936,9 +936,9 @@ def _person_options_dm(self, options_confirm_params: str, custom_submit_text = get_config_param(base_dir, 'customSubmitText') conversation_id = None convthread_id = None - reply_is_chat = False + reply_is_chat: bool = False - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(chooser_nickname): bold_reading = True @@ -1190,9 +1190,9 @@ def _person_options_report(self, options_confirm_params: str, custom_submit_text = get_config_param(base_dir, 'customSubmitText') conversation_id = None convthread_id = None - reply_is_chat = False + reply_is_chat: bool = False - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(chooser_nickname): bold_reading = True diff --git a/daemon_post_profile.py b/daemon_post_profile.py index 5c004a482..a4b1c77f8 100644 --- a/daemon_post_profile.py +++ b/daemon_post_profile.py @@ -156,7 +156,7 @@ def _profile_post_deactivate_account(base_dir: str, nickname: str, domain: str, fields: {}, self) -> bool: """ HTTP POST deactivate the account """ - deactivated = False + deactivated: bool = False if fields.get('deactivateThisAccount'): if fields['deactivateThisAccount'] == 'on': deactivate_account(base_dir, nickname, domain) @@ -639,7 +639,7 @@ def _profile_post_low_bandwidth(base_dir: str, path: str, is_artist(base_dir, nickname): curr_low_bandwidth = \ get_config_param(base_dir, 'lowBandwidth') - low_bandwidth = False + low_bandwidth: bool = False if fields.get('lowBandwidth'): if fields['lowBandwidth'] == 'on': low_bandwidth = True @@ -660,7 +660,7 @@ def _profile_post_dyslexic_font(base_dir: str, path: str, """ if path.startswith('/users/' + admin_nickname + '/') or \ is_artist(base_dir, nickname): - dyslexic_font2 = False + dyslexic_font2: bool = False if fields.get('dyslexicFont'): if fields['dyslexicFont'] == 'on': dyslexic_font2 = True @@ -681,7 +681,7 @@ def _profile_post_grayscale_theme(base_dir: str, path: str, """ if path.startswith('/users/' + admin_nickname + '/') or \ is_artist(base_dir, nickname): - grayscale = False + grayscale: bool = False if fields.get('grayscale'): if fields['grayscale'] == 'on': grayscale = True @@ -737,7 +737,7 @@ def _profile_post_notify_reactions(base_dir: str, notify_reactions_filename) actor_changed = True else: - notify_reactions_active = False + notify_reactions_active: bool = False if fields.get('notifyReactions'): if fields['notifyReactions'] == 'on' and \ not hide_reaction_button_active: @@ -771,7 +771,7 @@ def _profile_post_notify_likes(on_final_welcome_screen: bool, notify_likes_filename) actor_changed = True else: - notify_likes_active = False + notify_likes_active: bool = False if fields.get('notifyLikes'): if fields['notifyLikes'] == 'on' and \ not hide_like_button_active: @@ -793,7 +793,7 @@ def _profile_post_notify_likes(on_final_welcome_screen: bool, def _profile_post_block_military(nickname: str, fields: {}, self) -> None: """ HTTP POST block military instances """ - block_mil_instances = False + block_mil_instances: bool = False if fields.get('blockMilitary'): if fields['blockMilitary'] == 'on': block_mil_instances = True @@ -812,7 +812,7 @@ def _profile_post_block_military(nickname: str, fields: {}, self) -> None: def _profile_post_block_government(nickname: str, fields: {}, self) -> None: """ HTTP POST block government instances """ - block_gov_instances = False + block_gov_instances: bool = False if fields.get('blockGovernment'): if fields['blockGovernment'] == 'on': block_gov_instances = True @@ -831,7 +831,7 @@ def _profile_post_block_government(nickname: str, fields: {}, self) -> None: def _profile_post_block_bluesky(nickname: str, fields: {}, self) -> None: """ HTTP POST block bluesky bridges """ - block_bsky_instances = False + block_bsky_instances: bool = False if fields.get('blockBlueSky'): if fields['blockBlueSky'] == 'on': block_bsky_instances = True @@ -850,7 +850,7 @@ def _profile_post_block_bluesky(nickname: str, fields: {}, self) -> None: def _profile_post_block_nostr(nickname: str, fields: {}, self) -> None: """ HTTP POST block nostr bridges """ - block_nostr_instances = False + block_nostr_instances: bool = False if fields.get('blockNostr'): if fields['blockNostr'] == 'on': block_nostr_instances = True @@ -872,7 +872,7 @@ def _profile_post_no_reply_boosts(base_dir: str, nickname: str, domain: str, """ no_reply_boosts_filename = \ acct_dir(base_dir, nickname, domain) + '/.noReplyBoosts' - no_reply_boosts = False + no_reply_boosts: bool = False if fields.get('noReplyBoosts'): if fields['noReplyBoosts'] == 'on': no_reply_boosts = True @@ -897,7 +897,7 @@ def _profile_post_no_seen_posts(base_dir: str, nickname: str, domain: str, """ no_seen_posts_filename = \ acct_dir(base_dir, nickname, domain) + '/.noSeenPosts' - no_seen_posts = False + no_seen_posts: bool = False if fields.get('noSeenPosts'): if fields['noSeenPosts'] == 'on': no_seen_posts = True @@ -923,7 +923,7 @@ def _profile_post_watermark_enabled(base_dir: str, """ watermark_enabled_filename = \ acct_dir(base_dir, nickname, domain) + '/.watermarkEnabled' - watermark_enabled = False + watermark_enabled: bool = False if fields.get('watermarkEnabled'): if fields['watermarkEnabled'] == 'on': watermark_enabled = True @@ -1017,7 +1017,7 @@ def _profile_post_hide_recent_posts(base_dir: str, nickname: str, domain: str, def _profile_post_mutuals_replies(account_dir: str, fields: {}) -> None: """ HTTP POST show replies only from mutuals checkbox """ - show_replies_mutuals = False + show_replies_mutuals: bool = False if fields.get('repliesFromMutualsOnly'): if fields['repliesFromMutualsOnly'] == 'on': show_replies_mutuals = True @@ -1040,7 +1040,7 @@ def _profile_post_only_follower_replies(fields: {}, account_dir: str) -> None: """ HTTP POST show replies only from followers checkbox """ - show_replies_followers = False + show_replies_followers: bool = False if fields.get('repliesFromFollowersOnly'): if fields['repliesFromFollowersOnly'] == 'on': show_replies_followers = True @@ -1064,7 +1064,7 @@ def _profile_post_only_follower_replies(fields: {}, def _profile_post_show_quote_toots(fields: {}, account_dir: str) -> None: """ HTTP POST show quote toots checkbox on edit profile """ - show_quote_toots = False + show_quote_toots: bool = False if fields.get('showQuotes'): if fields['showQuotes'] == 'on': show_quote_toots = True @@ -1086,7 +1086,7 @@ def _profile_post_show_quote_toots(fields: {}, account_dir: str) -> None: def _profile_post_show_questions(fields: {}, account_dir: str) -> None: """ HTTP POST show poll/vote/question posts checkbox """ - show_vote_posts = False + show_vote_posts: bool = False if fields.get('showVotes'): if fields['showVotes'] == 'on': show_vote_posts = True @@ -1109,7 +1109,7 @@ def _profile_post_reverse_timelines(base_dir: str, nickname: str, fields: {}, self) -> None: """ HTTP POST reverse timelines checkbox """ - reverse = False + reverse: bool = False if fields.get('reverseTimelines'): if fields['reverseTimelines'] == 'on': reverse = True @@ -1131,7 +1131,7 @@ def _profile_post_bold_reading(base_dir: str, """ bold_reading_filename = \ acct_dir(base_dir, nickname, domain) + '/.boldReading' - bold_reading = False + bold_reading: bool = False if fields.get('boldReading'): if fields['boldReading'] == 'on': bold_reading = True @@ -1159,7 +1159,7 @@ def _profile_post_hide_reaction_button2(base_dir: str, acct_dir(base_dir, nickname, domain) + '/.hideReactionButton' notify_reactions_filename = \ acct_dir(base_dir, nickname, domain) + '/.notifyReactions' - hide_reaction_button_active = False + hide_reaction_button_active: bool = False if fields.get('hideReactionButton'): if fields['hideReactionButton'] == 'on': hide_reaction_button_active = True @@ -1187,7 +1187,7 @@ def _profile_post_minimize_images(base_dir: str, nickname: str, domain: str, min_images_for_accounts: []) -> None: """ HTTP POST Minimize all images from edit profile screen """ - minimize_all_images = False + minimize_all_images: bool = False if fields.get('minimizeAllImages'): if fields['minimizeAllImages'] == 'on': minimize_all_images = True @@ -1214,7 +1214,7 @@ def _profile_post_hide_like_button2(base_dir: str, nickname: str, domain: str, acct_dir(base_dir, nickname, domain) + '/.hideLikeButton' notify_likes_filename = \ acct_dir(base_dir, nickname, domain) + '/.notifyLikes' - hide_like_button_active = False + hide_like_button_active: bool = False if fields.get('hideLikeButton'): if fields['hideLikeButton'] == 'on': hide_like_button_active = True @@ -1243,7 +1243,7 @@ def _profile_post_remove_retweets(base_dir: str, nickname: str, domain: str, """ remove_twitter_filename = \ acct_dir(base_dir, nickname, domain) + '/.removeTwitter' - remove_twitter_active = False + remove_twitter_active: bool = False if fields.get('removeTwitter'): if fields['removeTwitter'] == 'on': remove_twitter_active = True @@ -1274,7 +1274,7 @@ def _profile_post_dms_from_followers(base_dir: str, nickname: str, domain: str, follow_dms_filename) actor_changed = True else: - follow_dms_active = False + follow_dms_active: bool = False if fields.get('followDMs'): if fields['followDMs'] == 'on': follow_dms_active = True @@ -1347,7 +1347,7 @@ def _profile_post_keep_dms(base_dir: str, actor_changed: bool) -> bool: """ HTTP POST keep DMs during post expiry """ - expire_keep_dms = False + expire_keep_dms: bool = False if fields.get('expiryKeepDMs'): if fields['expiryKeepDMs'] == 'on': expire_keep_dms = True @@ -1364,11 +1364,11 @@ def _profile_post_reject_spam_actors(base_dir: str, fields: {}) -> None: """ HTTP POST reject spam actors """ - reject_spam_actors = False + reject_spam_actors: bool = False if fields.get('rejectSpamActors'): if fields['rejectSpamActors'] == 'on': reject_spam_actors = True - curr_reject_spam_actors = False + curr_reject_spam_actors: bool = False actor_spam_filter_filename = \ acct_dir(base_dir, nickname, domain) + '/.reject_spam_actors' if os.path.isfile(actor_spam_filter_filename): @@ -1402,7 +1402,7 @@ def _profile_post_approve_followers(on_final_welcome_screen: bool, if fields['approveFollowers'] == 'on': approve_followers = True - premium_activated = False + premium_activated: bool = False if fields.get('premiumAccount'): if fields['premiumAccount'] == 'on': # turn on premium flag @@ -1464,7 +1464,7 @@ def _profile_post_broch_mode(base_dir: str, domain_full: str, fields: {}) -> None: """ HTTP POST broch mode """ - broch_mode = False + broch_mode: bool = False if fields.get('brochMode'): if fields['brochMode'] == 'on': broch_mode = True @@ -1479,7 +1479,7 @@ def _profile_post_verify_all_signatures(base_dir: str, fields: {}, self) -> None: """ HTTP POST verify all signatures """ - verify_all_signatures = False + verify_all_signatures: bool = False if fields.get('verifyallsignatures'): if fields['verifyallsignatures'] == 'on': verify_all_signatures = True @@ -1492,7 +1492,7 @@ def _profile_post_show_nodeinfo_version(base_dir: str, fields: {}, self) -> None: """ HTTP POST show nodeinfo version """ - show_node_info_version = False + show_node_info_version: bool = False if fields.get('showNodeInfoVersion'): if fields['showNodeInfoVersion'] == 'on': show_node_info_version = True @@ -1505,7 +1505,7 @@ def _profile_post_show_nodeinfo_version(base_dir: str, fields: {}, def _profile_post_show_nodeinfo(base_dir: str, fields: {}, self) -> None: """ HTTP POST Show number of accounts within nodeinfo """ - show_node_info_accounts = False + show_node_info_accounts: bool = False if fields.get('showNodeInfoAccounts'): if fields['showNodeInfoAccounts'] == 'on': show_node_info_accounts = True @@ -2311,7 +2311,7 @@ def _profile_post_libretranslate_url(base_dir: str, fields: {}) -> None: def _profile_post_replies_unlisted(base_dir: str, fields: {}, self) -> None: """ HTTP POST change public replies unlisted """ - pub_replies_unlisted = False + pub_replies_unlisted: bool = False if self.server.public_replies_unlisted or \ get_config_param(base_dir, "publicRepliesUnlisted") is True: pub_replies_unlisted = True @@ -2333,7 +2333,7 @@ def _profile_post_replies_unlisted(base_dir: str, fields: {}, self) -> None: def _profile_post_registrations_open(base_dir: str, fields: {}, self) -> None: """ HTTP POST change registrations open status """ - registrations_open = False + registrations_open: bool = False if self.server.registration or \ get_config_param(base_dir, "registration") == 'open': registrations_open = True @@ -2758,8 +2758,8 @@ def profile_edit(self, calling_domain: str, cookie: str, if boundary: # get the various avatar, banner and background images - actor_changed = True - send_move_activity = False + actor_changed: bool = True + send_move_activity: bool = False profile_media_types = ( 'avatar', 'image', 'banner', 'search_banner', @@ -2884,8 +2884,8 @@ def profile_edit(self, calling_domain: str, cookie: str, post_bytes_str = post_bytes.decode('utf-8') redirect_path: str = '' - check_name_and_bio = False - on_final_welcome_screen = False + check_name_and_bio: bool = False + on_final_welcome_screen: bool = False if 'name="previewAvatar"' in post_bytes_str: redirect_path = '/welcome_profile' elif 'name="initialWelcomeScreen"' in post_bytes_str: @@ -3297,11 +3297,11 @@ def profile_edit(self, calling_domain: str, cookie: str, notify_likes_filename = \ acct_dir(base_dir, nickname, domain) + '/.notifyLikes' - hide_reaction_button_active = False + hide_reaction_button_active: bool = False if fields.get('hideReactionButton'): if fields['hideReactionButton'] == 'on': hide_reaction_button_active = True - hide_like_button_active = False + hide_like_button_active: bool = False if fields.get('hideLikeButton'): if fields['hideLikeButton'] == 'on': hide_like_button_active = True diff --git a/daemon_post_question.py b/daemon_post_question.py index 34ce3a8d6..87a88309d 100644 --- a/daemon_post_question.py +++ b/daemon_post_question.py @@ -221,7 +221,7 @@ def _send_reply_to_question(self, base_dir: str, in_reply_to = message_id in_reply_to_atom_uri = message_id subject = None - schedule_post = False + schedule_post: bool = False event_date = None event_time = None event_end_time = None diff --git a/daemon_post_receive.py b/daemon_post_receive.py index c7ed49156..1269f3fd5 100644 --- a/daemon_post_receive.py +++ b/daemon_post_receive.py @@ -123,9 +123,9 @@ def _receive_new_post_process_newpost(self, fields: {}, is then sent to the outbox """ if not fields.get('pinToProfile'): - pin_to_profile = False + pin_to_profile: bool = False else: - pin_to_profile = True + pin_to_profile: bool = True # is the post message empty? if not fields['message']: # remove the pinned content from profile screen @@ -318,8 +318,8 @@ def _receive_new_post_process_newblog(self, fields: {}, print('WARN: blog posts must have content') return NEW_POST_FAILED # submit button on newblog screen - save_to_file = False - client_to_server = False + save_to_file: bool = False + client_to_server: bool = False city = None conversation_id = None if fields.get('conversationId'): @@ -570,8 +570,8 @@ def _receive_new_post_process_newunlisted(self, fields: {}, and is then sent to the outbox """ city = get_spoofed_city(city, base_dir, nickname, domain) - save_to_file = False - client_to_server = False + save_to_file: bool = False + client_to_server: bool = False conversation_id = None if fields.get('conversationId'): @@ -742,8 +742,8 @@ def _receive_new_post_process_newfollowers(self, fields: {}, and is then sent to the outbox """ city = get_spoofed_city(city, base_dir, nickname, domain) - save_to_file = False - client_to_server = False + save_to_file: bool = False + client_to_server: bool = False conversation_id = None if fields.get('conversationId'): @@ -928,8 +928,8 @@ def _receive_new_post_process_newdm(self, fields: {}, print('A DM was posted') if '@' in mentions_str: city = get_spoofed_city(city, base_dir, nickname, domain) - save_to_file = False - client_to_server = False + save_to_file: bool = False + client_to_server: bool = False conversation_id = None if fields.get('conversationId'): @@ -944,7 +944,7 @@ def _receive_new_post_process_newdm(self, fields: {}, nickname, domain_full, person_cache) - reply_is_chat = False + reply_is_chat: bool = False if fields.get('replychatmsg'): reply_is_chat = fields['replychatmsg'] @@ -1120,9 +1120,9 @@ def _receive_new_post_process_newreminder(self, fields: {}, nickname: str, if '@' + handle not in mentions_str: mentions_str = '@' + handle + ' ' + mentions_str city = get_spoofed_city(city, base_dir, nickname, domain) - save_to_file = False - client_to_server = False - comments_enabled = False + save_to_file: bool = False + client_to_server: bool = False + comments_enabled: bool = False conversation_id = None convthread_id = None mentions_message = mentions_str + fields['message'] @@ -1472,7 +1472,7 @@ def _receive_new_post_process_newreading(self, fields: {}, if not fields.get('bookurl'): print(post_type + ' no bookurl') return NEW_POST_FAILED - book_rating = 0.0 + book_rating: float = 0.0 if fields.get('bookrating'): if isinstance(fields['bookrating'], (float, int)): book_rating = fields['bookrating'] @@ -1587,9 +1587,9 @@ def _receive_new_post_process_newreading(self, fields: {}, if fields['schedulePost']: return NEW_POST_SUCCESS if not fields.get('pinToProfile'): - pin_to_profile = False + pin_to_profile: bool = False else: - pin_to_profile = True + pin_to_profile: bool = True if pin_to_profile: sys_language = system_language content_str = \ @@ -1678,7 +1678,7 @@ def _receive_new_post_process_newshare(self, fields: {}, else: print('Adding wanted item') shares_file_type = 'wanted' - share_on_profile = False + share_on_profile: bool = False if fields.get('shareOnProfile'): if fields['shareOnProfile'] == 'on': share_on_profile = True @@ -1931,7 +1931,7 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, print('WARN: no text fields could be extracted from POST') # was the citations button pressed on the newblog screen? - citations_button_press = False + citations_button_press: bool = False if post_type == 'newblog' and fields.get('submitCitations'): if fields['submitCitations'] == translate['Citations']: citations_button_press = True @@ -2038,9 +2038,9 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, if fields.get('mentions'): mentions_str = fields['mentions'].strip() + ' ' if not fields.get('commentsEnabled'): - comments_enabled = False + comments_enabled: bool = False else: - comments_enabled = True + comments_enabled: bool = True buy_url: str = '' if fields.get('buyUrl'): @@ -2503,7 +2503,7 @@ def receive_new_post(self, post_type, path: str, if self.server.new_post_thread.get(new_post_thread_name): print('Waiting for previous new post thread to end') - wait_ctr = 0 + wait_ctr: int = 0 np_thread = self.server.new_post_thread[new_post_thread_name] while np_thread.is_alive() and wait_ctr < 8: time.sleep(1) diff --git a/daemon_post_search.py b/daemon_post_search.py index 1c027f2fa..54ee5534f 100644 --- a/daemon_post_search.py +++ b/daemon_post_search.py @@ -105,7 +105,7 @@ def _receive_search_hashtag(self, actor_str: str, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True hashtag_str = \ @@ -260,7 +260,7 @@ def _receive_search_my_posts(self, search_str: str, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True history_str = \ @@ -379,7 +379,7 @@ def _receive_search_bookmarks(self, search_str: str, timezone = None if account_timezone.get(nickname): timezone = account_timezone.get(nickname) - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True bookmarks_str = \ @@ -473,7 +473,7 @@ def _receive_search_handle(self, search_str: str, instance_software: {}) -> bool: """Receive a search for a fediverse handle or url from the search screen """ - remote_only = False + remote_only: bool = False if search_str.endswith(';remote'): search_str = search_str.replace(';remote', '') remote_only = True @@ -596,7 +596,7 @@ def _receive_search_handle(self, search_str: str, self.server.postreq_busy = False return True - bold_reading = False + bold_reading: bool = False if bold_reading_nicknames.get(nickname): bold_reading = True diff --git a/daemon_utils.py b/daemon_utils.py index 36de080d6..f802f29d5 100644 --- a/daemon_utils.py +++ b/daemon_utils.py @@ -185,7 +185,8 @@ def _get_outbox_thread_index(self, nickname: str, return 0 # increment the ring buffer index - index = self.server.outbox_thread_index[account_outbox_thread_name] + 1 + index: int = \ + self.server.outbox_thread_index[account_outbox_thread_name] + 1 if index >= max_outbox_threads_per_account: index = 0 @@ -684,7 +685,7 @@ def show_person_options(self, calling_domain: str, path: str, options_link = None if len(options_list) > 3: options_link = options_list[3] - is_group = False + is_group: bool = False donate_url = None website_url = None gemini_link = None @@ -708,7 +709,7 @@ def show_person_options(self, calling_domain: str, path: str, ssb_address = None email_address = None deltachat_invite = None - locked_account = False + locked_account: bool = False also_known_as = None moved_to: str = '' repo_url = None diff --git a/desktop_client.py b/desktop_client.py index 6053b11bf..e91d56e30 100644 --- a/desktop_client.py +++ b/desktop_client.py @@ -229,7 +229,7 @@ def _has_read_post(actor: str, post_id: str, post_category: str) -> bool: def _post_is_to_you(actor: str, post_json_object: {}) -> bool: """Returns true if the post is to the actor """ - to_your_actor = False + to_your_actor: bool = False if post_json_object.get('to'): if isinstance(post_json_object['to'], list): if actor in post_json_object['to']: @@ -272,8 +272,8 @@ def _new_desktop_notifications(actor: str, inbox_json: {}, return if not inbox_json.get('orderedItems'): return - dm_done = False - reply_done = False + dm_done: bool = False + reply_done: bool = False for post_json_object in inbox_json['orderedItems']: if not post_json_object.get('id'): continue @@ -286,7 +286,7 @@ def _new_desktop_notifications(actor: str, inbox_json: {}, if is_dm(post_json_object): if not dm_done: if not _has_read_post(actor, post_json_object['id'], 'dm'): - changed = False + changed: bool = False if not notify_json.get('dmPostId'): changed = True else: @@ -301,7 +301,7 @@ def _new_desktop_notifications(actor: str, inbox_json: {}, if not reply_done: if not _has_read_post(actor, post_json_object['id'], 'replies'): - changed = False + changed: bool = False if not notify_json.get('repliesPostId'): changed = True else: @@ -560,7 +560,7 @@ def _desktop_reply_to_post(session, post_id: str, attach = None media_type = None attached_image_description = None - is_article = False + is_article: bool = False subject = None comments_enabled = True city = 'London, England' @@ -649,7 +649,7 @@ def _desktop_new_post(session, media_type = None attached_image_description = None city = 'London, England' - is_article = False + is_article: bool = False subject = None comments_enabled = True subject = None @@ -698,7 +698,7 @@ def _safe_message(content: str) -> str: def _timeline_is_empty(box_json: {}) -> bool: """Returns true if the given timeline is empty """ - empty = False + empty: bool = False if not box_json: empty = True else: @@ -776,7 +776,7 @@ def _show_likes_on_post(post_json_object: {}, max_likes: int) -> None: if not isinstance(object_likes['items'], list): return print('') - ctr = 0 + ctr: int = 0 for item in object_likes['items']: print(' ❤ ' + str(item['actor'])) ctr += 1 @@ -799,7 +799,7 @@ def _show_replies_on_post(post_json_object: {}, max_replies: int) -> None: if not isinstance(object_replies['items'], list): return print('') - ctr = 0 + ctr: int = 0 for item in object_replies['items']: url_str = get_url_from_post(item['url']) item_url = remove_html(url_str) @@ -846,10 +846,10 @@ def _read_local_box_post(session, nickname: str, domain: str, if not name_str: return {} recent_posts_cache = {} - allow_local_network_access = False + allow_local_network_access: bool = False yt_replace_domain = None twitter_replacement_domain = None - show_vote_posts = False + show_vote_posts: bool = False languages_understood: list[str] = [] person_url = local_actor_url(http_prefix, nickname, domain_full) actor_json = \ @@ -1015,7 +1015,7 @@ def _desktop_show_actor(http_prefix: str, _say_command(say_str, say_str, screenreader, system_language, espeak) if actor_json.get('alsoKnownAs'): also_known_as_str: str = '' - ctr = 0 + ctr: int = 0 for alt_actor in actor_json['alsoKnownAs']: if ctr > 0: also_known_as_str += ', ' @@ -1069,12 +1069,12 @@ def _desktop_show_profile(session, nickname: str, if not actor: return {} - is_http = False + is_http: bool = False if 'http://' in actor: is_http = True - is_gnunet = False - is_ipfs = False - is_ipns = False + is_gnunet: bool = False + is_ipfs: bool = False + is_ipns: bool = False actor_json, _ = \ get_actor_json(domain, actor, is_http, is_gnunet, is_ipfs, is_ipns, False, True, signing_priv_key_pem, session, @@ -1114,7 +1114,7 @@ def _desktop_show_profile_from_handle(session, nickname: str, domain: str, def _desktop_get_box_post_object(box_json: {}, index: int) -> {}: """Gets the post with the given index from the timeline """ - ctr = 0 + ctr: int = 0 for post_json_object in box_json['orderedItems']: if not post_json_object.get('type'): continue @@ -1268,7 +1268,7 @@ def _desktop_show_box(indent: str, continue # append icons to the end of the name - space_added = False + space_added: bool = False reply_id = get_reply_to(post_json_object['object']) if reply_id: if not space_added: @@ -1452,8 +1452,8 @@ def _desktop_new_dm_base(session, to_handle: str, attach = None media_type = None attached_image_description = None - city = 'London, England' - is_article = False + city: str = 'London, England' + is_article: bool = False subject = None comments_enabled = True subject = None @@ -1604,7 +1604,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, """Runs the desktop and screen reader client, which announces new inbox items """ - bold_reading = False + bold_reading: bool = False # TODO: this should probably be retrieved somehow from the server signing_priv_key_pem = None @@ -1655,10 +1655,10 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, original_screen_reader = screenreader sounds_dir = 'theme/default/sounds/' # prev_say: str = '' - # prev_calendar = False - # prev_follow = False + # prev_calendar: bool = False + # prev_follow: bool = False # prev_like: str = '' - # prev_share = False + # prev_share: bool = False dm_sound_filename = sounds_dir + 'dm.ogg' reply_sound_filename = sounds_dir + 'reply.ogg' # calendar_sound_filename = sounds_dir + 'calendar.ogg' @@ -1672,7 +1672,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, content = None cached_webfingers = {} person_cache = {} - pgp_key_upload = False + pgp_key_upload: bool = False say_str = indent + 'Loading translations file' _say_command(say_str, say_str, screenreader, @@ -1702,7 +1702,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, "repliesNotifyChanged": False } prev_timeline_first_id: str = '' - desktop_shown = False + desktop_shown: bool = False while (1): if not pgp_key_upload: if not has_local_pg_pkey(): @@ -1796,7 +1796,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, else: command_str = _desktop_wait_for_cmd(30, debug) if command_str: - refresh_timeline = False + refresh_timeline: bool = False if command_str.startswith('/'): command_str = command_str[1:] @@ -2103,7 +2103,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, refresh_timeline = True print('') elif command_str == 'like' or command_str.startswith('like '): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2151,7 +2151,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, 'remove ignore ', 'unignore ', 'unmute '))): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2189,7 +2189,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, elif (command_str in ('mute', 'ignore') or string_starts_with(command_str, ('mute ', 'ignore '))): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2240,7 +2240,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, 'remove bookmark ', 'unbookmark ', 'unbm '))): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2279,7 +2279,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, elif (command_str in ('bookmark', 'bm') or string_starts_with(command_str, ('bookmark ', 'bm '))): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2318,7 +2318,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, 'remove block ', 'rm block ', 'unblock ')): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2363,7 +2363,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, print('') elif command_str.startswith('block '): block_actor = None - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2415,7 +2415,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, refresh_timeline = True print('') elif command_str in ('unlike', 'undo like'): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2454,7 +2454,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, print('') elif string_starts_with(command_str, ('announce', 'boost', 'retweet')): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2510,7 +2510,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, 'unboost', 'undo boost', 'undo retweet')): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2778,14 +2778,14 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, say_str = 'Notification sounds on' _say_command(say_str, say_str, screenreader, system_language, espeak) - notification_sounds = True + notification_sounds: bool = True elif command_str in ('sounds off', 'sound off', 'nosound'): say_str = 'Notification sounds off' _say_command(say_str, say_str, screenreader, system_language, espeak) - notification_sounds = False + notification_sounds: bool = False elif command_str in ('speak', 'screen reader on', 'speak on', @@ -2813,7 +2813,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, else: print('No --screenreader option was specified') elif command_str.startswith('open'): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: @@ -2826,10 +2826,10 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, if post_json_object: if post_json_object['type'] == 'Announce': recent_posts_cache = {} - allow_local_network_access = False + allow_local_network_access: bool = False yt_replace_domain = None twitter_replacement_domain = None - show_vote_posts = False + show_vote_posts: bool = False block_military = {} block_government = {} block_bluesky = {} @@ -2867,7 +2867,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, speakable_text(http_prefix, nickname, domain, domain_full, base_dir, content, translate) - link_opened = False + link_opened: bool = False for url in detected_links: if '://' in url: webbrowser.open(url) @@ -2898,7 +2898,7 @@ def run_desktop_client(base_dir: str, proxy_type: str, http_prefix: str, refresh_timeline = True elif (command_str in ('delete', 'rm') or string_starts_with(command_str, ('delete ', 'rm '))): - curr_index = 0 + curr_index: int = 0 if ' ' in command_str: post_index = command_str.split(' ')[-1].strip() if len(post_index) > 5: diff --git a/donate.py b/donate.py index 25861f241..fee825fc7 100644 --- a/donate.py +++ b/donate.py @@ -44,7 +44,7 @@ def get_donation_url(actor_json: {}) -> str: if not name_value: continue name_value_lower = name_value.lower() - found = False + found: bool = False for donation_type_str in donation_type_list: if donation_type_str in name_value_lower: found = True @@ -81,7 +81,7 @@ def get_donation_url(actor_json: {}) -> str: def set_donation_url(actor_json: {}, donate_url: str) -> None: """Sets a link used for donations """ - not_url = False + not_url: bool = False if '.' not in donate_url: not_url = True if '://' not in donate_url: diff --git a/enigma.py b/enigma.py index b40a3ca83..c9d6da13c 100644 --- a/enigma.py +++ b/enigma.py @@ -47,7 +47,7 @@ def get_enigma_pub_key(actor_json: {}) -> str: def set_enigma_pub_key(actor_json: {}, enigma_pub_key: str) -> None: """Sets a Enigma public key for the given actor """ - remove_key = False + remove_key: bool = False if not enigma_pub_key: remove_key = True diff --git a/epicyon.py b/epicyon.py index e8c9543c4..33f93d5b3 100644 --- a/epicyon.py +++ b/epicyon.py @@ -903,7 +903,7 @@ def _command_options() -> None: print(poisoned_str) sys.exit() - debug = False + debug: bool = False if argb.debug: debug = True else: @@ -1012,7 +1012,7 @@ def _command_options() -> None: print('origin_domain: ' + str(origin_domain)) if argb.posts.startswith('@'): argb.posts = argb.posts[1:] - url_with_at = False + url_with_at: bool = False if '://' in argb.posts and '/@' in argb.posts and \ '/@/' not in argb.posts: url_with_at = True @@ -1257,7 +1257,7 @@ def _command_options() -> None: argb.port = 80 elif argb.gnunet: proxy_type = 'gnunet' - max_blocked_domains = 0 + max_blocked_domains: int = 0 if not argb.language: argb.language = 'en' signing_priv_key_pem = None @@ -1312,7 +1312,7 @@ def _command_options() -> None: print('origin_domain: ' + str(origin_domain)) if argb.postsraw.startswith('@'): argb.postsraw = argb.postsraw[1:] - url_with_at = False + url_with_at: bool = False if '://' in argb.postsraw and '/@' in argb.postsraw and \ '/@/' not in argb.postsraw: url_with_at = True @@ -1391,8 +1391,8 @@ def _command_options() -> None: sys.exit() if argb.instance_software: - debug = False - http_prefix = 'https' + debug: bool = False + http_prefix: str = 'https' if '127.0.0.1' in argb.instance_software or \ 'localhost' in argb.instance_software: http_prefix = 'http' @@ -1974,7 +1974,7 @@ def _command_options() -> None: accounts_dir = acct_dir(base_dir, argb.nickname, domain) approve_follows_filename = accounts_dir + '/followrequests.txt' - approve_ctr = 0 + approve_ctr: int = 0 if os.path.isfile(approve_follows_filename): try: with open(approve_follows_filename, 'r', @@ -2061,7 +2061,7 @@ def _command_options() -> None: if attach: media_type = get_attachment_media_type(attach) reply_to = argb.replyto - is_article = False + is_article: bool = False if not domain: domain = get_config_param(base_dir, 'domain') signing_priv_key_pem = None @@ -3946,7 +3946,7 @@ def _command_options() -> None: delete_all_posts(base_dir, nickname, domain, 'outbox') test_save_to_file = True - test_c2s = False + test_c2s: bool = False test_comments_enabled = True test_attach_image_filename = None test_media_type = None @@ -3955,16 +3955,16 @@ def _command_options() -> None: test_in_reply_to = None test_in_reply_to_atom_uri = None test_subject = None - test_schedule_post = False + test_schedule_post: bool = False test_event_date = None test_event_time = None test_event_end_time = None test_event_category: str = '' test_location = None - test_is_article = False + test_is_article: bool = False conversation_id = None convthread_id = None - low_bandwidth = False + low_bandwidth: bool = False languages_understood = [argb.language] translate = {} buy_url: str = '' @@ -4149,7 +4149,7 @@ def _command_options() -> None: registration = get_config_param(base_dir, 'registration') if not registration: - registration = False + registration: bool = False map_format = get_config_param(base_dir, 'mapFormat') if map_format: diff --git a/fitnessFunctions.py b/fitnessFunctions.py index 74343ee7c..bfd6db638 100644 --- a/fitnessFunctions.py +++ b/fitnessFunctions.py @@ -104,7 +104,7 @@ def html_watch_points_graph(base_dir: str, fitness: {}, fitness_id: str, if average_time > max_average_time: max_average_time = average_time - ctr = 0 + ctr: int = 0 for watch_point in watch_points_list: name = watch_point.split(' ', 1)[1] average_time = float(watch_point.split(' ')[0]) diff --git a/flags.py b/flags.py index f0ab515e5..8a9ba74f0 100644 --- a/flags.py +++ b/flags.py @@ -315,7 +315,7 @@ def is_unlisted_post(post_json_object: {}) -> bool: return False if not post_json_object['object'].get('cc'): return False - has_followers = False + has_followers: bool = False if isinstance(post_json_object['object']['to'], list): for recipient in post_json_object['object']['to']: if recipient.endswith('/followers'): @@ -583,7 +583,7 @@ def is_valid_date(date_str: str) -> bool: date_sections = date_str.split('-') if len(date_sections) != 3: return False - date_sect_ctr = 0 + date_sect_ctr: int = 0 for section_str in date_sections: if not section_str.isdigit(): return False diff --git a/follow.py b/follow.py index 85892bfb0..b1e7f9483 100644 --- a/follow.py +++ b/follow.py @@ -130,7 +130,7 @@ def _remove_from_follow_base(base_dir: str, # for each possible users path construct an actor and # check if it exists in the file users_paths = get_user_paths() - actor_found = False + actor_found: bool = False for users_name in users_paths: accept_deny_actor = \ '://' + accept_deny_domain + users_name + accept_deny_nickname @@ -275,7 +275,7 @@ def is_follower_of_person(base_dir: str, nickname: str, domain: str, return False handle = follower_nickname + '@' + follower_domain - already_following = False + already_following: bool = False followers_str = load_string(followers_file, 'EX: is_follower_of_person ' + @@ -411,7 +411,7 @@ def _get_no_of_follows(base_dir: str, nickname: str, domain: str, filename = accounts_dir + '/' + follow_file if not os.path.isfile(filename): return 0 - ctr = 0 + ctr: int = 0 lines: list[str] = \ load_list(filename, 'EX: _get_no_of_follows ' + filename) @@ -468,7 +468,7 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str, print('EX: get_following_feed unable to convert to int ' + str(page_number)) path = path.split('?page=')[0] - header_only = False + header_only: bool = False if not path.endswith('/' + follow_file): return None @@ -531,9 +531,9 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str, filename = accounts_dir + '/' + follow_file + '.txt' if not os.path.isfile(filename): return following - curr_page = 1 - page_ctr = 0 - total_ctr = 0 + curr_page: int = 1 + page_ctr: int = 0 + total_ctr: int = 0 lines: list[str] = \ load_list(filename, 'EX: get_following_feed ' + filename) @@ -569,7 +569,7 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str, append_str = remove_eol(append_str1) following['orderedItems'].append(append_str) if page_ctr >= follows_per_page: - page_ctr = 0 + page_ctr: int = 0 curr_page += 1 following['totalItems'] = total_ctr last_page = int(total_ctr / follows_per_page) @@ -591,7 +591,7 @@ def follow_approval_required(base_dir: str, nickname_to_follow: str, follow_request_handle): return False - manually_approve_follows = False + manually_approve_follows: bool = False domain_to_follow = remove_domain_port(domain_to_follow) actor_filename = data_dir(base_dir) + '/' + \ nickname_to_follow + '@' + domain_to_follow + '.json' @@ -619,7 +619,7 @@ def no_of_follow_requests(base_dir: str, approve_follows_filename = accounts_dir + '/followrequests.txt' if not os.path.isfile(approve_follows_filename): return 0 - ctr = 0 + ctr: int = 0 lines: list[str] = \ load_list(approve_follows_filename, 'EX: no_of_follow_requests ' + @@ -772,7 +772,7 @@ def followed_account_accepts(session, base_dir: str, http_prefix: str, nickname_to_follow + '@' + domain_to_follow + ' port ' + str(port) + ' to ' + accept_handle + ' port ' + str(from_port)) - client_to_server = False + client_to_server: bool = False if remove_follow_activity: # remove the follow request json @@ -787,7 +787,7 @@ def followed_account_accepts(session, base_dir: str, http_prefix: str, 'followed_account_accepts unable to delete ' + follow_activity_filename) - group_account = False + group_account: bool = False if follow_json: if follow_json.get('actor'): actor_url = get_actor_from_post(follow_json) @@ -863,9 +863,9 @@ def followed_account_rejects(session, session_onion, session_i2p, nickname_to_follow + '@' + domain_to_follow + ' port ' + str(port) + ' to ' + nickname + '@' + domain + ' port ' + str(from_port)) - client_to_server = False + client_to_server: bool = False deny_handle = get_full_domain(nickname + '@' + domain, from_port) - group_account = False + group_account: bool = False if has_group_type(base_dir, person_url, person_cache): group_account = True # remove from the follow requests file @@ -938,7 +938,7 @@ def send_follow_request(session, base_dir: str, status_number, _ = get_status_number() - group_account = False + group_account: bool = False if follow_nickname: followed_id = followed_actor follow_handle = follow_nickname + '@' + request_domain @@ -1527,7 +1527,7 @@ def follower_approval_active(base_dir: str, nickname: str, domain: str) -> bool: """Returns true if the given account requires follower approval """ - manually_approves_followers = False + manually_approves_followers: bool = False actor_filename = acct_dir(base_dir, nickname, domain) + '.json' if os.path.isfile(actor_filename): actor_json = load_json(actor_filename) @@ -1558,7 +1558,7 @@ def remove_follower(base_dir: str, handle = remove_nickname + '@' + remove_domain handle = handle.lower() new_followers_str: str = '' - found = False + found: bool = False for handle2 in followers_list: if not handle2: continue diff --git a/followerSync.py b/followerSync.py index 32324c784..31dd0fcd8 100644 --- a/followerSync.py +++ b/followerSync.py @@ -54,7 +54,7 @@ def _get_followers_for_domain(base_dir: str, if line_str.endswith('@' + search_domain): nick = line_str.split('@')[0] paths_list = get_user_paths() - found = False + found: bool = False for prefix in ('https', 'http'): if found: break diff --git a/gemini.py b/gemini.py index bdce3270e..12dbb03aa 100644 --- a/gemini.py +++ b/gemini.py @@ -60,7 +60,7 @@ def blog_to_gemini(base_dir: str, nickname: str, domain: str, links: list[str] = [] if '://' in content_text: sections = content_text.split('://') - ctr = 0 + ctr: int = 0 prev_section: str = '' for section in sections: if ctr > 0: diff --git a/git.py b/git.py index bfe335c15..140258c3f 100644 --- a/git.py +++ b/git.py @@ -102,9 +102,9 @@ def _get_git_hash(patch_str: str) -> str: def _get_patch_description(patch_str: str) -> str: """Returns the description from a given patch """ - patch_lines = patch_str.split('\n') + patch_lines: list = patch_str.split('\n') description: str = '' - started = False + started: bool = False for line in patch_lines: if started: if line.strip() == '---': diff --git a/happening.py b/happening.py index 3c1c818c3..18d1000f9 100644 --- a/happening.py +++ b/happening.py @@ -297,7 +297,7 @@ def get_todays_events(base_dir: str, nickname: str, domain: str, return events calendar_post_ids: list[str] = [] - recreate_events_file = False + recreate_events_file: bool = False try: with open(calendar_filename, 'r', encoding='utf-8') as fp_events: for post_id in fp_events: @@ -428,7 +428,7 @@ def _icalendar_day(base_dir: str, nickname: str, domain: str, post_id = None sender_name: str = '' sender_actor = None - event_is_public = False + event_is_public: bool = False event_start = None event_end = None @@ -583,7 +583,7 @@ def get_month_events_icalendar(base_dir: str, nickname: str, domain: str, text_match: str) -> str: """Returns today's events in icalendar format """ - only_show_reminders = False + only_show_reminders: bool = False month_events = \ get_calendar_events(base_dir, nickname, domain, year, month_number, text_match, @@ -624,7 +624,7 @@ def day_events_check(base_dir: str, nickname: str, domain: str, if not os.path.isfile(calendar_filename): return False - events_exist = False + events_exist: bool = False try: with open(calendar_filename, 'r', encoding='utf-8') as fp_events: for post_id in fp_events: @@ -684,7 +684,7 @@ def get_this_weeks_events(base_dir: str, nickname: str, domain: str) -> {}: return events calendar_post_ids: list[str] = [] - recreate_events_file = False + recreate_events_file: bool = False try: with open(calendar_filename, 'r', encoding='utf-8') as fp_events: for post_id in fp_events: @@ -761,7 +761,7 @@ def get_calendar_events(base_dir: str, nickname: str, domain: str, return events calendar_post_ids: list[str] = [] - recreate_events_file = False + recreate_events_file: bool = False try: with open(calendar_filename, 'r', encoding='utf-8') as fp_events: for post_id in fp_events: @@ -1134,8 +1134,8 @@ def dav_put_response(base_dir: str, nickname: str, domain: str, if etag in recent_dav_etags[nickname]: return 'Not modified' - stored_count = 0 - reading_event = False + stored_count: int = 0 + reading_event: bool = False lines_list = xml_str.split('\n') event_list: list[dict] = [] for line in lines_list: diff --git a/httpcodes.py b/httpcodes.py index d9b6420bc..b02ee1576 100644 --- a/httpcodes.py +++ b/httpcodes.py @@ -11,7 +11,7 @@ import time def write2(self, msg) -> bool: - tries = 0 + tries: int = 0 while tries < 5: try: self.wfile.write(msg) diff --git a/httpheaders.py b/httpheaders.py index d4de0765a..91f865583 100644 --- a/httpheaders.py +++ b/httpheaders.py @@ -248,7 +248,7 @@ def update_headers_catalog(base_dir: str, headers_catalog: {}, This allows us to spot anything unexpected for later investigation """ headers_catalog_fieldname = data_dir(base_dir) + '/headers_catalog.json' - changed = False + changed: bool = False for fieldname, fieldvalue in headers.items(): if fieldname in headers_catalog: continue diff --git a/importFollowing.py b/importFollowing.py index de130679e..07e19b28c 100644 --- a/importFollowing.py +++ b/importFollowing.py @@ -111,9 +111,9 @@ def _update_import_following(base_dir: str, # get the appropriate session curr_session = main_session curr_proxy_type = httpd.proxy_type - use_onion_session = False - use_i2p_session = False - use_yggdrasil_session = False + use_onion_session: bool = False + use_i2p_session: bool = False + use_yggdrasil_session: bool = False if '.onion' not in domain and \ httpd.onion_domain and '.onion' in following_domain: curr_session = httpd.session_onion diff --git a/inbox.py b/inbox.py index b46ea9e5f..9dc0fedbd 100644 --- a/inbox.py +++ b/inbox.py @@ -216,7 +216,7 @@ def _inbox_store_post_to_html_cache(recent_posts_cache: {}, not_dm = not is_dm(post_json_object) yt_replace_domain = get_config_param(base_dir, 'youtubedomain') twitter_replacement_domain = get_config_param(base_dir, 'twitterdomain') - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True individual_post_as_html(signing_priv_key_pem, @@ -274,8 +274,8 @@ def valid_inbox_filenames(base_dir: str, nickname: str, domain: str, print('Not an inbox directory: ' + inbox_dir) return True expected_str = expected_domain + ':' + str(expected_port) - expected_found = False - ctr = 0 + expected_found: bool = False + ctr: int = 0 for subdir, _, files in os.walk(inbox_dir): for fname in files: filename = os.path.join(subdir, fname) @@ -459,7 +459,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str, post_nickname = None post_domain = None actor = None - obj_dict_exists = False + obj_dict_exists: bool = False # who is sending the post? sending_actor = None @@ -510,7 +510,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str, # allow quote toots going to the shared inbox if nickname != 'inbox': if is_quote_toot(post_json_object, content_str): - allow_quotes = False + allow_quotes: bool = False if sending_actor: allow_quotes = \ quote_toots_allowed(base_dir, nickname, domain, @@ -622,7 +622,7 @@ def save_post_to_inbox_queue(base_dir: str, http_prefix: str, handle + '/inbox/' + post_id.replace('/', '#') + '.json' filename = inbox_queue_dir + '/' + post_id.replace('/', '#') + '.json' - shared_inbox_item = False + shared_inbox_item: bool = False if nickname == 'inbox': nickname = original_domain shared_inbox_item = True @@ -672,7 +672,7 @@ def _inbox_post_recipients_add(base_dir: str, to_list: [], """Given a list of post recipients (to_list) from 'to' or 'cc' parameters populate a recipients_dict with the handle for each """ - follower_recipients = False + follower_recipients: bool = False for recipient in to_list: if not recipient: continue @@ -747,7 +747,7 @@ def _inbox_post_recipients(base_dir: str, post_json_object: {}, actor = get_actor_from_post(post_json_object) # first get any specific people which the post is addressed to - follower_recipients = False + follower_recipients: bool = False if has_object_dict(post_json_object): if post_json_object['object'].get('to'): if isinstance(post_json_object['object']['to'], list): @@ -1388,7 +1388,7 @@ def _bounce_dm(sender_post_id: str, session, http_prefix: str, last_bounce_message[0] = curr_time sender_nickname = sending_handle.split('@')[0] - group_account = False + group_account: bool = False if sending_handle.startswith('!'): sending_handle = sending_handle[1:] group_account = True @@ -1401,9 +1401,9 @@ def _bounce_dm(sender_post_id: str, session, http_prefix: str, # create the bounce DM subject = None content = translate['DM bounce'] - save_to_file = False - client_to_server = False - comments_enabled = False + save_to_file: bool = False + client_to_server: bool = False + comments_enabled: bool = False attach_image_filename = None media_type = None image_description: str = '' @@ -1411,7 +1411,7 @@ def _bounce_dm(sender_post_id: str, session, http_prefix: str, city = 'London, England' in_reply_to = remove_id_ending(sender_post_id) in_reply_to_atom_uri = None - schedule_post = False + schedule_post: bool = False event_date = None event_time = None event_end_time = None @@ -1419,7 +1419,7 @@ def _bounce_dm(sender_post_id: str, session, http_prefix: str, location = None conversation_id = None convthread_id = None - low_bandwidth = False + low_bandwidth: bool = False buy_url: str = '' chat_url: str = '' auto_cw_cache = {} @@ -1524,7 +1524,7 @@ def _is_valid_dm(base_dir: str, nickname: str, domain: str, port: int, if not sending_actor_domain: return False # Is this DM to yourself? eg. a reminder - sending_to_self = False + sending_to_self: bool = False if sending_actor_nickname == nickname and \ sending_actor_domain == domain: sending_to_self = True @@ -1577,7 +1577,7 @@ def _is_valid_dm(base_dir: str, nickname: str, domain: str, port: int, not get_reply_to(obj): bounced_id = \ remove_id_ending(post_json_object['id']) - bounce_chat = False + bounce_chat: bool = False if obj.get('type'): if obj['type'] == 'ChatMessage': bounce_chat = True @@ -1620,7 +1620,7 @@ def _create_reply_notification_file(base_dir: str, nickname: str, domain: str, The file can then be used by other systems to create a notification xmpp, matrix, email, etc """ - is_reply_to_muted_post = False + is_reply_to_muted_post: bool = False if post_is_dm: return is_reply_to_muted_post if not is_reply(post_json_object, actor): @@ -1803,7 +1803,7 @@ def _former_representations_to_edits(base_dir: str, post_history_json = load_json(post_history_filename) # check each former post and add it to the edits file if needed - posts_added = False + posts_added: bool = False for prev_post_json in prev_edits_list: prev_post_obj = prev_post_json if has_object_dict(prev_post_json): @@ -1933,7 +1933,7 @@ def _inbox_after_initial(server, inbox_start_time, _update_last_seen(base_dir, handle, actor) - post_is_dm = False + post_is_dm: bool = False is_group = _group_handle(base_dir, handle) fitness_performance(inbox_start_time, server.fitness, 'INBOX', '_group_handle', @@ -1956,7 +1956,7 @@ def _inbox_after_initial(server, inbox_start_time, get_attributed_to(message_json['attributedTo']) quote_post_nickname = None quote_post_domain_full = None - allow_quotes = False + allow_quotes: bool = False if quote_post_actor: quote_post_nickname = get_nickname_from_actor(quote_post_actor) quote_post_domain, quote_post_port = \ @@ -2421,7 +2421,7 @@ def _inbox_after_initial(server, inbox_start_time, debug) inbox_start_time = time.time() - is_reply_to_muted_post = False + is_reply_to_muted_post: bool = False if not is_group: # create a DM notification file if needed @@ -2472,7 +2472,7 @@ def _inbox_after_initial(server, inbox_start_time, debug) inbox_start_time = time.time() - show_vote_posts = True + show_vote_posts: bool = True show_vote_file = acct_dir(base_dir, nickname, domain) + '/.noVotes' if os.path.isfile(show_vote_file): show_vote_posts = False @@ -2805,7 +2805,7 @@ def _inbox_after_initial(server, inbox_start_time, def clear_queue_items(base_dir: str, queue: []) -> None: """Clears the queue for each account """ - ctr = 0 + ctr: int = 0 queue.clear() dir_str = data_dir(base_dir) for _, dirs, _ in os.walk(dir_str): @@ -3018,7 +3018,7 @@ def _inbox_quota_exceeded(queue: {}, queue_filename: str, def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool): """check if a json signature exists on this post """ - has_json_signature = False + has_json_signature: bool = False jwebsig_type = None original_json = queue_json['original'] if not original_json.get('@context') or \ @@ -3043,7 +3043,7 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool): print('unrecognized @context: ' + unknown_context) - already_unknown = False + already_unknown: bool = False if os.path.isfile(unknown_contexts_file): if text_in_file(unknown_context, unknown_contexts_file): already_unknown = True @@ -3058,7 +3058,7 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool): unknown_signatures_file = \ data_dir(base_dir) + '/unknownJsonSignatures.txt' - already_unknown = False + already_unknown: bool = False if os.path.isfile(unknown_signatures_file): if text_in_file(jwebsig_type, unknown_signatures_file): already_unknown = True @@ -3176,7 +3176,7 @@ def _receive_follow_request(session, session_onion, session_i2p, handle_dir) return True - is_already_follower = False + is_already_follower: bool = False if is_follower_of_person(base_dir, nickname_to_follow, domain_to_follow_full, nickname, domain_full): @@ -3449,7 +3449,7 @@ def run_inbox_queue(server, inbox_start_time = time.time() curr_session_time = int(time.time()) - session_last_update = 0 + session_last_update: int = 0 session = create_session(proxy_type) if session: session_last_update = curr_session_time @@ -3461,9 +3461,9 @@ def run_inbox_queue(server, session_onion = None session_i2p = None session_yggdrasil = None - session_last_update_onion = 0 - session_last_update_i2p = 0 - session_last_update_yggdrasil = 0 + session_last_update_onion: int = 0 + session_last_update_i2p: int = 0 + session_last_update_yggdrasil: int = 0 if proxy_type != 'tor' and onion_domain: print('Starting onion session when starting inbox queue') session_onion = create_session('tor') @@ -3503,8 +3503,8 @@ def run_inbox_queue(server, 'accounts': {} } - heart_beat_ctr = 0 - queue_restore_ctr = 0 + heart_beat_ctr: int = 0 + queue_restore_ctr: int = 0 curr_mitm_servers: list[str] = [] # time when the last DM bounce message was sent @@ -3519,7 +3519,7 @@ def run_inbox_queue(server, 'INBOX', 'while_loop_start', debug) inbox_start_time = time.time() # the last time that a quote request was last received - last_quote_request = 0 + last_quote_request: int = 0 while True: time.sleep(1) inbox_start_time = time.time() @@ -3538,7 +3538,7 @@ def run_inbox_queue(server, inbox_start_time = time.time() print('>>> Heartbeat Q:' + str(len(queue)) + ' ' + '{:%F %T}'.format(datetime.datetime.now())) - heart_beat_ctr = 0 + heart_beat_ctr: int = 0 # save MITM servers list if it has changed if str(server.mitm_servers) != str(curr_mitm_servers): @@ -3549,7 +3549,7 @@ def run_inbox_queue(server, # restore any remaining queue items queue_restore_ctr += 1 if queue_restore_ctr >= 30: - queue_restore_ctr = 0 + queue_restore_ctr: int = 0 _restore_queue_items(base_dir, queue) fitness_performance(inbox_start_time, server.fitness, 'INBOX', 'restore_queue', debug) @@ -3768,7 +3768,7 @@ def run_inbox_queue(server, print('DEBUG: checking http header signature') pprint(queue_json['httpHeaders']) post_str = json.dumps(queue_json['post']) - http_signature_failed = False + http_signature_failed: bool = False if not verify_post_headers(http_prefix, pub_key, queue_json['httpHeaders'], queue_json['path'], False, @@ -3870,7 +3870,7 @@ def run_inbox_queue(server, curr_destination = queue_json['destination'] # if the post contains a collection of posts then split it up - remove_queue_item = False + remove_queue_item: bool = False posts_list_json = split_post_collection(queue_json['post']) for curr_post_json in posts_list_json: @@ -4089,10 +4089,10 @@ def run_inbox_queue(server, destination = \ curr_destination.replace(inbox_handle, handle) languages_understood: list[str] = [] - mitm = False + mitm: bool = False if queue_json.get('mitm'): mitm = True - bold_reading = False + bold_reading: bool = False bold_reading_filename = \ acct_handle_dir(base_dir, handle) + '/.boldReading' if os.path.isfile(bold_reading_filename): diff --git a/inbox_receive.py b/inbox_receive.py index ce6a29120..386cf0611 100644 --- a/inbox_receive.py +++ b/inbox_receive.py @@ -109,7 +109,7 @@ def inbox_update_index(boxname: str, base_dir: str, handle: str, if '/' in destination_filename: destination_filename = destination_filename.split('/')[-1] - written = False + written: bool = False if os.path.isfile(index_filename): try: with open(index_filename, 'r+', encoding='utf-8') as fp_index: @@ -192,7 +192,7 @@ def _person_receive_update(base_dir: str, domain_full = get_full_domain(domain, port) update_domain_full = get_full_domain(update_domain, update_port) users_paths = get_user_paths() - users_str_found = False + users_str_found: bool = False for users_str in users_paths: actor = update_domain_full + users_str + update_nickname if actor in person_json['id']: @@ -277,7 +277,7 @@ def _person_receive_update(base_dir: str, new_nickname + '@' + new_domain_full refollow_str: str = '' refollow_filename = data_dir(base_dir) + '/actors_moved.txt' - refollow_file_exists = False + refollow_file_exists: bool = False if os.path.isfile(refollow_filename): refollow_str = \ load_string(refollow_filename, @@ -500,23 +500,23 @@ def receive_edit_to_post(recent_posts_cache: {}, message_json: {}, remove_post_from_cache(message_json, recent_posts_cache) # regenerate html for the post page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, nickname, domain) not_dm = not is_dm(message_json) timezone = get_account_timezone(base_dir, nickname, domain) - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True - bold_reading = False + bold_reading: bool = False bold_reading_filename = \ acct_dir(base_dir, nickname, domain) + '/.boldReading' if os.path.isfile(bold_reading_filename): bold_reading = True timezone = get_account_timezone(base_dir, nickname, domain) lists_enabled = get_config_param(base_dir, "listsEnabled") - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -1081,16 +1081,16 @@ def receive_like(recent_posts_cache: {}, print('Liked post nickname: ' + handle_name + ' ' + domain) print('Liked post cache: ' + str(cached_post_filename)) page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(liked_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if handle_name in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -1331,16 +1331,16 @@ def receive_reaction(recent_posts_cache: {}, print('Reaction post nickname: ' + handle_name + ' ' + domain) print('Reaction post cache: ' + str(cached_post_filename)) page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(reaction_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if handle_name in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -1530,16 +1530,16 @@ def receive_zot_reaction(recent_posts_cache: {}, print('Reaction post nickname: ' + handle_name + ' ' + domain) print('Reaction post cache: ' + str(cached_post_filename)) page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(reaction_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if handle_name in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -1672,16 +1672,16 @@ def receive_bookmark(recent_posts_cache: {}, print('Bookmarked post nickname: ' + nickname + ' ' + domain) print('Bookmarked post cache: ' + str(cached_post_filename)) page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, nickname, domain) not_dm = not is_dm(bookmarked_post_json) timezone = get_account_timezone(base_dir, nickname, domain) - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -1837,7 +1837,7 @@ def receive_announce(recent_posts_cache: {}, return False if debug: print('DEBUG: receiving announce on ' + handle) - is_quote = False + is_quote: bool = False if not has_object_string(message_json, debug): if not is_quote_toot(message_json, ''): return False @@ -1983,9 +1983,9 @@ def receive_announce(recent_posts_cache: {}, domain_full = get_full_domain(domain, port) # Generate html. This also downloads the announced post. - page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + page_number: bool = 1 + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, nickname, domain) not_dm = True @@ -2070,7 +2070,7 @@ def receive_announce(recent_posts_cache: {}, block_bluesky, block_nostr) # are annouced/boosted replies allowed? - announce_denied = False + announce_denied: bool = False if post_json_object: if has_object_dict(post_json_object): if post_json_object['object'].get('inReplyTo'): @@ -2086,7 +2086,7 @@ def receive_announce(recent_posts_cache: {}, else: print('REJECT: Announce/Boost of reply denied ' + actor_url + ' 🔁 ' + announce_url) - not_in_onion = True + not_in_onion: bool = True if onion_domain: if onion_domain in announce_url: not_in_onion = False @@ -2224,17 +2224,17 @@ def receive_question_vote(server, base_dir: str, nickname: str, domain: str, print('EX: replytoQuestion unable to delete ' + cached_post_filename) - page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + page_number: int = 1 + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, nickname, domain) not_dm = not is_dm(question_json) timezone = get_account_timezone(base_dir, nickname, domain) - mitm = False + mitm: bool = False if os.path.isfile(question_post_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/inbox_receive_undo.py b/inbox_receive_undo.py index c4f6dcceb..8a59bdb87 100644 --- a/inbox_receive_undo.py +++ b/inbox_receive_undo.py @@ -257,17 +257,17 @@ def receive_undo_like(recent_posts_cache: {}, print('Unliked post json: ' + str(liked_post_json)) print('Unliked post nickname: ' + handle_name + ' ' + domain) print('Unliked post cache: ' + str(cached_post_filename)) - page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + page_number: int = 1 + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(liked_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if handle_name in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -415,17 +415,17 @@ def receive_undo_reaction(recent_posts_cache: {}, print('Unreaction post nickname: ' + handle_name + ' ' + domain) print('Unreaction post cache: ' + str(cached_post_filename)) - page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + page_number: int = 1 + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, handle_name, domain) not_dm = not is_dm(reaction_post_json) timezone = get_account_timezone(base_dir, handle_name, domain) - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if handle_name in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -559,17 +559,17 @@ def receive_undo_bookmark(recent_posts_cache: {}, print('Unbookmarked post json: ' + str(bookmarked_post_json)) print('Unbookmarked post nickname: ' + nickname + ' ' + domain) print('Unbookmarked post cache: ' + str(cached_post_filename)) - page_number = 1 - show_published_date_only = False - show_individual_post_icons = True + page_number: int = 1 + show_published_date_only: bool = False + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, nickname, domain) not_dm = not is_dm(bookmarked_post_json) timezone = get_account_timezone(base_dir, nickname, domain) - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/languages.py b/languages.py index 034377888..b18163eab 100644 --- a/languages.py +++ b/languages.py @@ -204,9 +204,9 @@ def get_links_from_content(content: str) -> {}: """ if '
str: locn = _get_location_from_tags(post_obj['tag']) # location representation used by pixelfed - locn_exists = False + locn_exists: bool = False locn2 = None if post_obj.get('location'): locn2 = post_obj['location'] @@ -637,7 +637,7 @@ def _geocoords_from_gmaps_link(url: str) -> (int, float, float): coords_str = coords_str.split('/place/', 1)[1] # NOTE: zoom may have been replaced by metres elevation - zoom_exists = False + zoom_exists: bool = False if 'z' in coords_str: coords_str = coords_str.split('z', 1)[0] zoom_exists = True @@ -965,7 +965,7 @@ def get_map_links_from_post_content(content: str, session) -> []: osm_domain = 'openstreetmap.org' sections = content.split('://') map_links: list[str] = [] - ctr = 0 + ctr: int = 0 for link_str in sections: if ctr == 0: ctr += 1 @@ -997,7 +997,7 @@ def get_map_links_from_post_content(content: str, session) -> []: ctr += 1 # https://en.wikipedia.org/wiki/Geo_URI_scheme - ctr = 0 + ctr: int = 0 sections = content.split('geo:') for link_str in sections: if ctr == 0: @@ -1046,7 +1046,7 @@ def add_tag_map_links(tag_maps_dir: str, tag_name: str, secs_since_epoch = \ int((date_from_string_format(published, ['%Y-%m-%dT%H:%M:%S%z']) - date_epoch()).total_seconds()) - links_changed = False + links_changed: bool = False for link in map_links: line = str(secs_since_epoch) + ' ' + link + ' ' + post_url if line in existing_map_links: @@ -1059,7 +1059,7 @@ def add_tag_map_links(tag_maps_dir: str, tag_name: str, # sort the list of map links existing_map_links.sort(reverse=True) map_links_str: str = '' - ctr = 0 + ctr: int = 0 for link in existing_map_links: if not link: continue @@ -1113,7 +1113,7 @@ def _hashtag_map_to_format(base_dir: str, tag_name: str, map_format: str, session) -> str: """Returns the KML/GPX for a given hashtag between the given times """ - place_ctr = 0 + place_ctr: int = 0 osm_domain = 'openstreetmap.org' tag_map_filename = base_dir + '/tagmaps/' + tag_name + '.txt' diff --git a/markdown.py b/markdown.py index 47aef5a59..d271d4349 100644 --- a/markdown.py +++ b/markdown.py @@ -26,9 +26,9 @@ def _markdown_get_sections(markdown: str) -> []: return [markdown] lines = markdown.split('\n') sections: list[str] = [] - section_text = '' - section_active = False - ctr = 0 + section_text: str = '' + section_active: bool = False + ctr: int = 0 for line in lines: if ctr > 0: section_text += '\n' @@ -136,9 +136,9 @@ def _markdown_replace_quotes(markdown: str) -> str: if '> ' not in markdown: return markdown lines = markdown.split('\n') - result = '' + result: str = '' prev_quote_line = None - code_section = False + code_section: bool = False for line in lines: # avoid code sections if not code_section: @@ -184,14 +184,14 @@ def _markdown_replace_links(markdown: str) -> str: Optionally replace image links """ sections = _markdown_get_sections(markdown) - result = '' + result: str = '' for section_text in sections: if '' in section_text or \ '](' not in section_text: result += section_text continue sections_links = section_text.split('](') - ctr = 0 + ctr: int = 0 for link_section in sections_links: if ctr == 0: ctr += 1 @@ -253,7 +253,7 @@ def _markdown_replace_misskey(markdown: str) -> str: if '$[' not in markdown or ']' not in markdown: return markdown sections = _markdown_get_sections(markdown) - result = '' + result: str = '' for section_text in sections: if '' in section_text or \ '$[' not in section_text or \ @@ -262,7 +262,7 @@ def _markdown_replace_misskey(markdown: str) -> str: result += section_text continue sections_links = section_text.split('$[') - ctr = 0 + ctr: int = 0 for link_section in sections_links: if ctr == 0: ctr += 1 @@ -280,8 +280,8 @@ def _markdown_replace_misskey(markdown: str) -> str: # get the type of animation animation_type = misskey_str.split(' ')[0] append_emoji = None - mfm_type = '' - found = False + mfm_type: str = '' + found: bool = False for anim, anim_emoji in animation_types.items(): if animation_type.startswith(anim): mfm_type = anim @@ -313,11 +313,11 @@ def _markdown_replace_bullet_points(markdown: str) -> str: """ lines = markdown.split('\n') bullet_style = ('* ', ' * ', '- ', ' - ') - bullet_matched = '' - start_line = -1 - line_ctr = 0 - changed = False - code_section = False + bullet_matched: str = '' + start_line: int = -1 + line_ctr: int = 0 + changed: bool = False + code_section: bool = False for line in lines: if not line.strip(): # skip blank lines @@ -370,11 +370,11 @@ def _markdown_replace_code(markdown: str) -> str: """Replaces code sections within markdown """ lines = markdown.split('\n') - start_line = -1 - line_ctr = 0 - changed = False - section_active = False - url_encode = False + start_line: int = -1 + line_ctr: int = 0 + changed: bool = False + section_active: bool = False + url_encode: bool = False html_escape_table = { "&": "&", '"': """, @@ -422,8 +422,8 @@ def markdown_example_numbers(markdown: str) -> str: document are sequential """ lines = markdown.split('\n') - example_number = 1 - line_ctr = 0 + example_number: int = 1 + line_ctr: int = 0 for line in lines: if not line.strip(): # skip blank lines @@ -453,9 +453,9 @@ def markdown_to_html(markdown: str) -> str: # replace headers lines_list = markdown.split('\n') - html_str = '' - ctr = 0 - code_section = False + html_str: str = '' + ctr: int = 0 + code_section: bool = False titles = { "h6": '######', "h5": '#####', diff --git a/mastoapiv1.py b/mastoapiv1.py index 545b3396c..12f870c71 100644 --- a/mastoapiv1.py +++ b/mastoapiv1.py @@ -66,8 +66,8 @@ def _meta_data_instance_v1(show_accounts: bool, }) rule_ctr += 1 - is_bot = False - is_group = False + is_bot: bool = False + is_group: bool = False if admin_actor['type'] == 'Group': is_group = True elif admin_actor['type'] != 'Person': @@ -224,19 +224,19 @@ def _get_masto_api_v1account(base_dir: str, nickname: str, domain: str, if account_json.get('published'): joined_date = account_json['published'] noindex = not account_is_indexable(account_json) - discoverable = True + discoverable: bool = True if 'discoverable' in account_json: if account_json['discoverable'] is False: discoverable = False - group = False - bot = False + group: bool = False + bot: bool = False if account_json['type'] == 'Group': group = True elif account_json['type'] != 'Person': bot = True - no_of_statuses = 0 - no_of_followers = 0 - no_of_following = 0 + no_of_statuses: int = 0 + no_of_followers: int = 0 + no_of_following: int = 0 fields: list[dict] = [] published = None if show_accounts and not broch_mode: diff --git a/mastoapiv2.py b/mastoapiv2.py index 1294f3e1b..19531875c 100644 --- a/mastoapiv2.py +++ b/mastoapiv2.py @@ -73,8 +73,8 @@ def _meta_data_instance_v2(show_accounts: bool, }) rule_ctr += 1 - is_bot = False - is_group = False + is_bot: bool = False + is_group: bool = False if admin_actor['type'] == 'Group': is_group = True elif admin_actor['type'] != 'Person': @@ -104,9 +104,9 @@ def _meta_data_instance_v2(show_accounts: bool, if 'discoverable' in admin_actor: if admin_actor['discoverable'] is False: discoverable = False - no_of_statuses = 0 - no_of_followers = 0 - no_of_following = 0 + no_of_statuses: int = 0 + no_of_followers: int = 0 + no_of_following: int = 0 if show_accounts: no_of_followers = lines_in_file(account_dir + '/followers.txt') no_of_following = lines_in_file(account_dir + '/following.txt') diff --git a/media.py b/media.py index 207e25b67..5b53222c7 100644 --- a/media.py +++ b/media.py @@ -488,7 +488,7 @@ def convert_image_to_low_bandwidth(image_filename: str) -> None: print('Low bandwidth image conversion: ' + cmd) subprocess.call(cmd, shell=True) # wait for conversion to happen - ctr = 0 + ctr: int = 0 while not os.path.isfile(low_bandwidth_filename): print('Waiting for low bandwidth image conversion ' + str(ctr)) time.sleep(0.2) diff --git a/migrate.py b/migrate.py index 66b5d0c75..3cf41ae98 100644 --- a/migrate.py +++ b/migrate.py @@ -34,7 +34,7 @@ def _move_following_handles_for_account(base_dir: str, mitm_servers: []) -> int: """Goes through all follows for an account and updates any that have moved """ - ctr = 0 + ctr: int = 0 following_filename = \ acct_dir(base_dir, nickname, domain) + '/following.txt' if not os.path.isfile(following_filename): @@ -67,7 +67,7 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str, for each account. Returns 1 if moved, 0 otherwise """ - ctr = 0 + ctr: int = 0 if '@' not in handle: return ctr if len(handle) < 5: @@ -98,13 +98,13 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str, if not person_url: return ctr - gnunet = False + gnunet: bool = False if http_prefix == 'gnunet': gnunet = True - ipfs = False + ipfs: bool = False if http_prefix == 'ipfs': ipfs = True - ipns = False + ipns: bool = False if http_prefix == 'ipns': ipns = True mitm_servers: list[str] = [] @@ -242,7 +242,7 @@ def migrate_accounts(base_dir: str, session, Returns the number of accounts migrated """ # update followers and following lists for each account - ctr = 0 + ctr: int = 0 dir_str = data_dir(base_dir) for _, dirs, _ in os.walk(dir_str): for handle in dirs: diff --git a/newsdaemon.py b/newsdaemon.py index 09e362df3..b5878b289 100644 --- a/newsdaemon.py +++ b/newsdaemon.py @@ -154,7 +154,7 @@ def _hashtag_logical_and(tree: [], hashtags: [], moderated: bool, if len(tree) < 3: return False for arg_index in range(1, len(tree)): - arg_value = False + arg_value: bool = False if isinstance(tree[arg_index], str): arg_value = tree[arg_index] in hashtags elif isinstance(tree[arg_index], list): @@ -173,7 +173,7 @@ def _hashtag_logical_or(tree: [], hashtags: [], moderated: bool, if len(tree) < 3: return False for arg_index in range(1, len(tree)): - arg_value = False + arg_value: bool = False if isinstance(tree[arg_index], str): arg_value = tree[arg_index] in hashtags elif isinstance(tree[arg_index], list): @@ -191,9 +191,9 @@ def _hashtag_logical_xor(tree: [], hashtags: [], moderated: bool, """ if len(tree) < 3: return False - true_ctr = 0 + true_ctr: int = 0 for arg_index in range(1, len(tree)): - arg_value = False + arg_value: bool = False if isinstance(tree[arg_index], str): arg_value = tree[arg_index] in hashtags elif isinstance(tree[arg_index], list): @@ -272,7 +272,7 @@ def hashtag_rule_tree(operators: [], conditions_str.startswith('"'): tags_in_conditions.append(conditions_str) tree = [conditions_str.strip()] - ctr = 0 + ctr: int = 0 while ctr < len(operators): oper = operators[ctr] opmatch = ' ' + oper + ' ' @@ -462,7 +462,7 @@ def _create_news_mirror(base_dir: str, domain: str, os.mkdir(mirror_dir) # count the directories - no_of_dirs = 0 + no_of_dirs: int = 0 for _, dirs, _ in os.walk(mirror_dir): no_of_dirs = len(dirs) break @@ -478,7 +478,7 @@ def _create_news_mirror(base_dir: str, domain: str, with open(mirror_index_filename, 'r', encoding='utf-8') as fp_index: # remove the oldest directories - ctr = 0 + ctr: int = 0 while no_of_dirs > max_mirrored_articles: ctr += 1 if ctr > 5000: @@ -656,7 +656,7 @@ def _convert_rss_to_activitypub(base_dir: str, http_prefix: str, # NOTE: the id when the post is created will not be # consistent (it's based on the current time, not the # published time), so we change that later - save_to_file = False + save_to_file: bool = False attach_image_filename = None media_type = None image_description = None diff --git a/newswire.py b/newswire.py index 78ed41091..761b1518a 100644 --- a/newswire.py +++ b/newswire.py @@ -340,7 +340,7 @@ def parse_feed_date(pub_date: str, unique_string_identifier: str) -> str: 'UT' ) for date_format in formats: - timezone_mismatch = False + timezone_mismatch: bool = False for timezone_ending in timezone_endings: if timezone_ending in pub_date and \ timezone_ending not in date_format: @@ -482,7 +482,7 @@ def _get_podcast_categories(xml_item: str, xml_str: str) -> str: item_str = xml_str category_list = item_str.split(category_tag) - first_category = True + first_category: bool = True for episode_category in category_list: if first_category: first_category = False @@ -608,8 +608,8 @@ def xml_podcast_to_dict(base_dir: str, xml_item: str, xml_str: str) -> {}: "socialInteract": [], } - pod_lines = xml_item.split('' not in pod_line: ctr += 1 @@ -649,7 +649,7 @@ def xml_podcast_to_dict(base_dir: str, xml_item: str, xml_str: str) -> {}: if pod_text: pod_entry['text'] = pod_text - appended = False + appended: bool = False if pod_key + 's' in podcast_properties: if isinstance(podcast_properties[pod_key + 's'], list): podcast_properties[pod_key + 's'].append(pod_entry) @@ -738,8 +738,8 @@ def get_link_from_rss_item(rss_item: str, mime_type = None if preferred_mime_types and '' not in xml_str: return {} - result = {} + result: dict = {} # is this an rss feed containing hashtag categories? if '#categories' in xml_str: @@ -838,10 +838,10 @@ def _xml2str_to_dict(base_dir: str, domain: str, xml_str: str, max_categories_feed_item_size_kb) return {} - rss_items = xml_str.split('') - post_ctr = 0 - max_bytes = max_feed_item_size_kb * 1024 - first_item = True + rss_items: list = xml_str.split('') + post_ctr: int = 0 + max_bytes: int = max_feed_item_size_kb * 1024 + first_item: bool = True for rss_item in rss_items: if first_item: first_item = False @@ -952,7 +952,7 @@ def _xml1str_to_dict(base_dir: str, domain: str, xml_str: str, item_str = '#categories' in xml_str: @@ -960,10 +960,10 @@ def _xml1str_to_dict(base_dir: str, domain: str, xml_str: str, max_categories_feed_item_size_kb) return {} - rss_items = xml_str.split(item_str) - post_ctr = 0 - max_bytes = max_feed_item_size_kb * 1024 - first_item = True + rss_items: list = xml_str.split(item_str) + post_ctr: int = 0 + max_bytes: int = max_feed_item_size_kb * 1024 + first_item: bool = True for rss_item in rss_items: if first_item: first_item = False @@ -1071,11 +1071,11 @@ def _atom_feed_to_dict(base_dir: str, domain: str, xml_str: str, """ if '' not in xml_str: return {} - result = {} - atom_items = xml_str.split('') - post_ctr = 0 - max_bytes = max_feed_item_size_kb * 1024 - first_item = True + result: dict = {} + atom_items: list = xml_str.split('') + post_ctr: int = 0 + max_bytes: int = max_feed_item_size_kb * 1024 + first_item: bool = True for atom_item in atom_items: if first_item: first_item = False @@ -1148,7 +1148,7 @@ def _atom_feed_to_dict(base_dir: str, domain: str, xml_str: str, unescaped_text(obj_str.split('')[0]) obj_str = remove_script(obj_str, None, None, None) sections = obj_str.split('') - post_ctr = 0 - max_bytes = max_feed_item_size_kb * 1024 - first_entry = True + post_ctr: int = 0 + max_bytes: int = max_feed_item_size_kb * 1024 + first_entry: bool = True for atom_item in atom_items: if first_entry: first_entry = False @@ -1669,7 +1669,7 @@ def _add_account_blogs_to_newswire(base_dir: str, nickname: str, domain: str, if not os.path.isfile(index_filename): return # local blog entries are unmoderated by default - moderated = False + moderated: bool = False # local blogs can potentially be moderated moderated_filename = \ @@ -1680,7 +1680,7 @@ def _add_account_blogs_to_newswire(base_dir: str, nickname: str, domain: str, try: with open(index_filename, 'r', encoding='utf-8') as fp_index: post_filename = 'start' - ctr = 0 + ctr: int = 0 while post_filename: post_filename = fp_index.readline() if not post_filename: @@ -1843,13 +1843,13 @@ def get_dict_from_newswire(session, base_dir: str, domain: str, continue # should this feed be moderated? - moderated = False + moderated: bool = False if '*' in url: moderated = True url = url.replace('*', '').strip() # should this feed content be mirrored? - mirrored = False + mirrored: bool = False if '!' in url: mirrored = True url = url.replace('!', '').strip() @@ -1877,7 +1877,7 @@ def get_dict_from_newswire(session, base_dir: str, domain: str, # are there too many posts? If so then remove the oldest ones no_of_posts = len(sorted_result.items()) if no_of_posts > max_newswire_posts: - ctr = 0 + ctr: int = 0 removals: list[str] = [] for date_str, item in sorted_result.items(): ctr += 1 diff --git a/outbox.py b/outbox.py index 0c44fa2d1..4524d0522 100644 --- a/outbox.py +++ b/outbox.py @@ -186,7 +186,7 @@ def _person_receive_update_outbox(base_dir: str, http_prefix: str, actor_json = load_json(actor_filename) if not actor_json: return - actor_changed = False + actor_changed: bool = False # update fields within actor if 'attachment' in updated_actor_json: # these attachments are updatable via c2s @@ -328,7 +328,7 @@ def post_message_to_outbox(session, translate: {}, message_json) # is Bold Reading enabled for this account? - bold_reading = False + bold_reading: bool = False if server.bold_reading.get(post_to_nickname): bold_reading = True @@ -448,7 +448,7 @@ def post_message_to_outbox(session, translate: {}, message_json['object']['attributedTo'] = actor_url message_attachments = get_post_attachments(message_json['object']) if message_attachments: - attachment_index = 0 + attachment_index: int = 0 attach = message_attachments[attachment_index] if attach.get('mediaType'): file_extension = 'png' @@ -537,7 +537,7 @@ def post_message_to_outbox(session, translate: {}, if debug: print('DEBUG: save_post_to_box') - is_edited_post = False + is_edited_post: bool = False if message_json['type'] == 'Update' and \ message_json['object']['type'] in ('Note', 'Event'): is_edited_post = True @@ -635,7 +635,7 @@ def post_message_to_outbox(session, translate: {}, # should this also go to the media timeline? if box_name_index == 'inbox': - show_vote_posts = True + show_vote_posts: bool = True show_vote_file = \ acct_dir(base_dir, post_to_nickname, domain) + '/.noVotes' if os.path.isfile(show_vote_file): @@ -672,20 +672,20 @@ def post_message_to_outbox(session, translate: {}, saved_filename, debug) # regenerate the html - use_cache_only = False - page_number = 1 - show_individual_post_icons = True + use_cache_only: bool = False + page_number: int = 1 + show_individual_post_icons: bool = True manually_approve_followers = \ follower_approval_active(base_dir, post_to_nickname, domain) timezone = \ get_account_timezone(base_dir, post_to_nickname, domain) - mitm = False + mitm: bool = False if os.path.isfile(saved_filename.replace('.json', '') + '.mitm'): mitm = True - minimize_all_images = False + minimize_all_images: bool = False if post_to_nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/person.py b/person.py index 4000fd236..406154d9b 100644 --- a/person.py +++ b/person.py @@ -225,7 +225,7 @@ def get_actor_update_json(actor_json: {}) -> {}: """ pub_number, _ = get_status_number() manually_approves_followers = actor_json['manuallyApprovesFollowers'] - memorial = False + memorial: bool = False if actor_json.get('memorial'): memorial = True indexable = account_is_indexable(actor_json) @@ -863,7 +863,7 @@ def person_upgrade_actor(base_dir: str, person_json: {}, filename: str) -> None: """Alter the actor to add any new properties """ - update_actor = False + update_actor: bool = False if not os.path.isfile(filename): print('WARN: actor file not found ' + filename) return @@ -1100,7 +1100,7 @@ def person_lookup(domain: str, path: str, base_dir: str) -> {}: elif path.endswith('#main-key'): path = path.replace('#main-key', '') # is this a shared inbox lookup? - is_shared_inbox = False + is_shared_inbox: bool = False if path in ('/inbox', '/users/inbox', '/sharedInbox'): # shared inbox actor on @domain@domain path = '/users/inbox' @@ -1626,8 +1626,8 @@ def deactivate_account(base_dir: str, nickname: str, domain: str) -> bool: def activate_account2(base_dir: str, nickname: str, domain: str) -> bool: """Makes a deactivated account available """ - activated = False - handle = nickname + '@' + domain + activated: bool = False + handle: str = nickname + '@' + domain deactivated_dir = base_dir + '/deactivated' deactivated_account_dir = deactivated_dir + '/' + handle @@ -1846,7 +1846,7 @@ def get_actor_json(host_domain: str, handle: str, http: bool, gnunet: bool, if debug: print('get_actor_json for ' + handle) original_actor: str = handle - group_account = False + group_account: bool = False nickname: str = '' domain: str = '' @@ -1872,7 +1872,7 @@ def get_actor_json(host_domain: str, handle: str, http: bool, gnunet: bool, if '/@/' not in handle: handle = handle.replace('/@', detected_users_path) paths = get_user_paths() - user_path_found = False + user_path_found: bool = False for user_path in paths: if user_path in handle: nickname = handle.split(user_path)[1] @@ -1959,7 +1959,7 @@ def get_actor_json(host_domain: str, handle: str, http: bool, gnunet: bool, wf_request = None original_actor_lower = original_actor.lower() - ends_with_instance_actor = False + ends_with_instance_actor: bool = False if original_actor_lower.endswith('/actor') or \ original_actor_lower.endswith('/instance.actor'): ends_with_instance_actor = True @@ -2021,7 +2021,7 @@ def get_actor_json(host_domain: str, handle: str, http: bool, gnunet: bool, person_url = person_url.replace(user_path, '/actor/') if not person_url and group_account: person_url = http_prefix + '://' + domain + '/c/' + nickname - try_single_person = False + try_single_person: bool = False if not person_url: # try single user instance person_url = http_prefix + '://' + domain + '/' + nickname @@ -2153,9 +2153,9 @@ def valid_sending_actor(session, base_dir: str, # NOTE: the actor should not be obtained from the local cache, # because they may have changed fields which are being tested here, # such as the bio length - gnunet = False - ipfs = False - ipns = False + gnunet: bool = False + ipfs: bool = False + ipns: bool = False actor_json, _ = get_actor_json(domain, sending_actor, True, gnunet, ipfs, ipns, debug, True, @@ -2225,8 +2225,8 @@ def valid_sending_actor(session, base_dir: str, # Spam actors will sometimes have attached fields which are all empty if actor_json.get('attachment'): if isinstance(actor_json['attachment'], list): - no_of_tags = 0 - tags_without_value = 0 + no_of_tags: int = 0 + tags_without_value: int = 0 for tag in actor_json['attachment']: if not isinstance(tag, dict): continue @@ -2262,12 +2262,12 @@ def valid_sending_actor(session, base_dir: str, def get_featured_hashtags(actor_json: {}) -> str: """returns a string containing featured hashtags """ - result = '' + result: str = '' if not actor_json.get('tag'): return result if not isinstance(actor_json['tag'], list): return result - ctr = 0 + ctr: int = 0 for tag_dict in actor_json['tag']: if not tag_dict.get('type'): continue @@ -2306,12 +2306,12 @@ def get_featured_hashtags_as_html(actor_json: {}, profile_description: str) -> str: """returns a html string containing featured hashtags """ - result = '' + result: str = '' if not actor_json.get('tag'): return result if not isinstance(actor_json['tag'], list): return result - ctr = 0 + ctr: int = 0 for tag_dict in actor_json['tag']: if not tag_dict.get('type'): continue @@ -2425,7 +2425,7 @@ def update_memorial_flags(base_dir: str, person_cache: {}) -> None: if not actor_json.get('id'): continue nickname = account.split('@')[0] - actor_changed = False + actor_changed: bool = False if not actor_json.get('memorial'): if nickname in memorials: actor_json['memorial'] = True diff --git a/pgp.py b/pgp.py index 448da37ff..7a63b941d 100644 --- a/pgp.py +++ b/pgp.py @@ -108,7 +108,7 @@ def get_deltachat_invite(actor_json: {}, translate: {}) -> str: name_value = property_value['schema:name'] if not name_value: continue - found = False + found: bool = False for possible_str in match_strings: if possible_str in name_value.lower(): found = True @@ -198,7 +198,7 @@ def get_pgp_fingerprint(actor_json: {}) -> str: def set_email_address(actor_json: {}, email_address: str) -> None: """Sets the email address for the given actor """ - not_email_address = False + not_email_address: bool = False if '@' not in email_address: not_email_address = True if '.' not in email_address: @@ -272,7 +272,7 @@ def set_deltachat_invite(actor_json: {}, invite_link: str, """Sets the deltachat invite link for the given actor """ invite_link = invite_link.strip() - not_url = False + not_url: bool = False if '.' not in invite_link: not_url = True if '://' not in invite_link: @@ -318,7 +318,7 @@ def set_deltachat_invite(actor_json: {}, invite_link: str, def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None: """Sets a PGP public key for the given actor """ - remove_key = False + remove_key: bool = False if not pgp_pub_key: remove_key = True else: @@ -389,7 +389,7 @@ def set_pgp_pub_key(actor_json: {}, pgp_pub_key: str) -> None: def set_pgp_fingerprint(actor_json: {}, fingerprint: str) -> None: """Sets a PGP fingerprint for the given actor """ - remove_fingerprint = False + remove_fingerprint: bool = False if not fingerprint: remove_fingerprint = True else: @@ -467,7 +467,7 @@ def extract_pgp_public_key(content: str) -> str: if '\n' not in content: return None lines_list = content.split('\n') - extracting = False + extracting: bool = False public_key = '' for line in lines_list: if not extracting: @@ -829,8 +829,8 @@ def pgp_public_key_upload(base_dir: str, session, 'Content-type': 'application/json', 'Authorization': auth_header } - quiet = not debug - tries = 0 + quiet: bool = not debug + tries: int = 0 while tries < 4: post_result = \ post_json(http_prefix, domain_full, diff --git a/poison.py b/poison.py index c0e3c0ae7..0d8411c67 100644 --- a/poison.py +++ b/poison.py @@ -2041,7 +2041,7 @@ def html_poisoned(dictionary: [], twograms: {}) -> str: prev_wrd = '' for word_index in range(no_of_words): wrd = '' - pair_found = False + pair_found: bool = False if prev_wrd: # common word sequences if twograms.get(prev_wrd) and \ diff --git a/posts.py b/posts.py index a201f2fc5..98001af58 100644 --- a/posts.py +++ b/posts.py @@ -188,7 +188,7 @@ def no_of_followers_on_domain(base_dir: str, handle: str, if not os.path.isfile(filename): return 0 - ctr = 0 + ctr: int = 0 try: with open(filename, 'r', encoding='utf-8') as fp_followers: for follower_handle in fp_followers: @@ -363,7 +363,7 @@ def get_person_box(signing_priv_key_pem: str, origin_domain: str, system_language: str, mitm_servers: []) -> (str, str, str, str, str, str, str, bool): - debug = False + debug: bool = False profile_str = 'https://www.w3.org/ns/activitystreams' as_header = { 'Accept': 'application/activity+json; profile="' + profile_str + '"' @@ -401,7 +401,7 @@ def get_person_box(signing_priv_key_pem: str, origin_domain: str, if not person_json: return None, None, None, None, None, None, None, None - is_group = False + is_group: bool = False if person_json.get('type'): if person_json['type'] == 'Group': is_group = True @@ -510,13 +510,13 @@ def _is_public_feed_post(item: {}, person_posts: {}, debug: bool) -> bool: this_item = item['object'] # check that this is a public post # #Public should appear in the "to" list - item_is_note = False + item_is_note: bool = False if item['type'] in ('Note', 'Event', 'Page'): item_is_note = True if isinstance(this_item, dict): if this_item.get('to'): - is_public = False + is_public: bool = False if isinstance(this_item['to'], list): for recipient in this_item['to']: if recipient.endswith('#Public') or \ @@ -534,7 +534,7 @@ def _is_public_feed_post(item: {}, person_posts: {}, debug: bool) -> bool: return False elif isinstance(this_item, str) or item_is_note: if item.get('to'): - is_public = False + is_public: bool = False if isinstance(item['to'], list): for recipient in item['to']: if recipient.endswith('#Public') or \ @@ -608,7 +608,7 @@ def _get_posts(session, outbox_url: str, max_posts: int, if debug: print('Returning the raw feed') result: list[dict] = [] - i = 0 + i: int = 0 user_feed = parse_user_feed(signing_priv_key_pem, session, outbox_url, as_header, project_version, http_prefix, @@ -633,7 +633,7 @@ def _get_posts(session, outbox_url: str, max_posts: int, if not user_feed: return person_posts - i = 0 + i: int = 0 for item in user_feed: if is_create_inside_announce(item): item = item['object'] @@ -666,11 +666,11 @@ def _get_posts(session, outbox_url: str, max_posts: int, content = content.replace(''', "'") mentions: list[str] = [] - emoji = {} - summary = '' - in_reply_to = '' + emoji: dict = {} + summary: str = '' + in_reply_to: str = '' attachment: list[list] = [] - sensitive = False + sensitive: bool = False if isinstance(this_item, dict): if this_item.get('tag'): for tag_item in this_item['tag']: @@ -743,7 +743,7 @@ def _get_posts(session, outbox_url: str, max_posts: int, if debug: print('url not permitted ' + url_str) - sensitive = False + sensitive: bool = False if this_item.get('sensitive'): sensitive = this_item['sensitive'] @@ -844,7 +844,7 @@ def get_post_domains(session, outbox_url: str, max_posts: int, debug: bool, post_domains = domain_list - i = 0 + i: int = 0 user_feed = parse_user_feed(signing_priv_key_pem, session, outbox_url, as_header, project_version, http_prefix, domain, @@ -917,7 +917,7 @@ def _get_posts_for_blocked_domains(base_dir: str, blocked_posts = {} - i = 0 + i: int = 0 user_feed = parse_user_feed(signing_priv_key_pem, session, outbox_url, as_header, project_version, http_prefix, domain, @@ -1746,7 +1746,7 @@ def _create_post_mentions(cc_url: str, new_post: {}, to_cc = new_post['object']['cc'] if len(to_recipients) != 1: return - to_public_recipient = False + to_public_recipient: bool = False if to_recipients[0].endswith('#Public') or \ to_recipients[0] == 'as:Public' or \ to_recipients[0] == 'Public': @@ -1914,7 +1914,7 @@ def create_post_base(base_dir: str, local_actor_url(http_prefix, nickname, domain) + \ '/statuses/' + status_number - sensitive = False + sensitive: bool = False summary = None if subject: summary = remove_invalid_chars(valid_content_warning(subject)) @@ -1934,7 +1934,7 @@ def create_post_base(base_dir: str, if mention not in to_cc: to_cc.append(mention) - is_public = False + is_public: bool = False for recipient in to_recipients: if recipient.endswith('#Public') or \ recipient == 'as:Public' or \ @@ -2152,7 +2152,7 @@ def _post_is_addressed_to_followers(nickname: str, domain: str, port: int, local_actor_url(http_prefix, nickname, domain_full) + '/followers' # does the followers url exist in 'to' or 'cc' lists? - addressed_to_followers = False + addressed_to_followers: bool = False if followers_url in to_list: addressed_to_followers = True elif followers_url in cc_list: @@ -2306,7 +2306,7 @@ def create_public_post(base_dir: str, """Public post """ domain_full = get_full_domain(domain, port) - is_moderation_report = False + is_moderation_report: bool = False event_uuid = None category = None join_mode = None @@ -2507,10 +2507,10 @@ def create_news_post(base_dir: str, languages_understood: [], translate: {}, buy_url: str, chat_url: str, session) -> {}: auto_cw_cache = {} - client_to_server = False + client_to_server: bool = False in_reply_to = None in_reply_to_atom_uri = None - schedule_post = False + schedule_post: bool = False event_date = None event_time = None event_end_time = None @@ -2558,10 +2558,10 @@ def create_question_post(base_dir: str, local_actor = local_actor_url(http_prefix, nickname, domain_full) buy_url = '' chat_url = '' - is_moderation_report = False - is_article = False + is_moderation_report: bool = False + is_article: bool = False in_reply_to = in_reply_to_atom_uri = None - schedule_post = False + schedule_post: bool = False event_date = event_time = location = event_uuid = category = None join_mode = end_date = end_time = event_category = None maximum_attendee_capacity = replies_moderation_option = None @@ -2637,8 +2637,8 @@ def create_unlisted_post(base_dir: str, """ domain_full = get_full_domain(domain, port) local_actor = local_actor_url(http_prefix, nickname, domain_full) - is_moderation_report = False - is_article = False + is_moderation_report: bool = False + is_article: bool = False event_uuid = category = join_mode = None maximum_attendee_capacity = None replies_moderation_option = None @@ -2701,8 +2701,8 @@ def create_followers_only_post(base_dir: str, """ domain_full = get_full_domain(domain, port) local_actor = local_actor_url(http_prefix, nickname, domain_full) - is_moderation_report = False - is_article = False + is_moderation_report: bool = False + is_article: bool = False event_uuid = category = join_mode = None maximum_attendee_capacity = None replies_moderation_option = None @@ -2806,8 +2806,8 @@ def create_direct_message_post(base_dir: str, return None post_to = None post_cc = None - is_moderation_report = False - is_article = False + is_moderation_report: bool = False + is_article: bool = False event_uuid = category = join_mode = None maximum_attendee_capacity = None replies_moderation_option = None @@ -2931,9 +2931,9 @@ def create_report_post(base_dir: str, buy_url = '' chat_url = '' is_moderation_report = True - is_article = False + is_article: bool = False in_reply_to = in_reply_to_atom_uri = None - schedule_post = False + schedule_post: bool = False event_date = None event_time = None location = None @@ -3057,11 +3057,11 @@ def thread_send_post(session, post_json_str: str, federation_list: [], nickname: str, domain: str) -> None: """Sends a with retries """ - tries = 0 + tries: int = 0 send_interval_sec = 30 for _ in range(20): post_result = None - unauthorized = False + unauthorized: bool = False if debug: print('Getting post_json_string for ' + inbox_url) try: @@ -3083,7 +3083,7 @@ def thread_send_post(session, post_json_str: str, federation_list: [], if unauthorized: # try again with application/ld+json header post_result = None - unauthorized = False + unauthorized: bool = False if debug: print('Getting ld post_json_string for ' + inbox_url) try: @@ -3239,8 +3239,8 @@ def send_post(signing_priv_key_pem: str, project_version: str, return 5 # shared_inbox is optional - is_moderation_report = False - schedule_post = False + is_moderation_report: bool = False + schedule_post: bool = False event_date = event_time = location = None event_uuid = category = None join_mode = None @@ -3298,7 +3298,7 @@ def send_post(signing_priv_key_pem: str, project_version: str, post_path = inbox_url.split(to_domain, 1)[1] if not post_json_object.get('signature'): - json_copied = False + json_copied: bool = False try: signed_post_json_object = post_json_object.copy() json_copied = True @@ -3698,8 +3698,8 @@ def add_to_field(activity_type: str, post_json_object: {}, pprint(post_json_object) print('DEBUG: no "to" field when sending to named addresses 2') - is_same_type = False - to_field_added = False + is_same_type: bool = False + to_field_added: bool = False if post_json_object.get('object'): if isinstance(post_json_object['object'], str): if post_json_object.get('type'): @@ -3797,7 +3797,7 @@ def _send_to_named_addresses(server, session, session_onion, session_i2p, return if not post_json_object.get('object'): return - is_profile_update = False + is_profile_update: bool = False if has_object_dict(post_json_object): if _is_profile_update(post_json_object): # use the original object, which has a 'to' @@ -3878,7 +3878,7 @@ def _send_to_named_addresses(server, session, session_onion, session_i2p, # any particular account in terms of delivery time random.shuffle(recipients) # this is after the message has arrived at the server - client_to_server = False + client_to_server: bool = False for address in recipients: to_nickname = get_nickname_from_actor(address) if not to_nickname: @@ -4123,7 +4123,7 @@ def send_to_followers(server, session, session_onion, session_i2p, # print(str(grouped)) # this is after the message has arrived at the server - client_to_server = False + client_to_server: bool = False curr_proxy_type = None if domain.endswith('.onion'): @@ -4136,7 +4136,7 @@ def send_to_followers(server, session, session_onion, session_i2p, sending_start_time = date_utcnow() print('Sending post to followers begins ' + sending_start_time.strftime("%Y-%m-%dT%H:%M:%SZ")) - sending_ctr = 0 + sending_ctr: int = 0 # randomize the order of sending to instances randomized_instances: list[str] = [] @@ -4213,7 +4213,7 @@ def send_to_followers(server, session, session_onion, session_i2p, ' does not have a shared inbox') to_port = port - index = 0 + index: int = 0 to_domain = follower_handles[index].split('@')[1] if ':' in to_domain: to_port = get_port_from_domain(to_domain) @@ -4264,7 +4264,7 @@ def send_to_followers(server, session, session_onion, session_i2p, if with_shared_inbox: to_nickname = follower_handles[index].split('@')[0] - group_account = False + group_account: bool = False if to_nickname.startswith('!'): group_account = True to_nickname = to_nickname[1:] @@ -4306,7 +4306,7 @@ def send_to_followers(server, session, session_onion, session_i2p, print('Sending post to followers ' + handle) to_nickname = handle.split('@')[0] - group_account = False + group_account: bool = False if to_nickname.startswith('!'): group_account = True to_nickname = to_nickname[1:] @@ -4629,7 +4629,7 @@ def remove_post_interactions(post_json_object: {}, force: bool) -> bool: marketers and other surveillance-oriented organizations. Returns False if this is a private post """ - has_object = False + has_object: bool = False if has_object_dict(post_json_object): has_object = True if has_object: @@ -4763,8 +4763,8 @@ def _create_box_items(base_dir: str, index_filename = \ acct_dir(base_dir, timeline_nickname, original_domain) + \ '/' + index_box_name + '.index' - total_posts_count = 0 - posts_added_to_timeline = 0 + total_posts_count: int = 0 + posts_added_to_timeline: int = 0 if not os.path.isfile(index_filename): return total_posts_count, posts_added_to_timeline @@ -4781,7 +4781,7 @@ def _create_box_items(base_dir: str, prev_post_filename = None try: with open(index_filename, 'r', encoding='utf-8') as fp_index: - posts_added_to_timeline = 0 + posts_added_to_timeline: int = 0 while posts_added_to_timeline < items_per_page: post_filename = fp_index.readline() @@ -4923,7 +4923,7 @@ def _create_box_indexed(recent_posts_cache: {}, print('ERROR: invalid boxname ' + boxname) return None - unauthorized_premium = False + unauthorized_premium: bool = False if not authorized and boxname == 'outbox': unauthorized_premium = is_premium_account(base_dir, nickname, domain) @@ -5053,14 +5053,14 @@ def _create_box_indexed(recent_posts_cache: {}, for post_str in posts_in_box: # Check if the post has replies - has_replies = False + has_replies: bool = False if post_str.endswith(''): has_replies = True # remove the replies identifier post_str = post_str.replace('', '') # Check if the post was delivered via a third party - mitm = False + mitm: bool = False if post_str.endswith(''): mitm = True # remove the mitm identifier @@ -5114,7 +5114,7 @@ def _expire_announce_cache_for_person(base_dir: str, if not os.path.isdir(cache_dir): print('No cached announces for ' + nickname + '@' + domain) return 0 - expired_post_count = 0 + expired_post_count: int = 0 posts_in_cache = os.scandir(cache_dir) for cache_filename in posts_in_cache: cache_filename = cache_filename.name @@ -5143,7 +5143,7 @@ def _expire_conversations_for_person(base_dir: str, if not os.path.isdir(conv_dir): print('No conversations for ' + nickname + '@' + domain) return 0 - expired_post_count = 0 + expired_post_count: int = 0 posts_in_conv = os.scandir(conv_dir) for conv_filename in posts_in_conv: conv_filename = conv_filename.name @@ -5175,7 +5175,7 @@ def _expire_posts_cache_for_person(base_dir: str, if not os.path.isdir(cache_dir): print('No cached posts for ' + nickname + '@' + domain) return 0 - expired_post_count = 0 + expired_post_count: int = 0 posts_in_cache = os.scandir(cache_dir) for cache_filename in posts_in_cache: cache_filename = cache_filename.name @@ -5204,7 +5204,7 @@ def _novel_fields_for_person(nickname: str, domain: str, box_dir = create_person_dir(nickname, domain, base_dir, boxname) posts_in_box = os.scandir(box_dir) - posts_ctr = 0 + posts_ctr: int = 0 fields: list[str] = [] expected_fields = ( 'alsoKnownAs', @@ -5402,7 +5402,7 @@ def _expire_posts_for_person(http_prefix: str, nickname: str, domain: str, keep_dms: bool) -> int: """Removes posts older than some number of days """ - expired_post_count = 0 + expired_post_count: int = 0 if max_age_days <= 0: return expired_post_count @@ -5471,8 +5471,8 @@ def _expire_posts_for_person(http_prefix: str, nickname: str, domain: str, def get_post_expiry_keep_dms(base_dir: str, nickname: str, domain: str) -> int: """Returns true if dms should expire """ - keep_dms = True - handle = nickname + '@' + domain + keep_dms: bool = True + handle: str = nickname + '@' + domain expire_dms_filename = \ acct_handle_dir(base_dir, handle) + '/.expire_posts_dms' if os.path.isfile(expire_dms_filename): @@ -5504,7 +5504,7 @@ def expire_posts(base_dir: str, http_prefix: str, recent_posts_cache: {}, debug: bool) -> int: """Expires posts for instance accounts """ - expired_post_count = 0 + expired_post_count: int = 0 dir_str = data_dir(base_dir) for _, dirs, _ in os.walk(dir_str): for handle in dirs: @@ -5586,7 +5586,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str, os.mkdir(archive_dir) box_dir = create_person_dir(nickname, domain, base_dir, boxname) posts_in_box = os.scandir(box_dir) - no_of_posts = 0 + no_of_posts: int = 0 for _ in posts_in_box: no_of_posts += 1 if no_of_posts <= max_posts_in_box: @@ -5599,7 +5599,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str, index_filename = \ acct_handle_dir(base_dir, handle) + '/' + boxname + '.index' if os.path.isfile(index_filename): - index_ctr = 0 + index_ctr: int = 0 # get the existing index entries as a string new_index = '' try: @@ -5623,9 +5623,9 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str, ext = '.' + ext_name posts_in_box = os.scandir(box_dir) edits_in_box_dict = {} - edits_ctr = 0 - edits_removed_ctr = 0 - edit_files_ctr = 0 + edits_ctr: int = 0 + edits_removed_ctr: int = 0 + edit_files_ctr: int = 0 for post_filename in posts_in_box: post_filename = post_filename.name if not post_filename.endswith(ext): @@ -5676,7 +5676,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str, edits_in_box_sorted = \ OrderedDict(sorted(edits_in_box_dict.items(), reverse=False)) - remove_edits_ctr = 0 + remove_edits_ctr: int = 0 for published_str, edit_filename in edits_in_box_sorted.items(): file_path = os.path.join(box_dir, edit_filename) if not os.path.isfile(file_path): @@ -5706,8 +5706,8 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str, print('Removed ' + str(remove_edits_ctr) + ' ' + boxname + ' ' + ext_name + ' for ' + nickname + '@' + domain) - posts_in_box_dict = {} - posts_ctr = 0 + posts_in_box_dict: dict = {} + posts_ctr: int = 0 posts_in_box = os.scandir(box_dir) for post_filename in posts_in_box: post_filename = post_filename.name @@ -5742,7 +5742,7 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str, # directory containing cached html posts post_cache_dir = box_dir.replace('/' + boxname, '/postcache') - remove_ctr = 0 + remove_ctr: int = 0 for published_str, post_filename in posts_in_box_sorted.items(): file_path = os.path.join(box_dir, post_filename) if not os.path.isfile(file_path): @@ -5834,10 +5834,10 @@ def get_public_posts_of_person(base_dir: str, nickname: str, domain: str, if debug: print('Session was not created') return - person_cache = {} - cached_webfingers = {} + person_cache: dict = {} + cached_webfingers: dict = {} federation_list: list[str] = [] - group_account = False + group_account: bool = False if nickname.startswith('!'): nickname = nickname[1:] group_account = True @@ -6116,13 +6116,13 @@ def check_domains(session, base_dir: str, mitm_servers: []) -> None: """Checks follower accounts for references to globally blocked domains """ - word_frequency = {} + word_frequency: dict = {} non_mutuals = _get_non_mutuals_of_person(base_dir, nickname, domain) if not non_mutuals: print('No non-mutual followers were found') return follower_warning_filename = data_dir(base_dir) + '/followerWarnings.txt' - update_follower_warnings = False + update_follower_warnings: bool = False follower_warning_str = '' if os.path.isfile(follower_warning_filename): follower_warning_str = \ @@ -6198,7 +6198,7 @@ def populate_replies_json(base_dir: str, nickname: str, domain: str, with open(post_replies_filename, 'r', encoding='utf-8') as fp_replies: for message_id in fp_replies: - reply_found = False + reply_found: bool = False # examine inbox and outbox for boxname in replies_boxes: message_id2 = remove_eol(message_id) @@ -6571,7 +6571,7 @@ def download_announce(session, base_dir: str, http_prefix: str, # Check the content of the announce convert_post_content_to_html(announced_json) content_str = announced_json['content'] - using_content_map = False + using_content_map: bool = False if 'contentMap' in announced_json: if announced_json['contentMap'].get(system_language): content_str = announced_json['contentMap'][system_language] @@ -6799,7 +6799,7 @@ def post_is_muted(base_dir: str, nickname: str, domain: str, post_dir + '/inbox/' + message_id.replace('/', '#') + '.json.muted' if os.path.isfile(mute_filename): return True - is_muted = False + is_muted: bool = False mute_filename = \ post_dir + '/outbox/' + \ message_id.replace('/', '#') + '.json.muted' @@ -7067,7 +7067,7 @@ def json_post_allows_comments(post_json_object: {}) -> bool: else: # capabilities exist but there is no reply field reply_control = 'noreply' - obj_dict_exists = False + obj_dict_exists: bool = False if has_object_dict(post_json_object): obj_dict_exists = True post_obj = post_json_object['object'] diff --git a/pyjsonld.py b/pyjsonld.py index 6d1680fa4..e94239f79 100644 --- a/pyjsonld.py +++ b/pyjsonld.py @@ -1497,7 +1497,7 @@ class JsonLdProcessor(object): # split N-Quad input into lines lines = re.split(eoln, input_) - line_number = 0 + line_number: int = 0 for line in lines: line_number += 1 @@ -1563,7 +1563,7 @@ class JsonLdProcessor(object): dataset[name] = [triple] # add triple if unique to its graph else: - unique = True + unique: bool = True triples = dataset[name] for t in dataset[name]: if JsonLdProcessor._compare_rdf_triples(t, triple): @@ -3250,8 +3250,8 @@ class JsonLdProcessor(object): return False # check ducktype - wildcard = True - matches_some = False + wildcard: bool = True + matches_some: bool = False for k, v in frame.items(): if _is_keyword(k): # skip non-@id and non-@type @@ -3505,9 +3505,9 @@ class JsonLdProcessor(object): path_namer_copy = copy.deepcopy(path_namer) # build adjacent path - path = '' - skipped = False - recurse = [] + path: str = '' + skipped: bool = False + recurse: list = [] for bnode in permutation: # use canonical name if available if namer.is_named(bnode): @@ -4370,10 +4370,10 @@ class UniqueNamer(object): :param prefix: the prefix to use (''). """ - self.prefix = prefix - self.counter = 0 - self.existing = {} - self.order = [] + self.prefix: str = prefix + self.counter: int = 0 + self.existing: dict = {} + self.order: list = [] """ Gets the new name for the given old name, where if no old name is @@ -4541,7 +4541,7 @@ def _validate_type_value(v): return # must be an array - is_valid = False + is_valid: bool = False if _is_array(v): # must contain only strings is_valid = True @@ -4617,7 +4617,7 @@ def _is_subject(v): # 1. It is an Object. # 2. It is not a @value, @set, or @list. # 3. It has more than 1 key OR any existing key is not @id. - rval = False + rval: bool = False if (_is_object(v) and '@value' not in v and '@set' not in v and '@list' not in v): rval = len(v) > 1 or '@id' not in v @@ -4678,7 +4678,7 @@ def _is_bnode(v): # 1. It is an Object. # 2. If it has an @id key its value begins with '_:'. # 3. It has no keys OR is not a @value, @set, or @list. - rval = False + rval: bool = False if _is_object(v): if '@id' in v: rval = v['@id'].startswith('_:') diff --git a/question.py b/question.py index 8ffab2cb8..9aa68e360 100644 --- a/question.py +++ b/question.py @@ -146,7 +146,7 @@ def question_update_votes(base_dir: str, nickname: str, domain: str, voters_filename) newlines: list[str] = [] - save_voters_file = False + save_voters_file: bool = False if lines: for vote_line in lines: if vote_line.startswith(actor_url + @@ -172,11 +172,11 @@ def question_update_votes(base_dir: str, nickname: str, domain: str, return None, None # update the vote counts - question_totals_changed = False + question_totals_changed: bool = False for possible_answer in question_json['object']['oneOf']: if not possible_answer.get('name'): continue - total_items = 0 + total_items: int = 0 lines: list[str] = \ load_list(voters_filename, 'EX: question_update_votes unable to read ' + diff --git a/quote.py b/quote.py index c7472d5c8..41707710d 100644 --- a/quote.py +++ b/quote.py @@ -25,7 +25,7 @@ def get_quote_toot_url(post_json_object: str) -> str: '_misskey_quote', 'quote' ) post_obj = post_json_object - obj_exists = False + obj_exists: bool = False if has_object_dict(post_json_object): post_obj = post_json_object['object'] obj_exists = True @@ -62,7 +62,7 @@ def get_quote_toot_url(post_json_object: str) -> str: if not isinstance(item, dict): continue if item.get('rel'): - mk_quote = False + mk_quote: bool = False if isinstance(item['rel'], list): for rel_str in item['rel']: if not isinstance(rel_str, str): diff --git a/reaction.py b/reaction.py index 729794c18..2f02007c0 100644 --- a/reaction.py +++ b/reaction.py @@ -111,7 +111,7 @@ def _reactionpost(recent_posts_cache: {}, reaction_post_nickname = None reaction_post_domain = None reaction_post_port = None - group_account = False + group_account: bool = False if actor_reaction: reaction_post_nickname = get_nickname_from_actor(actor_reaction) reaction_post_domain, reaction_post_port = \ @@ -492,7 +492,7 @@ def _update_common_reactions(base_dir: str, emoji_content: str) -> None: common_reactions_filename) if common_reactions: new_common_reactions: list[str] = [] - reaction_found = False + reaction_found: bool = False for line in common_reactions: if ' ' + emoji_content in line: if not reaction_found: @@ -737,10 +737,10 @@ def undo_reaction_collection_entry(recent_posts_cache: {}, return if not obj['reactions'].get('items'): return - total_items = 0 + total_items: int = 0 if obj['reactions'].get('totalItems'): total_items = obj['reactions']['totalItems'] - item_found = False + item_found: bool = False for like_item in obj['reactions']['items']: if not like_item.get('actor'): continue diff --git a/reading.py b/reading.py index 5d57fc155..bdaef7a95 100644 --- a/reading.py +++ b/reading.py @@ -565,15 +565,15 @@ def html_profile_book_list(base_dir: str, actor: str, no_of_books: int, reverse=True)) html_str = '
\n' html_str += '


' - info_shown = False + info_shown: bool = False accounts: list[str] = [] dir_str = data_dir(base_dir) @@ -397,7 +397,7 @@ def html_moderation_info(translate: {}, base_dir: str, break accounts.sort() - cols = 5 + cols: int = 5 if len(accounts) > 10: info_form += '
' + translate['Show Accounts'] info_form += '\n' @@ -409,7 +409,7 @@ def html_moderation_info(translate: {}, base_dir: str, info_form += ' \n' info_form += '\n' - col = 0 + col: int = 0 dir_str = data_dir(base_dir) for acct in accounts: acct_nickname = acct.split('@')[0] @@ -471,7 +471,7 @@ def html_moderation_info(translate: {}, base_dir: str, blocking_filename = dir_str + '/blocking.txt' if os.path.isfile(blocking_filename): blocking_reasons_filename = dir_str + '/blocking_reasons.txt' - blocking_reasons_exist = False + blocking_reasons_exist: bool = False if os.path.isfile(blocking_reasons_filename): blocking_reasons_exist = True blocked_lines: list[str] = \ diff --git a/webapp_person_options.py b/webapp_person_options.py index 06f3e3ca4..590820b96 100644 --- a/webapp_person_options.py +++ b/webapp_person_options.py @@ -189,8 +189,8 @@ def html_person_options(default_timeline: str, copyfile(dir_str + '/options-background.jpg', dir_str + '/options-background.jpg') - dormant = False - offline = False + dormant: bool = False + offline: bool = False if options_domain in sites_unavailable: offline = True follow_str = 'Follow' @@ -199,7 +199,7 @@ def html_person_options(default_timeline: str, block_str = 'Block' nickname = None options_nickname = None - follows_you = False + follows_you: bool = False if origin_path_str.startswith('/users/'): nickname = origin_path_str.split('/users/')[1] if '/' in nickname: @@ -372,7 +372,7 @@ def html_person_options(default_timeline: str, '

' + \ translate['Other accounts'] + ': ' - ctr = 0 + ctr: int = 0 if isinstance(also_known_as, list): for alt_actor in also_known_as: if alt_actor == options_actor: @@ -628,7 +628,7 @@ def html_person_options(default_timeline: str, options_str += checkbox_str # checkbox for permission to post to newswire - newswire_posts_permitted = False + newswire_posts_permitted: bool = False if options_domain_full == domain_full: admin_nickname = get_config_param(base_dir, 'admin') if (nickname == admin_nickname or diff --git a/webapp_post.py b/webapp_post.py index 07089ff0d..faf329724 100644 --- a/webapp_post.py +++ b/webapp_post.py @@ -608,7 +608,7 @@ def _get_post_from_recent_cache(session, if show_public_only: return None - try_cache = False + try_cache: bool = False bm_timeline = box_name in ('bookmarks', 'tlbookmarks') if store_to_cache or bm_timeline: try_cache = True @@ -3284,7 +3284,7 @@ def individual_post_as_html(signing_priv_key_pem: str, loc_str, loc_address) # does this look like a geolocation link? if resembles_url(loc_str): - bounding_box_degrees = 0.001 + bounding_box_degrees: float = 0.001 map_str = \ html_open_street_map(loc_str, bounding_box_degrees, @@ -3574,7 +3574,7 @@ def html_individual_post(recent_posts_cache: {}, max_recent_posts: int, follow_str += ' \n' post_str += follow_str + '

\n' - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True post_str += \ @@ -3621,7 +3621,7 @@ def html_individual_post(recent_posts_cache: {}, max_recent_posts: int, break post_json_object = load_json(post_filename) if post_json_object: - mitm = False + mitm: bool = False if os.path.isfile(post_filename.replace('.json', '') + '.mitm'): mitm = True @@ -3771,7 +3771,7 @@ def html_post_replies(recent_posts_cache: {}, max_recent_posts: int, """ replies_str: str = '' if replies_json.get('orderedItems'): - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True for item in replies_json['orderedItems']: @@ -3849,7 +3849,7 @@ def html_emoji_reaction_picker(recent_posts_cache: {}, max_recent_posts: int, block_nostr: {}) -> str: """Returns the emoji picker screen """ - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account diff --git a/webapp_profile.py b/webapp_profile.py index 77958700b..862a94109 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -185,7 +185,7 @@ def _valid_profile_preview_post(post_json_object: {}, """ if not isinstance(post_json_object, dict): return False, None - is_announced_feed_item = False + is_announced_feed_item: bool = False if is_create_inside_announce(post_json_object): is_announced_feed_item = True post_json_object = post_json_object['object'] @@ -277,10 +277,10 @@ def html_profile_after_search(authorized: bool, block_nostr: {}) -> str: """Show a profile page after a search for a fediverse address """ - http = False - gnunet = False - ipfs = False - ipns = False + http: bool = False + gnunet: bool = False + ipfs: bool = False + ipns: bool = False if http_prefix == 'http': http = True elif http_prefix == 'gnunet': @@ -338,7 +338,7 @@ def html_profile_after_search(authorized: bool, if os.path.isfile(base_dir + '/epicyon.css'): css_filename = base_dir + '/epicyon.css' - is_group = False + is_group: bool = False if profile_json.get('type'): if profile_json['type'] == 'Group': is_group = True @@ -541,7 +541,7 @@ def html_profile_after_search(authorized: bool, domain_full = get_full_domain(domain, port) - follow_is_permitted = True + follow_is_permitted: bool = True if not profile_json.get('followers'): # no followers collection specified within actor follow_is_permitted = False @@ -626,10 +626,10 @@ def html_profile_after_search(authorized: bool, if debug: print('DEBUG: no user feed in profile preview') else: - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True - i = 0 + i: int = 0 for item in user_feed: if not isinstance(item, dict): continue @@ -845,7 +845,7 @@ def _get_profile_header(base_dir: str, http_prefix: str, nickname: str, '

' + translate['Other accounts'] + ': ' actor = local_actor_url(http_prefix, nickname, domain_full) - ctr = 0 + ctr: int = 0 if isinstance(also_known_as, list): for alt_actor in also_known_as: if alt_actor == actor: @@ -1038,7 +1038,7 @@ def _get_profile_header_after_search(base_dir: str, other_accounts_html = \ '

' + translate['Other accounts'] + ': ' - ctr = 0 + ctr: int = 0 if isinstance(also_known_as, list): for alt_actor in also_known_as: if alt_actor == actor: @@ -1182,7 +1182,7 @@ def html_profile(signing_priv_key_pem: str, block_nostr: {}) -> str: """Show the profile page as html """ - show_moved_accounts = False + show_moved_accounts: bool = False if authorized: moved_accounts_filename = data_dir(base_dir) + '/actors_moved.txt' if os.path.isfile(moved_accounts_filename): @@ -1293,7 +1293,7 @@ def html_profile(signing_priv_key_pem: str, login_button: str = '' follow_approvals_section: str = '' - follow_approvals = False + follow_approvals: bool = False edit_profile_str: str = '' logout_str: str = '' actor = profile_json['id'] @@ -1665,7 +1665,7 @@ def html_profile(signing_priv_key_pem: str, # keyboard navigation user_path_str = '/users/' + nickname deft = default_timeline - is_group = False + is_group: bool = False followers_str = translate['Followers'] if premium: followers_str = translate['Fans'] @@ -1819,7 +1819,7 @@ def html_profile(signing_priv_key_pem: str, if selected == 'posts' and not premium: if hide_recent_posts.get(nickname): - max_profile_posts = 0 + max_profile_posts: int = 0 else: max_profile_posts = \ get_max_profile_posts(base_dir, nickname, domain, 20) @@ -1977,11 +1977,11 @@ def _html_profile_posts(recent_posts_cache: {}, max_recent_posts: int, """ separator_str = html_post_separator(base_dir, None) profile_str: str = '' - max_items = max_profile_posts - ctr = 0 - curr_page = 1 - box_name = 'outbox' - minimize_all_images = False + max_items: int = max_profile_posts + ctr: int = 0 + curr_page: int = 1 + box_name: str = 'outbox' + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True shown_items: list[str] = [] @@ -2086,8 +2086,8 @@ def _html_profile_following(translate: {}, base_dir: str, http_prefix: str, for following_actor in following_json['orderedItems']: # is this a dormant followed account? - dormant = False - offline = False + dormant: bool = False + offline: bool = False following_domain, _ = get_domain_from_actor(following_actor) if authorized: @@ -2238,7 +2238,7 @@ def _html_edit_profile_graphic_design(base_dir: str, translate: {}) -> str: """ graphics_str = begin_edit_section(translate['Graphic Design']) - low_bandwidth = get_config_param(base_dir, 'lowBandwidth') + low_bandwidth: bool = get_config_param(base_dir, 'lowBandwidth') if not low_bandwidth: low_bandwidth = False graphics_str += _html_themes_dropdown(base_dir, translate) @@ -2332,13 +2332,13 @@ def _html_edit_profile_instance(base_dir: str, translate: {}, translate['Instance Logo'] + '' + \ '
\n
\n' - public_replies_unlisted = False + public_replies_unlisted: bool = False if get_config_param(base_dir, "publicRepliesUnlisted") is True: public_replies_unlisted = True instance_str += \ edit_check_box(translate['Public replies default to unlisted scope'], 'publicRepliesUnlisted', public_replies_unlisted) - registrations_open = False + registrations_open: bool = False if get_config_param(base_dir, "registration") == 'open': registrations_open = True instance_str += \ @@ -2347,7 +2347,7 @@ def _html_edit_profile_instance(base_dir: str, translate: {}, if registrations_open: remaining_config_exists = \ get_config_param(base_dir, 'registrationsRemaining') - registrations_remaining = 0 + registrations_remaining: int = 0 if remaining_config_exists is not None: registrations_remaining = int(remaining_config_exists) instance_str += \ @@ -2908,7 +2908,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, idx = 'Block military instances' if translate.get(idx): name = translate[idx] - block_mil = False + block_mil: bool = False if block_military.get(nickname): block_mil = block_military[nickname] edit_profile_form += \ @@ -2917,7 +2917,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, idx = 'Block government instances' if translate.get(idx): name = translate[idx] - block_gov = False + block_gov: bool = False if block_government.get(nickname): block_gov = block_government[nickname] edit_profile_form += \ @@ -2926,7 +2926,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, idx = 'Block BlueSky bridges' if translate.get(idx): name = translate[idx] - block_bsky = False + block_bsky: bool = False if block_bluesky.get(nickname): block_bsky = block_bluesky[nickname] edit_profile_form += \ @@ -2935,7 +2935,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, idx = 'Block Nostr bridges' if translate.get(idx): name = translate[idx] - blocknostr = False + blocknostr: bool = False if block_nostr.get(nickname): blocknostr = block_nostr[nickname] edit_profile_form += \ @@ -2944,7 +2944,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, cw_lists_str: str = '' for name, list_json in cw_lists.items(): variablename = get_cw_list_variable(name) - list_is_enabled = False + list_is_enabled: bool = False if lists_enabled: if name in lists_enabled: list_is_enabled = True @@ -3296,7 +3296,7 @@ def _html_edit_profile_options(is_admin: bool, edit_profile_form += \ edit_check_box(bold_str, 'boldReading', bold_reading) - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True minimize_all_images_str = translate['Minimize all images'] @@ -3304,7 +3304,7 @@ def _html_edit_profile_options(is_admin: bool, edit_check_box(minimize_all_images_str, 'minimizeAllImages', minimize_all_images) - reverse = False + reverse: bool = False if nickname in reverse_sequence: reverse = True reverse_str = translate['Reverse timelines'] @@ -3420,7 +3420,7 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, also_known_as_str: str = '' if actor_json.get('alsoKnownAs'): also_known_as = actor_json['alsoKnownAs'] - ctr = 0 + ctr: int = 0 for alt_actor in also_known_as: if ctr > 0: also_known_as_str += ', ' @@ -3560,7 +3560,7 @@ def html_edit_profile(server, translate: {}, return '' domain_full = get_full_domain(domain, port) - bold_reading = False + bold_reading: bool = False if server.bold_reading.get(nickname): bold_reading = True @@ -3698,7 +3698,7 @@ def html_edit_profile(server, translate: {}, path.startswith('/users/' + str(admin_nickname) + '/'): graphics_str = _html_edit_profile_graphic_design(base_dir, translate) - is_admin = False + is_admin: bool = False if admin_nickname: if path.startswith('/users/' + admin_nickname + '/'): is_admin = True @@ -3761,32 +3761,32 @@ def html_edit_profile(server, translate: {}, featured_hashtags) # whether to show quote toots - show_quote_toots = False + show_quote_toots: bool = False if os.path.isfile(account_dir + '/.allowQuotes'): show_quote_toots = True # whether to show votes - show_vote_posts = True + show_vote_posts: bool = True if os.path.isfile(account_dir + '/.noVotes'): show_vote_posts = False # only show replies from followers - show_replies_followers = False + show_replies_followers: bool = False if os.path.isfile(account_dir + '/.repliesFromFollowersOnly'): show_replies_followers = True # only show replies from mutuals - show_replies_mutuals = False + show_replies_mutuals: bool = False if os.path.isfile(account_dir + '/.repliesFromMutualsOnly'): show_replies_mutuals = True # don't show follows on profile - hide_follows = False + hide_follows: bool = False if os.path.isfile(account_dir + '/.hideFollows'): hide_follows = True # don't show recent public posts on profile - hide_recent_posts = False + hide_recent_posts: bool = False if os.path.isfile(account_dir + '/.hideRecentPosts'): hide_recent_posts = True @@ -3795,19 +3795,19 @@ def html_edit_profile(server, translate: {}, # are boosts of replies permitted in the inbox? no_reply_boosts_filename = account_dir + '/.noReplyBoosts' - no_reply_boosts = False + no_reply_boosts: bool = False if os.path.isfile(no_reply_boosts_filename): no_reply_boosts = True # are seen posts permitted in timelines? no_seen_posts_filename = account_dir + '/.noSeenPosts' - no_seen_posts = False + no_seen_posts: bool = False if os.path.isfile(no_seen_posts_filename): no_seen_posts = True # is watermarking enabled? watermark_enabled_filename = account_dir + '/.watermarkEnabled' - watermark_enabled = False + watermark_enabled: bool = False if os.path.isfile(watermark_enabled_filename): watermark_enabled = True @@ -3951,7 +3951,7 @@ def _individual_follow_as_html(signing_priv_key_pem: str, avatar_url = follow_url + '/avatar.png' display_name = get_display_name(base_dir, follow_url, person_cache) - is_group = False + is_group: bool = False if not display_name: # lookup the correct webfinger for the follow_url follow_url_handle = follow_url_nickname + '@' + follow_url_domain_full diff --git a/webapp_question.py b/webapp_question.py index f512023a7..7e14c0f16 100644 --- a/webapp_question.py +++ b/webapp_question.py @@ -34,7 +34,7 @@ def insert_question(base_dir: str, translate: {}, votes_filename = \ acct_dir(base_dir, nickname, domain) + '/questions.txt' - show_question_results = False + show_question_results: bool = False if os.path.isfile(votes_filename): if text_in_file(message_id, votes_filename): show_question_results = True @@ -73,7 +73,7 @@ def insert_question(base_dir: str, translate: {}, continue if not question_option.get('replies'): continue - votes = 0 + votes: int = 0 try: votes = int(question_option['replies']['totalItems']) except BaseException: @@ -87,7 +87,7 @@ def insert_question(base_dir: str, translate: {}, continue if not question_option.get('replies'): continue - votes = 0 + votes: int = 0 try: votes = int(question_option['replies']['totalItems']) except BaseException: diff --git a/webapp_search.py b/webapp_search.py index 5a7d19b4f..c07769cb3 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -136,7 +136,7 @@ def html_search_emoji(translate: {}, base_dir: str, search_str: str, emoji_form += '

' + \ translate['No results'] + '
' - heading_shown = False + heading_shown: bool = False emoji_form += '
' msg_str1 = translate['Copy the text then paste it into your post'] msg_str2 = ': str: """Search results for shared items """ - curr_page = 1 - ctr = 0 + curr_page: int = 1 + ctr: int = 0 shared_items_form: str = '' search_str_lower = urllib.parse.unquote(search_str) search_str_lower = search_str_lower.lower().strip('\n').strip('\r') @@ -315,7 +315,7 @@ def html_search_shared_items(translate: {}, shared_items_form += \ '

' + \ '' + title_str + '

' - results_exist = False + results_exist: bool = False dir_str = data_dir(base_dir) for _, dirs, files in os.walk(dir_str): for handle in dirs: @@ -685,7 +685,7 @@ def html_skills_search(actor: str, translate: {}, base_dir: str, '
' else: skill_search_form += '
' - ctr = 0 + ctr: int = 0 for skill_match in results: skill_match_fields = skill_match.split(';') if len(skill_match_fields) != 4: @@ -818,7 +818,7 @@ def html_history_search(translate: {}, base_dir: str, end_index = no_of_box_filenames - 1 index = start_index - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True while index <= end_index: @@ -831,7 +831,7 @@ def html_history_search(translate: {}, base_dir: str, index += 1 continue show_individual_post_icons = True - allow_deletion = False + allow_deletion: bool = False # get the list of mutuals for the current account mutuals_list = get_mutuals_of_person(base_dir, nickname, domain) post_str = \ @@ -1060,19 +1060,19 @@ def html_hashtag_search(nickname: str, domain: str, port: int, if not is_public_post(post_json_object): index += 1 continue - show_individual_post_icons = False + show_individual_post_icons: bool = False if nickname: show_individual_post_icons = True - allow_deletion = False + allow_deletion: bool = False show_repeats = show_individual_post_icons show_icons = show_individual_post_icons - manually_approves_followers = False - show_public_only = False - store_to_sache = False - allow_downloads = True + manually_approves_followers: bool = False + show_public_only: bool = False + store_to_sache: bool = False + allow_downloads: bool = True avatar_url = None - show_avatar_options = True - minimize_all_images = False + show_avatar_options: bool = True + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -1244,7 +1244,7 @@ def html_hashtag_search_remote(nickname: str, domain: str, port: int, '" alt="' + translate['Page up'] + \ '">\n
\n' text_mode_separator = '

' - post_ctr = 0 + post_ctr: int = 0 for post_id in lines: print('Hashtag post_id ' + post_id) post_json_object = \ @@ -1284,17 +1284,17 @@ def html_hashtag_search_remote(nickname: str, domain: str, port: int, # render harmless any dangerous markup harmless_markup(post_json_object) - show_individual_post_icons = False - allow_deletion = False - show_repeats = show_individual_post_icons - show_icons = show_individual_post_icons - manually_approves_followers = False - show_public_only = False - store_to_sache = False - allow_downloads = True + show_individual_post_icons: bool = False + allow_deletion: bool = False + show_repeats: bool = show_individual_post_icons + show_icons: bool = show_individual_post_icons + manually_approves_followers: bool = False + show_public_only: bool = False + store_to_sache: bool = False + allow_downloads: bool = True avatar_url = None - show_avatar_options = True - minimize_all_images = False + show_avatar_options: bool = True + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True # get the list of mutuals for the current account @@ -1523,7 +1523,7 @@ def hashtag_search_json(nickname: str, domain: str, port: int, hashtag_json['prev'] = \ http_prefix + '://' + domain_full + '/tags/' + \ hashtag + '?page=' + str(page_number - 1) - page_items = 0 + page_items: int = 0 for index, _ in enumerate(lines): post_id = lines[index].strip('\n').strip('\r') if ' ' not in post_id: diff --git a/webapp_timeline.py b/webapp_timeline.py index 00f0834c3..6400d6287 100644 --- a/webapp_timeline.py +++ b/webapp_timeline.py @@ -489,14 +489,14 @@ def html_timeline(default_timeline: str, block_nostr: {}) -> str: """Show the timeline as html """ - enable_timing_log = False + enable_timing_log: bool = False timeline_start_time = time.time() account_dir = acct_dir(base_dir, nickname, domain) # should the calendar icon be highlighted? - new_calendar_event = False + new_calendar_event: bool = False calendar_image = 'calendar.png' calendar_path = '/calendar' calendar_file = account_dir + '/.newCalendar' @@ -514,7 +514,7 @@ def html_timeline(default_timeline: str, calendar_path = '/calendar' # should the DM button be highlighted? - new_dm = False + new_dm: bool = False dm_file = account_dir + '/.newDM' if os.path.isfile(dm_file): new_dm = True @@ -525,7 +525,7 @@ def html_timeline(default_timeline: str, print('EX: html_timeline unable to delete ' + dm_file) # should the Replies button be highlighted? - new_reply = False + new_reply: bool = False reply_file = account_dir + '/.newReply' if os.path.isfile(reply_file): new_reply = True @@ -536,7 +536,7 @@ def html_timeline(default_timeline: str, print('EX: html_timeline unable to delete ' + reply_file) # should the Shares button be highlighted? - new_share = False + new_share: bool = False new_share_file = account_dir + '/.newShare' if os.path.isfile(new_share_file): new_share = True @@ -547,7 +547,7 @@ def html_timeline(default_timeline: str, print('EX: html_timeline unable to delete ' + new_share_file) # should the Wanted button be highlighted? - new_wanted = False + new_wanted: bool = False new_wanted_file = account_dir + '/.newWanted' if os.path.isfile(new_wanted_file): new_wanted = True @@ -558,7 +558,7 @@ def html_timeline(default_timeline: str, print('EX: html_timeline unable to delete ' + new_wanted_file) # should the Moderation/reports button be highlighted? - new_report = False + new_report: bool = False new_report_file = account_dir + '/.newReport' if os.path.isfile(new_report_file): new_report = True @@ -569,7 +569,7 @@ def html_timeline(default_timeline: str, print('EX: html_timeline unable to delete ' + new_report_file) # show polls/votes? - show_vote_posts = True + show_vote_posts: bool = True show_vote_file = account_dir + '/.noVotes' if os.path.isfile(show_vote_file): show_vote_posts = False @@ -777,7 +777,7 @@ def html_timeline(default_timeline: str, _log_timeline_timing(enable_timing_log, timeline_start_time, box_name, '4') # if this is a news instance and we are viewing the news timeline - news_header = False + news_header: bool = False if default_timeline == 'tlfeatures' and box_name == 'tlfeatures': news_header = True @@ -998,14 +998,14 @@ def html_timeline(default_timeline: str, '\n \n' # show the posts - item_ctr = 0 + item_ctr: int = 0 if timeline_json: if 'orderedItems' not in timeline_json: print('ERROR: no orderedItems in timeline for ' + box_name + ' ' + str(timeline_json)) return '' - use_cache_only = False + use_cache_only: bool = False if box_name == 'inbox': use_cache_only = True @@ -1020,12 +1020,12 @@ def html_timeline(default_timeline: str, tl_str += '
' tl_str += '
\n' - minimize_all_images = False + minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True no_seen_posts_filename = account_dir + '/.noSeenPosts' - no_seen_posts = False + no_seen_posts: bool = False if os.path.isfile(no_seen_posts_filename): no_seen_posts = True @@ -1325,21 +1325,21 @@ def _html_shares_timeline(translate: {}, page_number: int, items_per_page: int, ' \n' separator_str = html_post_separator(base_dir, None) - ctr = 0 + ctr: int = 0 - is_admin_account = False + is_admin_account: bool = False if admin_actor and actor == admin_actor: is_admin_account = True - is_moderator_account = False + is_moderator_account: bool = False if is_moderator(base_dir, nickname): is_moderator_account = True for _, shared_item in shares_json.items(): - show_contact_button = False + show_contact_button: bool = False actor_url = get_actor_from_post(shared_item) if actor_url != actor: show_contact_button = True - show_remove_button = False + show_remove_button: bool = False if '___' + domain in shared_item['shareId']: if actor_url == actor or \ is_admin_account or is_moderator_account: @@ -1744,7 +1744,7 @@ def html_inbox_dms(default_timeline: str, """Show the DM timeline as html """ artist = is_artist(base_dir, nickname) - show_announces = False + show_announces: bool = False return html_timeline(default_timeline, recent_posts_cache, max_recent_posts, translate, page_number, diff --git a/webapp_utils.py b/webapp_utils.py index 3638a742b..83941ad46 100644 --- a/webapp_utils.py +++ b/webapp_utils.py @@ -324,7 +324,7 @@ def _set_actor_property_url(actor_json: {}, actor_json['attachment'].remove(property_found) prefixes = get_protocol_prefixes() - prefix_found = False + prefix_found: bool = False for prefix in prefixes: if url.startswith(prefix): prefix_found = True @@ -526,7 +526,7 @@ def shares_timeline_json(actor: str, page_number: int, items_per_page: int, continue # actor who owns this share owner = actor.split('/users/')[0] + '/users/' + account_nickname - ctr = 0 + ctr: int = 0 for item_id, item in shares_json.items(): # assign owner to the item item['actor'] = owner @@ -555,7 +555,7 @@ def shares_timeline_json(actor: str, page_number: int, items_per_page: int, shares_json = load_json(shares_filename) if not shares_json: continue - ctr = 0 + ctr: int = 0 for item_id, item in shares_json.items(): # assign owner to the item if '--shareditems--' not in item_id: @@ -583,7 +583,7 @@ def shares_timeline_json(actor: str, page_number: int, items_per_page: int, break # sort the shared items in descending order of publication date shares_json = OrderedDict(sorted(all_shares_json.items(), reverse=True)) - last_page = False + last_page: bool = False start_index = items_per_page * page_number max_index = len(shares_json.items()) if max_index < items_per_page: @@ -592,8 +592,8 @@ def shares_timeline_json(actor: str, page_number: int, items_per_page: int, last_page = True start_index = max_index - items_per_page start_index = max(start_index, 0) - ctr = 0 - result_json = {} + ctr: int = 0 + result_json: dict = {} for published, item in shares_json.items(): if ctr >= start_index + items_per_page: break @@ -652,7 +652,7 @@ def get_shares_collection(actor: str, page_number: int, items_per_page: int, def post_contains_public(post_json_object: {}) -> bool: """Does the given post contain #Public """ - contains_public = False + contains_public: bool = False if not post_json_object['object'].get('to'): return contains_public @@ -1110,7 +1110,7 @@ def load_individual_post_as_html_from_cache(base_dir: str, if not os.path.isfile(cached_post_filename): return post_html - tries = 0 + tries: int = 0 while tries < 3: post_html = \ load_string(cached_post_filename, @@ -1309,7 +1309,7 @@ def get_post_attachments_as_html(base_dir: str, attachment_dict += post_attachments - media_style_added = False + media_style_added: bool = False post_id = None if post_json_object['object'].get('id'): post_id = post_json_object['object']['id'] @@ -1479,7 +1479,7 @@ def get_post_attachments_as_html(base_dir: str, # display svg images if they have first been rendered harmless svg_harmless = True if 'svg' in media_type: - svg_harmless = False + svg_harmless: bool = False if '://' + domain_full + '/' in image_url: svg_harmless = True else: @@ -1556,7 +1556,7 @@ def get_post_attachments_as_html(base_dir: str, # optionally hide the image attributed_actor = None - minimize_images = False + minimize_images: bool = False if minimize_all_images: minimize_images = True if post_json_object['object'].get('attributedTo'): @@ -2059,7 +2059,7 @@ def html_search_result_share(base_dir: str, shared_item: {}, translate: {}, translate['Contact'] + '\n' # should the remove button be shown? - show_remove_button = False + show_remove_button: bool = False nickname = get_nickname_from_actor(actor) if not nickname: return '' @@ -2213,8 +2213,8 @@ def html_common_emoji(base_dir: str, no_of_emoji: int) -> str: 'EX: html_common_emoji unable to load file') if not common_emoji: return '' - line_ctr = 0 - ctr = 0 + line_ctr: int = 0 + ctr: int = 0 html_str: str = '' while ctr < no_of_emoji and line_ctr < len(common_emoji): name_initial = common_emoji[line_ctr].split(' ') diff --git a/webfinger.py b/webfinger.py index 4a6e4459b..9510810f7 100644 --- a/webfinger.py +++ b/webfinger.py @@ -34,7 +34,7 @@ from utils import is_yggdrasil_url def _parse_handle(handle: str) -> (str, str, bool): """Parses a handle and returns nickname and domain """ - group_account = False + group_account: bool = False if '.' not in handle: if not is_yggdrasil_url(handle): return None, None, False @@ -401,17 +401,17 @@ def webfinger_lookup(path: str, base_dir: str, handle = 'inbox@' + handle_domain # if this is a lookup for a handle using its onion domain # then swap the onion domain for the clearnet version - onionify = False + onionify: bool = False if onion_domain: if onion_domain in handle: handle = handle.replace(onion_domain, domain) onionify = True - i2pify = False + i2pify: bool = False if i2p_domain: if i2p_domain in handle: handle = handle.replace(i2p_domain, domain) i2pify = True - yggdrasilify = False + yggdrasilify: bool = False if yggdrasil_domain: if yggdrasil_domain in handle: handle = handle.replace(yggdrasil_domain, domain) @@ -447,7 +447,7 @@ def webfinger_lookup(path: str, base_dir: str, def _webfinger_update_avatar(wf_json: {}, actor_json: {}) -> bool: """Updates the avatar image link """ - found = False + found: bool = False url_str = get_url_from_post(actor_json['icon']['url']) avatar_url = remove_html(url_str) media_type = actor_json['icon']['mediaType'] @@ -492,7 +492,7 @@ def _webfinger_update_vcard(wf_json: {}, actor_json: {}) -> bool: def _webfinger_add_blog_link(wf_json: {}, actor_json: {}) -> bool: """Adds a blog link to webfinger if needed """ - found = False + found: bool = False if '/users/' in actor_json['id']: blog_url = \ actor_json['id'].split('/users/')[0] + '/blog/' + \ @@ -527,7 +527,7 @@ def _webfinger_update_from_profile(wf_json: {}, actor_json: {}) -> bool: if not actor_json.get('attachment'): return False - changed = False + changed: bool = False webfinger_property_name = { "xmpp": "xmpp", @@ -556,7 +556,7 @@ def _webfinger_update_from_profile(wf_json: {}, actor_json: {}) -> bool: if not name_value: continue property_name = name_value.lower() - found = False + found: bool = False for name, alias in webfinger_property_name.items(): if name == property_name: if alias in aliases_not_found: @@ -578,8 +578,8 @@ def _webfinger_update_from_profile(wf_json: {}, actor_json: {}) -> bool: if '://' in new_value: new_value = new_value.split('://')[1] - alias_index = 0 - found = False + alias_index: int = 0 + found: bool = False for alias in wf_json['aliases']: if alias.startswith(webfinger_property_name[property_name] + ':'): found = True @@ -628,9 +628,9 @@ def webfinger_update(base_dir: str, nickname: str, domain: str, return filename = base_dir + wf_subdir + '/' + handle + '.json' - onionify = False - i2pify = False - yggdrasilify = False + onionify: bool = False + i2pify: bool = False + yggdrasilify: bool = False if onion_domain: if onion_domain in handle: handle = handle.replace(onion_domain, domain) diff --git a/website.py b/website.py index d80b74efc..ccb6f2c72 100644 --- a/website.py +++ b/website.py @@ -45,7 +45,7 @@ def get_website(actor_json: {}, translate: {}) -> str: name_value = property_value['schema:name'] if not name_value: continue - found = False + found: bool = False name_value_lower = name_value.lower() if name_value_lower.endswith(' ' + website_str) or \ name_value_lower.endswith(' homepage'): @@ -126,7 +126,7 @@ def set_website(actor_json: {}, website_url: str, translate: {}) -> None: """Sets a web address """ website_url = website_url.strip() - not_url = False + not_url: bool = False if '.' not in website_url: not_url = True if '://' not in website_url: @@ -173,7 +173,7 @@ def set_gemini_link(actor_json: {}, gemini_link: str) -> None: """Sets a gemini link """ gemini_link = gemini_link.strip() - not_link = False + not_link: bool = False if '.' not in gemini_link: not_link = True if '://' not in gemini_link: diff --git a/xmpp.py b/xmpp.py index c31861523..d7ff7073f 100644 --- a/xmpp.py +++ b/xmpp.py @@ -63,7 +63,7 @@ def get_xmpp_address(actor_json: {}) -> str: def set_xmpp_address(actor_json: {}, xmpp_address: str) -> None: """Sets an xmpp address for the given actor """ - not_xmpp_address = False + not_xmpp_address: bool = False if '@' not in xmpp_address: not_xmpp_address = True if '.' not in xmpp_address: