From 9544505bfa34e520015764b817b6a6b77493f8f9 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Tue, 16 Jul 2024 12:21:28 +0100 Subject: [PATCH] File pointer naming convention --- daemon.py | 8 ++-- daemon_get.py | 4 +- daemon_get_css.py | 4 +- daemon_post_links.py | 20 ++++----- daemon_post_newswire.py | 24 +++++------ daemon_post_person_options.py | 12 +++--- daemon_post_profile.py | 76 +++++++++++++++++------------------ daemon_post_receive.py | 4 +- daemon_utils.py | 4 +- epicyon.py | 4 +- follow.py | 6 +-- 11 files changed, 83 insertions(+), 83 deletions(-) diff --git a/daemon.py b/daemon.py index 658d5ca46..a9ecabc9d 100644 --- a/daemon.py +++ b/daemon.py @@ -369,8 +369,8 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(media_tag_filename): try: with open(media_tag_filename, 'r', - encoding='utf-8') as efile: - etag = efile.read() + encoding='utf-8') as fp_efile: + etag = fp_efile.read() except OSError: print('EX: do_HEAD unable to read ' + media_tag_filename) @@ -386,8 +386,8 @@ class PubServer(BaseHTTPRequestHandler): etag = md5(media_binary).hexdigest() # nosec try: with open(media_tag_filename, 'w+', - encoding='utf-8') as efile: - efile.write(etag) + encoding='utf-8') as fp_efile: + fp_efile.write(etag) except OSError: print('EX: do_HEAD unable to write ' + media_tag_filename) diff --git a/daemon_get.py b/daemon_get.py index a35b0dcff..d20da6e2e 100644 --- a/daemon_get.py +++ b/daemon_get.py @@ -5800,8 +5800,8 @@ def daemon_http_get(self) -> None: if os.path.isfile(filename): content = None try: - with open(filename, 'r', encoding='utf-8') as rfile: - content = rfile.read() + 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: diff --git a/daemon_get_css.py b/daemon_get_css.py index dadab8ef6..50c41a611 100644 --- a/daemon_get_css.py +++ b/daemon_get_css.py @@ -103,8 +103,8 @@ def get_fonts(self, calling_domain: str, path: str, if os.path.isfile(font_filename): font_binary = None try: - with open(font_filename, 'rb') as fontfile: - font_binary = fontfile.read() + with open(font_filename, 'rb') as fp_font: + font_binary = fp_font.read() except OSError: print('EX: unable to load font ' + font_filename) if font_binary: diff --git a/daemon_post_links.py b/daemon_post_links.py index f0be2fcfa..6b0d4b166 100644 --- a/daemon_post_links.py +++ b/daemon_post_links.py @@ -32,8 +32,8 @@ def _links_update_edited(fields: {}, links_filename: str) -> None: links_str += fields['newColLink'] + '\n' try: with open(links_filename, 'w+', - encoding='utf-8') as linksfile: - linksfile.write(links_str) + encoding='utf-8') as fp_links: + fp_links.write(links_str) except OSError: print('EX: _links_update unable to write ' + links_filename) @@ -43,8 +43,8 @@ def _links_update_edited(fields: {}, links_filename: str) -> None: links_str = fields['newColLink'] + '\n' try: with open(links_filename, 'w+', - encoding='utf-8') as linksfile: - linksfile.write(links_str) + encoding='utf-8') as fp_links: + fp_links.write(links_str) except OSError: print('EX: _links_update unable to write ' + links_filename) @@ -67,8 +67,8 @@ def _links_update_about(fields: {}, allow_local_network_access: bool, allow_local_network_access, []): try: with open(about_filename, 'w+', - encoding='utf-8') as aboutfile: - aboutfile.write(about_str) + encoding='utf-8') as fp_about: + fp_about.write(about_str) except OSError: print('EX: unable to write about ' + about_filename) @@ -90,8 +90,8 @@ def _links_update_tos(fields: {}, allow_local_network_access: bool, if not dangerous_markup(tos_str, allow_local_network_access, []): try: - with open(tos_filename, 'w+', encoding='utf-8') as tosfile: - tosfile.write(tos_str) + 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: @@ -111,8 +111,8 @@ def _links_update_sepcification(fields: {}, specification_str = fields['editedSpecification'] try: with open(specification_filename, 'w+', - encoding='utf-8') as specificationfile: - specificationfile.write(specification_str) + encoding='utf-8') as fp_specification: + fp_specification.write(specification_str) except OSError: print('EX: unable to write specification ' + specification_filename) diff --git a/daemon_post_newswire.py b/daemon_post_newswire.py index dfacbda2b..63fbf9232 100644 --- a/daemon_post_newswire.py +++ b/daemon_post_newswire.py @@ -116,8 +116,8 @@ def newswire_update(self, calling_domain: str, cookie: str, newswire_str += fields['newNewswireFeed'] + '\n' try: with open(newswire_filename, 'w+', - encoding='utf-8') as newsfile: - newsfile.write(newswire_str) + encoding='utf-8') as fp_news: + fp_news.write(newswire_str) except OSError: print('EX: unable to write ' + newswire_filename) else: @@ -126,8 +126,8 @@ def newswire_update(self, calling_domain: str, cookie: str, newswire_str = fields['newNewswireFeed'] + '\n' try: with open(newswire_filename, 'w+', - encoding='utf-8') as newsfile: - newsfile.write(newswire_str) + encoding='utf-8') as fp_news: + fp_news.write(newswire_str) except OSError: print('EX: unable to write ' + newswire_filename) else: @@ -145,8 +145,8 @@ def newswire_update(self, calling_domain: str, cookie: str, if fields.get('filteredWordsNewswire'): try: with open(filter_newswire_filename, 'w+', - encoding='utf-8') as filterfile: - filterfile.write(fields['filteredWordsNewswire']) + encoding='utf-8') as fp_filter: + fp_filter.write(fields['filteredWordsNewswire']) except OSError: print('EX: newswire_update unable to write ' + filter_newswire_filename) @@ -186,8 +186,8 @@ def newswire_update(self, calling_domain: str, cookie: str, if fields.get('hashtagRulesList'): try: with open(hashtag_rules_filename, 'w+', - encoding='utf-8') as rulesfile: - rulesfile.write(fields['hashtagRulesList']) + encoding='utf-8') as fp_rules: + fp_rules.write(fields['hashtagRulesList']) except OSError: print('EX: newswire_update unable to write 4 ' + hashtag_rules_filename) @@ -206,8 +206,8 @@ def newswire_update(self, calling_domain: str, cookie: str, newswire_trusted += '\n' try: with open(newswire_tusted_filename, 'w+', - encoding='utf-8') as trustfile: - trustfile.write(newswire_trusted) + encoding='utf-8') as fp_trust: + fp_trust.write(newswire_trusted) except OSError: print('EX: newswire_update unable to write 5 ' + newswire_tusted_filename) @@ -313,8 +313,8 @@ def citations_update(self, calling_domain: str, cookie: str, # reloading the newblog screen try: with open(citations_filename, 'w+', - encoding='utf-8') as citfile: - citfile.write(citations_str) + encoding='utf-8') as fp_cit: + fp_cit.write(citations_str) except OSError: print('EX: citations_update unable to write ' + citations_filename) diff --git a/daemon_post_person_options.py b/daemon_post_person_options.py index 2e3e70f4c..15a47389c 100644 --- a/daemon_post_person_options.py +++ b/daemon_post_person_options.py @@ -597,8 +597,8 @@ def _person_options_post_to_news(self, options_confirm_params: str, nw_written = False try: with open(nw_filename, 'w+', - encoding='utf-8') as nofile: - nofile.write('\n') + 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 ' + @@ -657,8 +657,8 @@ def _person_options_post_to_features(self, options_confirm_params: str, feat_written = False try: with open(feat_filename, 'w+', - encoding='utf-8') as nofile: - nofile.write('\n') + encoding='utf-8') as fp_no: + fp_no.write('\n') feat_written = True except OSError as ex: 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 try: with open(nw_filename, 'w+', - encoding='utf-8') as modfile: - modfile.write('\n') + encoding='utf-8') as fp_mod: + fp_mod.write('\n') except OSError: print('EX: _person_options_mod_news ' + 'unable to write ' + nw_filename) diff --git a/daemon_post_profile.py b/daemon_post_profile.py index 47e41c532..d2499256d 100644 --- a/daemon_post_profile.py +++ b/daemon_post_profile.py @@ -225,8 +225,8 @@ def _profile_post_git_projects(base_dir: str, nickname: str, domain: str, if fields.get('gitProjects'): try: with open(git_projects_filename, 'w+', - encoding='utf-8') as afile: - afile.write(fields['gitProjects'].lower()) + encoding='utf-8') as fp_git: + fp_git.write(fields['gitProjects'].lower()) except OSError: print('EX: unable to write git ' + git_projects_filename) else: @@ -247,8 +247,8 @@ def _profile_post_peertube_instances(base_dir: str, fields: {}, self, peertube_instances.clear() try: with open(peertube_instances_file, 'w+', - encoding='utf-8') as afile: - afile.write(fields['ptInstances']) + encoding='utf-8') as fp_peertube: + fp_peertube.write(fields['ptInstances']) except OSError: print('EX: unable to write peertube ' + peertube_instances_file) @@ -395,8 +395,8 @@ def _profile_post_allowed_instances(base_dir: str, nickname: str, domain: str, inst_filename = allowed_instances_filename try: with open(inst_filename, 'w+', - encoding='utf-8') as afile: - afile.write(fields['allowedInstances']) + encoding='utf-8') as fp_inst: + fp_inst.write(fields['allowedInstances']) except OSError: print('EX: unable to write allowed instances ' + allowed_instances_filename) @@ -421,8 +421,8 @@ def _profile_post_dm_instances(base_dir: str, nickname: str, domain: str, if fields.get('dmAllowedInstances'): try: with open(dm_allowed_instances_filename, 'w+', - encoding='utf-8') as afile: - afile.write(fields['dmAllowedInstances']) + encoding='utf-8') as fp_dm: + fp_dm.write(fields['dmAllowedInstances']) except OSError: print('EX: unable to write allowed DM instances ' + dm_allowed_instances_filename) @@ -528,8 +528,8 @@ def _profile_post_autogenerated_tags(base_dir: str, if fields.get('autoTags'): try: with open(auto_tags_filename, 'w+', - encoding='utf-8') as autofile: - autofile.write(fields['autoTags']) + encoding='utf-8') as fp_auto: + fp_auto.write(fields['autoTags']) except OSError: print('EX: unable to write auto tags ' + auto_tags_filename) @@ -552,8 +552,8 @@ def _profile_post_word_replacements(base_dir: str, if fields.get('switchwords'): try: with open(switch_filename, 'w+', - encoding='utf-8') as switchfile: - switchfile.write(fields['switchwords']) + encoding='utf-8') as fp_switch: + fp_switch.write(fields['switchwords']) except OSError: print('EX: unable to write switches ' + switch_filename) @@ -577,8 +577,8 @@ def _profile_post_filtered_words_within_bio(base_dir: str, if fields.get('filteredWordsBio'): try: with open(filter_bio_filename, 'w+', - encoding='utf-8') as filterfile: - filterfile.write(fields['filteredWordsBio']) + encoding='utf-8') as fp_filter: + fp_filter.write(fields['filteredWordsBio']) except OSError: print('EX: unable to write bio filter ' + filter_bio_filename) @@ -600,8 +600,8 @@ def _profile_post_filtered_words(base_dir: str, nickname: str, domain: str, if fields.get('filteredWords'): try: with open(filter_filename, 'w+', - encoding='utf-8') as filterfile: - filterfile.write(fields['filteredWords']) + encoding='utf-8') as fp_filter: + fp_filter.write(fields['filteredWords']) except OSError: print('EX: unable to write filter ' + filter_filename) @@ -719,8 +719,8 @@ def _profile_post_notify_reactions(base_dir: str, notify_react_filename = notify_reactions_filename try: with open(notify_react_filename, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_notify: + fp_notify.write('\n') except OSError: print('EX: unable to write notify reactions ' + notify_reactions_filename) @@ -733,8 +733,8 @@ def _profile_post_notify_reactions(base_dir: str, notify_reactions_active = True try: with open(notify_reactions_filename, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_notify: + fp_notify.write('\n') except OSError: print('EX: unable to write ' + 'notify reactions ' + @@ -761,8 +761,8 @@ def _profile_post_notify_likes(on_final_welcome_screen: bool, # default setting from welcome screen try: with open(notify_likes_filename, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_notify: + fp_notify.write('\n') except OSError: print('EX: unable to write notify likes ' + notify_likes_filename) @@ -775,8 +775,8 @@ def _profile_post_notify_likes(on_final_welcome_screen: bool, notify_likes_active = True try: with open(notify_likes_filename, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_notify: + fp_notify.write('\n') except OSError: print('EX: unable to write notify likes ' + 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): try: with open(no_reply_boosts_filename, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_reply: + fp_reply.write('\n') except OSError: print('EX: unable to write noReplyBoosts ' + 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): try: with open(hide_follows_filename, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_hide: + fp_hide.write('\n') except OSError: print('EX: unable to write hideFollows ' + hide_follows_filename) @@ -1019,8 +1019,8 @@ def _profile_post_bold_reading(base_dir: str, self.server.bold_reading[nickname] = True try: with open(bold_reading_filename, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_bold: + fp_bold.write('\n') except OSError: print('EX: unable to write bold reading ' + bold_reading_filename) @@ -1050,8 +1050,8 @@ def _profile_post_hide_reaction_button2(base_dir: str, hide_reaction_button_active = True try: with open(hide_reaction_button_file, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_hide: + fp_hide.write('\n') except OSError: print('EX: unable to write hide reaction ' + hide_reaction_button_file) @@ -1142,8 +1142,8 @@ def _profile_post_remove_retweets(base_dir: str, nickname: str, domain: str, remove_twitter_active = True try: with open(remove_twitter_filename, 'w+', - encoding='utf-8') as rfile: - rfile.write('\n') + encoding='utf-8') as fp_remove: + fp_remove.write('\n') except OSError: print('EX: unable to write remove twitter ' + remove_twitter_filename) @@ -1168,8 +1168,8 @@ def _profile_post_dms_from_followers(base_dir: str, nickname: str, domain: str, # the welcome screen try: with open(follow_dms_filename, 'w+', - encoding='utf-8') as ffile: - ffile.write('\n') + encoding='utf-8') as fp_foll: + fp_foll.write('\n') except OSError: print('EX: unable to write follow DMs ' + follow_dms_filename) @@ -1181,8 +1181,8 @@ def _profile_post_dms_from_followers(base_dir: str, nickname: str, domain: str, follow_dms_active = True try: with open(follow_dms_filename, 'w+', - encoding='utf-8') as ffile: - ffile.write('\n') + encoding='utf-8') as fp_foll: + fp_foll.write('\n') except OSError: print('EX: unable to write follow DMs 2 ' + follow_dms_filename) diff --git a/daemon_post_receive.py b/daemon_post_receive.py index e6df55f16..c3a7a734d 100644 --- a/daemon_post_receive.py +++ b/daemon_post_receive.py @@ -1778,8 +1778,8 @@ def _receive_new_post_process(self, post_type: str, path: str, headers: {}, acct_dir(base_dir, nickname, domain) + '/.lastUsed' try: with open(last_used_filename, 'w+', - encoding='utf-8') as lastfile: - lastfile.write(str(int(time.time()))) + encoding='utf-8') as fp_last: + fp_last.write(str(int(time.time()))) except OSError: print('EX: _receive_new_post_process unable to write ' + last_used_filename) diff --git a/daemon_utils.py b/daemon_utils.py index 6605ee1a2..8541d9c61 100644 --- a/daemon_utils.py +++ b/daemon_utils.py @@ -829,8 +829,8 @@ def etag_exists(self, media_filename: str) -> bool: curr_etag = '' try: with open(media_filename + '.etag', 'r', - encoding='utf-8') as efile: - curr_etag = efile.read() + encoding='utf-8') as fp_media: + curr_etag = fp_media.read() except OSError: print('EX: _etag_exists unable to read ' + str(media_filename)) diff --git a/epicyon.py b/epicyon.py index d1ed2adf5..ff4e16cfc 100644 --- a/epicyon.py +++ b/epicyon.py @@ -1717,8 +1717,8 @@ def _command_options() -> None: if os.path.isfile(approve_follows_filename): try: with open(approve_follows_filename, 'r', - encoding='utf-8') as approvefile: - for approve in approvefile: + encoding='utf-8') as fp_approve: + for approve in fp_approve: approve1 = remove_eol(approve) print(approve1) approve_ctr += 1 diff --git a/follow.py b/follow.py index bd5292e89..d5585f2e0 100644 --- a/follow.py +++ b/follow.py @@ -146,14 +146,14 @@ def _remove_from_follow_base(base_dir: str, with open(approve_follows_filename + '.new', 'w+', encoding='utf-8') as approvefilenew: with open(approve_follows_filename, 'r', - encoding='utf-8') as approvefile: + encoding='utf-8') as fp_approve: if not accept_deny_actor: - for approve_handle in approvefile: + for approve_handle in fp_approve: accept_deny_handle = accept_or_deny_handle if not approve_handle.startswith(accept_deny_handle): approvefilenew.write(approve_handle) else: - for approve_handle in approvefile: + for approve_handle in fp_approve: if accept_deny_actor not in approve_handle: approvefilenew.write(approve_handle) except OSError as ex: