Standardise file pointer names

main
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):
try:
with open(blocking_reasons_filename, 'a+',
encoding='utf-8') as reas_file:
reas_file.write(reason_line)
encoding='utf-8') as fp_reas:
fp_reas.write(reason_line)
except OSError:
print('EX: unable to add blocking reason ' +
block_id)
@ -268,8 +268,8 @@ def _add_global_block_reason(base_dir: str,
reasons_str = ''
try:
with open(blocking_reasons_filename, 'r',
encoding='utf-8') as reas_file:
reasons_str = reas_file.read()
encoding='utf-8') as fp_reas:
reasons_str = fp_reas.read()
except OSError:
print('EX: unable to read blocking reasons')
reasons_lines = reasons_str.split('\n')
@ -281,16 +281,16 @@ def _add_global_block_reason(base_dir: str,
new_reasons_str += reason_line
try:
with open(blocking_reasons_filename, 'w+',
encoding='utf-8') as reas_file:
reas_file.write(new_reasons_str)
encoding='utf-8') as fp_reas:
fp_reas.write(new_reasons_str)
except OSError:
print('EX: unable to save blocking reasons' +
blocking_reasons_filename)
else:
try:
with open(blocking_reasons_filename, 'w+',
encoding='utf-8') as reas_file:
reas_file.write(reason_line)
encoding='utf-8') as fp_reas:
fp_reas.write(reason_line)
except OSError:
print('EX: unable to save blocking reason ' +
block_id + ' ' + blocking_reasons_filename)
@ -315,8 +315,8 @@ def add_global_block(base_dir: str,
return False
# block an account handle or domain
try:
with open(blocking_filename, 'a+', encoding='utf-8') as block_file:
block_file.write(block_handle + '\n')
with open(blocking_filename, 'a+', encoding='utf-8') as fp_block:
fp_block.write(block_handle + '\n')
except OSError:
print('EX: unable to save blocked handle ' + block_handle)
return False
@ -328,8 +328,8 @@ def add_global_block(base_dir: str,
return False
# block a hashtag
try:
with open(blocking_filename, 'a+', encoding='utf-8') as block_file:
block_file.write(block_hashtag + '\n')
with open(blocking_filename, 'a+', encoding='utf-8') as fp_block:
fp_block.write(block_hashtag + '\n')
except OSError:
print('EX: unable to save blocked hashtag ' + block_hashtag)
return False
@ -363,8 +363,8 @@ def _add_block_reason(base_dir: str,
blocking_reasons_filename):
try:
with open(blocking_reasons_filename, 'a+',
encoding='utf-8') as reas_file:
reas_file.write(reason_line)
encoding='utf-8') as fp_reas:
fp_reas.write(reason_line)
except OSError:
print('EX: unable to add blocking reason 2 ' +
block_id)
@ -372,8 +372,8 @@ def _add_block_reason(base_dir: str,
reasons_str = ''
try:
with open(blocking_reasons_filename, 'r',
encoding='utf-8') as reas_file:
reasons_str = reas_file.read()
encoding='utf-8') as fp_reas:
reasons_str = fp_reas.read()
except OSError:
print('EX: unable to read blocking reasons 2')
reasons_lines = reasons_str.split('\n')
@ -385,16 +385,16 @@ def _add_block_reason(base_dir: str,
new_reasons_str += reason_line
try:
with open(blocking_reasons_filename, 'w+',
encoding='utf-8') as reas_file:
reas_file.write(new_reasons_str)
encoding='utf-8') as fp_reas:
fp_reas.write(new_reasons_str)
except OSError:
print('EX: unable to save blocking reasons 2' +
blocking_reasons_filename)
else:
try:
with open(blocking_reasons_filename, 'w+',
encoding='utf-8') as reas_file:
reas_file.write(reason_line)
encoding='utf-8') as fp_reas:
fp_reas.write(reason_line)
except OSError:
print('EX: unable to save blocking reason 2 ' +
block_id + ' ' + blocking_reasons_filename)
@ -425,8 +425,8 @@ def add_block(base_dir: str, nickname: str, domain: str,
following_str = ''
try:
with open(following_filename, 'r',
encoding='utf-8') as foll_file:
following_str = foll_file.read()
encoding='utf-8') as fp_foll:
following_str = fp_foll.read()
except OSError:
print('EX: Unable to read following ' + following_filename)
return False
@ -436,8 +436,8 @@ def add_block(base_dir: str, nickname: str, domain: str,
try:
with open(following_filename, 'w+',
encoding='utf-8') as foll_file:
foll_file.write(following_str)
encoding='utf-8') as fp_foll:
fp_foll.write(following_str)
except OSError:
print('EX: Unable to write following ' + following_str)
return False
@ -450,8 +450,8 @@ def add_block(base_dir: str, nickname: str, domain: str,
followers_str = ''
try:
with open(followers_filename, 'r',
encoding='utf-8') as foll_file:
followers_str = foll_file.read()
encoding='utf-8') as fp_foll:
followers_str = fp_foll.read()
except OSError:
print('EX: Unable to read followers ' + followers_filename)
return False
@ -461,15 +461,15 @@ def add_block(base_dir: str, nickname: str, domain: str,
try:
with open(followers_filename, 'w+',
encoding='utf-8') as foll_file:
foll_file.write(followers_str)
encoding='utf-8') as fp_foll:
fp_foll.write(followers_str)
except OSError:
print('EX: Unable to write followers ' + followers_str)
return False
try:
with open(blocking_filename, 'a+', encoding='utf-8') as block_file:
block_file.write(block_handle + '\n')
with open(blocking_filename, 'a+', encoding='utf-8') as fp_block:
fp_block.write(block_handle + '\n')
except OSError:
print('EX: unable to append block handle ' + block_handle)
return False
@ -501,8 +501,8 @@ def _remove_global_block_reason(base_dir: str,
reasons_str = ''
try:
with open(unblocking_filename, 'r',
encoding='utf-8') as reas_file:
reasons_str = reas_file.read()
encoding='utf-8') as fp_reas:
reasons_str = fp_reas.read()
except OSError:
print('EX: unable to read blocking reasons 3')
reasons_lines = reasons_str.split('\n')
@ -513,8 +513,8 @@ def _remove_global_block_reason(base_dir: str,
new_reasons_str += line + '\n'
try:
with open(unblocking_filename, 'w+',
encoding='utf-8') as reas_file:
reas_file.write(new_reasons_str)
encoding='utf-8') as fp_reas:
fp_reas.write(new_reasons_str)
except OSError:
print('EX: unable to save blocking reasons 2' +
unblocking_filename)
@ -1293,8 +1293,8 @@ def mute_post(base_dir: str, nickname: str, domain: str, port: int,
try:
with open(post_filename + '.muted', 'w+',
encoding='utf-8') as mute_file:
mute_file.write('\n')
encoding='utf-8') as fp_mute:
fp_mute.write('\n')
except OSError:
print('EX: Failed to save mute file ' + post_filename + '.muted')
return
@ -1637,8 +1637,8 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
continue
try:
with open(following_filename, 'r',
encoding='utf-8') as foll_file:
follow_list = foll_file.readlines()
encoding='utf-8') as fp_foll:
follow_list = fp_foll.readlines()
for handle in follow_list:
if '@' not in handle:
continue
@ -1654,10 +1654,10 @@ def set_broch_mode(base_dir: str, domain_full: str, enabled: bool) -> None:
# write the allow file
try:
with open(allow_filename, 'w+',
encoding='utf-8') as allow_file:
allow_file.write(domain_full + '\n')
encoding='utf-8') as fp_allow:
fp_allow.write(domain_full + '\n')
for allowed in allowed_domains:
allow_file.write(allowed + '\n')
fp_allow.write(allowed + '\n')
print('Broch mode enabled')
except OSError as 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
lines = []
try:
with open(post_filename, 'r', encoding='utf-8') as post_file:
lines = post_file.readlines()
with open(post_filename, 'r', encoding='utf-8') as fp_post:
lines = fp_post.readlines()
except OSError:
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 ' +
str(len(removals)) + ' entries')
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:
reply_post_id = remove_eol(reply_post_id)
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:
print('EX: unable to remove replies from post ' +
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):
try:
with open(post_filename, 'r',
encoding='utf-8') as post_file:
return post_file.read() + '\n'
encoding='utf-8') as fp_post:
return fp_post.read() + '\n'
except OSError:
print('EX: unable to read blog 3 ' + post_filename)
return ''
lines = []
try:
with open(post_filename, 'r', encoding='utf-8') as post_file:
lines = post_file.readlines()
with open(post_filename, 'r', encoding='utf-8') as fp_post:
lines = fp_post.readlines()
except OSError:
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):
continue
try:
with open(post_filename, 'r', encoding='utf-8') as post_file:
replies_str += post_file.read() + '\n'
with open(post_filename, 'r', encoding='utf-8') as fp_post:
replies_str += fp_post.read() + '\n'
except OSError:
print('EX: unable to read blog replies ' + post_filename)
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 = ''
try:
with open(bookmarks_index_filename, 'r',
encoding='utf-8') as index_file:
index_str = index_file.read().replace(bookmark_index + '\n', '')
encoding='utf-8') as fp_index:
index_str = fp_index.read().replace(bookmark_index + '\n', '')
except OSError:
print('EX: undo_bookmarks_collection_entry unable to read ' +
bookmarks_index_filename)
if index_str:
try:
with open(bookmarks_index_filename, 'w+',
encoding='utf-8') as bmi_file:
bmi_file.write(index_str)
encoding='utf-8') as fp_bmi:
fp_bmi.write(index_str)
except OSError:
print('EX: unable to write bookmarks index ' +
bookmarks_index_filename)
@ -246,11 +246,11 @@ def update_bookmarks_collection(recent_posts_cache: {},
if not text_in_file(bookmark_index, bookmarks_index_filename):
try:
with open(bookmarks_index_filename, 'r+',
encoding='utf-8') as bmi_file:
content = bmi_file.read()
encoding='utf-8') as fp_bmi:
content = fp_bmi.read()
if bookmark_index + '\n' not in content:
bmi_file.seek(0, 0)
bmi_file.write(bookmark_index + '\n' + content)
fp_bmi.seek(0, 0)
fp_bmi.write(bookmark_index + '\n' + content)
if debug:
print('DEBUG: bookmark added to index')
except OSError as ex:
@ -259,8 +259,8 @@ def update_bookmarks_collection(recent_posts_cache: {},
else:
try:
with open(bookmarks_index_filename, 'w+',
encoding='utf-8') as bm_file:
bm_file.write(bookmark_index + '\n')
encoding='utf-8') as fp_bm:
fp_bm.write(bookmark_index + '\n')
except OSError:
print('EX: unable to write bookmarks index ' +
bookmarks_index_filename)

View File

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

12
city.py
View File

@ -226,8 +226,8 @@ def spoof_geolocation(base_dir: str,
"", "", 0)
cities = []
try:
with open(locations_filename, 'r', encoding='utf-8') as loc_file:
cities = loc_file.readlines()
with open(locations_filename, 'r', encoding='utf-8') as fp_loc:
cities = fp_loc.readlines()
except OSError:
print('EX: unable to read locations ' + locations_filename)
@ -238,8 +238,8 @@ def spoof_geolocation(base_dir: str,
if os.path.isfile(nogo_filename):
nogo_list = []
try:
with open(nogo_filename, 'r', encoding='utf-8') as nogo_file:
nogo_list = nogo_file.readlines()
with open(nogo_filename, 'r', encoding='utf-8') as fp_nogo:
nogo_list = fp_nogo.readlines()
except OSError:
print('EX: spoof_geolocation unable to read ' + nogo_filename)
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'
if os.path.isfile(city_filename):
try:
with open(city_filename, 'r', encoding='utf-8') as city_file:
city1 = city_file.read()
with open(city_filename, 'r', encoding='utf-8') as fp_city:
city1 = fp_city.read()
city = remove_eol(city1)
except OSError:
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
try:
with open(filename, 'r', encoding='utf-8') as css_file:
content = css_file.read().lower()
with open(filename, 'r', encoding='utf-8') as fp_css:
content = fp_css.read().lower()
except OSError:
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
try:
with open(switch_words_filename, 'r',
encoding='utf-8') as words_file:
rules = words_file.readlines()
encoding='utf-8') as fp_words:
rules = fp_words.readlines()
except OSError:
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):
return []
try:
with open(filename, 'r', encoding='utf-8') as tags_file:
return tags_file.readlines()
with open(filename, 'r', encoding='utf-8') as fp_tags:
return fp_tags.readlines()
except OSError:
print('EX: unable to read auto tags ' + filename)
return []
@ -1381,8 +1381,8 @@ def add_html_tags(base_dir: str, http_prefix: str,
following = []
try:
with open(following_filename, 'r',
encoding='utf-8') as foll_file:
following = foll_file.readlines()
encoding='utf-8') as fp_foll:
following = fp_foll.readlines()
except OSError:
print('EX: add_html_tags unable to read ' +
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):
try:
with open(conversation_filename, 'w+',
encoding='utf-8') as conv_file:
conv_file.write(post_id + '\n')
encoding='utf-8') as fp_conv:
fp_conv.write(post_id + '\n')
return True
except OSError:
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):
try:
with open(conversation_filename, 'a+',
encoding='utf-8') as conv_file:
conv_file.write(post_id + '\n')
encoding='utf-8') as fp_conv:
fp_conv.write(post_id + '\n')
return True
except OSError:
print('EX: update_conversation 2 ' +
@ -89,8 +89,8 @@ def mute_conversation(base_dir: str, nickname: str, domain: str,
return
try:
with open(conversation_filename + '.muted', 'w+',
encoding='utf-8') as conv_file:
conv_file.write('\n')
encoding='utf-8') as fp_conv:
fp_conv.write('\n')
except OSError:
print('EX: unable to write mute ' + conversation_filename)

View File

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

View File

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

View File

@ -83,8 +83,8 @@ def get_favicon(self, calling_domain: str,
if os.path.isfile(favicon_filename):
fav_binary = None
try:
with open(favicon_filename, 'rb') as fav_file:
fav_binary = fav_file.read()
with open(favicon_filename, 'rb') as fp_fav:
fav_binary = fp_fav.read()
except OSError:
print('EX: unable to read favicon ' + favicon_filename)
if fav_binary:
@ -133,8 +133,8 @@ def show_cached_favicon(self, referer_domain: str, path: str,
return
media_binary = None
try:
with open(fav_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(fav_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read cached favicon ' + fav_filename)
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_binary = None
try:
with open(avatar_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(avatar_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read avatar ' + avatar_filename)
if media_binary:
@ -136,8 +136,8 @@ def show_cached_avatar(self, referer_domain: str, path: str,
return
media_binary = None
try:
with open(media_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(media_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read cached avatar ' + media_filename)
if media_binary:
@ -186,8 +186,8 @@ def show_help_screen_image(self, path: str,
if os.path.isfile(media_filename):
media_binary = None
try:
with open(media_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(media_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read help image ' + media_filename)
if media_binary:
@ -237,8 +237,8 @@ def show_manual_image(self, path: str,
if os.path.isfile(media_filename):
media_binary = None
try:
with open(media_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(media_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read manual image ' +
media_filename)
@ -290,8 +290,8 @@ def show_specification_image(self, path: str,
if os.path.isfile(media_filename):
media_binary = None
try:
with open(media_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(media_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read specification image ' +
media_filename)
@ -335,8 +335,8 @@ def show_share_image(self, path: str,
media_file_type = get_image_mime_type(media_filename)
media_binary = None
try:
with open(media_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(media_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read binary ' + media_filename)
if media_binary:
@ -393,8 +393,8 @@ def show_icon(self, path: str,
if os.path.isfile(media_filename):
media_binary = None
try:
with open(media_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(media_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read icon image ' + media_filename)
if media_binary:
@ -465,8 +465,8 @@ def show_media(self, path: str, base_dir: str,
media_binary = None
try:
with open(media_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(media_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read media binary ' + media_filename)
if media_binary:
@ -513,8 +513,8 @@ def show_qrcode(self, calling_domain: str, path: str,
media_binary = None
while tries < 5:
try:
with open(qr_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(qr_filename, 'rb') as fp_av:
media_binary = fp_av.read()
break
except OSError as ex:
print('EX: _show_qrcode ' + str(tries) + ' ' + str(ex))
@ -562,8 +562,8 @@ def search_screen_banner(self, path: str,
media_binary = None
while tries < 5:
try:
with open(banner_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(banner_filename, 'rb') as fp_av:
media_binary = fp_av.read()
break
except OSError as ex:
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
while tries < 5:
try:
with open(banner_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(banner_filename, 'rb') as fp_av:
media_binary = fp_av.read()
break
except OSError as 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
while tries < 5:
try:
with open(bg_filename, 'rb') as av_file:
bg_binary = av_file.read()
with open(bg_filename, 'rb') as fp_av:
bg_binary = fp_av.read()
break
except OSError as ex:
print('EX: _show_default_profile_background ' +
@ -702,8 +702,8 @@ def show_background_image(self, path: str,
bg_binary = None
while tries < 5:
try:
with open(bg_filename, 'rb') as av_file:
bg_binary = av_file.read()
with open(bg_filename, 'rb') as fp_av:
bg_binary = fp_av.read()
break
except OSError as ex:
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_binary = None
try:
with open(emoji_filename, 'rb') as av_file:
media_binary = av_file.read()
with open(emoji_filename, 'rb') as fp_av:
media_binary = fp_av.read()
except OSError:
print('EX: unable to read emoji image ' + emoji_filename)
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 ' +
media_filename)
try:
with open(media_filename, 'wb') as av_file:
av_file.write(media_bytes)
with open(media_filename, 'wb') as fp_av:
fp_av.write(media_bytes)
except OSError:
print('EX: receive_image_attachment unable to write ' + media_filename)
if debug:

View File

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

View File

@ -278,8 +278,8 @@ def _send_reply_to_question(self, base_dir: str,
# record the vote
try:
with open(votes_filename, 'a+',
encoding='utf-8') as votes_file:
votes_file.write(message_id + '\n')
encoding='utf-8') as fp_votes:
fp_votes.write(message_id + '\n')
except OSError:
print('EX: unable to write vote ' +
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
post_id += '\n'
with open(read_posts_filename, 'r+',
encoding='utf-8') as read_file:
content = read_file.read()
encoding='utf-8') as fp_read:
content = fp_read.read()
if post_id not in content:
read_file.seek(0, 0)
read_file.write(post_id + content)
fp_read.seek(0, 0)
fp_read.write(post_id + content)
except OSError as ex:
print('EX: Failed to mark post as read 1 ' + str(ex))
else:
try:
with open(read_posts_filename, 'w+',
encoding='utf-8') as read_file:
read_file.write(post_id + '\n')
encoding='utf-8') as fp_read:
fp_read.write(post_id + '\n')
except OSError as 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
try:
with open(filters_filename, 'a+',
encoding='utf-8') as filters_file:
filters_file.write(words + '\n')
encoding='utf-8') as fp_filters:
fp_filters.write(words + '\n')
except OSError:
print('EX: unable to append filters ' + filters_filename)
return False
@ -48,8 +48,8 @@ def add_global_filter(base_dir: str, words: str) -> bool:
if text_in_file(words, filters_filename):
return False
try:
with open(filters_filename, 'a+', encoding='utf-8') as filters_file:
filters_file.write(words + '\n')
with open(filters_filename, 'a+', encoding='utf-8') as fp_filters:
fp_filters.write(words + '\n')
except OSError:
print('EX: unable to append filters ' + filters_filename)
return False

View File

@ -74,8 +74,8 @@ def receiving_calendar_events(base_dir: str, nickname: str, domain: str,
following_handles = None
try:
with open(following_filename, 'r',
encoding='utf-8') as following_file:
following_handles = following_file.read()
encoding='utf-8') as fp_following:
following_handles = fp_following.read()
except OSError:
print('EX: receiving_calendar_events ' + following_filename)
if following_handles:
@ -120,8 +120,8 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str,
print('Calendar file exists')
try:
with open(calendar_filename, 'r',
encoding='utf-8') as calendar_file:
following_handles = calendar_file.read()
encoding='utf-8') as fp_calendar:
following_handles = fp_calendar.read()
except OSError:
print('EX: _receive_calendar_events ' + calendar_filename)
else:
@ -130,8 +130,8 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str,
following_handles = ''
try:
with open(following_filename, 'r',
encoding='utf-8') as following_file:
following_handles = following_file.read()
encoding='utf-8') as fp_following:
following_handles = fp_following.read()
except OSError:
print('EX: _receive_calendar_events 2 ' + calendar_filename)
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,
'@' + from_nickname + '@' + from_domain)
try:
with open(patch_filename, 'w+', encoding='utf-8') as patch_file:
patch_file.write(patch_str)
with open(patch_filename, 'w+', encoding='utf-8') as fp_patch:
fp_patch.write(patch_str)
patch_notify_filename = \
acct_dir(base_dir, nickname, domain) + '/.newPatchContent'
with open(patch_notify_filename, 'w+',
encoding='utf-8') as patch_file:
patch_file.write(patch_str)
encoding='utf-8') as fp_patch_notify:
fp_patch_notify.write(patch_str)
return True
except OSError as 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)
try:
with open(tl_events_filename, 'r+',
encoding='utf-8') as tl_events_file:
content = tl_events_file.read()
encoding='utf-8') as fp_tl_events:
content = fp_tl_events.read()
if event_id + '\n' not in content:
tl_events_file.seek(0, 0)
tl_events_file.write(event_id + '\n' + content)
fp_tl_events.seek(0, 0)
fp_tl_events.write(event_id + '\n' + content)
except OSError as ex:
print('EX: Failed to write entry to events file ' +
tl_events_filename + ' ' + str(ex))
@ -163,8 +163,8 @@ def save_event_post(base_dir: str, handle: str, post_id: str,
else:
try:
with open(tl_events_filename, 'w+',
encoding='utf-8') as tl_events_file:
tl_events_file.write(event_id + '\n')
encoding='utf-8') as fp_tl_events:
fp_tl_events.write(event_id + '\n')
except OSError:
print('EX: save_event_post unable to write ' +
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
try:
with open(calendar_filename, 'a+', encoding='utf-8') as calendar_file:
calendar_file.write(post_id + '\n')
with open(calendar_filename, 'a+', encoding='utf-8') as fp_calendar:
fp_calendar.write(post_id + '\n')
except OSError:
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=' + \
str(event_month_number) + '?day=' + str(event_day_of_month)
try:
with open(cal_notify_filename, 'w+', encoding='utf-8') as cal_file:
cal_file.write(notify_str)
with open(cal_notify_filename, 'w+', encoding='utf-8') as fp_cal:
fp_cal.write(notify_str)
except OSError:
print('EX: save_event_post unable to write ' + cal_notify_filename)
return False
@ -298,8 +298,8 @@ def get_todays_events(base_dir: str, nickname: str, domain: str,
calendar_post_ids = []
recreate_events_file = False
try:
with open(calendar_filename, 'r', encoding='utf-8') as events_file:
for post_id in events_file:
with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
for post_id in fp_events:
post_id = remove_eol(post_id)
post_filename = \
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:
try:
with open(calendar_filename, 'w+',
encoding='utf-8') as calendar_file:
encoding='utf-8') as fp_calendar:
for post_id in calendar_post_ids:
calendar_file.write(post_id + '\n')
fp_calendar.write(post_id + '\n')
except OSError:
print('EX: unable to recreate events file 1 ' +
calendar_filename)
@ -605,8 +605,8 @@ def day_events_check(base_dir: str, nickname: str, domain: str,
events_exist = False
try:
with open(calendar_filename, 'r', encoding='utf-8') as events_file:
for post_id in events_file:
with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
for post_id in fp_events:
post_id = remove_eol(post_id)
post_filename = \
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 = []
recreate_events_file = False
try:
with open(calendar_filename, 'r', encoding='utf-8') as events_file:
for post_id in events_file:
with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
for post_id in fp_events:
post_id = remove_eol(post_id)
post_filename = \
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:
try:
with open(calendar_filename, 'w+',
encoding='utf-8') as calendar_file:
encoding='utf-8') as fp_calendar:
for post_id in calendar_post_ids:
calendar_file.write(post_id + '\n')
fp_calendar.write(post_id + '\n')
except OSError:
print('EX: unable to recreate events file 2 ' +
calendar_filename)
@ -738,8 +738,8 @@ def get_calendar_events(base_dir: str, nickname: str, domain: str,
calendar_post_ids = []
recreate_events_file = False
try:
with open(calendar_filename, 'r', encoding='utf-8') as events_file:
for post_id in events_file:
with open(calendar_filename, 'r', encoding='utf-8') as fp_events:
for post_id in fp_events:
post_id = remove_eol(post_id)
post_filename = \
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:
try:
with open(calendar_filename, 'w+',
encoding='utf-8') as calendar_file:
encoding='utf-8') as fp_calendar:
for post_id in calendar_post_ids:
calendar_file.write(post_id + '\n')
fp_calendar.write(post_id + '\n')
except OSError:
print('EX: unable to recreate events file 3 ' +
calendar_filename)

View File

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

View File

@ -58,8 +58,8 @@ def manual_deny_follow_request(session, session_onion, session_i2p,
# Store rejected follows
try:
with open(rejected_follows_filename, 'a+',
encoding='utf-8') as rejects_file:
rejects_file.write(deny_handle + '\n')
encoding='utf-8') as fp_rejects:
fp_rejects.write(deny_handle + '\n')
except OSError:
print('EX: manual_deny_follow_request unable to append ' +
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):
try:
with open(approved_filename, 'a+',
encoding='utf-8') as approved_file:
approved_file.write(approve_handle + '\n')
encoding='utf-8') as fp_approved:
fp_approved.write(approve_handle + '\n')
except OSError:
print('EX: _approve_follower_handle unable to append ' +
approved_filename)
else:
try:
with open(approved_filename, 'w+',
encoding='utf-8') as approved_file:
approved_file.write(approve_handle + '\n')
encoding='utf-8') as fp_approved:
fp_approved.write(approve_handle + '\n')
except OSError:
print('EX: _approve_follower_handle unable to write ' +
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):
try:
with open(followers_filename, 'r+',
encoding='utf-8') as followers_file:
content = followers_file.read()
encoding='utf-8') as fp_followers:
content = fp_followers.read()
if approve_handle_full + '\n' not in content:
followers_file.seek(0, 0)
followers_file.write(approve_handle_full + '\n' +
content)
fp_followers.seek(0, 0)
fp_followers.write(approve_handle_full + '\n' +
content)
except OSError as ex:
print('WARN: Manual follow accept. ' +
'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)
try:
with open(followers_filename, 'w+',
encoding='utf-8') as followers_file:
followers_file.write(approve_handle_full + '\n')
encoding='utf-8') as fp_followers:
fp_followers.write(approve_handle_full + '\n')
except OSError:
print('EX: manual_approve_follow_request unable to write ' +
followers_filename)

View File

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

View File

@ -1624,11 +1624,11 @@ def _add_account_blogs_to_newswire(base_dir: str, nickname: str, domain: str,
moderated = True
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'
ctr = 0
while post_filename:
post_filename = index_file.readline()
post_filename = fp_index.readline()
if post_filename:
# if this is a full path then remove the directories
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')
try:
with open(notify_on_post_filename, 'r',
encoding='utf-8') as calendar_file:
following_handles = calendar_file.read()
encoding='utf-8') as fp_calendar:
following_handles = fp_calendar.read()
except OSError:
print('EX: _notify_on_post_arrival unable to read 1 ' +
notify_on_post_filename)
@ -56,8 +56,8 @@ def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
following_handles = ''
try:
with open(following_filename, 'r',
encoding='utf-8') as following_file:
following_handles = following_file.read()
encoding='utf-8') as fp_following:
following_handles = fp_following.read()
except OSError:
print('EX: _notify_on_post_arrival unable to read 2 ' +
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)
filename = base_dir + private_keys_subdir + '/' + handle + '.key'
try:
with open(filename, 'w+', encoding='utf-8') as text_file:
print(private_key_pem, file=text_file)
with open(filename, 'w+', encoding='utf-8') as fp_text:
print(private_key_pem, file=fp_text)
except OSError:
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)
filename = base_dir + public_keys_subdir + '/' + handle + '.pem'
try:
with open(filename, 'w+', encoding='utf-8') as text_file:
print(public_key_pem, file=text_file)
with open(filename, 'w+', encoding='utf-8') as fp_text:
print(public_key_pem, file=fp_text)
except OSError:
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 ' +
tag_filename)
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:
if match_str not in tagline:
tag_file.write(tagline)
fp_tag.write(tagline)
except OSError:
print('EX: _remove_tags_for_nickname unable to write ' +
tag_filename)
@ -1616,9 +1616,9 @@ def person_snooze(base_dir: str, nickname: str, domain: str,
if text_in_file(snooze_actor + ' ', snoozed_filename):
return
try:
with open(snoozed_filename, 'a+', encoding='utf-8') as snoozed_file:
snoozed_file.write(snooze_actor + ' ' +
str(int(time.time())) + '\n')
with open(snoozed_filename, 'a+', encoding='utf-8') as fp_snoozed:
fp_snoozed.write(snooze_actor + ' ' +
str(int(time.time())) + '\n')
except OSError:
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)
notes_filename = notes_dir + '/' + handle + '.txt'
try:
with open(notes_filename, 'w+', encoding='utf-8') as notes_file:
notes_file.write(notes)
with open(notes_filename, 'w+', encoding='utf-8') as fp_notes:
fp_notes.write(notes)
except OSError:
print('EX: unable to write ' + notes_filename)
return False

View File

@ -31,8 +31,8 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
petnames_str = ''
try:
with open(petnames_filename, 'r',
encoding='utf-8') as petnames_file:
petnames_str = petnames_file.read()
encoding='utf-8') as fp_petnames:
petnames_str = fp_petnames.read()
except OSError:
print('EX: set_pet_name unable to read ' + petnames_filename)
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
try:
with open(petnames_filename, 'w+',
encoding='utf-8') as petnames_file:
petnames_file.write(new_petnames_str)
encoding='utf-8') as fp_petnames:
fp_petnames.write(new_petnames_str)
except OSError:
print('EX: set_pet_name unable to save ' + petnames_filename)
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
try:
with open(petnames_filename, 'a+',
encoding='utf-8') as petnames_file:
petnames_file.write(entry)
encoding='utf-8') as fp_petnames:
fp_petnames.write(entry)
except OSError:
print('EX: set_pet_name unable to append ' + petnames_filename)
return False
@ -66,8 +66,8 @@ def set_pet_name(base_dir: str, nickname: str, domain: str,
# first entry
try:
with open(petnames_filename, 'w+', encoding='utf-8') as petnames_file:
petnames_file.write(entry)
with open(petnames_filename, 'w+', encoding='utf-8') as fp_petnames:
fp_petnames.write(entry)
except OSError:
print('EX: set_pet_name unable to write ' + petnames_filename)
return False
@ -88,8 +88,8 @@ def get_pet_name(base_dir: str, nickname: str, domain: str,
return ''
petnames_str = ''
try:
with open(petnames_filename, 'r', encoding='utf-8') as petnames_file:
petnames_str = petnames_file.read()
with open(petnames_filename, 'r', encoding='utf-8') as fp_petnames:
petnames_str = fp_petnames.read()
except OSError:
print('EX: get_pet_name unable to read ' + petnames_filename)
if ' ' + handle + '\n' in petnames_str:
@ -119,8 +119,8 @@ def _get_pet_name_handle(base_dir: str, nickname: str, domain: str,
return ''
petnames_str = ''
try:
with open(petnames_filename, 'r', encoding='utf-8') as petnames_file:
petnames_str = petnames_file.read()
with open(petnames_filename, 'r', encoding='utf-8') as fp_petnames:
petnames_str = fp_petnames.read()
except OSError:
print('EX: _get_pet_name_handle unable to read ' + petnames_filename)
if petname + ' ' in petnames_str:

View File

@ -199,15 +199,16 @@ def no_of_followers_on_domain(base_dir: str, handle: str,
ctr = 0
try:
with open(filename, 'r', encoding='utf-8') as followers_file:
for follower_handle in followers_file:
with open(filename, 'r', encoding='utf-8') as fp_followers:
for follower_handle in fp_followers:
if '@' in follower_handle:
follower_domain = follower_handle.split('@')[1]
follower_domain = remove_eol(follower_domain)
if domain == follower_domain:
ctr += 1
except OSError:
print('EX: no_of_followers_on_domain unable to read ' + filename)
except OSError as exc:
print('EX: no_of_followers_on_domain unable to read ' + filename +
' ' + str(exc))
return ctr
@ -1090,8 +1091,8 @@ def _update_hashtags_index(base_dir: str, tag: {}, new_post_id: str,
new_post_id + '\n'
# create a new tags index file
try:
with open(tags_filename, 'w+', encoding='utf-8') as tags_file:
tags_file.write(tag_line)
with open(tags_filename, 'w+', encoding='utf-8') as fp_tags:
fp_tags.write(tag_line)
except OSError:
print('EX: _update_hashtags_index unable to write tags file ' +
tags_filename)
@ -1104,11 +1105,11 @@ def _update_hashtags_index(base_dir: str, tag: {}, new_post_id: str,
str(days_since_epoch) + ' ' + nickname + ' ' + \
new_post_id + '\n'
try:
with open(tags_filename, 'r+', encoding='utf-8') as tags_file:
content = tags_file.read()
with open(tags_filename, 'r+', encoding='utf-8') as fp_tags:
content = fp_tags.read()
if tag_line not in content:
tags_file.seek(0, 0)
tags_file.write(tag_line + content)
fp_tags.seek(0, 0)
fp_tags.write(tag_line + content)
except OSError as ex:
print('EX: Failed to write entry to tags file ' +
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):
try:
with open(schedule_index_filename, 'r+',
encoding='utf-8') as schedule_file:
content = schedule_file.read()
encoding='utf-8') as fp_schedule:
content = fp_schedule.read()
if index_str + '\n' not in content:
schedule_file.seek(0, 0)
schedule_file.write(index_str + '\n' + content)
fp_schedule.seek(0, 0)
fp_schedule.write(index_str + '\n' + content)
print('DEBUG: scheduled post added to index')
except OSError as ex:
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:
try:
with open(schedule_index_filename, 'w+',
encoding='utf-8') as schedule_file:
schedule_file.write(index_str + '\n')
encoding='utf-8') as fp_schedule:
fp_schedule.write(index_str + '\n')
except OSError as ex:
print('EX: Failed to write entry to scheduled posts index2 ' +
schedule_index_filename + ' ' + str(ex))
@ -1608,8 +1609,8 @@ def _create_post_mod_report(base_dir: str,
# save to index file
moderation_index_file = data_dir(base_dir) + '/moderation.txt'
try:
with open(moderation_index_file, 'a+', encoding='utf-8') as mod_file:
mod_file.write(new_post_id + '\n')
with open(moderation_index_file, 'a+', encoding='utf-8') as fp_mod:
fp_mod.write(new_post_id + '\n')
except OSError:
print('EX: unable to write 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)
pinned_filename = account_dir + '/pinToProfile.txt'
try:
with open(pinned_filename, 'w+', encoding='utf-8') as pin_file:
pin_file.write(pinned_content)
with open(pinned_filename, 'w+', encoding='utf-8') as fp_pin:
fp_pin.write(pinned_content)
except OSError:
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):
try:
with open(post_log_filename, 'a+',
encoding='utf-8') as log_file:
log_file.write(log_str + '\n')
encoding='utf-8') as fp_log:
fp_log.write(log_str + '\n')
except OSError:
print('EX: thread_send_post unable to append ' +
post_log_filename)
else:
try:
with open(post_log_filename, 'w+',
encoding='utf-8') as log_file:
log_file.write(log_str + '\n')
encoding='utf-8') as fp_log:
fp_log.write(log_str + '\n')
except OSError:
print('EX: thread_send_post unable to write ' +
post_log_filename)
@ -4398,8 +4399,8 @@ def create_moderation(base_dir: str, nickname: str, domain: str, port: int,
lines = []
try:
with open(moderation_index_file, 'r',
encoding='utf-8') as index_file:
lines = index_file.readlines()
encoding='utf-8') as fp_index:
lines = fp_index.readlines()
except OSError:
print('EX: create_moderation unable to read ' +
moderation_index_file)
@ -4679,10 +4680,10 @@ def _create_box_items(base_dir: str,
first_post_id = first_post_id.replace('/', '#')
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
while posts_added_to_timeline < items_per_page:
post_filename = index_file.readline()
post_filename = fp_index.readline()
if not post_filename:
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
new_index = ''
try:
with open(index_filename, 'r', encoding='utf-8') as index_file:
for post_id in index_file:
with open(index_filename, 'r', encoding='utf-8') as fp_index:
for post_id in fp_index:
new_index += post_id
index_ctr += 1
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:
try:
with open(index_filename, 'w+',
encoding='utf-8') as index_file:
index_file.write(new_index)
encoding='utf-8') as fp_index:
fp_index.write(new_index)
except OSError:
print('EX: archive_posts_for_person unable to write ' +
index_filename)
@ -5903,8 +5904,8 @@ def populate_replies_json(base_dir: str, nickname: str, domain: str,
replies_boxes = ('outbox', 'inbox')
try:
with open(post_replies_filename, 'r',
encoding='utf-8') as replies_file:
for message_id in replies_file:
encoding='utf-8') as fp_replies:
for message_id in fp_replies:
reply_found = False
# examine inbox and outbox
for boxname in replies_boxes:
@ -5975,8 +5976,8 @@ def _reject_announce(announce_filename: str,
if not os.path.isfile(announce_filename + '.reject'):
try:
with open(announce_filename + '.reject', 'w+',
encoding='utf-8') as reject_announce_file:
reject_announce_file.write('\n')
encoding='utf-8') as fp_reject_announce:
fp_reject_announce.write('\n')
except OSError:
print('EX: _reject_announce unable to write ' +
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
try:
with open(voters_filename, 'w+',
encoding='utf-8') as voters_file:
voters_file.write(actor_url +
voters_file_separator +
reply_vote + '\n')
encoding='utf-8') as fp_voters:
fp_voters.write(actor_url +
voters_file_separator +
reply_vote + '\n')
except OSError:
print('EX: unable to write voters file ' + voters_filename)
else:
@ -137,10 +137,10 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
# append to the voters file
try:
with open(voters_filename, 'a+',
encoding='utf-8') as voters_file:
voters_file.write(actor_url +
voters_file_separator +
reply_vote + '\n')
encoding='utf-8') as fp_voters:
fp_voters.write(actor_url +
voters_file_separator +
reply_vote + '\n')
except OSError:
print('EX: unable to append to voters file ' + voters_filename)
else:
@ -148,8 +148,8 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
lines = []
try:
with open(voters_filename, 'r',
encoding='utf-8') as voters_file:
lines = voters_file.readlines()
encoding='utf-8') as fp_voters:
lines = fp_voters.readlines()
except OSError:
print('EX: question_update_votes unable to read ' +
voters_filename)
@ -170,9 +170,9 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
if save_voters_file:
try:
with open(voters_filename, 'w+',
encoding='utf-8') as voters_file:
encoding='utf-8') as fp_voters:
for vote_line in newlines:
voters_file.write(vote_line)
fp_voters.write(vote_line)
except OSError:
print('EX: unable to write voters file2 ' +
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):
try:
with open(recent_books_filename, 'r+',
encoding='utf-8') as recent_file:
content = recent_file.read()
encoding='utf-8') as fp_recent:
content = fp_recent.read()
if book_id + '\n' not in content:
recent_file.seek(0, 0)
recent_file.write(book_id + '\n' + content)
fp_recent.seek(0, 0)
fp_recent.write(book_id + '\n' + content)
if debug:
print('DEBUG: recent book added')
except OSError as ex:
@ -409,8 +409,8 @@ def _update_recent_books_list(base_dir: str, book_id: str,
else:
try:
with open(recent_books_filename, 'w+',
encoding='utf-8') as recent_file:
recent_file.write(book_id + '\n')
encoding='utf-8') as fp_recent:
fp_recent.write(book_id + '\n')
except OSError:
print('EX: unable to write recent books ' +
recent_books_filename)
@ -428,8 +428,8 @@ def _deduplicate_recent_books_list(base_dir: str,
recent_lines = []
try:
with open(recent_books_filename, 'r',
encoding='utf-8') as recent_file:
recent_lines = recent_file.read().split('\n')
encoding='utf-8') as fp_recent:
recent_lines = fp_recent.read().split('\n')
except OSError as ex:
print('WARN: Failed to read recent books trim ' +
recent_books_filename + ' ' + str(ex))
@ -446,8 +446,8 @@ def _deduplicate_recent_books_list(base_dir: str,
result += line + '\n'
try:
with open(recent_books_filename, 'w+',
encoding='utf-8') as recent_file:
recent_file.write(result)
encoding='utf-8') as fp_recent:
fp_recent.write(result)
except OSError:
print('EX: unable to deduplicate recent books ' +
recent_books_filename)
@ -459,8 +459,8 @@ def _deduplicate_recent_books_list(base_dir: str,
result += recent_lines[ctr] + '\n'
try:
with open(recent_books_filename, 'w+',
encoding='utf-8') as recent_file:
recent_file.write(result)
encoding='utf-8') as fp_recent:
fp_recent.write(result)
except OSError:
print('EX: unable to trim recent books ' +
recent_books_filename)

View File

@ -44,8 +44,8 @@ def _update_post_schedule(base_dir: str, handle: str, httpd,
index_lines = []
delete_schedule_post = False
nickname = handle.split('@')[0]
with open(schedule_index_filename, 'r', encoding='utf-8') as sched_file:
for line in sched_file:
with open(schedule_index_filename, 'r', encoding='utf-8') as fp_sched:
for line in fp_sched:
if ' ' not in line:
continue
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'
try:
with open(schedule_index_file, 'w+',
encoding='utf-8') as schedule_file:
encoding='utf-8') as fp_schedule:
for line in index_lines:
schedule_file.write(line)
fp_schedule.write(line)
except OSError:
print('EX: _update_post_schedule unable to write ' +
schedule_index_file)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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