File pointer naming convention

main
Bob Mottram 2024-07-16 12:21:28 +01:00
parent 7b978570d2
commit 9544505bfa
11 changed files with 83 additions and 83 deletions

View File

@ -369,8 +369,8 @@ class PubServer(BaseHTTPRequestHandler):
if os.path.isfile(media_tag_filename): if os.path.isfile(media_tag_filename):
try: try:
with open(media_tag_filename, 'r', with open(media_tag_filename, 'r',
encoding='utf-8') as efile: encoding='utf-8') as fp_efile:
etag = efile.read() etag = fp_efile.read()
except OSError: except OSError:
print('EX: do_HEAD unable to read ' + print('EX: do_HEAD unable to read ' +
media_tag_filename) media_tag_filename)
@ -386,8 +386,8 @@ class PubServer(BaseHTTPRequestHandler):
etag = md5(media_binary).hexdigest() # nosec etag = md5(media_binary).hexdigest() # nosec
try: try:
with open(media_tag_filename, 'w+', with open(media_tag_filename, 'w+',
encoding='utf-8') as efile: encoding='utf-8') as fp_efile:
efile.write(etag) fp_efile.write(etag)
except OSError: except OSError:
print('EX: do_HEAD unable to write ' + print('EX: do_HEAD unable to write ' +
media_tag_filename) media_tag_filename)

View File

@ -5800,8 +5800,8 @@ def daemon_http_get(self) -> None:
if os.path.isfile(filename): if os.path.isfile(filename):
content = None content = None
try: try:
with open(filename, 'r', encoding='utf-8') as rfile: with open(filename, 'r', encoding='utf-8') as fp_rfile:
content = rfile.read() content = fp_rfile.read()
except OSError: except OSError:
print('EX: unable to read file ' + filename) print('EX: unable to read file ' + filename)
if content: if content:

View File

