Revert "Replace file operations with functions"

This reverts commit 583a1ae83f.
main
bashrc 2026-04-26 17:06:45 +01:00
parent c0e4c5540a
commit 2e0b45077f
11 changed files with 234 additions and 124 deletions

View File

@ -21,8 +21,6 @@ from utils import resembles_url
from keys import get_instance_actor_key from keys import get_instance_actor_key
from session import get_json from session import get_json
from session import get_json_valid from session import get_json_valid
from data import save_string
from data import append_string
def _get_conversation_filename(base_dir: str, nickname: str, domain: str, def _get_conversation_filename(base_dir: str, nickname: str, domain: str,
@ -65,17 +63,23 @@ def update_conversation(base_dir: str, nickname: str, domain: str,
return False return False
post_id = remove_id_ending(post_json_object['object']['id']) post_id = remove_id_ending(post_json_object['object']['id'])
if not os.path.isfile(conversation_filename): if not os.path.isfile(conversation_filename):
if save_string(post_id + '\n', conversation_filename, try:
'EX: update_conversation ' + with open(conversation_filename, 'w+',
'unable to write to ' + encoding='utf-8') as fp_conv:
conversation_filename): fp_conv.write(post_id + '\n')
return True return True
except OSError:
print('EX: update_conversation ' +
'unable to write to ' + conversation_filename)
elif not text_in_file(post_id + '\n', conversation_filename): elif not text_in_file(post_id + '\n', conversation_filename):
if append_string(post_id + '\n', conversation_filename, try:
'EX: update_conversation 2 ' + with open(conversation_filename, 'a+',
'unable to write to ' + encoding='utf-8') as fp_conv:
conversation_filename): fp_conv.write(post_id + '\n')
return True return True
except OSError:
print('EX: update_conversation 2 ' +
'unable to write to ' + conversation_filename)
return False return False
@ -93,8 +97,12 @@ def mute_conversation(base_dir: str, nickname: str, domain: str,
return return
if os.path.isfile(conversation_filename + '.muted'): if os.path.isfile(conversation_filename + '.muted'):
return return
save_string('\n', conversation_filename + '.muted', try:
'EX: unable to write mute ' + conversation_filename) with open(conversation_filename + '.muted', 'w+',
encoding='utf-8') as fp_conv:
fp_conv.write('\n')
except OSError:
print('EX: unable to write mute ' + conversation_filename)
def unmute_conversation(base_dir: str, nickname: str, domain: str, def unmute_conversation(base_dir: str, nickname: str, domain: str,

View File

@ -19,8 +19,6 @@ from blocking import get_bsky_domains_list
from blocking import get_nostr_domains_list from blocking import get_nostr_domains_list
from blocking import update_blocked_cache from blocking import update_blocked_cache
from blocking import is_blocked_domain from blocking import is_blocked_domain
from data import load_string
from data import save_string
default_user_agent_blocks = [ default_user_agent_blocks = [
'fedilist', 'ncsc scan', 'fedifetcher' 'fedilist', 'ncsc scan', 'fedifetcher'
@ -66,8 +64,12 @@ def load_known_web_bots(base_dir: str) -> []:
known_bots_filename = data_dir(base_dir) + '/knownBots.txt' known_bots_filename = data_dir(base_dir) + '/knownBots.txt'
if not os.path.isfile(known_bots_filename): if not os.path.isfile(known_bots_filename):
return [] return []
crawlers_str = load_string(known_bots_filename, crawlers_str = None
'EX: unable to load web bots from ' + try:
with open(known_bots_filename, 'r', encoding='utf-8') as fp_crawlers:
crawlers_str = fp_crawlers.read()
except OSError:
print('EX: unable to load web bots from ' +
known_bots_filename) known_bots_filename)
if not crawlers_str: if not crawlers_str:
return [] return []
@ -91,9 +93,12 @@ def _save_known_web_bots(base_dir: str, known_bots: []) -> bool:
known_bots_str: str = '' known_bots_str: str = ''
for crawler in known_bots: for crawler in known_bots:
known_bots_str += crawler.strip() + '\n' known_bots_str += crawler.strip() + '\n'
if not save_string(known_bots_str, known_bots_filename, try:
"EX: unable to save known web bots to " + with open(known_bots_filename, 'w+', encoding='utf-8') as fp_crawlers:
known_bots_filename): fp_crawlers.write(known_bots_str)
except OSError:
print("EX: unable to save known web bots to " +
known_bots_filename)
return False return False
return True return True

View File

@ -105,7 +105,6 @@ from daemon_utils import has_accept
from daemon_utils import is_authorized from daemon_utils import is_authorized
from poison import load_dictionary from poison import load_dictionary
from poison import load_2grams from poison import load_2grams
from data import load_string
class PubServer(BaseHTTPRequestHandler): class PubServer(BaseHTTPRequestHandler):
@ -584,9 +583,14 @@ def load_tokens(base_dir: str, tokens_dict: {}, tokens_lookup: {}) -> None:
if not os.path.isfile(token_filename): if not os.path.isfile(token_filename):
continue continue
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
token = load_string(token_filename, token = None
'WARN: Unable to read token for ' + try:
nickname + ' [ex]') with open(token_filename, 'r',
encoding='utf-8') as fp_tok:
token = fp_tok.read()
except OSError as ex:
print('WARN: Unable to read token for ' +
nickname + ' ' + str(ex))
if not token: if not token:
continue continue
tokens_dict[nickname] = token tokens_dict[nickname] = token
@ -749,9 +753,13 @@ def run_daemon(accounts_data_dir: str,
robots_txt_filename = data_dir(base_dir) + '/robots.txt' robots_txt_filename = data_dir(base_dir) + '/robots.txt'
httpd.robots_txt = None httpd.robots_txt = None
if os.path.isfile(robots_txt_filename): if os.path.isfile(robots_txt_filename):
new_robots_txt = \ new_robots_txt = ''
load_string(robots_txt_filename, try:
'EX: error reading 1 ' + robots_txt_filename) with open(robots_txt_filename, 'r',
encoding='utf-8') as fp_robots:
new_robots_txt = fp_robots.read()
except OSError:
print('EX: error reading 1 ' + robots_txt_filename)
if new_robots_txt: if new_robots_txt:
httpd.robots_txt = new_robots_txt httpd.robots_txt = new_robots_txt

View File

@ -220,7 +220,6 @@ from daemon_get_links import edit_links2
from daemon_get_login import redirect_to_login_screen from daemon_get_login import redirect_to_login_screen
from daemon_get_login import show_login_screen from daemon_get_login import show_login_screen
from poison import html_poisoned from poison import html_poisoned
from data import load_string
# Blogs can be longer, so don't show many per page # Blogs can be longer, so don't show many per page
MAX_POSTS_IN_BLOGS_FEED = 4 MAX_POSTS_IN_BLOGS_FEED = 4
@ -6256,8 +6255,12 @@ def daemon_http_get(self) -> None:
return return
if os.path.isfile(filename): if os.path.isfile(filename):
content = load_string(filename, content = None
'EX: unable to read file ' + filename) try:
with open(filename, 'r', encoding='utf-8') as fp_rfile:
content = fp_rfile.read()
except OSError:
print('EX: unable to read file ' + filename)
if content: if content:
try: try:
content_json = json.loads(content) content_json = json.loads(content)
@ -6497,10 +6500,13 @@ def _get_ontology(self, calling_domain: str,
if ontology_str.endswith('.json'): if ontology_str.endswith('.json'):
ontology_file_type = 'application/ld+json' ontology_file_type = 'application/ld+json'
if os.path.isfile(ontology_filename): if os.path.isfile(ontology_filename):
ontology_file = \ ontology_file = None
load_string(ontology_filename, try:
'EX: unable to read ontology ' + with open(ontology_filename, 'r',
ontology_filename) encoding='utf-8') as fp_ont:
ontology_file = fp_ont.read()
except OSError:
print('EX: unable to read ontology ' + ontology_filename)
if ontology_file: if ontology_file:
ontology_file = \ ontology_file = \
ontology_file.replace('static.datafoodconsortium.org', ontology_file.replace('static.datafoodconsortium.org',

View File

@ -29,7 +29,6 @@ from daemon_utils import etag_exists
from fitnessFunctions import fitness_performance from fitnessFunctions import fitness_performance
from person import save_person_qrcode from person import save_person_qrcode
from lxmf import save_lxmf_qrcode from lxmf import save_lxmf_qrcode
from data import load_string
def show_avatar_or_banner(self, referer_domain: str, path: str, def show_avatar_or_banner(self, referer_domain: str, path: str,
@ -443,12 +442,16 @@ def show_media(self, path: str, base_dir: str,
last_modified_time.strftime('%a, %d %b %Y %H:%M:%S GMT') last_modified_time.strftime('%a, %d %b %Y %H:%M:%S GMT')
if media_filename.endswith('.vtt'): if media_filename.endswith('.vtt'):
media_transcript = \ media_transcript = None
load_string(media_filename, try:
'EX: unable to read media binary ' + with open(media_filename, 'r',
encoding='utf-8') as fp_vtt:
media_transcript = fp_vtt.read()
media_file_type = 'text/vtt; charset=utf-8'
except OSError:
print('EX: unable to read media binary ' +
media_filename) media_filename)
if media_transcript: if media_transcript:
media_file_type = 'text/vtt; charset=utf-8'
media_transcript = media_transcript.encode('utf-8') media_transcript = media_transcript.encode('utf-8')
set_headers_etag(self, media_filename, media_file_type, set_headers_etag(self, media_filename, media_file_type,
media_transcript, None, media_transcript, None,

View File

@ -49,7 +49,6 @@ from fitnessFunctions import fitness_performance
from securemode import secure_mode from securemode import secure_mode
from context import get_individual_post_context from context import get_individual_post_context
from conversation import convthread_id_to_conversation_tag from conversation import convthread_id_to_conversation_tag
from data import load_string
def _show_post_from_file(self, post_filename: str, liked_by: str, def _show_post_from_file(self, post_filename: str, liked_by: str,
@ -309,9 +308,12 @@ def show_individual_post(self, ssml_getreq: bool, authorized: bool,
if not os.path.isfile(ssml_filename): if not os.path.isfile(ssml_filename):
http_404(self, 74) http_404(self, 74)
return True return True
ssml_str = load_string(ssml_filename, ssml_str = None
'EX: unable to read ssml file ' + try:
ssml_filename) with open(ssml_filename, 'r', encoding='utf-8') as fp_ssml:
ssml_str = fp_ssml.read()
except OSError:
print('EX: unable to read ssml file ' + ssml_filename)
if ssml_str: if ssml_str:
msg = ssml_str.encode('utf-8') msg = ssml_str.encode('utf-8')
msglen = len(msg) msglen = len(msg)
@ -659,9 +661,12 @@ def show_individual_at_post(self, ssml_getreq: bool, authorized: bool,
if not os.path.isfile(ssml_filename): if not os.path.isfile(ssml_filename):
http_404(self, 67) http_404(self, 67)
return True return True
ssml_str = load_string(ssml_filename, ssml_str = None
'EX: unable to read ssml file 2 ' + try:
ssml_filename) with open(ssml_filename, 'r', encoding='utf-8') as fp_ssml:
ssml_str = fp_ssml.read()
except OSError:
print('EX: unable to read ssml file 2 ' + ssml_filename)
if ssml_str: if ssml_str:
msg = ssml_str.encode('utf-8') msg = ssml_str.encode('utf-8')
msglen = len(msg) msglen = len(msg)

View File

@ -23,8 +23,6 @@ from media import path_is_video
from media import path_is_audio from media import path_is_audio
from daemon_utils import get_user_agent from daemon_utils import get_user_agent
from daemon_utils import log_epicyon_instances from daemon_utils import log_epicyon_instances
from data import load_string
from data import save_string
def daemon_http_head(self) -> None: def daemon_http_head(self) -> None:
@ -120,11 +118,13 @@ def daemon_http_head(self) -> None:
last_modified_time.strftime(time_format_str) last_modified_time.strftime(time_format_str)
media_tag_filename = media_filename + '.etag' media_tag_filename = media_filename + '.etag'
if os.path.isfile(media_tag_filename): if os.path.isfile(media_tag_filename):
etag_str = load_string(media_tag_filename, try:
'EX: do_HEAD unable to read ' + with open(media_tag_filename, 'r',
encoding='utf-8') as fp_efile:
etag = fp_efile.read()
except OSError:
print('EX: do_HEAD unable to read ' +
media_tag_filename) media_tag_filename)
if etag_str:
etag = etag_str
else: else:
media_binary = None media_binary = None
try: try:
@ -135,8 +135,12 @@ def daemon_http_head(self) -> None:
media_filename) media_filename)
if media_binary: if media_binary:
etag = md5(media_binary).hexdigest() # nosec etag = md5(media_binary).hexdigest() # nosec
save_string(etag, media_tag_filename, try:
'EX: do_HEAD unable to write ' + with open(media_tag_filename, 'w+',
encoding='utf-8') as fp_efile:
fp_efile.write(etag)
except OSError:
print('EX: do_HEAD unable to write ' +
media_tag_filename) media_tag_filename)
else: else:
http_404(self, 151) http_404(self, 151)

View File

@ -18,7 +18,6 @@ from utils import get_nickname_from_actor
from utils import get_config_param from utils import get_config_param
from httpheaders import redirect_headers from httpheaders import redirect_headers
from content import extract_text_fields_in_post from content import extract_text_fields_in_post
from data import save_string
def _links_update_edited(fields: {}, links_filename: str) -> None: def _links_update_edited(fields: {}, links_filename: str) -> None:
@ -31,15 +30,23 @@ def _links_update_edited(fields: {}, links_filename: str) -> None:
if not links_str.endswith('\n'): if not links_str.endswith('\n'):
links_str += '\n' links_str += '\n'
links_str += fields['newColLink'] + '\n' links_str += fields['newColLink'] + '\n'
save_string(links_str, links_filename, try:
'EX: _links_update unable to write ' + with open(links_filename, 'w+',
encoding='utf-8') as fp_links:
fp_links.write(links_str)
except OSError:
print('EX: _links_update unable to write ' +
links_filename) links_filename)
else: else:
if fields.get('newColLink'): if fields.get('newColLink'):
# the text area is empty but there is a new link added # the text area is empty but there is a new link added
links_str = fields['newColLink'] + '\n' links_str = fields['newColLink'] + '\n'
save_string(links_str, links_filename, try:
'EX: _links_update unable to write ' + with open(links_filename, 'w+',
encoding='utf-8') as fp_links:
fp_links.write(links_str)
except OSError:
print('EX: _links_update unable to write ' +
links_filename) links_filename)
else: else:
if os.path.isfile(links_filename): if os.path.isfile(links_filename):
@ -58,8 +65,12 @@ def _links_update_about(fields: {}, allow_local_network_access: bool,
about_str = fields['editedAbout'] about_str = fields['editedAbout']
if not dangerous_markup(about_str, if not dangerous_markup(about_str,
allow_local_network_access, []): allow_local_network_access, []):
save_string(about_str, about_filename, try:
'EX: unable to write about ' + with open(about_filename, 'w+',
encoding='utf-8') as fp_about:
fp_about.write(about_str)
except OSError:
print('EX: unable to write about ' +
about_filename) about_filename)
else: else:
if os.path.isfile(about_filename): if os.path.isfile(about_filename):
@ -78,8 +89,11 @@ def _links_update_tos(fields: {}, allow_local_network_access: bool,
tos_str = fields['editedTOS'] tos_str = fields['editedTOS']
if not dangerous_markup(tos_str, if not dangerous_markup(tos_str,
allow_local_network_access, []): allow_local_network_access, []):
save_string(tos_str, tos_filename, try:
'EX: unable to write TOS ' + tos_filename) with open(tos_filename, 'w+', encoding='utf-8') as fp_tos:
fp_tos.write(tos_str)
except OSError:
print('EX: unable to write TOS ' + tos_filename)
else: else:
if os.path.isfile(tos_filename): if os.path.isfile(tos_filename):
try: try:
@ -95,8 +109,12 @@ def _links_update_sepcification(fields: {},
""" """
if fields.get('editedSpecification'): if fields.get('editedSpecification'):
specification_str = fields['editedSpecification'] specification_str = fields['editedSpecification']
save_string(specification_str, specification_filename, try:
'EX: unable to write specification ' + with open(specification_filename, 'w+',
encoding='utf-8') as fp_specification:
fp_specification.write(specification_str)
except OSError:
print('EX: unable to write specification ' +
specification_filename) specification_filename)
else: else:
if os.path.isfile(specification_filename): if os.path.isfile(specification_filename):

View File

@ -36,8 +36,6 @@ from flags import is_system_account
from person import person_upgrade_actor from person import person_upgrade_actor
from person import activate_account2 from person import activate_account2
from person import register_account from person import register_account
from data import load_string
from data import save_string
def post_login_screen(self, calling_domain: str, cookie: str, def post_login_screen(self, calling_domain: str, cookie: str,
@ -182,15 +180,21 @@ def post_login_screen(self, calling_domain: str, cookie: str,
acct_dir(base_dir, login_nickname, domain) + '/.salt' acct_dir(base_dir, login_nickname, domain) + '/.salt'
salt = create_password(32) salt = create_password(32)
if os.path.isfile(salt_filename): if os.path.isfile(salt_filename):
salt_str = load_string(salt_filename, try:
'EX: Unable to read salt for ' + with open(salt_filename, 'r',
login_nickname + ' [ex]') encoding='utf-8') as fp_salt:
if salt_str: salt = fp_salt.read()
salt = salt_str except OSError as ex:
print('EX: Unable to read salt for ' +
login_nickname + ' ' + str(ex))
else: else:
save_string(salt, salt_filename, try:
'EX: Unable to save salt for ' + with open(salt_filename, 'w+',
login_nickname + ' [ex]') encoding='utf-8') as fp_salt:
fp_salt.write(salt)
except OSError as ex:
print('EX: Unable to save salt for ' +
login_nickname + ' ' + str(ex))
token_text = login_nickname + login_password + salt token_text = login_nickname + login_password + salt
token = sha256(token_text.encode('utf-8')).hexdigest() token = sha256(token_text.encode('utf-8')).hexdigest()
@ -198,9 +202,13 @@ def post_login_screen(self, calling_domain: str, cookie: str,
login_handle = login_nickname + '@' + domain login_handle = login_nickname + '@' + domain
token_filename = \ token_filename = \
data_dir(base_dir) + '/' + login_handle + '/.token' data_dir(base_dir) + '/' + login_handle + '/.token'
save_string(token, token_filename, try:
'EX: Unable to save token for ' + with open(token_filename, 'w+',
login_nickname + ' [ex]') encoding='utf-8') as fp_tok:
fp_tok.write(token)
except OSError as ex:
print('EX: Unable to save token for ' +
login_nickname + ' ' + str(ex))
dir_str = data_dir(base_dir) dir_str = data_dir(base_dir)
person_upgrade_actor(base_dir, None, person_upgrade_actor(base_dir, None,

View File

@ -26,7 +26,6 @@ from timeFunctions import date_from_string_format
from httpheaders import redirect_headers from httpheaders import redirect_headers
from content import extract_text_fields_in_post from content import extract_text_fields_in_post
from content import load_dogwhistles from content import load_dogwhistles
from data import save_string
def newswire_update(self, calling_domain: str, cookie: str, def newswire_update(self, calling_domain: str, cookie: str,
@ -117,14 +116,22 @@ def newswire_update(self, calling_domain: str, cookie: str,
if not newswire_str.endswith('\n'): if not newswire_str.endswith('\n'):
newswire_str += '\n' newswire_str += '\n'
newswire_str += fields['newNewswireFeed'] + '\n' newswire_str += fields['newNewswireFeed'] + '\n'
save_string(newswire_str, newswire_filename, try:
'EX: unable to write ' + newswire_filename) with open(newswire_filename, 'w+',
encoding='utf-8') as fp_news:
fp_news.write(newswire_str)
except OSError:
print('EX: unable to write ' + newswire_filename)
else: else:
if fields.get('newNewswireFeed'): if fields.get('newNewswireFeed'):
# the text area is empty but there is a new feed added # the text area is empty but there is a new feed added
newswire_str = fields['newNewswireFeed'] + '\n' newswire_str = fields['newNewswireFeed'] + '\n'
save_string(newswire_str, newswire_filename, try:
'EX: unable to write ' + newswire_filename) with open(newswire_filename, 'w+',
encoding='utf-8') as fp_news:
fp_news.write(newswire_str)
except OSError:
print('EX: unable to write ' + newswire_filename)
else: else:
# text area has been cleared and there is no new feed # text area has been cleared and there is no new feed
if os.path.isfile(newswire_filename): if os.path.isfile(newswire_filename):
@ -138,9 +145,12 @@ def newswire_update(self, calling_domain: str, cookie: str,
filter_newswire_filename = \ filter_newswire_filename = \
data_dir(base_dir) + '/' + 'news@' + domain + '/filters.txt' data_dir(base_dir) + '/' + 'news@' + domain + '/filters.txt'
if fields.get('filteredWordsNewswire'): if fields.get('filteredWordsNewswire'):
save_string(fields['filteredWordsNewswire'], try:
filter_newswire_filename, with open(filter_newswire_filename, 'w+',
'EX: newswire_update unable to write ' + encoding='utf-8') as fp_filter:
fp_filter.write(fields['filteredWordsNewswire'])
except OSError:
print('EX: newswire_update unable to write ' +
filter_newswire_filename) filter_newswire_filename)
else: else:
if os.path.isfile(filter_newswire_filename): if os.path.isfile(filter_newswire_filename):
@ -153,25 +163,35 @@ def newswire_update(self, calling_domain: str, cookie: str,
# save dogwhistle words list # save dogwhistle words list
dogwhistles_filename = data_dir(base_dir) + '/dogwhistles.txt' dogwhistles_filename = data_dir(base_dir) + '/dogwhistles.txt'
if fields.get('dogwhistleWords'): if fields.get('dogwhistleWords'):
save_string(fields['dogwhistleWords'], try:
dogwhistles_filename, with open(dogwhistles_filename, 'w+',
'EX: newswire_update unable to write 2 ' + encoding='utf-8') as fp_dogwhistles:
fp_dogwhistles.write(fields['dogwhistleWords'])
except OSError:
print('EX: newswire_update unable to write 2 ' +
dogwhistles_filename) dogwhistles_filename)
self.server.dogwhistles = \ self.server.dogwhistles = \
load_dogwhistles(dogwhistles_filename) load_dogwhistles(dogwhistles_filename)
else: else:
# save an empty file # save an empty file
save_string('', dogwhistles_filename, try:
'EX: newswire_update unable unable to write 3 ' + with open(dogwhistles_filename, 'w+',
encoding='utf-8') as fp_dogwhistles:
fp_dogwhistles.write('')
except OSError:
print('EX: newswire_update unable unable to write 3 ' +
dogwhistles_filename) dogwhistles_filename)
self.server.dogwhistles = {} self.server.dogwhistles = {}
# save news tagging rules # save news tagging rules
hashtag_rules_filename = data_dir(base_dir) + '/hashtagrules.txt' hashtag_rules_filename = data_dir(base_dir) + '/hashtagrules.txt'
if fields.get('hashtagRulesList'): if fields.get('hashtagRulesList'):
save_string(fields['hashtagRulesList'], try:
hashtag_rules_filename, with open(hashtag_rules_filename, 'w+',
'EX: newswire_update unable to write 4 ' + encoding='utf-8') as fp_rules:
fp_rules.write(fields['hashtagRulesList'])
except OSError:
print('EX: newswire_update unable to write 4 ' +
hashtag_rules_filename) hashtag_rules_filename)
else: else:
if os.path.isfile(hashtag_rules_filename): if os.path.isfile(hashtag_rules_filename):
@ -186,8 +206,12 @@ def newswire_update(self, calling_domain: str, cookie: str,
newswire_trusted = fields['trustedNewswire'] newswire_trusted = fields['trustedNewswire']
if not newswire_trusted.endswith('\n'): if not newswire_trusted.endswith('\n'):
newswire_trusted += '\n' newswire_trusted += '\n'
save_string(newswire_trusted, newswire_tusted_filename, try:
'EX: newswire_update unable to write 5 ' + with open(newswire_tusted_filename, 'w+',
encoding='utf-8') as fp_trust:
fp_trust.write(newswire_trusted)
except OSError:
print('EX: newswire_update unable to write 5 ' +
newswire_tusted_filename) newswire_tusted_filename)
else: else:
if os.path.isfile(newswire_tusted_filename): if os.path.isfile(newswire_tusted_filename):
@ -291,8 +315,12 @@ def citations_update(self, calling_domain: str, cookie: str,
citations_str += citation_date + '\n' citations_str += citation_date + '\n'
# save citations dates, so that they can be added when # save citations dates, so that they can be added when
# reloading the newblog screen # reloading the newblog screen
save_string(citations_str, citations_filename, try:
'EX: citations_update unable to write ' + with open(citations_filename, 'w+',
encoding='utf-8') as fp_cit:
fp_cit.write(citations_str)
except OSError:
print('EX: citations_update unable to write ' +
citations_filename) citations_filename)
# redirect back to the default timeline # redirect back to the default timeline

View File

@ -49,7 +49,6 @@ from blocking import blocked_quote_toots_remove
from notifyOnPost import add_notify_on_post from notifyOnPost import add_notify_on_post
from notifyOnPost import remove_notify_on_post from notifyOnPost import remove_notify_on_post
from flags import is_moderator from flags import is_moderator
from data import save_string
def _person_options_page_number(options_confirm_params: str) -> int: def _person_options_page_number(options_confirm_params: str) -> int:
@ -612,9 +611,16 @@ def _person_options_post_to_news(self, options_confirm_params: str,
else: else:
if os.path.isdir(account_dir): if os.path.isdir(account_dir):
nw_filename = newswire_blocked_filename nw_filename = newswire_blocked_filename
if save_string('\n', nw_filename, nw_written = False
'EX: _person_options_post_to_news unable ' + try:
'to write ' + nw_filename + ' [ex]'): with open(nw_filename, 'w+',
encoding='utf-8') as fp_no:
fp_no.write('\n')
nw_written = True
except OSError as ex:
print('EX: _person_options_post_to_news unable ' +
'to write ' + nw_filename + ' ' + str(ex))
if nw_written:
refresh_newswire(base_dir) refresh_newswire(base_dir)
users_path_str = \ users_path_str = \
users_path + '/' + default_timeline + \ users_path + '/' + default_timeline + \
@ -665,10 +671,17 @@ def _person_options_post_to_features(self, options_confirm_params: str,
else: else:
if os.path.isdir(account_dir): if os.path.isdir(account_dir):
feat_filename = features_blocked_filename feat_filename = features_blocked_filename
if save_string('\n', feat_filename, feat_written = False
'EX: _person_options_post_to_features ' + try:
with open(feat_filename, 'w+',
encoding='utf-8') as fp_no:
fp_no.write('\n')
feat_written = True
except OSError as ex:
print('EX: _person_options_post_to_features ' +
'unable to write ' + feat_filename + 'unable to write ' + feat_filename +
' [ex]'): ' ' + str(ex))
if feat_written:
refresh_newswire(base_dir) refresh_newswire(base_dir)
users_path_str = \ users_path_str = \
users_path + '/' + default_timeline + \ users_path + '/' + default_timeline + \
@ -718,8 +731,12 @@ def _person_options_mod_news(self, options_confirm_params: str,
else: else:
if os.path.isdir(account_dir): if os.path.isdir(account_dir):
nw_filename = newswire_mod_filename nw_filename = newswire_mod_filename
save_string('\n', nw_filename, try:
'EX: _person_options_mod_news ' + with open(nw_filename, 'w+',
encoding='utf-8') as fp_mod:
fp_mod.write('\n')
except OSError:
print('EX: _person_options_mod_news ' +
'unable to write ' + nw_filename) 'unable to write ' + nw_filename)
users_path_str = \ users_path_str = \
users_path + '/' + default_timeline + \ users_path + '/' + default_timeline + \