mirror of https://gitlab.com/bashrc2/epicyon
File pointer naming convention
parent
9544505bfa
commit
a89a3211a1
|
@ -68,11 +68,11 @@ def remove_filter(base_dir: str, nickname: str, domain: str,
|
|||
new_filters_filename = filters_filename + '.new'
|
||||
try:
|
||||
with open(filters_filename, 'r', encoding='utf-8') as fp_filt:
|
||||
with open(new_filters_filename, 'w+', encoding='utf-8') as fpnew:
|
||||
with open(new_filters_filename, 'w+', encoding='utf-8') as fp_new:
|
||||
for line in fp_filt:
|
||||
line = remove_eol(line)
|
||||
if line != words:
|
||||
fpnew.write(line + '\n')
|
||||
fp_new.write(line + '\n')
|
||||
except OSError as ex:
|
||||
print('EX: unable to remove filter ' +
|
||||
filters_filename + ' ' + str(ex))
|
||||
|
@ -94,11 +94,11 @@ def remove_global_filter(base_dir: str, words: str) -> bool:
|
|||
new_filters_filename = filters_filename + '.new'
|
||||
try:
|
||||
with open(filters_filename, 'r', encoding='utf-8') as fp_filt:
|
||||
with open(new_filters_filename, 'w+', encoding='utf-8') as fpnew:
|
||||
with open(new_filters_filename, 'w+', encoding='utf-8') as fp_new:
|
||||
for line in fp_filt:
|
||||
line = remove_eol(line)
|
||||
if line != words:
|
||||
fpnew.write(line + '\n')
|
||||
fp_new.write(line + '\n')
|
||||
except OSError as ex:
|
||||
print('EX: unable to remove global filter ' +
|
||||
filters_filename + ' ' + str(ex))
|
||||
|
|
|
@ -144,18 +144,18 @@ def _remove_from_follow_base(base_dir: str,
|
|||
return
|
||||
try:
|
||||
with open(approve_follows_filename + '.new', 'w+',
|
||||
encoding='utf-8') as approvefilenew:
|
||||
encoding='utf-8') as fp_approve_new:
|
||||
with open(approve_follows_filename, 'r',
|
||||
encoding='utf-8') as fp_approve:
|
||||
if not accept_deny_actor:
|
||||
for approve_handle in fp_approve:
|
||||
accept_deny_handle = accept_or_deny_handle
|
||||
if not approve_handle.startswith(accept_deny_handle):
|
||||
approvefilenew.write(approve_handle)
|
||||
fp_approve_new.write(approve_handle)
|
||||
else:
|
||||
for approve_handle in fp_approve:
|
||||
if accept_deny_actor not in approve_handle:
|
||||
approvefilenew.write(approve_handle)
|
||||
fp_approve_new.write(approve_handle)
|
||||
except OSError as ex:
|
||||
print('EX: _remove_from_follow_base ' +
|
||||
approve_follows_filename + ' ' + str(ex))
|
||||
|
|
|
@ -23,8 +23,8 @@ def _text_in_file2(text: str, filename: str,
|
|||
if not case_sensitive:
|
||||
text = text.lower()
|
||||
try:
|
||||
with open(filename, 'r', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
with open(filename, 'r', encoding='utf-8') as fp_file:
|
||||
content = fp_file.read()
|
||||
if content:
|
||||
if not case_sensitive:
|
||||
content = content.lower()
|
||||
|
|
|
@ -185,8 +185,8 @@ def set_headers_etag(self, media_filename: str, file_format: str,
|
|||
if os.path.isfile(media_filename + '.etag'):
|
||||
try:
|
||||
with open(media_filename + '.etag', 'r',
|
||||
encoding='utf-8') as efile:
|
||||
etag = efile.read()
|
||||
encoding='utf-8') as fp_media:
|
||||
etag = fp_media.read()
|
||||
except OSError:
|
||||
print('EX: _set_headers_etag ' +
|
||||
'unable to read ' + media_filename + '.etag')
|
||||
|
@ -194,8 +194,8 @@ def set_headers_etag(self, media_filename: str, file_format: str,
|
|||
etag = md5(data).hexdigest() # nosec
|
||||
try:
|
||||
with open(media_filename + '.etag', 'w+',
|
||||
encoding='utf-8') as efile:
|
||||
efile.write(etag)
|
||||
encoding='utf-8') as fp_media:
|
||||
fp_media.write(etag)
|
||||
except OSError:
|
||||
print('EX: _set_headers_etag ' +
|
||||
'unable to write ' + media_filename + '.etag')
|
||||
|
|
8
inbox.py
8
inbox.py
|
@ -438,8 +438,8 @@ def store_hash_tags(base_dir: str, nickname: str, domain: str,
|
|||
content = tag_line + content
|
||||
try:
|
||||
with open(tags_filename, 'w+',
|
||||
encoding='utf-8') as tags_file2:
|
||||
tags_file2.write(content)
|
||||
encoding='utf-8') as fp_tags2:
|
||||
fp_tags2.write(content)
|
||||
hashtag_added = True
|
||||
except OSError as ex:
|
||||
print('EX: Failed to write entry to tags file ' +
|
||||
|
@ -3490,8 +3490,8 @@ def _receive_announce(recent_posts_cache: {},
|
|||
'inbox')
|
||||
try:
|
||||
with open(post_filename + '.tts', 'w+',
|
||||
encoding='utf-8') as ttsfile:
|
||||
ttsfile.write('\n')
|
||||
encoding='utf-8') as fp_tts:
|
||||
fp_tts.write('\n')
|
||||
except OSError:
|
||||
print('EX: unable to write recent post ' +
|
||||
post_filename)
|
||||
|
|
|
@ -221,18 +221,18 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
|
|||
|
||||
try:
|
||||
with open(approve_follows_filename + '.new', 'w+',
|
||||
encoding='utf-8') as approvefilenew:
|
||||
encoding='utf-8') as fp_approve_new:
|
||||
update_approved_followers = False
|
||||
follow_activity_filename = None
|
||||
with open(approve_follows_filename, 'r',
|
||||
encoding='utf-8') as approvefile:
|
||||
for handle_of_follow_requester in approvefile:
|
||||
encoding='utf-8') as fp_approve:
|
||||
for handle_of_follow_requester in fp_approve:
|
||||
# is this the approved follow?
|
||||
appr_handl = approve_handle_full
|
||||
if not handle_of_follow_requester.startswith(appr_handl):
|
||||
# this isn't the approved follow so it will remain
|
||||
# in the requests file
|
||||
approvefilenew.write(handle_of_follow_requester)
|
||||
fp_approve_new.write(handle_of_follow_requester)
|
||||
continue
|
||||
|
||||
handle_of_follow_requester = \
|
||||
|
|
5
media.py
5
media.py
|
@ -552,8 +552,9 @@ def _update_etag(media_filename: str) -> None:
|
|||
etag = sha1(data).hexdigest() # nosec
|
||||
# save the hash
|
||||
try:
|
||||
with open(media_filename + '.etag', 'w+', encoding='utf-8') as efile:
|
||||
efile.write(etag)
|
||||
with open(media_filename + '.etag', 'w+',
|
||||
encoding='utf-8') as fp_media:
|
||||
fp_media.write(etag)
|
||||
except OSError:
|
||||
print('EX: _update_etag unable to write ' +
|
||||
str(media_filename) + '.etag')
|
||||
|
|
24
migrate.py
24
migrate.py
|
@ -140,8 +140,8 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
|
|||
if os.path.isfile(following_filename):
|
||||
following_handles = []
|
||||
try:
|
||||
with open(following_filename, 'r', encoding='utf-8') as foll1:
|
||||
following_handles = foll1.readlines()
|
||||
with open(following_filename, 'r', encoding='utf-8') as fp_foll1:
|
||||
following_handles = fp_foll1.readlines()
|
||||
except OSError:
|
||||
print('EX: _update_moved_handle unable to read ' +
|
||||
following_filename)
|
||||
|
@ -153,11 +153,11 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
|
|||
acct_dir(base_dir, nickname, domain) + '/refollow.txt'
|
||||
|
||||
# unfollow the old handle
|
||||
with open(following_filename, 'w+', encoding='utf-8') as foll2:
|
||||
with open(following_filename, 'w+', encoding='utf-8') as fp_foll2:
|
||||
for follow_handle in following_handles:
|
||||
if follow_handle.strip("\n").strip("\r").lower() != \
|
||||
handle_lower:
|
||||
foll2.write(follow_handle)
|
||||
fp_foll2.write(follow_handle)
|
||||
continue
|
||||
handle_nickname = handle.split('@')[0]
|
||||
handle_domain = handle.split('@')[1]
|
||||
|
@ -173,8 +173,8 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
|
|||
if os.path.isfile(refollow_filename):
|
||||
try:
|
||||
with open(refollow_filename, 'a+',
|
||||
encoding='utf-8') as refoll:
|
||||
refoll.write(moved_to_handle + '\n')
|
||||
encoding='utf-8') as fp_refoll:
|
||||
fp_refoll.write(moved_to_handle + '\n')
|
||||
except OSError:
|
||||
print('EX: ' +
|
||||
'_update_moved_handle unable to append ' +
|
||||
|
@ -182,8 +182,8 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
|
|||
else:
|
||||
try:
|
||||
with open(refollow_filename, 'w+',
|
||||
encoding='utf-8') as refoll:
|
||||
refoll.write(moved_to_handle + '\n')
|
||||
encoding='utf-8') as fp_refoll:
|
||||
fp_refoll.write(moved_to_handle + '\n')
|
||||
except OSError:
|
||||
print('EX: _update_moved_handle unable to write ' +
|
||||
refollow_filename)
|
||||
|
@ -193,8 +193,8 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
|
|||
if os.path.isfile(followers_filename):
|
||||
follower_handles = []
|
||||
try:
|
||||
with open(followers_filename, 'r', encoding='utf-8') as foll3:
|
||||
follower_handles = foll3.readlines()
|
||||
with open(followers_filename, 'r', encoding='utf-8') as fp_foll3:
|
||||
follower_handles = fp_foll3.readlines()
|
||||
except OSError:
|
||||
print('EX: _update_moved_handle unable to read ' +
|
||||
followers_filename)
|
||||
|
@ -203,11 +203,11 @@ def _update_moved_handle(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
# remove followers who have moved
|
||||
try:
|
||||
with open(followers_filename, 'w+', encoding='utf-8') as foll4:
|
||||
with open(followers_filename, 'w+', encoding='utf-8') as fp_foll4:
|
||||
for follower_handle in follower_handles:
|
||||
if follower_handle.strip("\n").strip("\r").lower() != \
|
||||
handle_lower:
|
||||
foll4.write(follower_handle)
|
||||
fp_foll4.write(follower_handle)
|
||||
else:
|
||||
ctr += 1
|
||||
print('Removed follower who has moved ' + handle)
|
||||
|
|
20
person.py
20
person.py
|
@ -762,8 +762,8 @@ def create_person(base_dir: str, nickname: str, domain: str, port: int,
|
|||
follow_dms_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/.followDMs'
|
||||
try:
|
||||
with open(follow_dms_filename, 'w+', encoding='utf-8') as ffile:
|
||||
ffile.write('\n')
|
||||
with open(follow_dms_filename, 'w+', encoding='utf-8') as fp_foll:
|
||||
fp_foll.write('\n')
|
||||
except OSError:
|
||||
print('EX: create_person unable to write ' + follow_dms_filename)
|
||||
|
||||
|
@ -772,8 +772,8 @@ def create_person(base_dir: str, nickname: str, domain: str, port: int,
|
|||
notify_likes_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/.notifyLikes'
|
||||
try:
|
||||
with open(notify_likes_filename, 'w+', encoding='utf-8') as nfile:
|
||||
nfile.write('\n')
|
||||
with open(notify_likes_filename, 'w+', encoding='utf-8') as fp_lik:
|
||||
fp_lik.write('\n')
|
||||
except OSError:
|
||||
print('EX: create_person unable to write 2 ' +
|
||||
notify_likes_filename)
|
||||
|
@ -784,8 +784,8 @@ def create_person(base_dir: str, nickname: str, domain: str, port: int,
|
|||
acct_dir(base_dir, nickname, domain) + '/.notifyReactions'
|
||||
try:
|
||||
with open(notify_reactions_filename, 'w+',
|
||||
encoding='utf-8') as nfile:
|
||||
nfile.write('\n')
|
||||
encoding='utf-8') as fp_notify:
|
||||
fp_notify.write('\n')
|
||||
except OSError:
|
||||
print('EX: create_person unable to write 3 ' +
|
||||
notify_reactions_filename)
|
||||
|
@ -1592,8 +1592,8 @@ def is_person_snoozed(base_dir: str, nickname: str, domain: str,
|
|||
if content:
|
||||
try:
|
||||
with open(snoozed_filename, 'w+',
|
||||
encoding='utf-8') as snoozfile:
|
||||
snoozfile.write(content)
|
||||
encoding='utf-8') as fp_snooze:
|
||||
fp_snooze.write(content)
|
||||
except OSError:
|
||||
print('EX: is_person_snoozed unable to write ' +
|
||||
snoozed_filename)
|
||||
|
@ -1655,8 +1655,8 @@ def person_unsnooze(base_dir: str, nickname: str, domain: str,
|
|||
if content is not None:
|
||||
try:
|
||||
with open(snoozed_filename, 'w+',
|
||||
encoding='utf-8') as snoozfile:
|
||||
snoozfile.write(content)
|
||||
encoding='utf-8') as fp_snooze:
|
||||
fp_snooze.write(content)
|
||||
except OSError:
|
||||
print('EX: unable to write ' + snoozed_filename)
|
||||
|
||||
|
|
8
roles.py
8
roles.py
|
@ -327,12 +327,12 @@ def set_roles_from_list(base_dir: str, domain: str, admin_nickname: str,
|
|||
roles_list = fields[list_name].split(',')
|
||||
try:
|
||||
with open(roles_filename, 'w+',
|
||||
encoding='utf-8') as rolesfile:
|
||||
encoding='utf-8') as fp_roles:
|
||||
for roles_nick in roles_list:
|
||||
roles_nick = roles_nick.strip()
|
||||
roles_dir = acct_dir(base_dir, roles_nick, domain)
|
||||
if os.path.isdir(roles_dir):
|
||||
rolesfile.write(roles_nick + '\n')
|
||||
fp_roles.write(roles_nick + '\n')
|
||||
except OSError as ex:
|
||||
print('EX: unable to write ' + list_name + ' ' +
|
||||
roles_filename + ' ' + str(ex))
|
||||
|
@ -347,12 +347,12 @@ def set_roles_from_list(base_dir: str, domain: str, admin_nickname: str,
|
|||
roles_list = fields[list_name].split('\n')
|
||||
try:
|
||||
with open(roles_filename, 'w+',
|
||||
encoding='utf-8') as rolesfile:
|
||||
encoding='utf-8') as fp_roles:
|
||||
for roles_nick in roles_list:
|
||||
roles_nick = roles_nick.strip()
|
||||
roles_dir = acct_dir(base_dir, roles_nick, domain)
|
||||
if os.path.isdir(roles_dir):
|
||||
rolesfile.write(roles_nick + '\n')
|
||||
fp_roles.write(roles_nick + '\n')
|
||||
except OSError as ex:
|
||||
print('EX: unable to write ' + list_name + ' ' +
|
||||
roles_filename + ' ' + str(ex))
|
||||
|
|
31
tests.py
31
tests.py
|
@ -4532,8 +4532,8 @@ def _test_translation_labels() -> None:
|
|||
if source_file.startswith('flycheck_'):
|
||||
continue
|
||||
source_str = ''
|
||||
with open(source_file, 'r', encoding='utf-8') as file_source:
|
||||
source_str = file_source.read()
|
||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
||||
source_str = fp_source.read()
|
||||
if not source_str:
|
||||
continue
|
||||
if 'translate[' not in source_str:
|
||||
|
@ -5173,8 +5173,8 @@ def _test_post_variable_names():
|
|||
if source_file.startswith('flycheck_'):
|
||||
continue
|
||||
source_str = ''
|
||||
with open(source_file, 'r', encoding='utf-8') as file_source:
|
||||
source_str = file_source.read()
|
||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
||||
source_str = fp_source.read()
|
||||
if not source_str:
|
||||
continue
|
||||
if ' name="' not in source_str:
|
||||
|
@ -5208,8 +5208,8 @@ def _test_config_param_names():
|
|||
if source_file.startswith('flycheck_'):
|
||||
continue
|
||||
source_str = ''
|
||||
with open(source_file, 'r', encoding='utf-8') as file_source:
|
||||
source_str = file_source.read()
|
||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
||||
source_str = fp_source.read()
|
||||
if not source_str:
|
||||
continue
|
||||
for fname in fnames:
|
||||
|
@ -5256,8 +5256,8 @@ def _test_source_contains_no_tabs():
|
|||
if source_file.startswith('flycheck_'):
|
||||
continue
|
||||
source_str = ''
|
||||
with open(source_file, 'r', encoding='utf-8') as file_source:
|
||||
source_str = file_source.read()
|
||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
||||
source_str = fp_source.read()
|
||||
if not source_str:
|
||||
continue
|
||||
if '\t' in source_str:
|
||||
|
@ -5279,8 +5279,8 @@ def _test_checkbox_names():
|
|||
if source_file.startswith('flycheck_'):
|
||||
continue
|
||||
source_str = ''
|
||||
with open(source_file, 'r', encoding='utf-8') as file_source:
|
||||
source_str = file_source.read()
|
||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
||||
source_str = fp_source.read()
|
||||
if not source_str:
|
||||
continue
|
||||
for fname in fnames:
|
||||
|
@ -5319,8 +5319,8 @@ def _test_post_field_names(source_file: str, fieldnames: []):
|
|||
fnames.append(field + '.get')
|
||||
|
||||
source_str = ''
|
||||
with open(source_file, 'r', encoding='utf-8') as file_source:
|
||||
source_str = file_source.read()
|
||||
with open(source_file, 'r', encoding='utf-8') as fp_source:
|
||||
source_str = fp_source.read()
|
||||
if not source_str:
|
||||
return
|
||||
for fname in fnames:
|
||||
|
@ -6810,8 +6810,11 @@ def _test_spoofed_geolocation() -> None:
|
|||
|
||||
kml_str += '</Document>\n'
|
||||
kml_str += '</kml>'
|
||||
with open('unittest_decoy.kml', 'w+', encoding='utf-8') as kmlfile:
|
||||
kmlfile.write(kml_str)
|
||||
try:
|
||||
with open('unittest_decoy.kml', 'w+', encoding='utf-8') as fp_kml:
|
||||
fp_kml.write(kml_str)
|
||||
except OSError:
|
||||
print('EX: unable to write unittest_decoy.kml')
|
||||
|
||||
|
||||
def _test_skills() -> None:
|
||||
|
|
52
theme.py
52
theme.py
|
@ -363,8 +363,8 @@ def _set_theme_from_dict(base_dir: str, name: str,
|
|||
if not os.path.isfile(template_filename):
|
||||
continue
|
||||
|
||||
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
||||
css = cssfile.read()
|
||||
with open(template_filename, 'r', encoding='utf-8') as fp_css:
|
||||
css = fp_css.read()
|
||||
for param_name, param_value in theme_params.items():
|
||||
if param_name == 'newswire-publish-icon':
|
||||
if param_value.lower() == 'true':
|
||||
|
@ -405,8 +405,8 @@ def _set_theme_from_dict(base_dir: str, name: str,
|
|||
|
||||
filename = base_dir + '/' + filename
|
||||
try:
|
||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||
cssfile.write(css)
|
||||
with open(filename, 'w+', encoding='utf-8') as fp_css:
|
||||
fp_css.write(css)
|
||||
except OSError:
|
||||
print('EX: _set_theme_from_dict unable to write ' + filename)
|
||||
|
||||
|
@ -428,11 +428,11 @@ def _set_background_format(base_dir: str,
|
|||
if not os.path.isfile(css_filename):
|
||||
return
|
||||
try:
|
||||
with open(css_filename, 'r', encoding='utf-8') as cssfile:
|
||||
css = cssfile.read()
|
||||
with open(css_filename, 'r', encoding='utf-8') as fp_css:
|
||||
css = fp_css.read()
|
||||
css = css.replace('background.jpg', 'background.' + extension)
|
||||
with open(css_filename, 'w+', encoding='utf-8') as cssfile2:
|
||||
cssfile2.write(css)
|
||||
with open(css_filename, 'w+', encoding='utf-8') as fp_css2:
|
||||
fp_css2.write(css)
|
||||
except OSError as ex:
|
||||
print('EX: _set_background_format ' + css_filename + ' ' + str(ex))
|
||||
|
||||
|
@ -446,24 +446,24 @@ def enable_grayscale(base_dir: str) -> None:
|
|||
if not os.path.isfile(template_filename):
|
||||
continue
|
||||
try:
|
||||
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
||||
css = cssfile.read()
|
||||
with open(template_filename, 'r', encoding='utf-8') as fp_css:
|
||||
css = fp_css.read()
|
||||
if 'grayscale' not in css:
|
||||
css = \
|
||||
css.replace('body, html {',
|
||||
'body, html {\n' +
|
||||
' filter: grayscale(100%);')
|
||||
filename = base_dir + '/' + filename
|
||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||
cssfile.write(css)
|
||||
with open(filename, 'w+', encoding='utf-8') as fp_css:
|
||||
fp_css.write(css)
|
||||
except OSError as ex:
|
||||
print('EX: enable_grayscale unable to read ' +
|
||||
template_filename + ' ' + str(ex))
|
||||
grayscale_filename = data_dir(base_dir) + '/.grayscale'
|
||||
if not os.path.isfile(grayscale_filename):
|
||||
try:
|
||||
with open(grayscale_filename, 'w+', encoding='utf-8') as grayfile:
|
||||
grayfile.write(' ')
|
||||
with open(grayscale_filename, 'w+', encoding='utf-8') as fp_gray:
|
||||
fp_gray.write(' ')
|
||||
except OSError as ex:
|
||||
print('EX: enable_grayscale unable to write ' +
|
||||
grayscale_filename + ' ' + str(ex))
|
||||
|
@ -478,14 +478,14 @@ def disable_grayscale(base_dir: str) -> None:
|
|||
if not os.path.isfile(template_filename):
|
||||
continue
|
||||
try:
|
||||
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
||||
css = cssfile.read()
|
||||
with open(template_filename, 'r', encoding='utf-8') as fp_css:
|
||||
css = fp_css.read()
|
||||
if 'grayscale' in css:
|
||||
css = \
|
||||
css.replace('\n filter: grayscale(100%);', '')
|
||||
filename = base_dir + '/' + filename
|
||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||
cssfile.write(css)
|
||||
with open(filename, 'w+', encoding='utf-8') as fp_css:
|
||||
fp_css.write(css)
|
||||
except OSError as ex:
|
||||
print('EX: disable_grayscale unable to read ' +
|
||||
template_filename + ' ' + str(ex))
|
||||
|
@ -506,8 +506,8 @@ def _set_dyslexic_font(base_dir: str) -> bool:
|
|||
template_filename = base_dir + '/' + filename
|
||||
if not os.path.isfile(template_filename):
|
||||
continue
|
||||
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
||||
css = cssfile.read()
|
||||
with open(template_filename, 'r', encoding='utf-8') as fp_css:
|
||||
css = fp_css.read()
|
||||
css = \
|
||||
set_css_param(css, "*src",
|
||||
"url('./fonts/OpenDyslexic-Regular.woff2" +
|
||||
|
@ -515,8 +515,8 @@ def _set_dyslexic_font(base_dir: str) -> bool:
|
|||
css = set_css_param(css, "*font-family", "'OpenDyslexic'")
|
||||
filename = base_dir + '/' + filename
|
||||
try:
|
||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||
cssfile.write(css)
|
||||
with open(filename, 'w+', encoding='utf-8') as fp_css:
|
||||
fp_css.write(css)
|
||||
except OSError:
|
||||
print('EX: _set_dyslexic_font unable to write ' + filename)
|
||||
return False
|
||||
|
@ -546,8 +546,8 @@ def _set_custom_font(base_dir: str):
|
|||
template_filename = base_dir + '/' + filename
|
||||
if not os.path.isfile(template_filename):
|
||||
continue
|
||||
with open(template_filename, 'r', encoding='utf-8') as cssfile:
|
||||
css = cssfile.read()
|
||||
with open(template_filename, 'r', encoding='utf-8') as fp_css:
|
||||
css = fp_css.read()
|
||||
css = \
|
||||
set_css_param(css, "*src",
|
||||
"url('./fonts/custom." +
|
||||
|
@ -558,8 +558,8 @@ def _set_custom_font(base_dir: str):
|
|||
css = set_css_param(css, "header-font", "'CustomFont'")
|
||||
filename = base_dir + '/' + filename
|
||||
try:
|
||||
with open(filename, 'w+', encoding='utf-8') as cssfile:
|
||||
cssfile.write(css)
|
||||
with open(filename, 'w+', encoding='utf-8') as fp_css:
|
||||
fp_css.write(css)
|
||||
except OSError:
|
||||
print('EX: _set_custom_font unable to write ' + filename)
|
||||
|
||||
|
|
49
utils.py
49
utils.py
|
@ -321,16 +321,19 @@ def text_in_file(text: str, filename: str,
|
|||
"""
|
||||
if not case_sensitive:
|
||||
text = text.lower()
|
||||
|
||||
content = None
|
||||
try:
|
||||
with open(filename, 'r', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
if content:
|
||||
if not case_sensitive:
|
||||
content = content.lower()
|
||||
if text in content:
|
||||
return True
|
||||
with open(filename, 'r', encoding='utf-8') as fp_file:
|
||||
content = fp_file.read()
|
||||
except OSError:
|
||||
print('EX: unable to find text in missing file ' + filename)
|
||||
|
||||
if content:
|
||||
if not case_sensitive:
|
||||
content = content.lower()
|
||||
if text in content:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
|
@ -594,8 +597,8 @@ def set_accounts_data_dir(base_dir: str, accounts_data_path: str) -> None:
|
|||
path = None
|
||||
try:
|
||||
with open(accounts_data_path_filename, 'r',
|
||||
encoding='utf-8') as file:
|
||||
path = file.read()
|
||||
encoding='utf-8') as fp_accounts:
|
||||
path = fp_accounts.read()
|
||||
except OSError:
|
||||
print('EX: unable to read ' + accounts_data_path_filename)
|
||||
if path.strip() == accounts_data_path:
|
||||
|
@ -604,8 +607,8 @@ def set_accounts_data_dir(base_dir: str, accounts_data_path: str) -> None:
|
|||
|
||||
try:
|
||||
with open(accounts_data_path_filename, 'w+',
|
||||
encoding='utf-8') as file:
|
||||
file.write(accounts_data_path)
|
||||
encoding='utf-8') as fp_accounts:
|
||||
fp_accounts.write(accounts_data_path)
|
||||
except OSError:
|
||||
print('EX: unable to write ' + accounts_data_path_filename)
|
||||
|
||||
|
@ -629,8 +632,8 @@ def data_dir(base_dir: str) -> str:
|
|||
path = None
|
||||
try:
|
||||
with open(accounts_data_path_filename, 'r',
|
||||
encoding='utf-8') as file:
|
||||
path = file.read()
|
||||
encoding='utf-8') as fp_accounts:
|
||||
path = fp_accounts.read()
|
||||
except OSError:
|
||||
print('EX: unable to read ' + accounts_data_path_filename)
|
||||
if path:
|
||||
|
@ -833,8 +836,8 @@ def is_editor(base_dir: str, nickname: str) -> bool:
|
|||
return True
|
||||
return False
|
||||
|
||||
with open(editors_file, 'r', encoding='utf-8') as editors:
|
||||
lines = editors.readlines()
|
||||
with open(editors_file, 'r', encoding='utf-8') as fp_editors:
|
||||
lines = fp_editors.readlines()
|
||||
if len(lines) == 0:
|
||||
admin_name = get_config_param(base_dir, 'admin')
|
||||
if admin_name:
|
||||
|
@ -859,8 +862,8 @@ def is_artist(base_dir: str, nickname: str) -> bool:
|
|||
return True
|
||||
return False
|
||||
|
||||
with open(artists_file, 'r', encoding='utf-8') as artists:
|
||||
lines = artists.readlines()
|
||||
with open(artists_file, 'r', encoding='utf-8') as fp_artists:
|
||||
lines = fp_artists.readlines()
|
||||
if len(lines) == 0:
|
||||
admin_name = get_config_param(base_dir, 'admin')
|
||||
if admin_name:
|
||||
|
@ -1210,8 +1213,8 @@ def get_followers_of_person(base_dir: str,
|
|||
continue
|
||||
if not os.path.isfile(filename):
|
||||
continue
|
||||
with open(filename, 'r', encoding='utf-8') as followingfile:
|
||||
for following_handle in followingfile:
|
||||
with open(filename, 'r', encoding='utf-8') as fp_following:
|
||||
for following_handle in fp_following:
|
||||
following_handle2 = remove_eol(following_handle)
|
||||
if following_handle2 == handle:
|
||||
if account not in followers:
|
||||
|
@ -2383,13 +2386,13 @@ def remove_moderation_post_from_index(base_dir: str, post_url: str,
|
|||
if text_in_file(post_id, moderation_index_file):
|
||||
try:
|
||||
with open(moderation_index_file, 'r',
|
||||
encoding='utf-8') as file1:
|
||||
lines = file1.readlines()
|
||||
encoding='utf-8') as fp_mod1:
|
||||
lines = fp_mod1.readlines()
|
||||
with open(moderation_index_file, 'w+',
|
||||
encoding='utf-8') as file2:
|
||||
encoding='utf-8') as fp_mod2:
|
||||
for line in lines:
|
||||
if line.strip("\n").strip("\r") != post_id:
|
||||
file2.write(line)
|
||||
fp_mod2.write(line)
|
||||
continue
|
||||
if debug:
|
||||
print('DEBUG: removed ' + post_id +
|
||||
|
|
|
@ -516,8 +516,8 @@ def html_new_post(edit_post_params: {},
|
|||
if os.path.isfile(dir_str + '/report.txt'):
|
||||
try:
|
||||
with open(dir_str + '/report.txt', 'r',
|
||||
encoding='utf-8') as file:
|
||||
custom_report_text = file.read()
|
||||
encoding='utf-8') as fp_report:
|
||||
custom_report_text = fp_report.read()
|
||||
if '</p>' not in custom_report_text:
|
||||
custom_report_text = \
|
||||
'<p class="login-subtext">' + \
|
||||
|
@ -558,8 +558,9 @@ def html_new_post(edit_post_params: {},
|
|||
dir_str = data_dir(base_dir)
|
||||
if os.path.isfile(dir_str + '/newpost.txt'):
|
||||
try:
|
||||
with open(dir_str + '/newpost.txt', 'r', encoding='utf-8') as file:
|
||||
new_post_text = '<p>' + file.read() + '</p>\n'
|
||||
with open(dir_str + '/newpost.txt', 'r',
|
||||
encoding='utf-8') as fp_new:
|
||||
new_post_text = '<p>' + fp_new.read() + '</p>\n'
|
||||
except OSError:
|
||||
print('EX: html_new_post unable to read ' +
|
||||
dir_str + '/newpost.txt')
|
||||
|
|
|
@ -134,8 +134,10 @@ def html_login(translate: {},
|
|||
if os.path.isfile(dir_str + '/login.txt'):
|
||||
# custom login message
|
||||
try:
|
||||
with open(dir_str + '/login.txt', 'r', encoding='utf-8') as file:
|
||||
login_text = '<p class="login-text">' + file.read() + '</p>'
|
||||
with open(dir_str + '/login.txt', 'r',
|
||||
encoding='utf-8') as fp_login:
|
||||
login_text = \
|
||||
'<p class="login-text">' + fp_login.read() + '</p>'
|
||||
except OSError:
|
||||
print('EX: html_login unable to read ' + dir_str + '/login.txt')
|
||||
|
||||
|
|
|
@ -2373,8 +2373,8 @@ def individual_post_as_html(signing_priv_key_pem: str,
|
|||
box_name)
|
||||
try:
|
||||
with open(announce_filename + '.tts', 'w+',
|
||||
encoding='utf-8') as ttsfile:
|
||||
ttsfile.write('\n')
|
||||
encoding='utf-8') as fp_tts:
|
||||
fp_tts.write('\n')
|
||||
except OSError:
|
||||
print('EX: unable to write tts ' +
|
||||
announce_filename + '.tts')
|
||||
|
|
|
@ -2317,8 +2317,8 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
|
|||
acct_dir(base_dir, nickname, domain) + '/filters.txt'
|
||||
if os.path.isfile(filter_filename):
|
||||
try:
|
||||
with open(filter_filename, 'r', encoding='utf-8') as filterfile:
|
||||
filter_str = filterfile.read()
|
||||
with open(filter_filename, 'r', encoding='utf-8') as fp_filter:
|
||||
filter_str = fp_filter.read()
|
||||
except OSError:
|
||||
print('EX: _html_edit_profile_filtering unable to read ' +
|
||||
filter_filename)
|
||||
|
@ -2340,8 +2340,8 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str,
|
|||
acct_dir(base_dir, nickname, domain) + '/replacewords.txt'
|
||||
if os.path.isfile(switch_filename):
|
||||
try:
|
||||
with open(switch_filename, 'r', encoding='utf-8') as switchfile:
|
||||
switch_str = switchfile.read()
|
||||
with open(switch_filename, 'r', encoding='utf-8') as fp_switch:
|
||||
switch_str = fp_switch.read()
|
||||
except OSError:
|
||||
print('EX: _html_edit_profile_filtering unable to save ' +
|
||||
switch_filename)
|
||||
|
|
|
@ -538,8 +538,8 @@ def html_timeline(default_timeline: str,
|
|||
new_calendar_event = True
|
||||
calendar_image = 'calendar_notify.png'
|
||||
try:
|
||||
with open(calendar_file, 'r', encoding='utf-8') as calfile:
|
||||
calendar_path = calfile.read().replace('##sent##', '')
|
||||
with open(calendar_file, 'r', encoding='utf-8') as fp_cal:
|
||||
calendar_path = fp_cal.read().replace('##sent##', '')
|
||||
calendar_path = remove_eol(calendar_path)
|
||||
if '/calendar' not in calendar_path:
|
||||
calendar_path = '/calendar'
|
||||
|
|
|
@ -35,8 +35,8 @@ def html_terms_of_service(base_dir: str,
|
|||
tos_text = 'Terms of Service go here.'
|
||||
if os.path.isfile(dir_str + '/tos.md'):
|
||||
try:
|
||||
with open(dir_str + '/tos.md', 'r', encoding='utf-8') as file:
|
||||
tos_text = markdown_to_html(file.read())
|
||||
with open(dir_str + '/tos.md', 'r', encoding='utf-8') as fp_tos:
|
||||
tos_text = markdown_to_html(fp_tos.read())
|
||||
except OSError:
|
||||
print('EX: html_terms_of_service unable to read ' +
|
||||
dir_str + '/tos.md')
|
||||
|
|
|
@ -1098,8 +1098,9 @@ def load_individual_post_as_html_from_cache(base_dir: str,
|
|||
tries = 0
|
||||
while tries < 3:
|
||||
try:
|
||||
with open(cached_post_filename, 'r', encoding='utf-8') as file:
|
||||
post_html = file.read()
|
||||
with open(cached_post_filename, 'r',
|
||||
encoding='utf-8') as fp_cached:
|
||||
post_html = fp_cached.read()
|
||||
break
|
||||
except OSError as ex:
|
||||
print('ERROR: load_individual_post_as_html_from_cache ' +
|
||||
|
|
Loading…
Reference in New Issue