Standardise file pointer names

merge-requests/30/head
Bob Mottram 2024-07-14 14:01:46 +01:00
parent d7ccc19b10
commit 1dc4cdbf59
38 changed files with 389 additions and 388 deletions

View File

@ -259,8 +259,8 @@ def _add_global_block_reason(base_dir: str,
blocking_reasons_filename): blocking_reasons_filename):
try: try:
with open(blocking_reasons_filename, 'a+', with open(blocking_reasons_filename, 'a+',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reas_file.write(reason_line) fp_reas.write(reason_line)
except OSError: except OSError:
print('EX: unable to add blocking reason ' + print('EX: unable to add blocking reason ' +
block_id) block_id)
@ -268,8 +268,8 @@ def _add_global_block_reason(base_dir: str,
reasons_str = '' reasons_str = ''
try: try:
with open(blocking_reasons_filename, 'r', with open(blocking_reasons_filename, 'r',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reasons_str = reas_file.read() reasons_str = fp_reas.read()
except OSError: except OSError:
print('EX: unable to read blocking reasons') print('EX: unable to read blocking reasons')
reasons_lines = reasons_str.split('\n') reasons_lines = reasons_str.split('\n')
@ -281,16 +281,16 @@ def _add_global_block_reason(base_dir: str,
new_reasons_str += reason_line new_reasons_str += reason_line
try: try:
with open(blocking_reasons_filename, 'w+', with open(blocking_reasons_filename, 'w+',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reas_file.write(new_reasons_str) fp_reas.write(new_reasons_str)
except OSError: except OSError:
print('EX: unable to save blocking reasons' + print('EX: unable to save blocking reasons' +
blocking_reasons_filename) blocking_reasons_filename)
else: else:
try: try:
with open(blocking_reasons_filename, 'w+', with open(blocking_reasons_filename, 'w+',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reas_file.write(reason_line) fp_reas.write(reason_line)
except OSError: except OSError:
print('EX: unable to save blocking reason ' + print('EX: unable to save blocking reason ' +
block_id + ' ' + blocking_reasons_filename) block_id + ' ' + blocking_reasons_filename)
@ -315,8 +315,8 @@ def add_global_block(base_dir: str,
return False return False
# block an account handle or domain # block an account handle or domain
try: try:
with open(blocking_filename, 'a+', encoding='utf-8') as block_file: with open(blocking_filename, 'a+', encoding='utf-8') as fp_block:
block_file.write(block_handle + '\n') fp_block.write(block_handle + '\n')
except OSError: except OSError:
print('EX: unable to save blocked handle ' + block_handle) print('EX: unable to save blocked handle ' + block_handle)
return False return False
@ -328,8 +328,8 @@ def add_global_block(base_dir: str,
return False return False
# block a hashtag # block a hashtag
try: try:
with open(blocking_filename, 'a+', encoding='utf-8') as block_file: with open(blocking_filename, 'a+', encoding='utf-8') as fp_block:
block_file.write(block_hashtag + '\n') fp_block.write(block_hashtag + '\n')
except OSError: except OSError:
print('EX: unable to save blocked hashtag ' + block_hashtag) print('EX: unable to save blocked hashtag ' + block_hashtag)
return False return False
@ -363,8 +363,8 @@ def _add_block_reason(base_dir: str,
blocking_reasons_filename): blocking_reasons_filename):
try: try:
with open(blocking_reasons_filename, 'a+', with open(blocking_reasons_filename, 'a+',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reas_file.write(reason_line) fp_reas.write(reason_line)
except OSError: except OSError:
print('EX: unable to add blocking reason 2 ' + print('EX: unable to add blocking reason 2 ' +
block_id) block_id)
@ -372,8 +372,8 @@ def _add_block_reason(base_dir: str,
reasons_str = '' reasons_str = ''
try: try:
with open(blocking_reasons_filename, 'r', with open(blocking_reasons_filename, 'r',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reasons_str = reas_file.read() reasons_str = fp_reas.read()
except OSError: except OSError:
print('EX: unable to read blocking reasons 2') print('EX: unable to read blocking reasons 2')
reasons_lines = reasons_str.split('\n') reasons_lines = reasons_str.split('\n')
@ -385,16 +385,16 @@ def _add_block_reason(base_dir: str,
new_reasons_str += reason_line new_reasons_str += reason_line
try: try:
with open(blocking_reasons_filename, 'w+', with open(blocking_reasons_filename, 'w+',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reas_file.write(new_reasons_str) fp_reas.write(new_reasons_str)
except OSError: except OSError:
print('EX: unable to save blocking reasons 2' + print('EX: unable to save blocking reasons 2' +
blocking_reasons_filename) blocking_reasons_filename)
else: else:
try: try:
with open(blocking_reasons_filename, 'w+', with open(blocking_reasons_filename, 'w+',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reas_file.write(reason_line) fp_reas.write(reason_line)
except OSError: except OSError:
print('EX: unable to save blocking reason 2 ' + print('EX: unable to save blocking reason 2 ' +
block_id + ' ' + blocking_reasons_filename) block_id + ' ' + blocking_reasons_filename)
@ -425,8 +425,8 @@ def add_block(base_dir: str, nickname: str, domain: str,
following_str = '' following_str = ''
try: try:
with open(following_filename, 'r', with open(following_filename, 'r',
encoding='utf-8') as foll_file: encoding='utf-8') as fp_foll:
following_str = foll_file.read() following_str = fp_foll.read()
except OSError: except OSError:
print('EX: Unable to read following ' + following_filename) print('EX: Unable to read following ' + following_filename)
return False return False
@ -436,8 +436,8 @@ def add_block(base_dir: str, nickname: str, domain: str,
try: try:
with open(following_filename, 'w+', with open(following_filename, 'w+',
encoding='utf-8') as foll_file: encoding='utf-8') as fp_foll:
foll_file.write(following_str) fp_foll.write(following_str)
except OSError: except OSError:
print('EX: Unable to write following ' + following_str) print('EX: Unable to write following ' + following_str)
return False return False
@ -450,8 +450,8 @@ def add_block(base_dir: str, nickname: str, domain: str,
followers_str = '' followers_str = ''
try: try:
with open(followers_filename, 'r', with open(followers_filename, 'r',
encoding='utf-8') as foll_file: encoding='utf-8') as fp_foll:
followers_str = foll_file.read() followers_str = fp_foll.read()
except OSError: except OSError:
print('EX: Unable to read followers ' + followers_filename) print('EX: Unable to read followers ' + followers_filename)
return False return False
@ -461,15 +461,15 @@ def add_block(base_dir: str, nickname: str, domain: str,
try: try:
with open(followers_filename, 'w+', with open(followers_filename, 'w+',
encoding='utf-8') as foll_file: encoding='utf-8') as fp_foll:
foll_file.write(followers_str) fp_foll.write(followers_str)
except OSError: except OSError:
print('EX: Unable to write followers ' + followers_str) print('EX: Unable to write followers ' + followers_str)
return False return False
try: try:
with open(blocking_filename, 'a+', encoding='utf-8') as block_file: with open(blocking_filename, 'a+', encoding='utf-8') as fp_block:
block_file.write(block_handle + '\n') fp_block.write(block_handle + '\n')
except OSError: except OSError:
print('EX: unable to append block handle ' + block_handle) print('EX: unable to append block handle ' + block_handle)
return False return False
@ -501,8 +501,8 @@ def _remove_global_block_reason(base_dir: str,
reasons_str = '' reasons_str = ''
try: try:
with open(unblocking_filename, 'r', with open(unblocking_filename, 'r',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reasons_str = reas_file.read() reasons_str = fp_reas.read()
except OSError: except OSError:
print('EX: unable to read blocking reasons 3') print('EX: unable to read blocking reasons 3')
reasons_lines = reasons_str.split('\n') reasons_lines = reasons_str.split('\n')
@ -513,8 +513,8 @@ def _remove_global_block_reason(base_dir: str,
new_reasons_str += line + '\n' new_reasons_str += line + '\n'
try: try:
with open(unblocking_filename, 'w+', with open(unblocking_filename, 'w+',
encoding='utf-8') as reas_file: encoding='utf-8') as fp_reas:
reas_file.write(new_reasons_str) fp_reas.write(new_reasons_str)
except OSError: except OSError:
print('EX: unable to save blocking reasons 2' + print('EX: unable to save blocking reasons 2' +
unblocking_filename) unblocking_filename)
@ -1293,8 +1293,8 @@ def mute_post(base_dir: str, nickname: str, domain: str, port: int,
try: try:
with open(post_filename + '.muted', 'w+', with open(post_filename + '.muted', 'w+',
encoding='utf-8') as mute_file: encoding='utf-8') as fp_mute:
mute_file.write('\n') fp_mute.write('\n')
except OSError: except OSError:
print('EX: Failed to save mute file ' + post_filename + '.muted') print('EX: Failed to save mute file ' + post_filename + '.muted')
return return
@ -1637,8 +1637,8 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
continue continue
try: try:
with open(following_filename, 'r', with open(following_filename, 'r',
encoding='utf-8') as foll_file: encoding='utf-8') as fp_foll:
follow_list = foll_file.readlines() follow_list = fp_foll.readlines()
for handle in follow_list: for handle in follow_list:
if '@' not in handle: if '@' not in handle:
continue continue
@ -1654,10 +1654,10 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
# write the allow file # write the allow file
try: try:
with open(allow_filename, 'w+', with open(allow_filename, 'w+',
encoding='utf-8') as allow_file: encoding='utf-8') as fp_allow:
allow_file.write(domain_full + '\n') fp_allow.write(domain_full + '\n')
for allowed in allowed_domains: for allowed in allowed_domains:
allow_file.write(allowed + '\n') fp_allow.write(allowed + '\n')
print('Broch mode enabled') print('Broch mode enabled')
except OSError as ex: except OSError as ex:
print('EX: Broch mode not enabled due to file write ' + str(ex)) print('EX: Broch mode not enabled due to file write ' + str(ex))

20
blog.py
View File

@ -80,8 +80,8 @@ def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {},
replies = 0 replies = 0
lines = [] lines = []
try: try:
with open(post_filename, 'r', encoding='utf-8') as post_file: with open(post_filename, 'r', encoding='utf-8') as fp_post:
lines = post_file.readlines() lines = fp_post.readlines()
except OSError: except OSError:
print('EX: failed to read blog ' + post_filename) print('EX: failed to read blog ' + post_filename)
@ -103,11 +103,11 @@ def _no_of_blog_replies(base_dir: str, http_prefix: str, translate: {},
print('Rewriting ' + post_filename + ' to remove ' + print('Rewriting ' + post_filename + ' to remove ' +
str(len(removals)) + ' entries') str(len(removals)) + ' entries')
try: try:
with open(post_filename, 'w+', encoding='utf-8') as post_file: with open(post_filename, 'w+', encoding='utf-8') as fp_post:
for reply_post_id in lines: for reply_post_id in lines:
reply_post_id = remove_eol(reply_post_id) reply_post_id = remove_eol(reply_post_id)
if reply_post_id not in removals: if reply_post_id not in removals:
post_file.write(reply_post_id + '\n') fp_post.write(reply_post_id + '\n')
except OSError as ex: except OSError as ex:
print('EX: unable to remove replies from post ' + print('EX: unable to remove replies from post ' +
post_filename + ' ' + str(ex)) post_filename + ' ' + str(ex))
@ -147,16 +147,16 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {},
if os.path.isfile(post_filename): if os.path.isfile(post_filename):
try: try:
with open(post_filename, 'r', with open(post_filename, 'r',
encoding='utf-8') as post_file: encoding='utf-8') as fp_post:
return post_file.read() + '\n' return fp_post.read() + '\n'
except OSError: except OSError:
print('EX: unable to read blog 3 ' + post_filename) print('EX: unable to read blog 3 ' + post_filename)
return '' return ''
lines = [] lines = []
try: try:
with open(post_filename, 'r', encoding='utf-8') as post_file: with open(post_filename, 'r', encoding='utf-8') as fp_post:
lines = post_file.readlines() lines = fp_post.readlines()
except OSError: except OSError:
print('EX: unable to read blog 4 ' + post_filename) print('EX: unable to read blog 4 ' + post_filename)
@ -172,8 +172,8 @@ def _get_blog_replies(base_dir: str, http_prefix: str, translate: {},
if not os.path.isfile(post_filename): if not os.path.isfile(post_filename):
continue continue
try: try:
with open(post_filename, 'r', encoding='utf-8') as post_file: with open(post_filename, 'r', encoding='utf-8') as fp_post:
replies_str += post_file.read() + '\n' replies_str += fp_post.read() + '\n'
except OSError: except OSError:
print('EX: unable to read blog replies ' + post_filename) print('EX: unable to read blog replies ' + post_filename)
rply = _get_blog_replies(base_dir, http_prefix, translate, rply = _get_blog_replies(base_dir, http_prefix, translate,

View File

@ -81,16 +81,16 @@ def undo_bookmarks_collection_entry(recent_posts_cache: {},
index_str = '' index_str = ''
try: try:
with open(bookmarks_index_filename, 'r', with open(bookmarks_index_filename, 'r',
encoding='utf-8') as index_file: encoding='utf-8') as fp_index:
index_str = index_file.read().replace(bookmark_index + '\n', '') index_str = fp_index.read().replace(bookmark_index + '\n', '')
except OSError: except OSError:
print('EX: undo_bookmarks_collection_entry unable to read ' + print('EX: undo_bookmarks_collection_entry unable to read ' +
bookmarks_index_filename) bookmarks_index_filename)
if index_str: if index_str:
try: try:
with open(bookmarks_index_filename, 'w+', with open(bookmarks_index_filename, 'w+',
encoding='utf-8') as bmi_file: encoding='utf-8') as fp_bmi:
bmi_file.write(index_str) fp_bmi.write(index_str)
except OSError: except OSError:
print('EX: unable to write bookmarks index ' + print('EX: unable to write bookmarks index ' +
bookmarks_index_filename) bookmarks_index_filename)
@ -246,11 +246,11 @@ def update_bookmarks_collection(recent_posts_cache: {},
if not text_in_file(bookmark_index, bookmarks_index_filename): if not text_in_file(bookmark_index, bookmarks_index_filename):
try: try:
with open(bookmarks_index_filename, 'r+', with open(bookmarks_index_filename, 'r+',
encoding='utf-8') as bmi_file: encoding='utf-8') as fp_bmi:
content = bmi_file.read() content = fp_bmi.read()
if bookmark_index + '\n' not in content: if bookmark_index + '\n' not in content:
bmi_file.seek(0, 0) fp_bmi.seek(0, 0)
bmi_file.write(bookmark_index + '\n' + content) fp_bmi.write(bookmark_index + '\n' + content)
if debug: if debug:
print('DEBUG: bookmark added to index') print('DEBUG: bookmark added to index')
except OSError as ex: except OSError as ex:
@ -259,8 +259,8 @@ def update_bookmarks_collection(recent_posts_cache: {},
else: else:
try: try:
with open(bookmarks_index_filename, 'w+', with open(bookmarks_index_filename, 'w+',
encoding='utf-8') as bm_file: encoding='utf-8') as fp_bm:
bm_file.write(bookmark_index + '\n') fp_bm.write(bookmark_index + '\n')
except OSError: except OSError:
print('EX: unable to write bookmarks index ' + print('EX: unable to write bookmarks index ' +
bookmarks_index_filename) bookmarks_index_filename)

View File

@ -32,8 +32,8 @@ def get_hashtag_category(base_dir: str, hashtag: str) -> str:
category_str = None category_str = None
try: try:
with open(category_filename, 'r', encoding='utf-8') as category_file: with open(category_filename, 'r', encoding='utf-8') as fp_category:
category_str = category_file.read() category_str = fp_category.read()
except OSError: except OSError:
print('EX: unable to read category ' + category_filename) print('EX: unable to read category ' + category_filename)
except UnicodeEncodeError as ex: except UnicodeEncodeError as ex:

12
city.py
View File

@ -226,8 +226,8 @@ def spoof_geolocation(base_dir: str,
"", "", 0) "", "", 0)
cities = [] cities = []
try: try:
with open(locations_filename, 'r', encoding='utf-8') as loc_file: with open(locations_filename, 'r', encoding='utf-8') as fp_loc:
cities = loc_file.readlines() cities = fp_loc.readlines()
except OSError: except OSError:
print('EX: unable to read locations ' + locations_filename) print('EX: unable to read locations ' + locations_filename)
@ -238,8 +238,8 @@ def spoof_geolocation(base_dir: str,
if os.path.isfile(nogo_filename): if os.path.isfile(nogo_filename):
nogo_list = [] nogo_list = []
try: try:
with open(nogo_filename, 'r', encoding='utf-8') as nogo_file: with open(nogo_filename, 'r', encoding='utf-8') as fp_nogo:
nogo_list = nogo_file.readlines() nogo_list = fp_nogo.readlines()
except OSError: except OSError:
print('EX: spoof_geolocation unable to read ' + nogo_filename) print('EX: spoof_geolocation unable to read ' + nogo_filename)
for line in nogo_list: for line in nogo_list:
@ -334,8 +334,8 @@ def get_spoofed_city(city: str, base_dir: str,
city_filename = acct_dir(base_dir, nickname, domain) + '/city.txt' city_filename = acct_dir(base_dir, nickname, domain) + '/city.txt'
if os.path.isfile(city_filename): if os.path.isfile(city_filename):
try: try:
with open(city_filename, 'r', encoding='utf-8') as city_file: with open(city_filename, 'r', encoding='utf-8') as fp_city:
city1 = city_file.read() city1 = fp_city.read()
city = remove_eol(city1) city = remove_eol(city1)
except OSError: except OSError:
print('EX: get_spoofed_city unable to read ' + city_filename) print('EX: get_spoofed_city unable to read ' + city_filename)

View File

@ -241,8 +241,8 @@ def dangerous_css(filename: str, allow_local_network_access: bool) -> bool:
content = None content = None
try: try:
with open(filename, 'r', encoding='utf-8') as css_file: with open(filename, 'r', encoding='utf-8') as fp_css:
content = css_file.read().lower() content = fp_css.read().lower()
except OSError: except OSError:
print('EX: unable to read css file ' + filename) print('EX: unable to read css file ' + filename)
@ -293,8 +293,8 @@ def switch_words(base_dir: str, nickname: str, domain: str, content: str,
return content return content
try: try:
with open(switch_words_filename, 'r', with open(switch_words_filename, 'r',
encoding='utf-8') as words_file: encoding='utf-8') as fp_words:
rules = words_file.readlines() rules = fp_words.readlines()
except OSError: except OSError:
print('EX: unable to read switches ' + switch_words_filename) print('EX: unable to read switches ' + switch_words_filename)
@ -1163,8 +1163,8 @@ def _load_auto_tags(base_dir: str, nickname: str, domain: str) -> []:
if not os.path.isfile(filename): if not os.path.isfile(filename):
return [] return []
try: try:
with open(filename, 'r', encoding='utf-8') as tags_file: with open(filename, 'r', encoding='utf-8') as fp_tags:
return tags_file.readlines() return fp_tags.readlines()
except OSError: except OSError:
print('EX: unable to read auto tags ' + filename) print('EX: unable to read auto tags ' + filename)
return [] return []
@ -1381,8 +1381,8 @@ def add_html_tags(base_dir: str, http_prefix: str,
following = [] following = []
try: try:
with open(following_filename, 'r', with open(following_filename, 'r',
encoding='utf-8') as foll_file: encoding='utf-8') as fp_foll:
following = foll_file.readlines() following = fp_foll.readlines()
except OSError: except OSError:
print('EX: add_html_tags unable to read ' + print('EX: add_html_tags unable to read ' +
following_filename) following_filename)

View File

@ -58,8 +58,8 @@ def update_conversation(base_dir: str, nickname: str, domain: str,
if not os.path.isfile(conversation_filename): if not os.path.isfile(conversation_filename):
try: try:
with open(conversation_filename, 'w+', with open(conversation_filename, 'w+',
encoding='utf-8') as conv_file: encoding='utf-8') as fp_conv:
conv_file.write(post_id + '\n') fp_conv.write(post_id + '\n')
return True return True
except OSError: except OSError:
print('EX: update_conversation ' + print('EX: update_conversation ' +
@ -67,8 +67,8 @@ def update_conversation(base_dir: str, nickname: str, domain: str,
elif not text_in_file(post_id + '\n', conversation_filename): elif not text_in_file(post_id + '\n', conversation_filename):
try: try:
with open(conversation_filename, 'a+', with open(conversation_filename, 'a+',
encoding='utf-8') as conv_file: encoding='utf-8') as fp_conv:
conv_file.write(post_id + '\n') fp_conv.write(post_id + '\n')
return True return True
except OSError: except OSError:
print('EX: update_conversation 2 ' + print('EX: update_conversation 2 ' +
@ -89,8 +89,8 @@ def mute_conversation(base_dir: str, nickname: str, domain: str,
return return
try: try:
with open(conversation_filename + '.muted', 'w+', with open(conversation_filename + '.muted', 'w+',
encoding='utf-8') as conv_file: encoding='utf-8') as fp_conv:
conv_file.write('\n') fp_conv.write('\n')
except OSError: except OSError:
print('EX: unable to write mute ' + conversation_filename) print('EX: unable to write mute ' + conversation_filename)

View File

@ -377,8 +377,8 @@ class PubServer(BaseHTTPRequestHandler):
else: else:
media_binary = None media_binary = None
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read media binary ' + print('EX: unable to read media binary ' +
media_filename) media_filename)

View File

@ -2343,8 +2343,8 @@ def daemon_http_get(self) -> None:
media_binary = None media_binary = None
while tries < 5: while tries < 5:
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
break break
except OSError as ex: except OSError as ex:
print('EX: manifest logo ' + print('EX: manifest logo ' +
@ -2384,8 +2384,8 @@ def daemon_http_get(self) -> None:
media_binary = None media_binary = None
while tries < 5: while tries < 5:
try: try:
with open(screen_filename, 'rb') as av_file: with open(screen_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
break break
except OSError as ex: except OSError as ex:
print('EX: manifest screenshot ' + print('EX: manifest screenshot ' +
@ -2425,8 +2425,8 @@ def daemon_http_get(self) -> None:
media_binary = None media_binary = None
while tries < 5: while tries < 5:
try: try:
with open(icon_filename, 'rb') as av_file: with open(icon_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
break break
except OSError as ex: except OSError as ex:
print('EX: login screen image ' + print('EX: login screen image ' +

View File

@ -83,8 +83,8 @@ def get_favicon(self, calling_domain: str,
if os.path.isfile(favicon_filename): if os.path.isfile(favicon_filename):
fav_binary = None fav_binary = None
try: try:
with open(favicon_filename, 'rb') as fav_file: with open(favicon_filename, 'rb') as fp_fav:
fav_binary = fav_file.read() fav_binary = fp_fav.read()
except OSError: except OSError:
print('EX: unable to read favicon ' + favicon_filename) print('EX: unable to read favicon ' + favicon_filename)
if fav_binary: if fav_binary:
@ -133,8 +133,8 @@ def show_cached_favicon(self, referer_domain: str, path: str,
return return
media_binary = None media_binary = None
try: try:
with open(fav_filename, 'rb') as av_file: with open(fav_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read cached favicon ' + fav_filename) print('EX: unable to read cached favicon ' + fav_filename)
if media_binary: if media_binary:

View File

@ -107,8 +107,8 @@ def show_avatar_or_banner(self, referer_domain: str, path: str,
media_image_type = get_image_mime_type(avatar_file) media_image_type = get_image_mime_type(avatar_file)
media_binary = None media_binary = None
try: try:
with open(avatar_filename, 'rb') as av_file: with open(avatar_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read avatar ' + avatar_filename) print('EX: unable to read avatar ' + avatar_filename)
if media_binary: if media_binary:
@ -136,8 +136,8 @@ def show_cached_avatar(self, referer_domain: str, path: str,
return return
media_binary = None media_binary = None
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read cached avatar ' + media_filename) print('EX: unable to read cached avatar ' + media_filename)
if media_binary: if media_binary:
@ -186,8 +186,8 @@ def show_help_screen_image(self, path: str,
if os.path.isfile(media_filename): if os.path.isfile(media_filename):
media_binary = None media_binary = None
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read help image ' + media_filename) print('EX: unable to read help image ' + media_filename)
if media_binary: if media_binary:
@ -237,8 +237,8 @@ def show_manual_image(self, path: str,
if os.path.isfile(media_filename): if os.path.isfile(media_filename):
media_binary = None media_binary = None
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read manual image ' + print('EX: unable to read manual image ' +
media_filename) media_filename)
@ -290,8 +290,8 @@ def show_specification_image(self, path: str,
if os.path.isfile(media_filename): if os.path.isfile(media_filename):
media_binary = None media_binary = None
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read specification image ' + print('EX: unable to read specification image ' +
media_filename) media_filename)
@ -335,8 +335,8 @@ def show_share_image(self, path: str,
media_file_type = get_image_mime_type(media_filename) media_file_type = get_image_mime_type(media_filename)
media_binary = None media_binary = None
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read binary ' + media_filename) print('EX: unable to read binary ' + media_filename)
if media_binary: if media_binary:
@ -393,8 +393,8 @@ def show_icon(self, path: str,
if os.path.isfile(media_filename): if os.path.isfile(media_filename):
media_binary = None media_binary = None
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read icon image ' + media_filename) print('EX: unable to read icon image ' + media_filename)
if media_binary: if media_binary:
@ -465,8 +465,8 @@ def show_media(self, path: str, base_dir: str,
media_binary = None media_binary = None
try: try:
with open(media_filename, 'rb') as av_file: with open(media_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read media binary ' + media_filename) print('EX: unable to read media binary ' + media_filename)
if media_binary: if media_binary:
@ -513,8 +513,8 @@ def show_qrcode(self, calling_domain: str, path: str,
media_binary = None media_binary = None
while tries < 5: while tries < 5:
try: try:
with open(qr_filename, 'rb') as av_file: with open(qr_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
break break
except OSError as ex: except OSError as ex:
print('EX: _show_qrcode ' + str(tries) + ' ' + str(ex)) print('EX: _show_qrcode ' + str(tries) + ' ' + str(ex))
@ -562,8 +562,8 @@ def search_screen_banner(self, path: str,
media_binary = None media_binary = None
while tries < 5: while tries < 5:
try: try:
with open(banner_filename, 'rb') as av_file: with open(banner_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
break break
except OSError as ex: except OSError as ex:
print('EX: _search_screen_banner ' + print('EX: _search_screen_banner ' +
@ -607,8 +607,8 @@ def column_image(self, side: str, path: str, base_dir: str, domain: str,
media_binary = None media_binary = None
while tries < 5: while tries < 5:
try: try:
with open(banner_filename, 'rb') as av_file: with open(banner_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
break break
except OSError as ex: except OSError as ex:
print('EX: _column_image ' + str(tries) + ' ' + str(ex)) print('EX: _column_image ' + str(tries) + ' ' + str(ex))
@ -650,8 +650,8 @@ def show_default_profile_background(self, base_dir: str, theme_name: str,
bg_binary = None bg_binary = None
while tries < 5: while tries < 5:
try: try:
with open(bg_filename, 'rb') as av_file: with open(bg_filename, 'rb') as fp_av:
bg_binary = av_file.read() bg_binary = fp_av.read()
break break
except OSError as ex: except OSError as ex:
print('EX: _show_default_profile_background ' + print('EX: _show_default_profile_background ' +
@ -702,8 +702,8 @@ def show_background_image(self, path: str,
bg_binary = None bg_binary = None
while tries < 5: while tries < 5:
try: try:
with open(bg_filename, 'rb') as av_file: with open(bg_filename, 'rb') as fp_av:
bg_binary = av_file.read() bg_binary = fp_av.read()
break break
except OSError as ex: except OSError as ex:
print('EX: _show_background_image ' + print('EX: _show_background_image ' +
@ -748,8 +748,8 @@ def show_emoji(self, path: str,
media_image_type = get_image_mime_type(emoji_filename) media_image_type = get_image_mime_type(emoji_filename)
media_binary = None media_binary = None
try: try:
with open(emoji_filename, 'rb') as av_file: with open(emoji_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
except OSError: except OSError:
print('EX: unable to read emoji image ' + emoji_filename) print('EX: unable to read emoji image ' + emoji_filename)
if media_binary: if media_binary:

View File

@ -68,8 +68,8 @@ def receive_image_attachment(self, length: int, path: str, base_dir: str,
print('WARN: _receive_image image binary is not recognized ' + print('WARN: _receive_image image binary is not recognized ' +
media_filename) media_filename)
try: try:
with open(media_filename, 'wb') as av_file: with open(media_filename, 'wb') as fp_av:
av_file.write(media_bytes) fp_av.write(media_bytes)
except OSError: except OSError:
print('EX: receive_image_attachment unable to write ' + media_filename) print('EX: receive_image_attachment unable to write ' + media_filename)
if debug: if debug:

View File

@ -501,8 +501,8 @@ def _profile_post_auto_cw(base_dir: str, nickname: str, domain: str,
if fields.get('autoCW'): if fields.get('autoCW'):
try: try:
with open(auto_cw_filename, 'w+', with open(auto_cw_filename, 'w+',
encoding='utf-8') as auto_cw_file: encoding='utf-8') as fp_auto_cw:
auto_cw_file.write(fields['autoCW']) fp_auto_cw.write(fields['autoCW'])
except OSError: except OSError:
print('EX: unable to write auto CW ' + print('EX: unable to write auto CW ' +
auto_cw_filename) auto_cw_filename)

View File

@ -278,8 +278,8 @@ def _send_reply_to_question(self, base_dir: str,
# record the vote # record the vote
try: try:
with open(votes_filename, 'a+', with open(votes_filename, 'a+',
encoding='utf-8') as votes_file: encoding='utf-8') as fp_votes:
votes_file.write(message_id + '\n') fp_votes.write(message_id + '\n')
except OSError: except OSError:
print('EX: unable to write vote ' + print('EX: unable to write vote ' +
votes_filename) votes_filename)

View File

@ -188,18 +188,18 @@ def _mark_post_as_read(actor: str, post_id: str, post_category: str) -> None:
# prepend to read posts file # prepend to read posts file
post_id += '\n' post_id += '\n'
with open(read_posts_filename, 'r+', with open(read_posts_filename, 'r+',
encoding='utf-8') as read_file: encoding='utf-8') as fp_read:
content = read_file.read() content = fp_read.read()
if post_id not in content: if post_id not in content:
read_file.seek(0, 0) fp_read.seek(0, 0)
read_file.write(post_id + content) fp_read.write(post_id + content)
except OSError as ex: except OSError as ex:
print('EX: Failed to mark post as read 1 ' + str(ex)) print('EX: Failed to mark post as read 1 ' + str(ex))
else: else:
try: try:
with open(read_posts_filename, 'w+', with open(read_posts_filename, 'w+',
encoding='utf-8') as read_file: encoding='utf-8') as fp_read:
read_file.write(post_id + '\n') fp_read.write(post_id + '\n')
except OSError as ex: except OSError as ex:
print('EX: Failed to mark post as read 2 ' + str(ex)) print('EX: Failed to mark post as read 2 ' + str(ex))

View File

@ -27,8 +27,8 @@ def add_filter(base_dir: str, nickname: str, domain: str, words: str) -> bool:
return False return False
try: try:
with open(filters_filename, 'a+', with open(filters_filename, 'a+',
encoding='utf-8') as filters_file: encoding='utf-8') as fp_filters:
filters_file.write(words + '\n') fp_filters.write(words + '\n')
except OSError: except OSError:
print('EX: unable to append filters ' + filters_filename) print('EX: unable to append filters ' + filters_filename)
return False return False
@ -48,8 +48,8 @@ def add_global_filter(base_dir: str, words: str) -> bool:
if text_in_file(words, filters_filename): if text_in_file(words, filters_filename):
return False return False
try: try:
with open(filters_filename, 'a+', encoding='utf-8') as filters_file: with open(filters_filename, 'a+', encoding='utf-8') as fp_filters:
filters_file.write(words + '\n') fp_filters.write(words + '\n')
except OSError: except OSError:
print('EX: unable to append filters ' + filters_filename) print('EX: unable to append filters ' + filters_filename)
return False return False

View File

@ -74,8 +74,8 @@ def receiving_calendar_events(base_dir: str, nickname: str, domain: str,
following_handles = None following_handles = None
try: try:
with open(following_filename, 'r', with open(following_filename, 'r',
encoding='utf-8') as following_file: encoding='utf-8') as fp_following:
following_handles = following_file.read() following_handles = fp_following.read()
except OSError: except OSError:
print('EX: receiving_calendar_events ' + following_filename) print('EX: receiving_calendar_events ' + following_filename)
if following_handles: if following_handles:
@ -120,8 +120,8 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str,
print('Calendar file exists') print('Calendar file exists')
try: try:
with open(calendar_filename, 'r', with open(calendar_filename, 'r',
encoding='utf-8') as calendar_file: encoding='utf-8') as fp_calendar:
following_handles = calendar_file.read() following_handles = fp_calendar.read()
except OSError: except OSError:
print('EX: _receive_calendar_events ' + calendar_filename) print('EX: _receive_calendar_events ' + calendar_filename)
else: else:
@ -130,8 +130,8 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str,
following_handles = '' following_handles = ''
try: try:
with open(following_filename, 'r', with open(following_filename, 'r',
encoding='utf-8') as following_file: encoding='utf-8') as fp_following:
following_handles = following_file.read() following_handles = fp_following.read()
except OSError: except OSError:
print('EX: _receive_calendar_events 2 ' + calendar_filename) print('EX: _receive_calendar_events 2 ' + calendar_filename)
if add: if add:

8
git.py
View File

@ -213,13 +213,13 @@ def receive_git_patch(base_dir: str, nickname: str, domain: str,
_git_add_from_handle(patch_str, _git_add_from_handle(patch_str,
'@' + from_nickname + '@' + from_domain) '@' + from_nickname + '@' + from_domain)
try: try:
with open(patch_filename, 'w+', encoding='utf-8') as patch_file: with open(patch_filename, 'w+', encoding='utf-8') as fp_patch:
patch_file.write(patch_str) fp_patch.write(patch_str)
patch_notify_filename = \ patch_notify_filename = \
acct_dir(base_dir, nickname, domain) + '/.newPatchContent' acct_dir(base_dir, nickname, domain) + '/.newPatchContent'
with open(patch_notify_filename, 'w+', with open(patch_notify_filename, 'w+',
encoding='utf-8') as patch_file: encoding='utf-8') as fp_patch_notify:
patch_file.write(patch_str) fp_patch_notify.write(patch_str)
return True return True
except OSError as ex: except OSError as ex:
print('EX: receive_git_patch ' + patch_filename + ' ' + str(ex)) print('EX: receive_git_patch ' + patch_filename + ' ' + str(ex))

View File

@ -151,11 +151,11 @@ def save_event_post(base_dir: str, handle: str, post_id: str,
_remove_event_from_timeline(event_id, tl_events_filename) _remove_event_from_timeline(event_id, tl_events_filename)
try: try:
with open(tl_events_filename, 'r+', with open(tl_events_filename, 'r+',
encoding='utf-8') as tl_events_file: encoding='utf-8') as fp_tl_events:
content = tl_events_file.read() content = fp_tl_events.read()
if event_id + '\n' not in content: if event_id + '\n' not in content:
tl_events_file.seek(0, 0) fp_tl_events.seek(0, 0)
tl_events_file.write(event_id + '\n' + content) fp_tl_events.write(event_id + '\n' + content)
except OSError as ex: except OSError as ex:
print('EX: Failed to write entry to events file ' + print('EX: Failed to write entry to events file ' +
tl_events_filename + ' ' + str(ex)) tl_events_filename + ' ' + str(ex))
@ -163,8 +163,8 @@ def save_event_post(base_dir: str, handle: str, post_id: str,
else: else:
try: try:
with open(tl_events_filename, 'w+', with open(tl_events_filename, 'w+',
encoding='utf-8') as tl_events_file: encoding='utf-8') as fp_tl_events:
tl_events_file.write(event_id + '\n') fp_tl_events.write(event_id + '\n')
except OSError: except OSError:
print('EX: save_event_post unable to write ' + print('EX: save_event_post unable to write ' +
tl_events_filename) tl_events_filename)
@ -185,8 +185,8 @@ def save_event_post(base_dir: str, handle: str, post_id: str,
# append the post Id to the file for the calendar month # append the post Id to the file for the calendar month
try: try:
with open(calendar_filename, 'a+', encoding='utf-8') as calendar_file: with open(calendar_filename, 'a+', encoding='utf-8') as fp_calendar:
calendar_file.write(post_id + '\n') fp_calendar.write(post_id + '\n')
except OSError: except OSError:
print('EX: unable to append to calendar ' + calendar_filename) print('EX: unable to append to calendar ' + calendar_filename)
@ -197,8 +197,8 @@ def save_event_post(base_dir: str, handle: str, post_id: str,
'/calendar?year=' + str(event_year) + '?month=' + \ '/calendar?year=' + str(event_year) + '?month=' + \
str(event_month_number) + '?day=' + str(event_day_of_month) str(event_month_number) + '?day=' + str(event_day_of_month)
try: try:
with open(cal_notify_filename, 'w+', encoding='utf-8') as cal_file: with open(cal_notify_filename, 'w+', encoding='utf-8') as fp_cal:
cal_file.write(notify_str) fp_cal.write(notify_str)
except OSError: except OSError:
print('EX: save_event_post unable to write ' + cal_notify_filename) print('EX: save_event_post unable to write ' + cal_notify_filename)
return False return False
@ -298,8 +298,8 @@ def get_todays_events(base_dir: str, nickname: str, domain: str,
calendar_post_ids = [] calendar_post_ids = []
recreate_events_file = False recreate_events_file = False
try: try:
with open(calendar_filename, 'r', encoding='utf-8') as events_file: with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
for post_id in events_file: for post_id in fp_events:
post_id = remove_eol(post_id) post_id = remove_eol(post_id)
post_filename = \ post_filename = \
locate_post(base_dir, nickname, domain, post_id) locate_post(base_dir, nickname, domain, post_id)
@ -374,9 +374,9 @@ def get_todays_events(base_dir: str, nickname: str, domain: str,
if recreate_events_file: if recreate_events_file:
try: try:
with open(calendar_filename, 'w+', with open(calendar_filename, 'w+',
encoding='utf-8') as calendar_file: encoding='utf-8') as fp_calendar:
for post_id in calendar_post_ids: for post_id in calendar_post_ids:
calendar_file.write(post_id + '\n') fp_calendar.write(post_id + '\n')
except OSError: except OSError:
print('EX: unable to recreate events file 1 ' + print('EX: unable to recreate events file 1 ' +
calendar_filename) calendar_filename)
@ -605,8 +605,8 @@ def day_events_check(base_dir: str, nickname: str, domain: str,
events_exist = False events_exist = False
try: try:
with open(calendar_filename, 'r', encoding='utf-8') as events_file: with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
for post_id in events_file: for post_id in fp_events:
post_id = remove_eol(post_id) post_id = remove_eol(post_id)
post_filename = \ post_filename = \
locate_post(base_dir, nickname, domain, post_id) locate_post(base_dir, nickname, domain, post_id)
@ -665,8 +665,8 @@ def get_this_weeks_events(base_dir: str, nickname: str, domain: str) -> {}:
calendar_post_ids = [] calendar_post_ids = []
recreate_events_file = False recreate_events_file = False
try: try:
with open(calendar_filename, 'r', encoding='utf-8') as events_file: with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
for post_id in events_file: for post_id in fp_events:
post_id = remove_eol(post_id) post_id = remove_eol(post_id)
post_filename = \ post_filename = \
locate_post(base_dir, nickname, domain, post_id) locate_post(base_dir, nickname, domain, post_id)
@ -709,9 +709,9 @@ def get_this_weeks_events(base_dir: str, nickname: str, domain: str) -> {}:
if recreate_events_file: if recreate_events_file:
try: try:
with open(calendar_filename, 'w+', with open(calendar_filename, 'w+',
encoding='utf-8') as calendar_file: encoding='utf-8') as fp_calendar:
for post_id in calendar_post_ids: for post_id in calendar_post_ids:
calendar_file.write(post_id + '\n') fp_calendar.write(post_id + '\n')
except OSError: except OSError:
print('EX: unable to recreate events file 2 ' + print('EX: unable to recreate events file 2 ' +
calendar_filename) calendar_filename)
@ -738,8 +738,8 @@ def get_calendar_events(base_dir: str, nickname: str, domain: str,
calendar_post_ids = [] calendar_post_ids = []
recreate_events_file = False recreate_events_file = False
try: try:
with open(calendar_filename, 'r', encoding='utf-8') as events_file: with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
for post_id in events_file: for post_id in fp_events:
post_id = remove_eol(post_id) post_id = remove_eol(post_id)
post_filename = \ post_filename = \
locate_post(base_dir, nickname, domain, post_id) locate_post(base_dir, nickname, domain, post_id)
@ -800,9 +800,9 @@ def get_calendar_events(base_dir: str, nickname: str, domain: str,
if recreate_events_file: if recreate_events_file:
try: try:
with open(calendar_filename, 'w+', with open(calendar_filename, 'w+',
encoding='utf-8') as calendar_file: encoding='utf-8') as fp_calendar:
for post_id in calendar_post_ids: for post_id in calendar_post_ids:
calendar_file.write(post_id + '\n') fp_calendar.write(post_id + '\n')
except OSError: except OSError:
print('EX: unable to recreate events file 3 ' + print('EX: unable to recreate events file 3 ' +
calendar_filename) calendar_filename)

View File

@ -248,8 +248,8 @@ def cache_svg_images(session, base_dir: str, http_prefix: str,
svg_written = False svg_written = False
cleaned_up = cleaned_up.encode('utf-8') cleaned_up = cleaned_up.encode('utf-8')
try: try:
with open(image_filename, 'wb') as im_file: with open(image_filename, 'wb') as fp_im:
im_file.write(cleaned_up) fp_im.write(cleaned_up)
svg_written = True svg_written = True
except OSError: except OSError:
print('EX: unable to write cleaned up svg ' + url) print('EX: unable to write cleaned up svg ' + url)
@ -422,16 +422,16 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str,
hashtag_added = False hashtag_added = False
if not os.path.isfile(tags_filename): if not os.path.isfile(tags_filename):
try: try:
with open(tags_filename, 'w+', encoding='utf-8') as tags_file: with open(tags_filename, 'w+', encoding='utf-8') as fp_tags:
tags_file.write(tag_line) fp_tags.write(tag_line)
hashtag_added = True hashtag_added = True
except OSError: except OSError:
print('EX: store_hash_tags unable to write ' + tags_filename) print('EX: store_hash_tags unable to write ' + tags_filename)
else: else:
content = '' content = ''
try: try:
with open(tags_filename, 'r', encoding='utf-8') as tags_file: with open(tags_filename, 'r', encoding='utf-8') as fp_tags:
content = tags_file.read() content = fp_tags.read()
except OSError: except OSError:
print('EX: store_hash_tags failed to read ' + tags_filename) print('EX: store_hash_tags failed to read ' + tags_filename)
if post_url not in content: if post_url not in content:
@ -3362,8 +3362,8 @@ def _receive_announce(recent_posts_cache: {},
post_filename.replace('.json', '') + '.mitm' post_filename.replace('.json', '') + '.mitm'
try: try:
with open(post_filename_mitm, 'w+', with open(post_filename_mitm, 'w+',
encoding='utf-8') as mitm_file: encoding='utf-8') as fp_mitm:
mitm_file.write('\n') fp_mitm.write('\n')
except OSError: except OSError:
print('EX: unable to write mitm ' + post_filename_mitm) print('EX: unable to write mitm ' + post_filename_mitm)
minimize_all_images = False minimize_all_images = False
@ -3705,16 +3705,16 @@ def populate_replies(base_dir: str, http_prefix: str, domain: str,
if not text_in_file(message_id, post_replies_filename): if not text_in_file(message_id, post_replies_filename):
try: try:
with open(post_replies_filename, 'a+', with open(post_replies_filename, 'a+',
encoding='utf-8') as replies_file: encoding='utf-8') as fp_replies:
replies_file.write(message_id + '\n') fp_replies.write(message_id + '\n')
except OSError: except OSError:
print('EX: populate_replies unable to append ' + print('EX: populate_replies unable to append ' +
post_replies_filename) post_replies_filename)
else: else:
try: try:
with open(post_replies_filename, 'w+', with open(post_replies_filename, 'w+',
encoding='utf-8') as replies_file: encoding='utf-8') as fp_replies:
replies_file.write(message_id + '\n') fp_replies.write(message_id + '\n')
except OSError: except OSError:
print('EX: populate_replies unable to write ' + print('EX: populate_replies unable to write ' +
post_replies_filename) post_replies_filename)
@ -4266,19 +4266,19 @@ def inbox_update_index(boxname: str, base_dir: str, handle: str,
written = False written = False
if os.path.isfile(index_filename): if os.path.isfile(index_filename):
try: try:
with open(index_filename, 'r+', encoding='utf-8') as index_file: with open(index_filename, 'r+', encoding='utf-8') as fp_index:
content = index_file.read() content = fp_index.read()
if destination_filename + '\n' not in content: if destination_filename + '\n' not in content:
index_file.seek(0, 0) fp_index.seek(0, 0)
index_file.write(destination_filename + '\n' + content) fp_index.write(destination_filename + '\n' + content)
written = True written = True
return True return True
except OSError as ex: except OSError as ex:
print('EX: Failed to write entry to index ' + str(ex)) print('EX: Failed to write entry to index ' + str(ex))
else: else:
try: try:
with open(index_filename, 'w+', encoding='utf-8') as index_file: with open(index_filename, 'w+', encoding='utf-8') as fp_index:
index_file.write(destination_filename + '\n') fp_index.write(destination_filename + '\n')
written = True written = True
except OSError as ex: except OSError as ex:
print('EX: Failed to write initial entry to index ' + str(ex)) print('EX: Failed to write initial entry to index ' + str(ex))
@ -4311,8 +4311,8 @@ def _update_last_seen(base_dir: str, handle: str, actor: str) -> None:
if os.path.isfile(last_seen_filename): if os.path.isfile(last_seen_filename):
try: try:
with open(last_seen_filename, 'r', with open(last_seen_filename, 'r',
encoding='utf-8') as last_seen_file: encoding='utf-8') as fp_last_seen:
days_since_epoch_file = last_seen_file.read() days_since_epoch_file = fp_last_seen.read()
if int(days_since_epoch_file) == days_since_epoch: if int(days_since_epoch_file) == days_since_epoch:
# value hasn't changed, so we can save writing # value hasn't changed, so we can save writing
# anything to file # anything to file
@ -4321,8 +4321,8 @@ def _update_last_seen(base_dir: str, handle: str, actor: str) -> None:
print('EX: _update_last_seen unable to read ' + last_seen_filename) print('EX: _update_last_seen unable to read ' + last_seen_filename)
try: try:
with open(last_seen_filename, 'w+', with open(last_seen_filename, 'w+',
encoding='utf-8') as last_seen_file: encoding='utf-8') as fp_last_seen:
last_seen_file.write(str(days_since_epoch)) fp_last_seen.write(str(days_since_epoch))
except OSError: except OSError:
print('EX: _update_last_seen unable to write ' + last_seen_filename) print('EX: _update_last_seen unable to write ' + last_seen_filename)
@ -5450,8 +5450,8 @@ def _inbox_after_initial(server, inbox_start_time,
destination_filename.replace('.json', '') + '.mitm' destination_filename.replace('.json', '') + '.mitm'
try: try:
with open(destination_filename_mitm, 'w+', with open(destination_filename_mitm, 'w+',
encoding='utf-8') as mitm_file: encoding='utf-8') as fp_mitm:
mitm_file.write('\n') fp_mitm.write('\n')
except OSError: except OSError:
print('EX: _inbox_after_initial unable to write ' + print('EX: _inbox_after_initial unable to write ' +
destination_filename_mitm) destination_filename_mitm)
@ -5471,8 +5471,8 @@ def _inbox_after_initial(server, inbox_start_time,
destination_filename_muted = destination_filename + '.muted' destination_filename_muted = destination_filename + '.muted'
try: try:
with open(destination_filename_muted, 'w+', with open(destination_filename_muted, 'w+',
encoding='utf-8') as mute_file: encoding='utf-8') as fp_mute:
mute_file.write('\n') fp_mute.write('\n')
except OSError: except OSError:
print('EX: _inbox_after_initial unable to write 2 ' + print('EX: _inbox_after_initial unable to write 2 ' +
destination_filename_muted) destination_filename_muted)
@ -5917,8 +5917,8 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool):
if not already_unknown: if not already_unknown:
try: try:
with open(unknown_contexts_file, 'a+', with open(unknown_contexts_file, 'a+',
encoding='utf-8') as unknown_file: encoding='utf-8') as fp_unknown:
unknown_file.write(unknown_context + '\n') fp_unknown.write(unknown_context + '\n')
except OSError: except OSError:
print('EX: _check_json_signature unable to append ' + print('EX: _check_json_signature unable to append ' +
unknown_contexts_file) unknown_contexts_file)
@ -5936,8 +5936,8 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool):
if not already_unknown: if not already_unknown:
try: try:
with open(unknown_signatures_file, 'a+', with open(unknown_signatures_file, 'a+',
encoding='utf-8') as unknown_file: encoding='utf-8') as fp_unknown:
unknown_file.write(jwebsig_type + '\n') fp_unknown.write(jwebsig_type + '\n')
except OSError: except OSError:
print('EX: _check_json_signature unable to append ' + print('EX: _check_json_signature unable to append ' +
unknown_signatures_file) unknown_signatures_file)
@ -6202,16 +6202,16 @@ def _receive_follow_request(session, session_onion, session_i2p,
return True return True
try: try:
with open(followers_filename, 'r+', with open(followers_filename, 'r+',
encoding='utf-8') as followers_file: encoding='utf-8') as fp_followers:
content = followers_file.read() content = fp_followers.read()
if approve_handle + '\n' not in content: if approve_handle + '\n' not in content:
followers_file.seek(0, 0) fp_followers.seek(0, 0)
if not group_account: if not group_account:
followers_file.write(approve_handle + fp_followers.write(approve_handle +
'\n' + content) '\n' + content)
else: else:
followers_file.write('!' + approve_handle + fp_followers.write('!' + approve_handle +
'\n' + content) '\n' + content)
except OSError as ex: except OSError as ex:
print('WARN: ' + print('WARN: ' +
'Failed to write entry to followers file ' + 'Failed to write entry to followers file ' +
@ -6219,8 +6219,8 @@ def _receive_follow_request(session, session_onion, session_i2p,
else: else:
try: try:
with open(followers_filename, 'w+', with open(followers_filename, 'w+',
encoding='utf-8') as followers_file: encoding='utf-8') as fp_followers:
followers_file.write(approve_handle + '\n') fp_followers.write(approve_handle + '\n')
except OSError: except OSError:
print('EX: _receive_follow_request unable to write ' + print('EX: _receive_follow_request unable to write ' +
followers_filename) followers_filename)

View File

@ -58,8 +58,8 @@ def manual_deny_follow_request(session, session_onion, session_i2p,
# Store rejected follows # Store rejected follows
try: try:
with open(rejected_follows_filename, 'a+', with open(rejected_follows_filename, 'a+',
encoding='utf-8') as rejects_file: encoding='utf-8') as fp_rejects:
rejects_file.write(deny_handle + '\n') fp_rejects.write(deny_handle + '\n')
except OSError: except OSError:
print('EX: manual_deny_follow_request unable to append ' + print('EX: manual_deny_follow_request unable to append ' +
rejected_follows_filename) rejected_follows_filename)
@ -134,16 +134,16 @@ def _approve_follower_handle(account_dir: str, approve_handle: str) -> None:
if not text_in_file(approve_handle, approved_filename): if not text_in_file(approve_handle, approved_filename):
try: try:
with open(approved_filename, 'a+', with open(approved_filename, 'a+',
encoding='utf-8') as approved_file: encoding='utf-8') as fp_approved:
approved_file.write(approve_handle + '\n') fp_approved.write(approve_handle + '\n')
except OSError: except OSError:
print('EX: _approve_follower_handle unable to append ' + print('EX: _approve_follower_handle unable to append ' +
approved_filename) approved_filename)
else: else:
try: try:
with open(approved_filename, 'w+', with open(approved_filename, 'w+',
encoding='utf-8') as approved_file: encoding='utf-8') as fp_approved:
approved_file.write(approve_handle + '\n') fp_approved.write(approve_handle + '\n')
except OSError: except OSError:
print('EX: _approve_follower_handle unable to write ' + print('EX: _approve_follower_handle unable to write ' +
approved_filename) approved_filename)
@ -327,12 +327,12 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
if not text_in_file(approve_handle_full, followers_filename): if not text_in_file(approve_handle_full, followers_filename):
try: try:
with open(followers_filename, 'r+', with open(followers_filename, 'r+',
encoding='utf-8') as followers_file: encoding='utf-8') as fp_followers:
content = followers_file.read() content = fp_followers.read()
if approve_handle_full + '\n' not in content: if approve_handle_full + '\n' not in content:
followers_file.seek(0, 0) fp_followers.seek(0, 0)
followers_file.write(approve_handle_full + '\n' + fp_followers.write(approve_handle_full + '\n' +
content) content)
except OSError as ex: except OSError as ex:
print('WARN: Manual follow accept. ' + print('WARN: Manual follow accept. ' +
'Failed to write entry to followers file ' + str(ex)) 'Failed to write entry to followers file ' + str(ex))
@ -344,8 +344,8 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
handle + ' is ' + approve_handle_full) handle + ' is ' + approve_handle_full)
try: try:
with open(followers_filename, 'w+', with open(followers_filename, 'w+',
encoding='utf-8') as followers_file: encoding='utf-8') as fp_followers:
followers_file.write(approve_handle_full + '\n') fp_followers.write(approve_handle_full + '\n')
except OSError: except OSError:
print('EX: manual_approve_follow_request unable to write ' + print('EX: manual_approve_follow_request unable to write ' +
followers_filename) followers_filename)

View File

@ -541,8 +541,8 @@ def _update_etag(media_filename: str) -> None:
# read the binary data # read the binary data
data = None data = None
try: try:
with open(media_filename, 'rb') as media_file: with open(media_filename, 'rb') as fp_media:
data = media_file.read() data = fp_media.read()
except OSError: except OSError:
print('EX: _update_etag unable to read ' + str(media_filename)) print('EX: _update_etag unable to read ' + str(media_filename))

View File

@ -53,19 +53,19 @@ def _update_feeds_outbox_index(base_dir: str, domain: str,
if not text_in_file(post_id, index_filename): if not text_in_file(post_id, index_filename):
try: try:
with open(index_filename, 'r+', with open(index_filename, 'r+',
encoding='utf-8') as feeds_file: encoding='utf-8') as fp_feeds:
content = feeds_file.read() content = fp_feeds.read()
if post_id + '\n' not in content: if post_id + '\n' not in content:
feeds_file.seek(0, 0) fp_feeds.seek(0, 0)
feeds_file.write(post_id + '\n' + content) fp_feeds.write(post_id + '\n' + content)
print('DEBUG: feeds post added to index') print('DEBUG: feeds post added to index')
except OSError as ex: except OSError as ex:
print('EX: Failed to write entry to feeds posts index ' + print('EX: Failed to write entry to feeds posts index ' +
index_filename + ' ' + str(ex)) index_filename + ' ' + str(ex))
else: else:
try: try:
with open(index_filename, 'w+', encoding='utf-8') as feeds_file: with open(index_filename, 'w+', encoding='utf-8') as fp_feeds:
feeds_file.write(post_id + '\n') fp_feeds.write(post_id + '\n')
except OSError: except OSError:
print('EX: _update_feeds_outbox_index unable to write ' + print('EX: _update_feeds_outbox_index unable to write ' +
index_filename) index_filename)
@ -76,8 +76,8 @@ def _save_arrived_time(post_filename: str, arrived: str) -> None:
""" """
try: try:
with open(post_filename + '.arrived', 'w+', with open(post_filename + '.arrived', 'w+',
encoding='utf-8') as arrived_file: encoding='utf-8') as fp_arrived:
arrived_file.write(arrived) fp_arrived.write(arrived)
except OSError: except OSError:
print('EX: _save_arrived_time unable to write ' + print('EX: _save_arrived_time unable to write ' +
post_filename + '.arrived') post_filename + '.arrived')
@ -501,8 +501,8 @@ def _create_news_mirror(base_dir: str, domain: str,
index_content = '' index_content = ''
try: try:
with open(mirror_index_filename, 'r', with open(mirror_index_filename, 'r',
encoding='utf-8') as index_file: encoding='utf-8') as fp_index:
index_content = index_file.read() index_content = fp_index.read()
for remove_post_id in removals: for remove_post_id in removals:
index_content = \ index_content = \
index_content.replace(remove_post_id + '\n', '') index_content.replace(remove_post_id + '\n', '')
@ -511,8 +511,8 @@ def _create_news_mirror(base_dir: str, domain: str,
mirror_index_filename) mirror_index_filename)
try: try:
with open(mirror_index_filename, 'w+', with open(mirror_index_filename, 'w+',
encoding='utf-8') as index_file: encoding='utf-8') as fp_index:
index_file.write(index_content) fp_index.write(index_content)
except OSError: except OSError:
print('EX: _create_news_mirror unable to write ' + print('EX: _create_news_mirror unable to write ' +
mirror_index_filename) mirror_index_filename)
@ -542,16 +542,16 @@ def _create_news_mirror(base_dir: str, domain: str,
if os.path.isfile(mirror_index_filename): if os.path.isfile(mirror_index_filename):
try: try:
with open(mirror_index_filename, 'a+', with open(mirror_index_filename, 'a+',
encoding='utf-8') as index_file: encoding='utf-8') as fp_index:
index_file.write(post_id_number + '\n') fp_index.write(post_id_number + '\n')
except OSError: except OSError:
print('EX: _create_news_mirror unable to append ' + print('EX: _create_news_mirror unable to append ' +
mirror_index_filename) mirror_index_filename)
else: else:
try: try:
with open(mirror_index_filename, 'w+', with open(mirror_index_filename, 'w+',
encoding='utf-8') as index_file: encoding='utf-8') as fp_index:
index_file.write(post_id_number + '\n') fp_index.write(post_id_number + '\n')
except OSError: except OSError:
print('EX: _create_news_mirror unable to write ' + print('EX: _create_news_mirror unable to write ' +
mirror_index_filename) mirror_index_filename)

View File

@ -1624,11 +1624,11 @@ def _add_account_blogs_to_newswire(base_dir: str, nickname: str, domain: str,
moderated = True moderated = True
try: try:
with open(index_filename, 'r', encoding='utf-8') as index_file: with open(index_filename, 'r', encoding='utf-8') as fp_index:
post_filename = 'start' post_filename = 'start'
ctr = 0 ctr = 0
while post_filename: while post_filename:
post_filename = index_file.readline() post_filename = fp_index.readline()
if post_filename: if post_filename:
# if this is a full path then remove the directories # if this is a full path then remove the directories
if '/' in post_filename: if '/' in post_filename:

View File

@ -45,8 +45,8 @@ def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
print('notify file exists') print('notify file exists')
try: try:
with open(notify_on_post_filename, 'r', with open(notify_on_post_filename, 'r',
encoding='utf-8') as calendar_file: encoding='utf-8') as fp_calendar:
following_handles = calendar_file.read() following_handles = fp_calendar.read()
except OSError: except OSError:
print('EX: _notify_on_post_arrival unable to read 1 ' + print('EX: _notify_on_post_arrival unable to read 1 ' +
notify_on_post_filename) notify_on_post_filename)
@ -56,8 +56,8 @@ def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
following_handles = '' following_handles = ''
try: try:
with open(following_filename, 'r', with open(following_filename, 'r',
encoding='utf-8') as following_file: encoding='utf-8') as fp_following:
following_handles = following_file.read() following_handles = fp_following.read()
except OSError: except OSError:
print('EX: _notify_on_post_arrival unable to read 2 ' + print('EX: _notify_on_post_arrival unable to read 2 ' +
following_filename) following_filename)

View File

@ -605,8 +605,8 @@ def _create_person_base(base_dir: str, nickname: str, domain: str, port: int,
os.mkdir(base_dir + private_keys_subdir) os.mkdir(base_dir + private_keys_subdir)
filename = base_dir + private_keys_subdir + '/' + handle + '.key' filename = base_dir + private_keys_subdir + '/' + handle + '.key'
try: try:
with open(filename, 'w+', encoding='utf-8') as text_file: with open(filename, 'w+', encoding='utf-8') as fp_text:
print(private_key_pem, file=text_file) print(private_key_pem, file=fp_text)
except OSError: except OSError:
print('EX: _create_person_base unable to save ' + filename) print('EX: _create_person_base unable to save ' + filename)
@ -616,8 +616,8 @@ def _create_person_base(base_dir: str, nickname: str, domain: str, port: int,
os.mkdir(base_dir + public_keys_subdir) os.mkdir(base_dir + public_keys_subdir)
filename = base_dir + public_keys_subdir + '/' + handle + '.pem' filename = base_dir + public_keys_subdir + '/' + handle + '.pem'
try: try:
with open(filename, 'w+', encoding='utf-8') as text_file: with open(filename, 'w+', encoding='utf-8') as fp_text:
print(public_key_pem, file=text_file) print(public_key_pem, file=fp_text)
except OSError: except OSError:
print('EX: _create_person_base unable to save 2 ' + filename) print('EX: _create_person_base unable to save 2 ' + filename)
@ -1409,10 +1409,10 @@ def _remove_tags_for_nickname(base_dir: str, nickname: str,
print('EX: _remove_tags_for_nickname unable to read ' + print('EX: _remove_tags_for_nickname unable to read ' +
tag_filename) tag_filename)
try: try:
with open(tag_filename, 'w+', encoding='utf-8') as tag_file: with open(tag_filename, 'w+', encoding='utf-8') as fp_tag:
for tagline in lines: for tagline in lines:
if match_str not in tagline: if match_str not in tagline:
tag_file.write(tagline) fp_tag.write(tagline)
except OSError: except OSError:
print('EX: _remove_tags_for_nickname unable to write ' + print('EX: _remove_tags_for_nickname unable to write ' +
tag_filename) tag_filename)
@ -1616,9 +1616,9 @@ def person_snooze(base_dir: str, nickname: str, domain: str,
if text_in_file(snooze_actor + ' ', snoozed_filename): if text_in_file(snooze_actor + ' ', snoozed_filename):
return return
try: try:
with open(snoozed_filename, 'a+', encoding='utf-8') as snoozed_file: with open(snoozed_filename, 'a+', encoding='utf-8') as fp_snoozed:
snoozed_file.write(snooze_actor + ' ' + fp_snoozed.write(snooze_actor + ' ' +
str(int(time.time())) + '\n') str(int(time.time())) + '\n')
except OSError: except OSError:
print('EX: person_snooze unable to append ' + snoozed_filename) print('EX: person_snooze unable to append ' + snoozed_filename)
@ -1674,8 +1674,8 @@ def set_person_notes(base_dir: str, nickname: str, domain: str,
os.mkdir(notes_dir) os.mkdir(notes_dir)
notes_filename = notes_dir + '/' + handle + '.txt' notes_filename = notes_dir + '/' + handle + '.txt'
try: try:
with open(notes_filename, 'w+', encoding='utf-8') as notes_file: with open(notes_filename, 'w+', encoding='utf-8') as fp_notes:
notes_file.write(notes) fp_notes.write(notes)
except OSError: except OSError:
print('EX: unable to write ' + notes_filename) print('EX: unable to write ' + notes_filename)
return False return False

View File

@ -31,8 +31,8 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
petnames_str = '' petnames_str = ''
try: try:
with open(petnames_filename, 'r', with open(petnames_filename, 'r',
encoding='utf-8') as petnames_file: encoding='utf-8') as fp_petnames:
petnames_str = petnames_file.read() petnames_str = fp_petnames.read()
except OSError: except OSError:
print('EX: set_pet_name unable to read ' + petnames_filename) print('EX: set_pet_name unable to read ' + petnames_filename)
if entry in petnames_str: if entry in petnames_str:
@ -48,8 +48,8 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
# save the updated petnames file # save the updated petnames file
try: try:
with open(petnames_filename, 'w+', with open(petnames_filename, 'w+',
encoding='utf-8') as petnames_file: encoding='utf-8') as fp_petnames:
petnames_file.write(new_petnames_str) fp_petnames.write(new_petnames_str)
except OSError: except OSError:
print('EX: set_pet_name unable to save ' + petnames_filename) print('EX: set_pet_name unable to save ' + petnames_filename)
return False return False
@ -57,8 +57,8 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
# entry does not exist in the petnames file # entry does not exist in the petnames file
try: try:
with open(petnames_filename, 'a+', with open(petnames_filename, 'a+',
encoding='utf-8') as petnames_file: encoding='utf-8') as fp_petnames:
petnames_file.write(entry) fp_petnames.write(entry)
except OSError: except OSError:
print('EX: set_pet_name unable to append ' + petnames_filename) print('EX: set_pet_name unable to append ' + petnames_filename)
return False return False
@ -66,8 +66,8 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
# first entry # first entry
try: try:
with open(petnames_filename, 'w+', encoding='utf-8') as petnames_file: with open(petnames_filename, 'w+', encoding='utf-8') as fp_petnames:
petnames_file.write(entry) fp_petnames.write(entry)
except OSError: except OSError:
print('EX: set_pet_name unable to write ' + petnames_filename) print('EX: set_pet_name unable to write ' + petnames_filename)
return False return False
@ -88,8 +88,8 @@ def get_pet_name(base_dir: str, nickname: str, domain: str,
return '' return ''
petnames_str = '' petnames_str = ''
try: try:
with open(petnames_filename, 'r', encoding='utf-8') as petnames_file: with open(petnames_filename, 'r', encoding='utf-8') as fp_petnames:
petnames_str = petnames_file.read() petnames_str = fp_petnames.read()
except OSError: except OSError:
print('EX: get_pet_name unable to read ' + petnames_filename) print('EX: get_pet_name unable to read ' + petnames_filename)
if ' ' + handle + '\n' in petnames_str: if ' ' + handle + '\n' in petnames_str:
@ -119,8 +119,8 @@ def _get_pet_name_handle(base_dir: str, nickname: str, domain: str,
return '' return ''
petnames_str = '' petnames_str = ''
try: try:
with open(petnames_filename, 'r', encoding='utf-8') as petnames_file: with open(petnames_filename, 'r', encoding='utf-8') as fp_petnames:
petnames_str = petnames_file.read() petnames_str = fp_petnames.read()
except OSError: except OSError:
print('EX: _get_pet_name_handle unable to read ' + petnames_filename) print('EX: _get_pet_name_handle unable to read ' + petnames_filename)
if petname + ' ' in petnames_str: if petname + ' ' in petnames_str:

View File

@ -199,15 +199,16 @@ def no_of_followers_on_domain(base_dir: str, handle: str,
ctr = 0 ctr = 0
try: try:
with open(filename, 'r', encoding='utf-8') as followers_file: with open(filename, 'r', encoding='utf-8') as fp_followers:
for follower_handle in followers_file: for follower_handle in fp_followers:
if '@' in follower_handle: if '@' in follower_handle:
follower_domain = follower_handle.split('@')[1] follower_domain = follower_handle.split('@')[1]
follower_domain = remove_eol(follower_domain) follower_domain = remove_eol(follower_domain)
if domain == follower_domain: if domain == follower_domain:
ctr += 1 ctr += 1
except OSError: except OSError as exc:
print('EX: no_of_followers_on_domain unable to read ' + filename) print('EX: no_of_followers_on_domain unable to read ' + filename +
' ' + str(exc))
return ctr return ctr
@ -1090,8 +1091,8 @@ def _update_hashtags_index(base_dir: str, tag: {}, new_post_id: str,
new_post_id + '\n' new_post_id + '\n'
# create a new tags index file # create a new tags index file
try: try:
with open(tags_filename, 'w+', encoding='utf-8') as tags_file: with open(tags_filename, 'w+', encoding='utf-8') as fp_tags:
tags_file.write(tag_line) fp_tags.write(tag_line)
except OSError: except OSError:
print('EX: _update_hashtags_index unable to write tags file ' + print('EX: _update_hashtags_index unable to write tags file ' +
tags_filename) tags_filename)
@ -1104,11 +1105,11 @@ def _update_hashtags_index(base_dir: str, tag: {}, new_post_id: str,
str(days_since_epoch) + ' ' + nickname + ' ' + \ str(days_since_epoch) + ' ' + nickname + ' ' + \
new_post_id + '\n' new_post_id + '\n'
try: try:
with open(tags_filename, 'r+', encoding='utf-8') as tags_file: with open(tags_filename, 'r+', encoding='utf-8') as fp_tags:
content = tags_file.read() content = fp_tags.read()
if tag_line not in content: if tag_line not in content:
tags_file.seek(0, 0) fp_tags.seek(0, 0)
tags_file.write(tag_line + content) fp_tags.write(tag_line + content)
except OSError as ex: except OSError as ex:
print('EX: Failed to write entry to tags file ' + print('EX: Failed to write entry to tags file ' +
tags_filename + ' ' + str(ex)) tags_filename + ' ' + str(ex))
@ -1127,11 +1128,11 @@ def _add_schedule_post(base_dir: str, nickname: str, domain: str,
if not text_in_file(index_str, schedule_index_filename): if not text_in_file(index_str, schedule_index_filename):
try: try:
with open(schedule_index_filename, 'r+', with open(schedule_index_filename, 'r+',
encoding='utf-8') as schedule_file: encoding='utf-8') as fp_schedule:
content = schedule_file.read() content = fp_schedule.read()
if index_str + '\n' not in content: if index_str + '\n' not in content:
schedule_file.seek(0, 0) fp_schedule.seek(0, 0)
schedule_file.write(index_str + '\n' + content) fp_schedule.write(index_str + '\n' + content)
print('DEBUG: scheduled post added to index') print('DEBUG: scheduled post added to index')
except OSError as ex: except OSError as ex:
print('EX: Failed to write entry to scheduled posts index ' + print('EX: Failed to write entry to scheduled posts index ' +
@ -1139,8 +1140,8 @@ def _add_schedule_post(base_dir: str, nickname: str, domain: str,
else: else:
try: try:
with open(schedule_index_filename, 'w+', with open(schedule_index_filename, 'w+',
encoding='utf-8') as schedule_file: encoding='utf-8') as fp_schedule:
schedule_file.write(index_str + '\n') fp_schedule.write(index_str + '\n')
except OSError as ex: except OSError as ex:
print('EX: Failed to write entry to scheduled posts index2 ' + print('EX: Failed to write entry to scheduled posts index2 ' +
schedule_index_filename + ' ' + str(ex)) schedule_index_filename + ' ' + str(ex))
@ -1608,8 +1609,8 @@ def _create_post_mod_report(base_dir: str,
# save to index file # save to index file
moderation_index_file = data_dir(base_dir) + '/moderation.txt' moderation_index_file = data_dir(base_dir) + '/moderation.txt'
try: try:
with open(moderation_index_file, 'a+', encoding='utf-8') as mod_file: with open(moderation_index_file, 'a+', encoding='utf-8') as fp_mod:
mod_file.write(new_post_id + '\n') fp_mod.write(new_post_id + '\n')
except OSError: except OSError:
print('EX: unable to write moderation index file ' + print('EX: unable to write moderation index file ' +
moderation_index_file) moderation_index_file)
@ -1969,8 +1970,8 @@ def pin_post2(base_dir: str, nickname: str, domain: str,
account_dir = acct_dir(base_dir, nickname, domain) account_dir = acct_dir(base_dir, nickname, domain)
pinned_filename = account_dir + '/pinToProfile.txt' pinned_filename = account_dir + '/pinToProfile.txt'
try: try:
with open(pinned_filename, 'w+', encoding='utf-8') as pin_file: with open(pinned_filename, 'w+', encoding='utf-8') as fp_pin:
pin_file.write(pinned_content) fp_pin.write(pinned_content)
except OSError: except OSError:
print('EX: unable to write ' + pinned_filename) print('EX: unable to write ' + pinned_filename)
@ -2903,16 +2904,16 @@ def thread_send_post(session, post_json_str: str, federation_list: [],
if os.path.isfile(post_log_filename): if os.path.isfile(post_log_filename):
try: try:
with open(post_log_filename, 'a+', with open(post_log_filename, 'a+',
encoding='utf-8') as log_file: encoding='utf-8') as fp_log:
log_file.write(log_str + '\n') fp_log.write(log_str + '\n')
except OSError: except OSError:
print('EX: thread_send_post unable to append ' + print('EX: thread_send_post unable to append ' +
post_log_filename) post_log_filename)
else: else:
try: try:
with open(post_log_filename, 'w+', with open(post_log_filename, 'w+',
encoding='utf-8') as log_file: encoding='utf-8') as fp_log:
log_file.write(log_str + '\n') fp_log.write(log_str + '\n')
except OSError: except OSError:
print('EX: thread_send_post unable to write ' + print('EX: thread_send_post unable to write ' +
post_log_filename) post_log_filename)
@ -4398,8 +4399,8 @@ def create_moderation(base_dir: str, nickname: str, domain: str, port: int,
lines = [] lines = []
try: try:
with open(moderation_index_file, 'r', with open(moderation_index_file, 'r',
encoding='utf-8') as index_file: encoding='utf-8') as fp_index:
lines = index_file.readlines() lines = fp_index.readlines()
except OSError: except OSError:
print('EX: create_moderation unable to read ' + print('EX: create_moderation unable to read ' +
moderation_index_file) moderation_index_file)
@ -4679,10 +4680,10 @@ def _create_box_items(base_dir: str,
first_post_id = first_post_id.replace('/', '#') first_post_id = first_post_id.replace('/', '#')
try: try:
with open(index_filename, 'r', encoding='utf-8') as index_file: with open(index_filename, 'r', encoding='utf-8') as fp_index:
posts_added_to_timeline = 0 posts_added_to_timeline = 0
while posts_added_to_timeline < items_per_page: while posts_added_to_timeline < items_per_page:
post_filename = index_file.readline() post_filename = fp_index.readline()
if not post_filename: if not post_filename:
break break
@ -5417,8 +5418,8 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
# get the existing index entries as a string # get the existing index entries as a string
new_index = '' new_index = ''
try: try:
with open(index_filename, 'r', encoding='utf-8') as index_file: with open(index_filename, 'r', encoding='utf-8') as fp_index:
for post_id in index_file: for post_id in fp_index:
new_index += post_id new_index += post_id
index_ctr += 1 index_ctr += 1
if index_ctr >= max_posts_in_box: if index_ctr >= max_posts_in_box:
@ -5430,8 +5431,8 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
if len(new_index) > 0: if len(new_index) > 0:
try: try:
with open(index_filename, 'w+', with open(index_filename, 'w+',
encoding='utf-8') as index_file: encoding='utf-8') as fp_index:
index_file.write(new_index) fp_index.write(new_index)
except OSError: except OSError:
print('EX: archive_posts_for_person unable to write ' + print('EX: archive_posts_for_person unable to write ' +
index_filename) index_filename)
@ -5903,8 +5904,8 @@ def populate_replies_json(base_dir: str, nickname: str, domain: str,
replies_boxes = ('outbox', 'inbox') replies_boxes = ('outbox', 'inbox')
try: try:
with open(post_replies_filename, 'r', with open(post_replies_filename, 'r',
encoding='utf-8') as replies_file: encoding='utf-8') as fp_replies:
for message_id in replies_file: for message_id in fp_replies:
reply_found = False reply_found = False
# examine inbox and outbox # examine inbox and outbox
for boxname in replies_boxes: for boxname in replies_boxes:
@ -5975,8 +5976,8 @@ def _reject_announce(announce_filename: str,
if not os.path.isfile(announce_filename + '.reject'): if not os.path.isfile(announce_filename + '.reject'):
try: try:
with open(announce_filename + '.reject', 'w+', with open(announce_filename + '.reject', 'w+',
encoding='utf-8') as reject_announce_file: encoding='utf-8') as fp_reject_announce:
reject_announce_file.write('\n') fp_reject_announce.write('\n')
except OSError: except OSError:
print('EX: _reject_announce unable to write ' + print('EX: _reject_announce unable to write ' +
announce_filename + '.reject') announce_filename + '.reject')

View File

@ -126,10 +126,10 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
# create a new voters file # create a new voters file
try: try:
with open(voters_filename, 'w+', with open(voters_filename, 'w+',
encoding='utf-8') as voters_file: encoding='utf-8') as fp_voters:
voters_file.write(actor_url + fp_voters.write(actor_url +
voters_file_separator + voters_file_separator +
reply_vote + '\n') reply_vote + '\n')
except OSError: except OSError:
print('EX: unable to write voters file ' + voters_filename) print('EX: unable to write voters file ' + voters_filename)
else: else:
@ -137,10 +137,10 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
# append to the voters file # append to the voters file
try: try:
with open(voters_filename, 'a+', with open(voters_filename, 'a+',
encoding='utf-8') as voters_file: encoding='utf-8') as fp_voters:
voters_file.write(actor_url + fp_voters.write(actor_url +
voters_file_separator + voters_file_separator +
reply_vote + '\n') reply_vote + '\n')
except OSError: except OSError:
print('EX: unable to append to voters file ' + voters_filename) print('EX: unable to append to voters file ' + voters_filename)
else: else:
@ -148,8 +148,8 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
lines = [] lines = []
try: try:
with open(voters_filename, 'r', with open(voters_filename, 'r',
encoding='utf-8') as voters_file: encoding='utf-8') as fp_voters:
lines = voters_file.readlines() lines = fp_voters.readlines()
except OSError: except OSError:
print('EX: question_update_votes unable to read ' + print('EX: question_update_votes unable to read ' +
voters_filename) voters_filename)
@ -170,9 +170,9 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
if save_voters_file: if save_voters_file:
try: try:
with open(voters_filename, 'w+', with open(voters_filename, 'w+',
encoding='utf-8') as voters_file: encoding='utf-8') as fp_voters:
for vote_line in newlines: for vote_line in newlines:
voters_file.write(vote_line) fp_voters.write(vote_line)
except OSError: except OSError:
print('EX: unable to write voters file2 ' + print('EX: unable to write voters file2 ' +
voters_filename) voters_filename)

View File

@ -396,11 +396,11 @@ def _update_recent_books_list(base_dir: str, book_id: str,
if os.path.isfile(recent_books_filename): if os.path.isfile(recent_books_filename):
try: try:
with open(recent_books_filename, 'r+', with open(recent_books_filename, 'r+',
encoding='utf-8') as recent_file: encoding='utf-8') as fp_recent:
content = recent_file.read() content = fp_recent.read()
if book_id + '\n' not in content: if book_id + '\n' not in content:
recent_file.seek(0, 0) fp_recent.seek(0, 0)
recent_file.write(book_id + '\n' + content) fp_recent.write(book_id + '\n' + content)
if debug: if debug:
print('DEBUG: recent book added') print('DEBUG: recent book added')
except OSError as ex: except OSError as ex:
@ -409,8 +409,8 @@ def _update_recent_books_list(base_dir: str, book_id: str,
else: else:
try: try:
with open(recent_books_filename, 'w+', with open(recent_books_filename, 'w+',
encoding='utf-8') as recent_file: encoding='utf-8') as fp_recent:
recent_file.write(book_id + '\n') fp_recent.write(book_id + '\n')
except OSError: except OSError:
print('EX: unable to write recent books ' + print('EX: unable to write recent books ' +
recent_books_filename) recent_books_filename)
@ -428,8 +428,8 @@ def _deduplicate_recent_books_list(base_dir: str,
recent_lines = [] recent_lines = []
try: try:
with open(recent_books_filename, 'r', with open(recent_books_filename, 'r',
encoding='utf-8') as recent_file: encoding='utf-8') as fp_recent:
recent_lines = recent_file.read().split('\n') recent_lines = fp_recent.read().split('\n')
except OSError as ex: except OSError as ex:
print('WARN: Failed to read recent books trim ' + print('WARN: Failed to read recent books trim ' +
recent_books_filename + ' ' + str(ex)) recent_books_filename + ' ' + str(ex))
@ -446,8 +446,8 @@ def _deduplicate_recent_books_list(base_dir: str,
result += line + '\n' result += line + '\n'
try: try:
with open(recent_books_filename, 'w+', with open(recent_books_filename, 'w+',
encoding='utf-8') as recent_file: encoding='utf-8') as fp_recent:
recent_file.write(result) fp_recent.write(result)
except OSError: except OSError:
print('EX: unable to deduplicate recent books ' + print('EX: unable to deduplicate recent books ' +
recent_books_filename) recent_books_filename)
@ -459,8 +459,8 @@ def _deduplicate_recent_books_list(base_dir: str,
result += recent_lines[ctr] + '\n' result += recent_lines[ctr] + '\n'
try: try:
with open(recent_books_filename, 'w+', with open(recent_books_filename, 'w+',
encoding='utf-8') as recent_file: encoding='utf-8') as fp_recent:
recent_file.write(result) fp_recent.write(result)
except OSError: except OSError:
print('EX: unable to trim recent books ' + print('EX: unable to trim recent books ' +
recent_books_filename) recent_books_filename)

View File

@ -44,8 +44,8 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
index_lines = [] index_lines = []
delete_schedule_post = False delete_schedule_post = False
nickname = handle.split('@')[0] nickname = handle.split('@')[0]
with open(schedule_index_filename, 'r', encoding='utf-8') as sched_file: with open(schedule_index_filename, 'r', encoding='utf-8') as fp_sched:
for line in sched_file: for line in fp_sched:
if ' ' not in line: if ' ' not in line:
continue continue
date_str = line.split(' ')[0] date_str = line.split(' ')[0]
@ -183,9 +183,9 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
acct_handle_dir(base_dir, handle) + '/schedule.index' acct_handle_dir(base_dir, handle) + '/schedule.index'
try: try:
with open(schedule_index_file, 'w+', with open(schedule_index_file, 'w+',
encoding='utf-8') as schedule_file: encoding='utf-8') as fp_schedule:
for line in index_lines: for line in index_lines:
schedule_file.write(line) fp_schedule.write(line)
except OSError: except OSError:
print('EX: _update_post_schedule unable to write ' + print('EX: _update_post_schedule unable to write ' +
schedule_index_file) schedule_index_file)

View File

@ -706,8 +706,8 @@ def post_image(session, attach_image_filename: str, federation_list: [],
content_type = 'image/svg+xml' content_type = 'image/svg+xml'
headers['Content-type'] = content_type headers['Content-type'] = content_type
with open(attach_image_filename, 'rb') as av_file: with open(attach_image_filename, 'rb') as fp_av:
media_binary = av_file.read() media_binary = fp_av.read()
_set_user_agent(session, http_prefix, domain_full) _set_user_agent(session, http_prefix, domain_full)
@ -792,8 +792,8 @@ def download_image(session, url: str, image_filename: str, debug: bool,
else: else:
media_binary = result.content media_binary = result.content
if binary_is_image(image_filename, media_binary): if binary_is_image(image_filename, media_binary):
with open(image_filename, 'wb') as im_file: with open(image_filename, 'wb') as fp_im:
im_file.write(media_binary) fp_im.write(media_binary)
if debug: if debug:
print('Image downloaded from ' + url) print('Image downloaded from ' + url)
return True return True

View File

@ -5726,8 +5726,8 @@ def _test_functions():
ctr += 1 ctr += 1
print(function_names_str + '\n') print(function_names_str + '\n')
with open('scripts/bad_function_names.sh', 'w+', with open('scripts/bad_function_names.sh', 'w+',
encoding='utf-8') as fn_file: encoding='utf-8') as fp_file:
fn_file.write(function_names_sh) fp_file.write(function_names_sh)
assert False assert False
# which modules is each function used within? # which modules is each function used within?

View File

@ -880,8 +880,8 @@ def html_new_post(edit_post_params: {},
citations_separator = '#####' citations_separator = '#####'
try: try:
with open(citations_filename, 'r', with open(citations_filename, 'r',
encoding='utf-8') as cit_file: encoding='utf-8') as fp_cit:
citations = cit_file.readlines() citations = fp_cit.readlines()
for line in citations: for line in citations:
if citations_separator not in line: if citations_separator not in line:
continue continue

View File

@ -72,8 +72,8 @@ def _minimize_attached_images(base_dir: str, nickname: str, domain: str,
print('Minimize file exists') print('Minimize file exists')
try: try:
with open(minimize_filename, 'r', with open(minimize_filename, 'r',
encoding='utf-8') as minimize_file: encoding='utf-8') as fp_minimize:
minimize_handles = minimize_file.read() minimize_handles = fp_minimize.read()
except OSError: except OSError:
print('EX: minimize_attached_images ' + minimize_filename) print('EX: minimize_attached_images ' + minimize_filename)
else: else:

View File

@ -1214,24 +1214,24 @@ def html_profile(signing_priv_key_pem: str,
if os.path.isfile(follow_requests_filename): if os.path.isfile(follow_requests_filename):
try: try:
with open(follow_requests_filename, 'r', with open(follow_requests_filename, 'r',
encoding='utf-8') as foll_file: encoding='utf-8') as fp_foll:
for line in foll_file: for line in fp_foll:
if len(line) > 0: if len(line) > 0:
follow_approvals = True follow_approvals = True
followers_button = 'buttonhighlighted' followers_button = 'buttonhighlighted'
if selected == 'followers': if selected == 'followers':
followers_button = 'buttonselectedhighlighted' followers_button = 'buttonselectedhighlighted'
break break
except OSError: except OSError as exc:
print('EX: html_profile unable to read ' + print('EX: html_profile unable to read ' +
follow_requests_filename) follow_requests_filename + ' ' + str(exc))
if selected == 'followers': if selected == 'followers':
if follow_approvals: if follow_approvals:
curr_follower_domains = \ curr_follower_domains = \
get_follower_domains(base_dir, nickname, domain) get_follower_domains(base_dir, nickname, domain)
with open(follow_requests_filename, 'r', with open(follow_requests_filename, 'r',
encoding='utf-8') as req_file: encoding='utf-8') as fp_req:
for follower_handle in req_file: for follower_handle in fp_req:
if len(follower_handle) > 0: if len(follower_handle) > 0:
follower_handle = \ follower_handle = \
remove_eol(follower_handle) remove_eol(follower_handle)
@ -1328,8 +1328,8 @@ def html_profile(signing_priv_key_pem: str,
pinned_content = None pinned_content = None
if os.path.isfile(pinned_filename): if os.path.isfile(pinned_filename):
try: try:
with open(pinned_filename, 'r', encoding='utf-8') as pin_file: with open(pinned_filename, 'r', encoding='utf-8') as fp_pin:
pinned_content = pin_file.read() pinned_content = fp_pin.read()
except OSError: except OSError:
print('EX: html_profile unable to read ' + pinned_filename) print('EX: html_profile unable to read ' + pinned_filename)
@ -2084,8 +2084,8 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
moderators_file = data_dir(base_dir) + '/moderators.txt' moderators_file = data_dir(base_dir) + '/moderators.txt'
if os.path.isfile(moderators_file): if os.path.isfile(moderators_file):
try: try:
with open(moderators_file, 'r', encoding='utf-8') as mod_file: with open(moderators_file, 'r', encoding='utf-8') as fp_mod:
moderators = mod_file.read() moderators = fp_mod.read()
except OSError: except OSError:
print('EX: _html_edit_profile_instance unable to read ' + print('EX: _html_edit_profile_instance unable to read ' +
moderators_file) moderators_file)
@ -2098,8 +2098,8 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
editors_file = data_dir(base_dir) + '/editors.txt' editors_file = data_dir(base_dir) + '/editors.txt'
if os.path.isfile(editors_file): if os.path.isfile(editors_file):
try: try:
with open(editors_file, 'r', encoding='utf-8') as edit_file: with open(editors_file, 'r', encoding='utf-8') as fp_edit:
editors = edit_file.read() editors = fp_edit.read()
except OSError: except OSError:
print('EX: _html_edit_profile_instance unable to read ' + print('EX: _html_edit_profile_instance unable to read ' +
editors_file) editors_file)
@ -2113,8 +2113,8 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
counselors_file = data_dir(base_dir) + '/counselors.txt' counselors_file = data_dir(base_dir) + '/counselors.txt'
if os.path.isfile(counselors_file): if os.path.isfile(counselors_file):
try: try:
with open(counselors_file, 'r', encoding='utf-8') as co_file: with open(counselors_file, 'r', encoding='utf-8') as fp_co:
counselors = co_file.read() counselors = fp_co.read()
except OSError: except OSError:
print('EX: _html_edit_profile_instance unable to read ' + print('EX: _html_edit_profile_instance unable to read ' +
counselors_file) counselors_file)
@ -2127,8 +2127,8 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
artists_file = data_dir(base_dir) + '/artists.txt' artists_file = data_dir(base_dir) + '/artists.txt'
if os.path.isfile(artists_file): if os.path.isfile(artists_file):
try: try:
with open(artists_file, 'r', encoding='utf-8') as art_file: with open(artists_file, 'r', encoding='utf-8') as fp_art:
artists = art_file.read() artists = fp_art.read()
except OSError: except OSError:
print('EX: _html_edit_profile_instance unable to read ' + print('EX: _html_edit_profile_instance unable to read ' +
artists_file) artists_file)
@ -2141,8 +2141,8 @@ def _html_edit_profile_instance(base_dir: str, translate: {},
devops_file = data_dir(base_dir) + '/devops.txt' devops_file = data_dir(base_dir) + '/devops.txt'
if os.path.isfile(devops_file): if os.path.isfile(devops_file):
try: try:
with open(devops_file, 'r', encoding='utf-8') as edit_file: with open(devops_file, 'r', encoding='utf-8') as fp_edit:
devops = edit_file.read() devops = fp_edit.read()
except OSError: except OSError:
print('EX: _html_edit_profile_instance unable to read ' + print('EX: _html_edit_profile_instance unable to read ' +
devops_file) devops_file)
@ -2267,8 +2267,8 @@ def _html_edit_profile_git_projects(base_dir: str, nickname: str, domain: str,
if os.path.isfile(git_projects_filename): if os.path.isfile(git_projects_filename):
try: try:
with open(git_projects_filename, 'r', with open(git_projects_filename, 'r',
encoding='utf-8') as git_file: encoding='utf-8') as fp_git:
git_projects_str = git_file.read() git_projects_str = fp_git.read()
except OSError: except OSError:
print('EX: _html_edit_profile_git_projects unable to read ' + print('EX: _html_edit_profile_git_projects unable to read ' +
git_projects_filename) git_projects_filename)
@ -2351,8 +2351,8 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
acct_dir(base_dir, nickname, domain) + '/autotags.txt' acct_dir(base_dir, nickname, domain) + '/autotags.txt'
if os.path.isfile(auto_tags_filename): if os.path.isfile(auto_tags_filename):
try: try:
with open(auto_tags_filename, 'r', encoding='utf-8') as auto_file: with open(auto_tags_filename, 'r', encoding='utf-8') as fp_auto:
auto_tags = auto_file.read() auto_tags = fp_auto.read()
except OSError: except OSError:
print('EX: _html_edit_profile_filtering unable to read ' + print('EX: _html_edit_profile_filtering unable to read ' +
auto_tags_filename) auto_tags_filename)
@ -2362,8 +2362,8 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
acct_dir(base_dir, nickname, domain) + '/autocw.txt' acct_dir(base_dir, nickname, domain) + '/autocw.txt'
if os.path.isfile(auto_cw_filename): if os.path.isfile(auto_cw_filename):
try: try:
with open(auto_cw_filename, 'r', encoding='utf-8') as cw_file: with open(auto_cw_filename, 'r', encoding='utf-8') as fp_cw:
auto_cw = cw_file.read() auto_cw = fp_cw.read()
except OSError: except OSError:
print('EX: _html_edit_profile_filtering unable to read ' + print('EX: _html_edit_profile_filtering unable to read ' +
auto_cw_filename) auto_cw_filename)
@ -2376,8 +2376,8 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
if os.path.isfile(dm_allowed_instances_filename): if os.path.isfile(dm_allowed_instances_filename):
try: try:
with open(dm_allowed_instances_filename, 'r', with open(dm_allowed_instances_filename, 'r',
encoding='utf-8') as dm_file: encoding='utf-8') as fp_dm:
dm_allowed_instances_str = dm_file.read() dm_allowed_instances_str = fp_dm.read()
except OSError: except OSError:
print('EX: _html_edit_profile_filtering unable to read ' + print('EX: _html_edit_profile_filtering unable to read ' +
dm_allowed_instances_filename) dm_allowed_instances_filename)
@ -2388,8 +2388,8 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
if os.path.isfile(allowed_instances_filename): if os.path.isfile(allowed_instances_filename):
try: try:
with open(allowed_instances_filename, 'r', with open(allowed_instances_filename, 'r',
encoding='utf-8') as allow_file: encoding='utf-8') as fp_allow:
allowed_instances_str = allow_file.read() allowed_instances_str = fp_allow.read()
except OSError: except OSError:
print('EX: _html_edit_profile_filtering unable to read ' + print('EX: _html_edit_profile_filtering unable to read ' +
allowed_instances_filename) allowed_instances_filename)
@ -2413,8 +2413,8 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
city_filename = acct_dir(base_dir, nickname, domain) + '/city.txt' city_filename = acct_dir(base_dir, nickname, domain) + '/city.txt'
if os.path.isfile(city_filename): if os.path.isfile(city_filename):
try: try:
with open(city_filename, 'r', encoding='utf-8') as city_file: with open(city_filename, 'r', encoding='utf-8') as fp_city:
city1 = city_file.read() city1 = fp_city.read()
city = remove_eol(city1) city = remove_eol(city1)
except OSError: except OSError:
print('EX: _html_edit_profile_filtering unable to read ' + print('EX: _html_edit_profile_filtering unable to read ' +
@ -2424,8 +2424,8 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
locations_filename = base_dir + '/locations.txt' locations_filename = base_dir + '/locations.txt'
cities = [] cities = []
try: try:
with open(locations_filename, 'r', encoding='utf-8') as loc_file: with open(locations_filename, 'r', encoding='utf-8') as fp_loc:
cities = loc_file.readlines() cities = fp_loc.readlines()
cities.sort() cities.sort()
except OSError: except OSError:
print('EX: _html_edit_profile_filtering unable to read ' + print('EX: _html_edit_profile_filtering unable to read ' +

View File

@ -95,8 +95,8 @@ def _get_help_for_timeline(base_dir: str, box_name: str) -> str:
instance_title = 'Epicyon' instance_title = 'Epicyon'
help_text = '' help_text = ''
try: try:
with open(help_filename, 'r', encoding='utf-8') as help_file: with open(help_filename, 'r', encoding='utf-8') as fp_help:
help_text = help_file.read() help_text = fp_help.read()
except OSError: except OSError:
print('EX: _get_help_for_timeline unable to read ' + help_filename) print('EX: _get_help_for_timeline unable to read ' + help_filename)
if help_text: if help_text:
@ -703,8 +703,8 @@ def html_timeline(default_timeline: str,
if os.path.isfile(follow_requests_filename): if os.path.isfile(follow_requests_filename):
try: try:
with open(follow_requests_filename, 'r', with open(follow_requests_filename, 'r',
encoding='utf-8') as foll_file: encoding='utf-8') as fp_foll:
for line in foll_file: for line in fp_foll:
if len(line) > 0: if len(line) > 0:
# show follow approvals icon # show follow approvals icon
follow_approvals = \ follow_approvals = \

View File

@ -96,8 +96,8 @@ def html_following_list(base_dir: str, following_filename: str) -> str:
""" """
msg = '' msg = ''
try: try:
with open(following_filename, 'r', encoding='utf-8') as following_file: with open(following_filename, 'r', encoding='utf-8') as fp_following:
msg = following_file.read() msg = fp_following.read()
except OSError: except OSError:
print('EX: html_following_list unable to read ' + following_filename) print('EX: html_following_list unable to read ' + following_filename)
if msg: if msg:
@ -129,8 +129,8 @@ def csv_following_list(following_filename: str,
""" """
msg = '' msg = ''
try: try:
with open(following_filename, 'r', encoding='utf-8') as following_file: with open(following_filename, 'r', encoding='utf-8') as fp_following:
msg = following_file.read() msg = fp_following.read()
except OSError: except OSError:
print('EX: csv_following_list unable to read ' + following_filename) print('EX: csv_following_list unable to read ' + following_filename)
if msg: if msg:
@ -2222,8 +2222,8 @@ def html_following_data_list(base_dir: str, nickname: str,
if os.path.isfile(following_filename): if os.path.isfile(following_filename):
try: try:
with open(following_filename, 'r', with open(following_filename, 'r',
encoding='utf-8') as following_file: encoding='utf-8') as fp_following:
msg = following_file.read() msg = fp_following.read()
# add your own handle, so that you can send DMs # add your own handle, so that you can send DMs
# to yourself as reminders # to yourself as reminders
msg += nickname + '@' + domain_full + '\n' msg += nickname + '@' + domain_full + '\n'