Variable types

main
bashrc 2026-04-28 14:04:50 +01:00
parent 0e8c586bfd
commit 39d9122081
118 changed files with 1493 additions and 1477 deletions

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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):

20
blog.py
View File

@ -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 += '<article><h1><a href="' + message_link + '">' + \
@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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'):

View File

@ -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:

24
city.py
View File

@ -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]

View File

@ -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 '</blockquote>' not in content:
return content
ctr = 1
found = True
found: bool = True
while found:
prefix = content.split('<blockquote>', ctr)[0] + '<blockquote>'
quoted_str = content.split('<blockquote>', ctr)[1]
@ -202,7 +202,7 @@ def html_replace_inline_quotes(content: str) -> str:
if '<p class="quote-inline">' not in content:
return content
sections = content.split('<p class="quote-inline">')
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 '&quot;' in new_content:
open_quote = True
open_quote: bool = True
content = new_content
new_content: str = ''
ctr = 0
sections = content.split('&quot;')
ctr: int = 0
sections: list = content.split('&quot;')
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 + "</span></a></span>"
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 '<a href' not in content:
return content
sections = content.split('<a href')
ctr = 0
remove_strings = []
sections: list = content.split('<a href')
ctr: int = 0
remove_strings: list = []
for section in sections:
if ctr == 0:
ctr = 1
@ -1157,11 +1157,11 @@ def remove_long_words(content: str, max_word_length: int,
content = replace_content_duplicates(content)
content = _remove_truncated_link(content)
non_html_list = False
non_html_list: bool = False
if '\n\n' in content and '<p>' not in content:
content = '<p>' + content.replace('\n\n', '</p> <p>') + '</p>'
non_html_list = True
non_html_list2 = False
non_html_list2: bool = False
if '\n' in content and '<p>' not in content:
content = '<p>' + content.replace('\n', '</p> <p>') + '</p>'
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 '<p>' in text:
text = text.replace('</p>', '\n').replace('<p>', '')
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('<p>')
changed: bool = False
paragraphs: list = content.split('<p>')
for text_html in paragraphs:
if '</p>' not in text_html:
continue
@ -2413,7 +2413,7 @@ def format_mixed_right_to_left(content: str,
prev_distilled = distilled
distilled = distilled.replace('<br><br><br>', '<br><br>')
paragraphs = distilled.split('<br><br>')
ctr = 0
ctr: int = 0
for text_html in paragraphs:
ctr += 1
if ctr < len(paragraphs):

View File

@ -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)

View File

@ -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,

View File

@ -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'):

View File

@ -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

178
daemon.py
View File

@ -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):

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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 = \

View File

@ -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 = \

View File

@ -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 ' + \

View File

@ -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:

View File

@ -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 = \

View File

@ -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 = \

View File

@ -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

View File

@ -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 = \

View File

@ -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'):

View File

@ -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):

View File

@ -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 + '='

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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:

View File

@ -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])

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

4
git.py
View File

@ -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() == '---':

View File

@ -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:

View File

@ -11,7 +11,7 @@ import time
def write2(self, msg) -> bool:
tries = 0
tries: int = 0
while tries < 5:
try:
self.wfile.write(msg)

View File

@ -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

View File

@ -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

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -204,9 +204,9 @@ def get_links_from_content(content: str) -> {}:
"""
if '<a href' not in content:
return {}
sections = content.split('<a href')
first = True
links = {}
sections: list = content.split('<a href')
first: bool = True
links: dict = {}
for subsection in sections:
if first:
first = False

View File

@ -110,7 +110,7 @@ def _create_like(recent_posts_cache: {},
liked_post_nickname = None
liked_post_domain = None
liked_post_port = None
group_account = False
group_account: bool = False
if actor_liked:
liked_post_nickname = get_nickname_from_actor(actor_liked)
liked_post_domain, liked_post_port = get_domain_from_actor(actor_liked)
@ -572,10 +572,10 @@ def undo_likes_collection_entry(recent_posts_cache: {},
return
if not obj['likes'].get('items'):
return
total_items = 0
total_items: int = 0
if obj['likes'].get('totalItems'):
total_items = obj['likes']['totalItems']
item_found = False
item_found: bool = False
for like_item in obj['likes']['items']:
if not like_item.get('actor'):
continue

View File

@ -200,12 +200,12 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
except OSError:
print('EX: manual_approve_follow_request unable to read ' +
approve_follows_filename)
exists = False
exists: bool = False
approve_handle_full = approve_handle
if approve_handle in approve_follows_str:
exists = True
elif '@' in approve_handle:
group_account = False
group_account: bool = False
if approve_handle.startswith('!'):
group_account = True
req_nick = approve_handle.split('@')[0].replace('!', '')
@ -237,7 +237,7 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
try:
with open(approve_follows_filename + '.new', 'w+',
encoding='utf-8') as fp_approve_new:
update_approved_followers = False
update_approved_followers: bool = False
follow_activity_filename = None
with open(approve_follows_filename, 'r',
encoding='utf-8') as fp_approve:

14
maps.py
View File

@ -252,7 +252,7 @@ def get_location_from_post(post_json_object: {}) -> 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'

View File

@ -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 '<code>' 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 '<code>' 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 = {
"&": "&amp;",
'"': "&quot;",
@ -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": '#####',

View File

@ -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:

View File

@ -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')

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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('<podcast:')
ctr = 0
pod_lines: list = xml_item.split('<podcast:')
ctr: int = 0
for pod_line in pod_lines:
if ctr == 0 or '>' 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 '<podcast:alternateEnclosure ' in rss_item:
enclosures = rss_item.split('<podcast:alternateEnclosure ')
ctr = 0
enclosures: list = rss_item.split('<podcast:alternateEnclosure ')
ctr: int = 0
for enclosure in enclosures:
if ctr == 0:
ctr += 1
@ -758,7 +758,7 @@ def get_link_from_rss_item(rss_item: str,
if 'uri="' not in enclosure:
continue
uris = enclosure.split('uri="')
ctr2 = 0
ctr2: int = 0
for uri in uris:
if ctr2 == 0:
ctr2 += 1
@ -830,7 +830,7 @@ def _xml2str_to_dict(base_dir: str, domain: str, xml_str: str,
"""
if '<item>' not in xml_str:
return {}
result = {}
result: dict = {}
# is this an rss feed containing hashtag categories?
if '<title>#categories</title>' 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('<item>')
post_ctr = 0
max_bytes = max_feed_item_size_kb * 1024
first_item = True
rss_items: list = xml_str.split('<item>')
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 = '<item'
if item_str not in xml_str:
return {}
result = {}
result: dict = {}
# is this an rss feed containing hashtag categories?
if '<title>#categories</title>' 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 '<entry>' not in xml_str:
return {}
result = {}
atom_items = xml_str.split('<entry>')
post_ctr = 0
max_bytes = max_feed_item_size_kb * 1024
first_item = True
result: dict = {}
atom_items: list = xml_str.split('<entry>')
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('</activity:object>')[0])
obj_str = remove_script(obj_str, None, None, None)
sections = obj_str.split('<link ')
ctr = 0
ctr: int = 0
for section_str in sections:
if ctr == 0:
ctr = 1
@ -1242,8 +1242,8 @@ def _json_feed_v1to_dict(base_dir: str, xml_str: str,
return {}
if not isinstance(feed_json['items'], list):
return {}
post_ctr = 0
result = {}
post_ctr: int = 0
result: dict = {}
for json_feed_item in feed_json['items']:
if not json_feed_item:
continue
@ -1350,11 +1350,11 @@ def _atom_feed_yt_to_dict(base_dir: str, xml_str: str,
return {}
if is_blocked_domain(base_dir, 'www.youtube.com', None, None):
return {}
result = {}
result: dict = {}
atom_items = xml_str.split('<entry>')
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

View File

@ -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

View File

@ -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

16
pgp.py
View File

@ -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,

View File

@ -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 \

162
posts.py
View File

@ -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('&apos;', "'")
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('<hasReplies>'):
has_replies = True
# remove the replies identifier
post_str = post_str.replace('<hasReplies>', '')
# Check if the post was delivered via a third party
mitm = False
mitm: bool = False
if post_str.endswith('<postmitm>'):
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']

View File

@ -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 ('<prefix><counter>').
"""
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('_:')

View File

@ -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 ' +

View File

@ -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):

View File

@ -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

View File

@ -565,15 +565,15 @@ def html_profile_book_list(base_dir: str, actor: str, no_of_books: int,
reverse=True))
html_str = '<div class="book_list_section">\n'
html_str += ' <ul class="book_list">\n'
ctr = 0
ctr: int = 0
for published_time_sec, book_url in recent_books_json.items():
if not reader_books_json.get(book_url):
continue
book_rating = None
book_wanted = False
book_reading = False
book_finished = False
book_event_type = ''
book_wanted: bool = False
book_reading: bool = False
book_finished: bool = False
book_event_type: str = ''
book_image_url = None
for event_type in ('want', 'finished', 'rated'):
if not reader_books_json[book_url].get(event_type):

View File

@ -52,7 +52,7 @@ def get_moved_accounts(base_dir: str, nickname: str, domain: str,
follow_str = ''
follow_list = follow_str.split('\n')
ctr = 0
ctr: int = 0
for line in refollow_list:
if ' ' not in line:
continue
@ -76,14 +76,14 @@ def get_moved_feed(base_dir: str, domain: str, port: int, path: str,
"""
# Don't show moved accounts to non-authorized viewers
if not authorized:
follows_per_page = 0
follows_per_page: int = 0
if '/moved' not in path:
return None
if '?page=' not in path:
path = path.replace('/moved', '/moved?page=true')
# handle page numbers
header_only = True
header_only: bool = True
page_number = None
if '?page=' in path:
page_number = path.split('?page=')[1]
@ -160,9 +160,9 @@ def get_moved_feed(base_dir: str, domain: str, port: int, path: str,
handle_domain = domain
handle_domain = remove_domain_port(handle_domain)
curr_page = 1
page_ctr = 0
total_ctr = 0
curr_page: int = 1
page_ctr: int = 0
total_ctr: int = 0
for handle, _ in lines.items():
# nickname@domain
page_ctr += 1
@ -186,7 +186,7 @@ def get_moved_feed(base_dir: str, domain: str, port: int, path: str,
if url:
following['orderedItems'].append(url)
if page_ctr >= follows_per_page:
page_ctr = 0
page_ctr: int = 0
curr_page += 1
following['totalItems'] = total_ctr
last_page = 1
@ -211,8 +211,8 @@ def update_moved_actors(base_dir: str, debug: bool) -> None:
if debug:
print('Updating moved actors')
actors_dict = {}
ctr = 0
actors_dict: dict = {}
ctr: int = 0
for _, _, files in os.walk(actors_cache_dir):
for actor_str in files:
if not actor_str.endswith('.json'):
@ -264,8 +264,8 @@ def update_moved_actors(base_dir: str, debug: bool) -> None:
else:
print('No accounts are following')
moved_str = ''
ctr = 0
moved_str: str = ''
ctr: int = 0
for handle in handles_to_check:
if not actors_dict.get(handle):
continue
@ -345,7 +345,7 @@ def _get_inactive_accounts(base_dir: str, nickname: str, domain: str,
if follower_domain in sites_unavailable:
result.append(handle)
continue
found = False
found: bool = False
for http_prefix in ('https://', 'http://'):
for users_str in users_list:
actor = \
@ -395,7 +395,7 @@ def get_inactive_feed(base_dir: str, domain: str, port: int, path: str,
if '?page=' not in path:
path = path.replace('/inactive', '/inactive?page=true')
# handle page numbers
header_only = True
header_only: bool = True
page_number = None
if '?page=' in path:
page_number = path.split('?page=')[1]
@ -472,9 +472,9 @@ def get_inactive_feed(base_dir: str, domain: str, port: int, path: str,
handle_domain = domain
handle_domain = remove_domain_port(handle_domain)
curr_page = 1
page_ctr = 0
total_ctr = 0
curr_page: int = 1
page_ctr: int = 0
total_ctr: int = 0
for handle in lines:
# nickname@domain
page_ctr += 1

View File

@ -240,7 +240,7 @@ def set_role(base_dir: str, nickname: str, domain: str,
if not actor_json.get('hasOccupation'):
return False
roles_list = get_actor_roles_list(actor_json)
actor_changed = False
actor_changed: bool = False
if role:
# add the role
if role_files.get(role):

View File

@ -42,7 +42,7 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
schedule_dir = acct_handle_dir(base_dir, handle) + '/scheduled/'
index_lines: list[str] = []
delete_schedule_post = False
delete_schedule_post: bool = False
nickname = handle.split('@')[0]
shared_items_federated_domains = httpd.shared_items_federated_domains
shared_item_federation_tokens = httpd.shared_item_federation_tokens

View File

@ -123,7 +123,7 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str,
with open(post_filename, 'r', encoding='utf-8') as fp_post:
data = fp_post.read().lower()
not_found = False
not_found: bool = False
for keyword in search_words:
if keyword not in data:
not_found = True
@ -165,7 +165,7 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
following_list: list[str] = []
mutuals_list: list[str] = []
check_searchable_by = False
check_searchable_by: bool = False
if box_name == 'inbox':
check_searchable_by = True
# https://codeberg.org/fediverse/fep/
@ -185,7 +185,7 @@ def search_box_posts(base_dir: str, nickname: str, domain: str,
data = fp_post.read()
data_lower = data.lower()
not_found = False
not_found: bool = False
for keyword in search_words:
if keyword not in data_lower:
not_found = True

View File

@ -97,8 +97,8 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str,
# Get the json for the c2s post, not saving anything to file
# Note that base_dir is set to None
save_to_file = False
client_to_server = True
save_to_file: bool = False
client_to_server: bool = True
if to_domain.lower().endswith('public'):
to_person_id = 'https://www.w3.org/ns/activitystreams#Public'
cc_str = \
@ -121,8 +121,8 @@ def send_post_via_server(signing_priv_key_pem: str, project_version: str,
local_actor_url(http_prefix,
from_nickname, from_domain_full)
is_moderation_report = False
schedule_post = False
is_moderation_report: bool = False
schedule_post: bool = False
event_uuid = category = join_mode = None
maximum_attendee_capacity = None
replies_moderation_option = None

View File

@ -144,7 +144,7 @@ def _get_json_request(session, url: str, session_headers: {},
result = session.get(url, headers=session_headers,
params=session_params, timeout=timeout_sec,
allow_redirects=True)
mitm = False
mitm: bool = False
try:
mitm = detect_mitm(result)
except BaseException:
@ -270,8 +270,8 @@ def _get_json_signed(session, url: str, domain_full: str, session_headers: {},
print('Signed GET to_domain: ' + to_domain + ' ' + str(to_port))
print('Signed GET url: ' + url)
print('Signed GET http_prefix: ' + http_prefix)
message_str = ''
with_digest = False
message_str: str = ''
with_digest: bool = False
if to_domain_full + '/' in url:
path = '/' + url.split(to_domain_full + '/')[1]
else:
@ -294,7 +294,7 @@ def _get_json_signed(session, url: str, domain_full: str, session_headers: {},
if debug:
print('Signed GET session_headers ' + str(session_headers))
return_json = True
return_json: bool = True
if 'json' not in content_type:
return_json = False
return _get_json_request(session, url, session_headers,
@ -550,7 +550,7 @@ def site_is_verified(session, base_dir: str, http_prefix: str,
"""
verified_sites_filename = \
acct_dir(base_dir, nickname, domain) + '/verified_sites.txt'
verified_file_exists = False
verified_file_exists: bool = False
if os.path.isfile(verified_sites_filename):
verified_file_exists = True
if text_in_file(url + '\n', verified_sites_filename, True):

View File

@ -88,7 +88,7 @@ def _load_dfc_ids(base_dir: str, system_language: str,
if not product_types['@graph'][0].get('rdfs:label'):
print('@graph list entry has no rdfs:label')
return None
language_exists = False
language_exists: bool = False
for label in product_types['@graph'][0]['rdfs:label']:
if not label.get('@language'):
continue
@ -369,7 +369,7 @@ def add_share(base_dir: str,
# has an image for this share been uploaded?
image_url = None
move_image = False
move_image: bool = False
if not image_filename:
shares_image_filename = \
acct_dir(base_dir, nickname, domain) + '/upload'
@ -446,7 +446,7 @@ def expire_shares(base_dir: str, max_shares_on_profile: int,
nickname = account.split('@')[0]
domain = account.split('@')[1]
shares_list = get_shares_files_list()
expired_ctr = 0
expired_ctr: int = 0
for shares_file_type in shares_list:
ctr = \
_expire_shares_for_account(base_dir, nickname, domain,
@ -526,7 +526,7 @@ def get_shares_feed_for_person(base_dir: str,
if '/' + shares_file_type not in path:
return None
# handle page numbers
header_only = True
header_only: bool = True
page_number = None
if '?page=' in path:
page_number = path.split('?page=')[1]
@ -566,7 +566,7 @@ def get_shares_feed_for_person(base_dir: str,
shares_file_type + '.json'
if header_only:
no_of_shares = 0
no_of_shares: int = 0
if os.path.isfile(shares_filename):
shares_json = load_json(shares_filename)
if shares_json:
@ -606,9 +606,9 @@ def get_shares_feed_for_person(base_dir: str,
if not os.path.isfile(shares_filename):
return shares
curr_page = 1
page_ctr = 0
total_ctr = 0
curr_page: int = 1
page_ctr: int = 0
total_ctr: int = 0
shares_json = load_json(shares_filename)
if shares_json:
@ -1307,9 +1307,9 @@ def outbox_undo_share_upload(base_dir: str, nickname: str, domain: str,
def _shares_catalog_params(path: str) -> (bool, float, float, str):
"""Returns parameters when accessing the shares catalog
"""
today = False
min_price = 0
max_price = 9999999
today: bool = False
min_price: int = 0
max_price: int = 9999999
match_pattern = None
if '?' not in path:
return today, min_price, max_price, match_pattern
@ -1568,7 +1568,7 @@ def generate_shared_item_federation_tokens(shared_items_federated_domains: [],
if tokens_json is None:
tokens_json = {}
tokens_added = False
tokens_added: bool = False
for domain_full in shared_items_federated_domains:
if not tokens_json.get(domain_full):
tokens_json[domain_full] = ''
@ -1600,7 +1600,7 @@ def update_shared_item_federation_token(base_dir: str,
tokens_json = load_json(tokens_filename)
if tokens_json is None:
tokens_json = {}
update_required = False
update_required: bool = False
if tokens_json.get(token_domain_full):
if tokens_json[token_domain_full] != new_token:
update_required = True
@ -1620,7 +1620,7 @@ def merge_shared_item_tokens(base_dir: str, domain_full: str,
the tokens dict accordingly
"""
removals: list[str] = []
changed = False
changed: bool = False
for token_domain_full, _ in tokens_json.items():
if domain_full:
if token_domain_full.startswith(domain_full):
@ -1839,7 +1839,7 @@ def _generate_next_shares_token_update(base_dir: str,
if next_update_str.isdigit():
next_update_sec = int(next_update_str)
curr_time = get_current_time_int()
updated = False
updated: bool = False
if next_update_sec:
if curr_time > next_update_sec:
next_update_days = randint(min_days, max_days)
@ -2378,12 +2378,12 @@ def add_shares_to_actor(base_dir: str,
"""
if 'attachment' not in actor_json:
actor_json['attachment']: list[dict] = []
changed = False
changed: bool = False
# remove any existing ValueFlows items from attachment list
new_attachment: list[dict] = []
for attach_item in actor_json['attachment']:
is_proposal = False
is_proposal: bool = False
if _is_valueflows_attachment(attach_item):
changed = True
is_proposal = True

View File

@ -537,7 +537,7 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
if post_json_object['object'].get('id'):
post_id = remove_id_ending(post_json_object['object']['id'])
follow_requests_exist = False
follow_requests_exist: bool = False
follow_requests_list: list[str] = []
accounts_dir = acct_dir(base_dir, nickname, domain_full)
approve_follows_filename = accounts_dir + '/followrequests.txt'
@ -551,11 +551,11 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str,
for i, _ in enumerate(follows):
follows[i] = follows[i].strip()
follow_requests_list = follows
post_dm = False
post_dm: bool = False
dm_filename = accounts_dir + '/.newDM'
if os.path.isfile(dm_filename):
post_dm = True
post_reply = False
post_reply: bool = False
reply_filename = accounts_dir + '/.newReply'
if os.path.isfile(reply_filename):
post_reply = True

2
ssb.py
View File

@ -59,7 +59,7 @@ def get_ssb_address(actor_json: {}) -> str:
def set_ssb_address(actor_json: {}, ssb_address: str) -> None:
"""Sets an ssb address for the given actor
"""
not_ssb_address = False
not_ssb_address: bool = False
if not ssb_address.startswith('@'):
not_ssb_address = True
if '=.' not in ssb_address:

789
tests.py

File diff suppressed because it is too large Load Diff

View File

@ -282,7 +282,7 @@ def set_css_param(css: str, param: str, value: str) -> str:
if param.startswith('rgba('):
return css.replace(param, value)
# if the parameter begins with * then don't prepend --
once_only = False
once_only: bool = False
if param.startswith('*'):
if param.startswith('**'):
once_only = True
@ -815,7 +815,7 @@ def set_theme(base_dir: str, name: str, domain: str,
dyslexic_font: bool, designer_reset: bool) -> bool:
"""Sets the theme with the given name as the current theme
"""
result = False
result: bool = False
prev_theme_name = get_theme(base_dir)

View File

@ -19,7 +19,7 @@ class thread_with_trace(threading.Thread):
def __init__(self, *args, **keywords):
self.start_time = date_utcnow()
self.is_started = False
tries = 0
tries: int = 0
while tries < 3:
try:
self._args, self._keywords = args, keywords
@ -32,7 +32,7 @@ class thread_with_trace(threading.Thread):
tries += 1
def start(self):
tries = 0
tries: int = 0
while tries < 3:
try:
self.__run_backup = self.run
@ -95,13 +95,13 @@ def remove_dormant_threads(base_dir: str, threads_list: [], debug: bool,
if not threads_list:
return
timeout_secs = int(timeout_mins * 60)
dormant_threads = []
timeout_secs: int = int(timeout_mins * 60)
dormant_threads: list = []
curr_time = date_utcnow()
changed = False
changed: bool = False
# which threads are dormant?
no_of_active_threads = 0
no_of_active_threads: int = 0
for thrd in threads_list:
remove_thread = False
@ -133,7 +133,7 @@ def remove_dormant_threads(base_dir: str, threads_list: [], debug: bool,
' active threads out of ' + str(len(threads_list)))
# remove the dormant threads
dormant_ctr = 0
dormant_ctr: int = 0
for thrd in dormant_threads:
if debug:
print('DEBUG: Removing dormant thread ' + str(dormant_ctr))
@ -144,7 +144,7 @@ def remove_dormant_threads(base_dir: str, threads_list: [], debug: bool,
# start scheduled threads
if len(threads_list) < 10:
ctr = 0
ctr: int = 0
for thrd in threads_list:
if not thrd.is_started:
print('Starting new send thread ' + str(ctr))

View File

@ -122,12 +122,12 @@ def convert_torrent_to_note(base_dir: str, nickname: str, domain: str,
'url': media_url
}]
comments_enabled = True
comments_enabled: bool = True
if 'commentsEnabled' in post_json_object:
if isinstance(post_json_object['commentsEnabled'], bool):
comments_enabled = post_json_object['commentsEnabled']
sensitive = False
sensitive: bool = False
if 'sensitive' in post_json_object:
if isinstance(post_json_object['sensitive'], bool):
sensitive = post_json_object['sensitive']

2
tox.py
View File

@ -62,7 +62,7 @@ def get_tox_address(actor_json: {}) -> str:
def set_tox_address(actor_json: {}, tox_address: str) -> None:
"""Sets an tox address for the given actor
"""
not_tox_address = False
not_tox_address: bool = False
if len(tox_address) != 76:
not_tox_address = True

View File

@ -71,8 +71,8 @@ def uninvert_text(text: str) -> str:
'\u2234': '\u2235'
}
matches = 0
possible_result = ''
matches: int = 0
possible_result: str = ''
for ch_test in text:
ch_result = ch_test
for ch1, ch_inv in flip_table.items():
@ -176,7 +176,7 @@ def _standardize_text_range(text: str,
"""Convert any fancy characters within the given range into ordinary ones
"""
offset = ord(offset)
ctr = 0
ctr: int = 0
text = list(text)
while ctr < len(text):
val = ord(text[ctr])

View File

@ -285,7 +285,7 @@ def get_content_from_post(post_json_object: {}, system_language: str,
'contentMap' in this_post_json['object'])):
this_post_json = post_json_object['object']
map_dict = content_type + 'Map'
has_contentmap_dict = False
has_contentmap_dict: bool = False
if this_post_json.get(map_dict):
if isinstance(this_post_json[map_dict], dict):
has_contentmap_dict = True
@ -617,7 +617,7 @@ def remove_html(content: str) -> str:
"""
if '<' not in content:
return content
removing = False
removing: bool = False
replacements = {
'<a href': ' <a href',
'<q>': '"',
@ -954,7 +954,7 @@ def load_json_onionify(filename: str, domain: str, onion_domain: str,
if '/Actor@' in filename:
filename = filename.replace('/Actor@', '/inbox@')
json_object = None
tries = 0
tries: int = 0
while tries < 5:
data = load_string(filename,
'EX: load_json_onionify exception ' + filename)
@ -1142,7 +1142,7 @@ def html_tag_has_closing(tag_name: str, content: str) -> bool:
if '<' + tag_name not in content_lower:
return True
sections = content_lower.split('<' + tag_name)
ctr = 0
ctr: int = 0
end_tag = '</' + tag_name + '>'
for section in sections:
if ctr == 0:
@ -1665,7 +1665,7 @@ def follow_person(base_dir: str, nickname: str, domain: str,
def votes_on_newswire_item(status: []) -> int:
"""Returns the number of votes on a newswire item
"""
total_votes = 0
total_votes: int = 0
for line in status:
if 'vote:' in line:
total_votes += 1
@ -2040,7 +2040,7 @@ def _remove_post_id_from_tag_index(tag_index_filename: str,
def _delete_hashtags_on_post(base_dir: str, post_json_object: {}) -> None:
"""Removes hashtags when a post is deleted
"""
remove_hashtag_index = False
remove_hashtag_index: bool = False
if has_object_dict(post_json_object):
if post_json_object['object'].get('content'):
if '#' in post_json_object['object']['content']:
@ -2413,7 +2413,7 @@ def delete_post(base_dir: str, http_prefix: str,
# remove cached html version of the post
delete_cached_html(base_dir, nickname, domain, post_json_object)
has_object = False
has_object: bool = False
if post_json_object.get('object'):
has_object = True
@ -2590,7 +2590,7 @@ def valid_nickname(domain: str, nickname: str) -> bool:
def no_of_accounts(base_dir: str) -> bool:
"""Returns the number of accounts on the system
"""
account_ctr = 0
account_ctr: int = 0
dir_str = data_dir(base_dir)
for _, dirs, _ in os.walk(dir_str):
for account in dirs:
@ -2603,7 +2603,7 @@ def no_of_accounts(base_dir: str) -> bool:
def no_of_active_accounts_monthly(base_dir: str, months: int) -> bool:
"""Returns the number of accounts on the system this month
"""
account_ctr = 0
account_ctr: int = 0
curr_time = int(time.time())
month_seconds = int(60*60*24*30*months)
dir_str = data_dir(base_dir)
@ -2910,7 +2910,7 @@ def get_actor_property_url(actor_json: {}, property_name: str) -> str:
continue
property_value['value'] = property_value[prop_value_name].strip()
prefixes = get_protocol_prefixes()
prefix_found = False
prefix_found: bool = False
prop_value = remove_html(property_value[prop_value_name])
for prefix in prefixes:
if prop_value.startswith(prefix):
@ -3730,7 +3730,7 @@ def binary_is_image(filename: str, media_binary) -> bool:
if len(media_binary) < 13:
return False
filename_lower = filename.lower()
bin_is_image = False
bin_is_image: bool = False
if filename_lower.endswith('.jpeg') or filename_lower.endswith('jpg'):
if media_binary[6:10] in (b'JFIF', b'Exif'):
bin_is_image = True
@ -3764,7 +3764,7 @@ def binary_is_image(filename: str, media_binary) -> bool:
def get_status_count(base_dir: str) -> int:
"""Get the total number of posts
"""
status_ctr = 0
status_ctr: int = 0
accounts_dir = data_dir(base_dir)
for _, dirs, _ in os.walk(accounts_dir):
for acct in dirs:

View File

@ -130,7 +130,7 @@ def convert_video_to_note(base_dir: str, nickname: str, domain: str,
if isinstance(post_json_object['commentsEnabled'], bool):
comments_enabled = post_json_object['commentsEnabled']
sensitive = False
sensitive: bool = False
if 'sensitive' in post_json_object:
if isinstance(post_json_object['sensitive'], bool):
sensitive = post_json_object['sensitive']

View File

@ -192,13 +192,13 @@ def _html_calendar_day(person_cache: {}, translate: {},
start_time_str: str = ''
end_time_str: str = ''
event_description = None
event_language = system_language
event_language: str = system_language
event_place = None
event_address = None
post_id = None
sender_name: str = ''
sender_actor = None
event_is_public = False
event_is_public: bool = False
# get the time place and description
for evnt in event_post:
event_language = system_language
@ -243,7 +243,7 @@ def _html_calendar_day(person_cache: {}, translate: {},
if evnt.get('name'):
event_place = remove_html(evnt['name'])
if '://' in event_place:
bounding_box_degrees = 0.001
bounding_box_degrees: float = 0.001
event_map = \
html_open_street_map(event_place,
bounding_box_degrees,
@ -405,7 +405,7 @@ def html_calendar(person_cache: {}, translate: {},
day_number = None
year: int = default_year
actor = http_prefix + '://' + domain_full + path.replace('/calendar', '')
only_show_reminders = False
only_show_reminders: bool = False
if '?' in actor:
first = True
for part in actor.split('?'):
@ -604,7 +604,7 @@ def html_calendar(person_cache: {}, translate: {},
translate['Switch to timeline view']
nav_links[timeline_link_str] = cal_actor + '/' + default_timeline
day_of_month = 0
day_of_month: int = 0
dow = week_day_of_month_start(month_number, year)
for week_of_month in range(1, 7):
if day_of_month == days_in_month:
@ -618,7 +618,7 @@ def html_calendar(person_cache: {}, translate: {},
day_of_month += 1
is_today = False
is_today: bool = False
if year == curr_date.year:
if curr_date.month == month_number:
if day_of_month == curr_date.day:

View File

@ -57,7 +57,7 @@ def _get_left_column_shares(base_dir: str,
return []
links_list: list[str] = []
ctr = 0
ctr: int = 0
for _, item in shares_json.items():
sharedesc = item['displayName']
if '<' in sharedesc or '?' in sharedesc:
@ -100,7 +100,7 @@ def _get_left_column_wanted(base_dir: str,
return []
links_list: list[str] = []
ctr = 0
ctr: int = 0
for _, item in shares_json.items():
sharedesc = item['displayName']
if '<' in sharedesc or ';' in sharedesc:
@ -220,10 +220,10 @@ def get_left_column_content(base_dir: str, nickname: str, domain_full: str,
# html_str += '<br>'
# flag used not to show the first separator
first_separator_added = False
first_separator_added: bool = False
links_filename = data_dir(base_dir) + '/links.txt'
links_file_contains_entries = False
links_file_contains_entries: bool = False
links_list: list[str] = None
if os.path.isfile(links_filename):
links_list = \
@ -395,11 +395,11 @@ def html_links_mobile(base_dir: str,
# is the user a site editor?
if nickname == 'news':
editor = False
artist = False
editor: bool = False
artist: bool = False
else:
editor = is_editor(base_dir, nickname)
artist = is_artist(base_dir, nickname)
editor: bool = is_editor(base_dir, nickname)
artist: bool = is_artist(base_dir, nickname)
domain = remove_domain_port(domain_full)

View File

@ -303,7 +303,7 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
html_str += separator_str
if moderated_item and 'vote:' + nickname in item[2]:
total_votes_str: str = ''
total_votes = 0
total_votes: int = 0
if moderator:
total_votes = votes_on_newswire_item(item[2])
total_votes_str = \
@ -331,7 +331,7 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
html_str += date_shown + '</span></p>\n'
else:
total_votes_str: str = ''
total_votes = 0
total_votes: int = 0
if moderator:
if moderated_item:
total_votes = votes_on_newswire_item(item[2])
@ -449,7 +449,7 @@ def html_citations(base_dir: str, nickname: str, domain: str,
# list of newswire items
if newswire:
ctr = 0
ctr: int = 0
for date_str, item in newswire.items():
item[0] = remove_html(item[0]).strip()
if not item[0]:
@ -510,14 +510,14 @@ def html_newswire_mobile(base_dir: str, nickname: str,
css_filename = base_dir + '/epicyon.css'
if nickname == 'news':
editor = False
moderator = False
editor: bool = False
moderator: bool = False
else:
# is the user a moderator?
moderator = is_moderator(base_dir, nickname)
moderator: bool = is_moderator(base_dir, nickname)
# is the user a site editor?
editor = is_editor(base_dir, nickname)
editor: bool = is_editor(base_dir, nickname)
show_publish_button = editor

View File

@ -85,13 +85,13 @@ def html_confirm_delete(server,
html_header_with_external_style(css_filename, instance_title, None,
preload_images)
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
if server.bold_reading.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

Some files were not shown because too many files have changed in this diff Show More