@ -103,8 +103,8 @@ def get_fonts(self, calling_domain: str, path: str,
if os.path.isfile(font_filename): if os.path.isfile(font_filename):
font_binary = None font_binary = None
try: try:
with open(font_filename, 'rb') as fontfile: with open(font_filename, 'rb') as fp_font:
font_binary = fontfile.read() font_binary = fp_font.read()
except OSError: except OSError:
print('EX: unable to load font ' + font_filename) print('EX: unable to load font ' + font_filename)
if font_binary: if font_binary:

View File

@ -32,8 +32,8 @@ def _links_update_edited(fields: {}, links_filename: str) -> None:
links_str += fields['newColLink'] + '\n' links_str += fields['newColLink'] + '\n'
try: try:
with open(links_filename, 'w+', with open(links_filename, 'w+',
encoding='utf-8') as linksfile: encoding='utf-8') as fp_links:
linksfile.write(links_str) fp_links.write(links_str)
except OSError: except OSError:
print('EX: _links_update unable to write ' + print('EX: _links_update unable to write ' +
links_filename) links_filename)
@ -43,8 +43,8 @@ def _links_update_edited(fields: {}, links_filename: str) -> None:
links_str = fields['newColLink'] + '\n' links_str = fields['newColLink'] + '\n'
try: try:
with open(links_filename, 'w+', with open(links_filename, 'w+',
encoding='utf-8') as linksfile: encoding='utf-8') as fp_links:
linksfile.write(links_str) fp_links.write(links_str)
except OSError: except OSError:
print('EX: _links_update unable to write ' + print('EX: _links_update unable to write ' +
links_filename) links_filename)
@ -67,8 +67,8 @@ def _links_update_about(fields: {}, allow_local_network_access: bool,
allow_local_network_access, []): allow_local_network_access, []):
try: try:
with open(about_filename, 'w+', with open(about_filename, 'w+',
encoding='utf-8') as aboutfile: encoding='utf-8') as fp_about:
aboutfile.write(about_str) fp_about.write(about_str)
except OSError: except OSError:
print('EX: unable to write about ' + print('EX: unable to write about ' +
about_filename) about_filename)
@ -90,8 +90,8 @@ def _links_update_tos(fields: {}, allow_local_network_access: bool,
if not dangerous_markup(tos_str, if not dangerous_markup(tos_str,
allow_local_network_access, []): allow_local_network_access, []):
try: try:
with open(tos_filename, 'w+', encoding='utf-8') as tosfile: with open(tos_filename, 'w+', encoding='utf-8') as fp_tos:
tosfile.write(tos_str) fp_tos.write(tos_str)
except OSError: except OSError:
print('EX: unable to write TOS ' + tos_filename) print('EX: unable to write TOS ' + tos_filename)
else: else:
@ -111,8 +111,8 @@ def _links_update_sepcification(fields: {},
specification_str = fields['editedSpecification'] specification_str = fields['editedSpecification']
try: try:
with open(specification_filename, 'w+', with open(specification_filename, 'w+',
encoding='utf-8') as specificationfile: encoding='utf-8') as fp_specification:
specificationfile.write(specification_str) fp_specification.write(specification_str)
except OSError: except OSError:
print('EX: unable to write specification ' + print('EX: unable to write specification ' +
specification_filename) specification_filename)

View File

@ -116,8 +116,8 @@ def newswire_update(self, calling_domain: str, cookie: str,
newswire_str += fields['newNewswireFeed'] + '\n' newswire_str += fields['newNewswireFeed'] + '\n'
try: try:
with open(newswire_filename, 'w+', with open(newswire_filename, 'w+',
encoding='utf-8') as newsfile: encoding='utf-8') as fp_news:
newsfile.write(newswire_str) fp_news.write(newswire_str)
except OSError: except OSError:
print('EX: unable to write ' + newswire_filename) print('EX: unable to write ' + newswire_filename)
else: else:
@ -126,8 +126,8 @@ def newswire_update(self, calling_domain: str, cookie: str,
newswire_str = fields['newNewswireFeed'] + '\n' newswire_str = fields['newNewswireFeed'] + '\n'
try: try:
with open(newswire_filename, 'w+', with open(newswire_filename, 'w+',
encoding='utf-8') as newsfile: encoding='utf-8') as fp_news:
newsfile.write(newswire_str) fp_news.write(newswire_str)
except OSError: except OSError:
print('EX: unable to write ' + newswire_filename) print('EX: unable to write ' + newswire_filename)
else: else:
@ -145,8 +145,8 @@ def newswire_update(self, calling_domain: str, cookie: str,
if fields.get('filteredWordsNewswire'): if fields.get('filteredWordsNewswire'):
try: try:
with open(filter_newswire_filename, 'w+', with open(filter_newswire_filename, 'w+',
encoding='utf-8') as filterfile: encoding='utf-8') as fp_filter:
filterfile.write(fields['filteredWordsNewswire']) fp_filter.write(fields['filteredWordsNewswire'])
except OSError: except OSError:
print('EX: newswire_update unable to write ' + print('EX: newswire_update unable to write ' +
filter_newswire_filename) filter_newswire_filename)
@ -186,8 +186,8 @@ def newswire_update(self, calling_domain: str, cookie: str,
if fields.get('hashtagRulesList'): if fields.get('hashtagRulesList'):
try: try:
with open(hashtag_rules_filename, 'w+', with open(hashtag_rules_filename, 'w+',
encoding='utf-8') as rulesfile: encoding='utf-8') as fp_rules:
rulesfile.write(fields['hashtagRulesList']) fp_rules.write(fields['hashtagRulesList'])
except OSError: except OSError:
print('EX: newswire_update unable to write 4 ' + print('EX: newswire_update unable to write 4 ' +
hashtag_rules_filename) hashtag_rules_filename)
@ -206,8 +206,8 @@ def newswire_update(self, calling_domain: str, cookie: str,
newswire_trusted += '\n' newswire_trusted += '\n'
try: try:
with open(newswire_tusted_filename, 'w+', with open(newswire_tusted_filename, 'w+',
encoding='utf-8') as trustfile: encoding='utf-8') as fp_trust:
trustfile.write(newswire_trusted) fp_trust.write(newswire_trusted)
except OSError: except OSError:
print('EX: newswire_update unable to write 5 ' + print('EX: newswire_update unable to write 5 ' +
newswire_tusted_filename) newswire_tusted_filename)
@ -313,8 +313,8 @@ def citations_update(self, calling_domain: str, cookie: str,
# reloading the newblog screen # reloading the newblog screen
try: try:
with open(citations_filename, 'w+', with open(citations_filename, 'w+',
encoding='utf-8') as citfile: encoding='utf-8') as fp_cit:
citfile.write(citations_str) fp_cit.write(citations_str)
except OSError: except OSError:
print('EX: citations_update unable to write ' + print('EX: citations_update unable to write ' +
citations_filename) citations_filename)

View File

@ -597,8 +597,8 @@ def _person_options_post_to_news(self, options_confirm_params: str,
nw_written = False nw_written = False
try: try:
with open(nw_filename, 'w+', with open(nw_filename, 'w+',
encoding='utf-8') as nofile: encoding='utf-8') as fp_no:
nofile.write('\n') fp_no.write('\n')
nw_written = True nw_written = True
except OSError as ex: except OSError as ex:
print('EX: _person_options_post_to_news unable ' + print('EX: _person_options_post_to_news unable ' +
@ -657,8 +657,8 @@ def _person_options_post_to_features(self, options_confirm_params: str,
feat_written = False feat_written = False
try: try:
with open(feat_filename, 'w+', with open(feat_filename, 'w+',
encoding='utf-8') as nofile: encoding='utf-8') as fp_no:
nofile.write('\n') fp_no.write('\n')
feat_written = True feat_written = True
except OSError as ex: except OSError as ex:
print('EX: _person_options_post_to_features ' + print('EX: _person_options_post_to_features ' +
@ -716,8 +716,8 @@ def _person_options_mod_news(self, options_confirm_params: str,
nw_filename = newswire_mod_filename nw_filename = newswire_mod_filename
try: try:
with open(nw_filename, 'w+', with open(nw_filename, 'w+',
encoding='utf-8') as modfile: encoding='utf-8') as fp_mod:
modfile.write('\n') fp_mod.write('\n')
except OSError: except OSError:
print('EX: _person_options_mod_news ' + print('EX: _person_options_mod_news ' +
'unable to write ' + nw_filename) 'unable to write ' + nw_filename)

View File

@ -225,8 +225,8 @@ def _profile_post_git_projects(base_dir: str, nickname: str, domain: str,
if fields.get('gitProjects'): if fields.get('gitProjects'):
try: try:
with open(git_projects_filename, 'w+', with open(git_projects_filename, 'w+',
encoding='utf-8') as afile: encoding='utf-8') as fp_git:
afile.write(fields['gitProjects'].lower()) fp_git.write(fields['gitProjects'].lower())
except OSError: except OSError:
print('EX: unable to write git ' + git_projects_filename) print('EX: unable to write git ' + git_projects_filename)
else: else:
@ -247,8 +247,8 @@ def _profile_post_peertube_instances(base_dir: str, fields: {}, self,
peertube_instances.clear() peertube_instances.clear()
try: try:
with open(peertube_instances_file, 'w+', with open(peertube_instances_file, 'w+',
encoding='utf-8') as afile: encoding='utf-8') as fp_peertube:
afile.write(fields['ptInstances']) fp_peertube.write(fields['ptInstances'])
except OSError: except OSError:
print('EX: unable to write peertube ' + print('EX: unable to write peertube ' +
peertube_instances_file) peertube_instances_file)
@ -395,8 +395,8 @@ def _profile_post_allowed_instances(base_dir: str, nickname: str, domain: str,
inst_filename = allowed_instances_filename inst_filename = allowed_instances_filename
try: try:
with open(inst_filename, 'w+', with open(inst_filename, 'w+',
encoding='utf-8') as afile: encoding='utf-8') as fp_inst:
afile.write(fields['allowedInstances']) fp_inst.write(fields['allowedInstances'])
except OSError: except OSError:
print('EX: unable to write allowed instances ' + print('EX: unable to write allowed instances ' +
allowed_instances_filename) allowed_instances_filename)
@ -421,8 +421,8 @@ def _profile_post_dm_instances(base_dir: str, nickname: str, domain: str,
if fields.get('dmAllowedInstances'): if fields.get('dmAllowedInstances'):
try: try:
with open(dm_allowed_instances_filename, 'w+', with open(dm_allowed_instances_filename, 'w+',
encoding='utf-8') as afile: encoding='utf-8') as fp_dm:
afile.write(fields['dmAllowedInstances']) fp_dm.write(fields['dmAllowedInstances'])
except OSError: except OSError:
print('EX: unable to write allowed DM instances ' + print('EX: unable to write allowed DM instances ' +
dm_allowed_instances_filename) dm_allowed_instances_filename)
@ -528,8 +528,8 @@ def _profile_post_autogenerated_tags(base_dir: str,
if fields.get('autoTags'): if fields.get('autoTags'):
try: try:
with open(auto_tags_filename, 'w+', with open(auto_tags_filename, 'w+',
encoding='utf-8') as autofile: encoding='utf-8') as fp_auto:
autofile.write(fields['autoTags']) fp_auto.write(fields['autoTags'])
except OSError: except OSError:
print('EX: unable to write auto tags ' + print('EX: unable to write auto tags ' +
auto_tags_filename) auto_tags_filename)
@ -552,8 +552,8 @@ def _profile_post_word_replacements(base_dir: str,
if fields.get('switchwords'): if fields.get('switchwords'):
try: try:
with open(switch_filename, 'w+', with open(switch_filename, 'w+',
encoding='utf-8') as switchfile: encoding='utf-8') as fp_switch:
switchfile.write(fields['switchwords']) fp_switch.write(fields['switchwords'])
except OSError: except OSError:
print('EX: unable to write switches ' + print('EX: unable to write switches ' +
switch_filename) switch_filename)
@ -577,8 +577,8 @@ def _profile_post_filtered_words_within_bio(base_dir: str,
if fields.get('filteredWordsBio'): if fields.get('filteredWordsBio'):
try: try:
with open(filter_bio_filename, 'w+', with open(filter_bio_filename, 'w+',
encoding='utf-8') as filterfile: encoding='utf-8') as fp_filter:
filterfile.write(fields['filteredWordsBio']) fp_filter.write(fields['filteredWordsBio'])
except OSError: except OSError:
print('EX: unable to write bio filter ' + print('EX: unable to write bio filter ' +
filter_bio_filename) filter_bio_filename)
@ -600,8 +600,8 @@ def _profile_post_filtered_words(base_dir: str, nickname: str, domain: str,
if fields.get('filteredWords'): if fields.get('filteredWords'):
try: try:
with open(filter_filename, 'w+', with open(filter_filename, 'w+',
encoding='utf-8') as filterfile: encoding='utf-8') as fp_filter:
filterfile.write(fields['filteredWords']) fp_filter.write(fields['filteredWords'])
except OSError: except OSError:
print('EX: unable to write filter ' + print('EX: unable to write filter ' +
filter_filename) filter_filename)
@ -719,8 +719,8 @@ def _profile_post_notify_reactions(base_dir: str,
notify_react_filename = notify_reactions_filename notify_react_filename = notify_reactions_filename
try: try:
with open(notify_react_filename, 'w+', with open(notify_react_filename, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_notify:
rfile.write('\n') fp_notify.write('\n')
except OSError: except OSError:
print('EX: unable to write notify reactions ' + print('EX: unable to write notify reactions ' +
notify_reactions_filename) notify_reactions_filename)
@ -733,8 +733,8 @@ def _profile_post_notify_reactions(base_dir: str,
notify_reactions_active = True notify_reactions_active = True
try: try:
with open(notify_reactions_filename, 'w+', with open(notify_reactions_filename, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_notify:
rfile.write('\n') fp_notify.write('\n')
except OSError: except OSError:
print('EX: unable to write ' + print('EX: unable to write ' +
'notify reactions ' + 'notify reactions ' +
@ -761,8 +761,8 @@ def _profile_post_notify_likes(on_final_welcome_screen: bool,
# default setting from welcome screen # default setting from welcome screen
try: try:
with open(notify_likes_filename, 'w+', with open(notify_likes_filename, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_notify:
rfile.write('\n') fp_notify.write('\n')
except OSError: except OSError:
print('EX: unable to write notify likes ' + print('EX: unable to write notify likes ' +
notify_likes_filename) notify_likes_filename)
@ -775,8 +775,8 @@ def _profile_post_notify_likes(on_final_welcome_screen: bool,
notify_likes_active = True notify_likes_active = True
try: try:
with open(notify_likes_filename, 'w+', with open(notify_likes_filename, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_notify:
rfile.write('\n') fp_notify.write('\n')
except OSError: except OSError:
print('EX: unable to write notify likes ' + print('EX: unable to write notify likes ' +
notify_likes_filename) notify_likes_filename)
@ -824,8 +824,8 @@ def _profile_post_no_reply_boosts(base_dir: str, nickname: str, domain: str,
if not os.path.isfile(no_reply_boosts_filename): if not os.path.isfile(no_reply_boosts_filename):
try: try:
with open(no_reply_boosts_filename, 'w+', with open(no_reply_boosts_filename, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_reply:
rfile.write('\n') fp_reply.write('\n')
except OSError: except OSError:
print('EX: unable to write noReplyBoosts ' + print('EX: unable to write noReplyBoosts ' +
no_reply_boosts_filename) no_reply_boosts_filename)
@ -859,8 +859,8 @@ def _profile_post_hide_follows(base_dir: str, nickname: str, domain: str,
if not os.path.isfile(hide_follows_filename): if not os.path.isfile(hide_follows_filename):
try: try:
with open(hide_follows_filename, 'w+', with open(hide_follows_filename, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_hide:
rfile.write('\n') fp_hide.write('\n')
except OSError: except OSError:
print('EX: unable to write hideFollows ' + print('EX: unable to write hideFollows ' +
hide_follows_filename) hide_follows_filename)
@ -1019,8 +1019,8 @@ def _profile_post_bold_reading(base_dir: str,
self.server.bold_reading[nickname] = True self.server.bold_reading[nickname] = True
try: try:
with open(bold_reading_filename, 'w+', with open(bold_reading_filename, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_bold:
rfile.write('\n') fp_bold.write('\n')
except OSError: except OSError:
print('EX: unable to write bold reading ' + print('EX: unable to write bold reading ' +
bold_reading_filename) bold_reading_filename)
@ -1050,8 +1050,8 @@ def _profile_post_hide_reaction_button2(base_dir: str,
hide_reaction_button_active = True hide_reaction_button_active = True
try: try:
with open(hide_reaction_button_file, 'w+', with open(hide_reaction_button_file, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_hide:
rfile.write('\n') fp_hide.write('\n')
except OSError: except OSError:
print('EX: unable to write hide reaction ' + print('EX: unable to write hide reaction ' +
hide_reaction_button_file) hide_reaction_button_file)
@ -1142,8 +1142,8 @@ def _profile_post_remove_retweets(base_dir: str, nickname: str, domain: str,
remove_twitter_active = True remove_twitter_active = True
try: try:
with open(remove_twitter_filename, 'w+', with open(remove_twitter_filename, 'w+',
encoding='utf-8') as rfile: encoding='utf-8') as fp_remove:
rfile.write('\n') fp_remove.write('\n')
except OSError: except OSError:
print('EX: unable to write remove twitter ' + print('EX: unable to write remove twitter ' +
remove_twitter_filename) remove_twitter_filename)
@ -1168,8 +1168,8 @@ def _profile_post_dms_from_followers(base_dir: str, nickname: str, domain: str,
# the welcome screen # the welcome screen
try: try:
with open(follow_dms_filename, 'w+', with open(follow_dms_filename, 'w+',
encoding='utf-8') as ffile: encoding='utf-8') as fp_foll:
ffile.write('\n') fp_foll.write('\n')
except OSError: except OSError:
print('EX: unable to write follow DMs ' + print('EX: unable to write follow DMs ' +
follow_dms_filename) follow_dms_filename)
@ -1181,8 +1181,8 @@ def _profile_post_dms_from_followers(base_dir: str, nickname: str, domain: str,
follow_dms_active = True follow_dms_active = True
try: try:
with open(follow_dms_filename, 'w+', with open(follow_dms_filename, 'w+',
encoding='utf-8') as ffile: encoding='utf-8') as fp_foll:
ffile.write('\n') fp_foll.write('\n')
except OSError: except OSError:
print('EX: unable to write follow DMs 2 ' + print('EX: unable to write follow DMs 2 ' +
follow_dms_filename) follow_dms_filename)

View File

@ -1778,8 +1778,8 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {},
acct_dir(base_dir, nickname, domain) + '/.lastUsed' acct_dir(base_dir, nickname, domain) + '/.lastUsed'
try: try:
with open(last_used_filename, 'w+', with open(last_used_filename, 'w+',
encoding='utf-8') as lastfile: encoding='utf-8') as fp_last:
lastfile.write(str(int(time.time()))) fp_last.write(str(int(time.time())))
except OSError: except OSError:
print('EX: _receive_new_post_process unable to write ' + print('EX: _receive_new_post_process unable to write ' +
last_used_filename) last_used_filename)

View File

@ -829,8 +829,8 @@ def etag_exists(self, media_filename: str) -> bool:
curr_etag = '' curr_etag = ''
try: try:
with open(media_filename + '.etag', 'r', with open(media_filename + '.etag', 'r',
encoding='utf-8') as efile: encoding='utf-8') as fp_media:
curr_etag = efile.read() curr_etag = fp_media.read()
except OSError: except OSError:
print('EX: _etag_exists unable to read ' + print('EX: _etag_exists unable to read ' +
str(media_filename)) str(media_filename))

View File

@ -1717,8 +1717,8 @@ def _command_options() -> None:
if os.path.isfile(approve_follows_filename): if os.path.isfile(approve_follows_filename):
try: try:
with open(approve_follows_filename, 'r', with open(approve_follows_filename, 'r',
encoding='utf-8') as approvefile: encoding='utf-8') as fp_approve:
for approve in approvefile: for approve in fp_approve:
approve1 = remove_eol(approve) approve1 = remove_eol(approve)
print(approve1) print(approve1)
approve_ctr += 1 approve_ctr += 1

View File

@ -146,14 +146,14 @@ def _remove_from_follow_base(base_dir: str,
with open(approve_follows_filename + '.new', 'w+', with open(approve_follows_filename + '.new', 'w+',
encoding='utf-8') as approvefilenew: encoding='utf-8') as approvefilenew:
with open(approve_follows_filename, 'r', with open(approve_follows_filename, 'r',
encoding='utf-8') as approvefile: encoding='utf-8') as fp_approve:
if not accept_deny_actor: if not accept_deny_actor:
for approve_handle in approvefile: for approve_handle in fp_approve:
accept_deny_handle = accept_or_deny_handle accept_deny_handle = accept_or_deny_handle
if not approve_handle.startswith(accept_deny_handle): if not approve_handle.startswith(accept_deny_handle):
approvefilenew.write(approve_handle) approvefilenew.write(approve_handle)
else: else:
for approve_handle in approvefile: for approve_handle in fp_approve:
if accept_deny_actor not in approve_handle: if accept_deny_actor not in approve_handle:
approvefilenew.write(approve_handle) approvefilenew.write(approve_handle)
except OSError as ex: except OSError as ex: