Check return values for lists

main
bashrc 2026-04-27 19:13:18 +01:00
parent dabbba296d
commit fa12fe6b15
19 changed files with 139 additions and 62 deletions

View File

@ -609,6 +609,8 @@ def update_blocked_cache(base_dir: str,
blocked_lines = load_list(global_blocking_filename,
'EX: update_blocked_cache unable to read ' +
global_blocking_filename + ' [ex]')
if blocked_lines is None:
return blocked_cache_last_updated
# remove newlines
for index, _ in enumerate(blocked_lines):
blocked_lines[index] = remove_eol(blocked_lines[index])
@ -1600,6 +1602,8 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
load_list(following_filename,
'EX: set_broch_mode failed to read ' +
following_filename + ' [ex]')
if follow_list is None:
continue
for handle in follow_list:
if '@' not in handle:
continue

View File

@ -86,6 +86,8 @@ def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {},
lines: list[str] = \
load_list(post_filename,
'EX: failed to read blog ' + post_filename)
if lines is None:
return 0
for reply_post_id in lines:
reply_post_id = remove_eol(reply_post_id)
@ -157,6 +159,8 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {},
lines: list[str] = \
load_list(post_filename,
'EX: unable to read blog 4 ' + post_filename)
if lines is None:
return ''
if lines:
replies_str: str = ''

View File

@ -72,6 +72,8 @@ def create_initial_last_seen(base_dir: str, http_prefix: str) -> None:
load_list(following_filename,
'EX: create_initial_last_seen ' +
following_filename)
if following_handles is None:
continue
for handle in following_handles:
if '#' in handle:
continue
@ -242,6 +244,8 @@ def get_follower_domains(base_dir: str, nickname: str, domain: str) -> []:
lines: list[str] = \
load_list(followers_file,
'EX: get_follower_domains ' + followers_file)
if lines is None:
return []
domains_list: list[str] = []
for handle in lines:
@ -329,6 +333,8 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
lines: list[str] = \
load_list(filename,
'EX: unfollow_account ' + filename)
if lines is None:
return False
if lines:
try:
@ -409,6 +415,9 @@ def _get_no_of_follows(base_dir: str, nickname: str, domain: str,
lines: list[str] = \
load_list(filename,
'EX: _get_no_of_follows ' + filename)
if lines is None:
return False
if lines:
for line in lines:
if '#' in line:
@ -528,6 +537,9 @@ def get_following_feed(base_dir: str, domain: str, port: int, path: str,
lines: list[str] = \
load_list(filename,
'EX: get_following_feed ' + filename)
if lines is None:
return following
for line in lines:
if '#' not in line:
if '@' in line and not line.startswith('http'):
@ -612,6 +624,9 @@ def no_of_follow_requests(base_dir: str,
load_list(approve_follows_filename,
'EX: no_of_follow_requests ' +
approve_follows_filename)
if lines is None:
return 0
if lines:
if follow_type == "onion":
for file_line in lines:

View File

@ -50,6 +50,9 @@ def _meta_data_instance_v1(show_accounts: bool,
rules_lines = load_list(rules_filename,
'EX: _meta_data_instance_v1 unable to read ' +
rules_filename)
if rules_lines is None:
return {}
rule_ctr = 1
for line in rules_lines:
line = line.strip()

View File

@ -57,6 +57,9 @@ def _meta_data_instance_v2(show_accounts: bool,
rules_lines: list[str] = \
load_list(rules_filename,
'EX: _meta_data_instance_v2 unable to read rules')
if rules_lines is None:
return {}
rule_ctr = 1
for line in rules_lines:
line = line.strip()

View File

@ -43,6 +43,9 @@ def _move_following_handles_for_account(base_dir: str,
load_list(following_filename,
'EX: _move_following_handles_for_account unable to read ' +
following_filename)
if following_handles is None:
return ctr
for follow_handle in following_handles:
follow_handle = follow_handle.strip("\n").strip("\r")
ctr += \
@ -155,6 +158,8 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
load_list(following_filename,
'EX: _update_moved_handle unable to read ' +
following_filename)
if following_handles is None:
return ctr
moved_to_handle = moved_to_nickname + '@' + moved_to_domain_full
handle_lower = handle.lower()
@ -205,6 +210,8 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
load_list(followers_filename,
'EX: _update_moved_handle unable to read ' +
followers_filename)
if follower_handles is None:
return ctr
handle_lower = handle.lower()

View File

@ -401,6 +401,8 @@ def _newswire_hashtag_processing(base_dir: str, post_json_object: {},
load_list(rules_filename,
'EX: _newswire_hashtag_processing unable to read ' +
rules_filename)
if rules is None:
return True
domain_full = get_full_domain(domain, port)

View File

@ -1827,6 +1827,9 @@ def get_dict_from_newswire(session, base_dir: str, domain: str,
load_list(subscriptions_filename,
'EX: get_dict_from_newswire unable to read ' +
subscriptions_filename)
if rss_feed is None:
return {}
result = {}
for url in rss_feed:
url = url.strip()

View File

@ -1323,6 +1323,8 @@ def reenable_account(base_dir: str, nickname: str, domain: str) -> None:
load_list(suspended_filename,
'EX: reenable_account unable to read ' +
suspended_filename)
if lines is None:
return
try:
with open(suspended_filename, 'w+', encoding='utf-8') as fp_sus:
for suspended in lines:
@ -1376,6 +1378,8 @@ def suspend_account(base_dir: str, nickname: str, domain: str) -> None:
load_list(moderators_file,
'EX: suspend_account unable too read ' +
moderators_file)
if lines is None:
return
for moderator in lines:
if moderator.strip('\n').strip('\r') == nickname:
return
@ -1400,6 +1404,8 @@ def suspend_account(base_dir: str, nickname: str, domain: str) -> None:
load_list(suspended_filename,
'EX: suspend_account unable to read 2 ' +
suspended_filename)
if lines is None:
return
for suspended in lines:
if suspended.strip('\n').strip('\r') == nickname:
return
@ -1436,6 +1442,8 @@ def can_remove_post(base_dir: str,
load_list(moderators_file,
'EX: can_remove_post unable to read ' +
moderators_file)
if lines is None:
return False
for moderator in lines:
if domain_full + '/users/' + \
moderator.strip('\n') + '/' in post_id:
@ -1470,6 +1478,8 @@ def _remove_tags_for_nickname(base_dir: str, nickname: str,
load_list(tag_filename,
'EX: _remove_tags_for_nickname unable to read ' +
tag_filename)
if lines is None:
continue
try:
with open(tag_filename, 'w+', encoding='utf-8') as fp_tag:
for tagline in lines:
@ -1522,6 +1532,8 @@ def remove_account(base_dir: str, nickname: str,
lines: list[str] = \
load_list(moderators_file,
'EX: remove_account unable to read ' + moderators_file)
if lines is None:
return False
for moderator in lines:
if moderator.strip('\n') == nickname:
return False

View File

@ -2432,6 +2432,8 @@ def _append_citations_to_blog_post(base_dir: str,
load_list(citations_filename,
'EX: _append_citations_to_blog_post unable to read ' +
citations_filename)
if citations is None:
return
for line in citations:
if citations_separator not in line:
continue
@ -4527,6 +4529,7 @@ def create_moderation(base_dir: str, nickname: str, domain: str, port: int,
load_list(moderation_index_file,
'EX: create_moderation unable to read ' +
moderation_index_file)
box_header['totalItems'] = len(lines)
if header_only:
return box_header

View File

@ -147,17 +147,18 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
newlines: list[str] = []
save_voters_file = False
for vote_line in lines:
if vote_line.startswith(actor_url +
voters_file_separator):
new_vote_line = actor_url + \
voters_file_separator + reply_vote + '\n'
if vote_line == new_vote_line:
break
save_voters_file = True
newlines.append(new_vote_line)
else:
newlines.append(vote_line)
if lines:
for vote_line in lines:
if vote_line.startswith(actor_url +
voters_file_separator):
new_vote_line = actor_url + \
voters_file_separator + reply_vote + '\n'
if vote_line == new_vote_line:
break
save_voters_file = True
newlines.append(new_vote_line)
else:
newlines.append(vote_line)
if save_voters_file:
try:
with open(voters_filename, 'w+',
@ -180,10 +181,11 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
load_list(voters_filename,
'EX: question_update_votes unable to read ' +
voters_filename)
for vote_line in lines:
if vote_line.endswith(voters_file_separator +
possible_answer['name'] + '\n'):
total_items += 1
if lines:
for vote_line in lines:
if vote_line.endswith(voters_file_separator +
possible_answer['name'] + '\n'):
total_items += 1
if possible_answer['replies']['totalItems'] != total_items:
possible_answer['replies']['totalItems'] = total_items
question_totals_changed = True

View File

@ -60,6 +60,9 @@ def _add_role(base_dir: str, nickname: str, domain: str,
load_list(role_file,
'EX: _add_role, failed to read roles file ' + role_file)
if lines is None:
return
for role_nickname in lines:
role_nickname = role_nickname.strip('\n').strip('\r')
if role_nickname == nickname:
@ -97,6 +100,8 @@ def _remove_role(base_dir: str, nickname: str, role_filename: str) -> None:
lines: list[str] = \
load_list(role_file,
'EX: _remove_role, failed to read roles file ' + role_file)
if lines is None:
return
try:
with open(role_file, 'w+', encoding='utf-8') as fp_role:
@ -281,6 +286,9 @@ def is_devops(base_dir: str, nickname: str) -> bool:
lines: list[str] = \
load_list(devops_file,
'EX: is_devops unable to read ' + devops_file)
if lines is None:
return False
if not lines:
# if there is nothing in the file
admin_name = get_config_param(base_dir, 'admin')
@ -288,10 +296,11 @@ def is_devops(base_dir: str, nickname: str) -> bool:
return False
if admin_name == nickname:
return True
for devops in lines:
devops = devops.strip('\n').strip('\r')
if devops == nickname:
return True
else:
for devops in lines:
devops = devops.strip('\n').strip('\r')
if devops == nickname:
return True
return False

View File

@ -5767,6 +5767,7 @@ def _test_thread_functions():
if 'thread_with_trace(' in source_str:
threads_called_in_modules.append(mod_name)
lines: list[str] = load_list(source_file, '')
assert lines is not None
modules[mod_name]['lines'] = lines
for mod_name in threads_called_in_modules:
@ -5926,6 +5927,7 @@ def _test_functions():
modules[mod_name]['source'] = source_str
# go through the source line by line
lines: list[str] = load_list(source_file, '')
assert lines is not None
modules[mod_name]['lines'] = lines
line_count = 0
prev_line = 'start'

View File

@ -1605,12 +1605,13 @@ def follow_person(base_dir: str, nickname: str, domain: str,
load_list(unfollowed_filename,
'EX: follow_person unable to read ' +
unfollowed_filename)
for line in lines:
if handle_to_follow not in line:
new_lines += line
save_string(new_lines, unfollowed_filename,
'EX: follow_person unable to write ' +
unfollowed_filename)
if lines is not None:
for line in lines:
if handle_to_follow not in line:
new_lines += line
save_string(new_lines, unfollowed_filename,
'EX: follow_person unable to write ' +
unfollowed_filename)
dir_str = data_dir(base_dir)
if not os.path.isdir(dir_str):

View File

@ -230,6 +230,8 @@ def get_left_column_content(base_dir: str, nickname: str, domain_full: str,
load_list(links_filename,
'EX: get_left_column_content unable to read ' +
links_filename)
if links_list is None:
links_list = []
if not front_page:
# show a number of shares

View File

@ -389,14 +389,15 @@ def html_citations(base_dir: str, nickname: str, domain: str,
load_list(citations_filename,
'EX: html_citations unable to read ' +
citations_filename + ' [ex]')
for line in citations:
if citations_separator not in line:
continue
sections = line.strip().split(citations_separator)
if len(sections) != 3:
continue
date_str = sections[0]
citations_selected.append(date_str)
if citations:
for line in citations:
if citations_separator not in line:
continue
sections = line.strip().split(citations_separator)
if len(sections) != 3:
continue
date_str = sections[0]
citations_selected.append(date_str)
# the css filename
css_filename = base_dir + '/epicyon-profile.css'

View File

@ -941,17 +941,18 @@ def html_new_post(edit_post_params: {},
load_list(citations_filename,
'EX: html_new_post unable to read ' +
citations_filename + ' [ex]')
for line in citations:
if citations_separator not in line:
continue
sections = line.strip().split(citations_separator)
if len(sections) != 3:
continue
title = sections[1]
link = sections[2]
citations_str += \
' <li><a href="' + link + '"><cite>' + \
title + '</cite></a></li>'
if citations:
for line in citations:
if citations_separator not in line:
continue
sections = line.strip().split(citations_separator)
if len(sections) != 3:
continue
title = sections[1]
link = sections[2]
citations_str += \
' <li><a href="' + link + '"><cite>' + \
title + '</cite></a></li>'
citations_str += ' </ul>\n'
citations_str += '</div>\n'

View File

@ -2761,24 +2761,25 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
load_list(locations_filename,
'EX: _html_edit_profile_filtering unable to read ' +
locations_filename)
cities.sort()
edit_profile_form += ' <select id="cityDropdown" ' + \
'name="cityDropdown" class="theme">\n'
city = city.lower()
for city_name in cities:
if ':' not in city_name:
continue
city_selected = ''
city_name = city_name.split(':')[0]
city_name = city_name.lower()
if city:
if city in city_name:
city_selected = ' selected'
edit_profile_form += \
' <option value="' + city_name + \
'"' + city_selected + '>' + \
city_name.title() + '</option>\n'
edit_profile_form += ' </select><br>\n'
if cities:
cities.sort()
edit_profile_form += ' <select id="cityDropdown" ' + \
'name="cityDropdown" class="theme">\n'
city = city.lower()
for city_name in cities:
if ':' not in city_name:
continue
city_selected = ''
city_name = city_name.split(':')[0]
city_name = city_name.lower()
if city:
if city in city_name:
city_selected = ' selected'
edit_profile_form += \
' <option value="' + city_name + \
'"' + city_selected + '>' + \
city_name.title() + '</option>\n'
edit_profile_form += ' </select><br>\n'
edit_profile_form += \
' <b><label class="labels">' + \

View File

@ -932,6 +932,8 @@ def html_hashtag_search(nickname: str, domain: str, port: int,
load_list(hashtag_index_file,
'EX: html_hashtag_search unable to read ' +
hashtag_index_file)
if lines is None:
return None
# read the css
css_filename = base_dir + '/epicyon-profile.css'