mirror of https://gitlab.com/bashrc2/epicyon
Replace open with text in file function
parent
f0f612fba1
commit
e1ac8f1ea1
|
@ -8,6 +8,7 @@ __status__ = "Production"
|
||||||
__module_group__ = "ActivityPub"
|
__module_group__ = "ActivityPub"
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from utils import text_in_file
|
||||||
from utils import has_object_string_object
|
from utils import has_object_string_object
|
||||||
from utils import has_users_path
|
from utils import has_users_path
|
||||||
from utils import get_full_domain
|
from utils import get_full_domain
|
||||||
|
@ -164,8 +165,8 @@ def _accept_follow(base_dir: str, message_json: {},
|
||||||
unfollowed_filename = \
|
unfollowed_filename = \
|
||||||
acct_dir(base_dir, nickname, accepted_domain_full) + '/unfollowed.txt'
|
acct_dir(base_dir, nickname, accepted_domain_full) + '/unfollowed.txt'
|
||||||
if os.path.isfile(unfollowed_filename):
|
if os.path.isfile(unfollowed_filename):
|
||||||
if followed_nickname + '@' + followed_domain_full in \
|
if text_in_file(followed_nickname + '@' + followed_domain_full,
|
||||||
open(unfollowed_filename, encoding='utf-8').read():
|
unfollowed_filename):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: follow accept arrived for ' +
|
print('DEBUG: follow accept arrived for ' +
|
||||||
nickname + '@' + accepted_domain_full +
|
nickname + '@' + accepted_domain_full +
|
||||||
|
|
|
@ -60,8 +60,7 @@ def add_global_block(base_dir: str,
|
||||||
block_hashtag = block_nickname
|
block_hashtag = block_nickname
|
||||||
# is the hashtag already blocked?
|
# is the hashtag already blocked?
|
||||||
if os.path.isfile(blocking_filename):
|
if os.path.isfile(blocking_filename):
|
||||||
if block_hashtag + '\n' in \
|
if text_in_file(block_hashtag + '\n', blocking_filename):
|
||||||
open(blocking_filename, encoding='utf-8').read():
|
|
||||||
return False
|
return False
|
||||||
# block a hashtag
|
# block a hashtag
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -340,8 +340,8 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
|
||||||
# later arrives then it can be ignored
|
# later arrives then it can be ignored
|
||||||
unfollowed_filename = base_dir + '/accounts/' + handle + '/unfollowed.txt'
|
unfollowed_filename = base_dir + '/accounts/' + handle + '/unfollowed.txt'
|
||||||
if os.path.isfile(unfollowed_filename):
|
if os.path.isfile(unfollowed_filename):
|
||||||
if handle_to_unfollow_lower not in \
|
if not text_in_file(handle_to_unfollow_lower,
|
||||||
open(unfollowed_filename, encoding='utf-8').read().lower():
|
unfollowed_filename, False):
|
||||||
try:
|
try:
|
||||||
with open(unfollowed_filename, 'a+',
|
with open(unfollowed_filename, 'a+',
|
||||||
encoding='utf-8') as fp_unfoll:
|
encoding='utf-8') as fp_unfoll:
|
||||||
|
|
6
inbox.py
6
inbox.py
|
@ -4569,8 +4569,7 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool):
|
||||||
|
|
||||||
already_unknown = False
|
already_unknown = False
|
||||||
if os.path.isfile(unknown_contexts_file):
|
if os.path.isfile(unknown_contexts_file):
|
||||||
if unknown_context in \
|
if text_in_file(unknown_context, unknown_contexts_file):
|
||||||
open(unknown_contexts_file, encoding='utf-8').read():
|
|
||||||
already_unknown = True
|
already_unknown = True
|
||||||
|
|
||||||
if not already_unknown:
|
if not already_unknown:
|
||||||
|
@ -4588,8 +4587,7 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool):
|
||||||
|
|
||||||
already_unknown = False
|
already_unknown = False
|
||||||
if os.path.isfile(unknown_signatures_file):
|
if os.path.isfile(unknown_signatures_file):
|
||||||
if jwebsig_type in \
|
if text_in_file(jwebsig_type, unknown_signatures_file):
|
||||||
open(unknown_signatures_file, encoding='utf-8').read():
|
|
||||||
already_unknown = True
|
already_unknown = True
|
||||||
|
|
||||||
if not already_unknown:
|
if not already_unknown:
|
||||||
|
|
7
posts.py
7
posts.py
|
@ -4294,7 +4294,12 @@ def archive_posts_for_person(http_prefix: str, nickname: str, domain: str,
|
||||||
# Time of file creation
|
# Time of file creation
|
||||||
full_filename = os.path.join(box_dir, post_filename)
|
full_filename = os.path.join(box_dir, post_filename)
|
||||||
if os.path.isfile(full_filename):
|
if os.path.isfile(full_filename):
|
||||||
content = open(full_filename, encoding='utf-8').read()
|
content = ''
|
||||||
|
try:
|
||||||
|
with open(full_filename, 'r', encoding='utf-8') as fp_content:
|
||||||
|
content = fp_content.read()
|
||||||
|
except OSError:
|
||||||
|
print('EX: unable to open content ' + full_filename)
|
||||||
if '"published":' in content:
|
if '"published":' in content:
|
||||||
published_str = content.split('"published":')[1]
|
published_str = content.split('"published":')[1]
|
||||||
if '"' in published_str:
|
if '"' in published_str:
|
||||||
|
|
5
theme.py
5
theme.py
|
@ -17,6 +17,7 @@ from utils import acct_dir
|
||||||
from utils import dangerous_svg
|
from utils import dangerous_svg
|
||||||
from utils import local_actor_url
|
from utils import local_actor_url
|
||||||
from utils import remove_html
|
from utils import remove_html
|
||||||
|
from utils import text_in_file
|
||||||
from shutil import copyfile
|
from shutil import copyfile
|
||||||
from shutil import make_archive
|
from shutil import make_archive
|
||||||
from shutil import unpack_archive
|
from shutil import unpack_archive
|
||||||
|
@ -65,8 +66,8 @@ def import_theme(base_dir: str, filename: str) -> bool:
|
||||||
# if the theme name in the default themes list?
|
# if the theme name in the default themes list?
|
||||||
default_themes_filename = base_dir + '/defaultthemes.txt'
|
default_themes_filename = base_dir + '/defaultthemes.txt'
|
||||||
if os.path.isfile(default_themes_filename):
|
if os.path.isfile(default_themes_filename):
|
||||||
if new_theme_name.title() + '\n' in \
|
test_str = new_theme_name.title() + '\n'
|
||||||
open(default_themes_filename, encoding='utf-8').read():
|
if text_in_file(test_str, default_themes_filename):
|
||||||
new_theme_name = new_theme_name + '2'
|
new_theme_name = new_theme_name + '2'
|
||||||
|
|
||||||
theme_dir = base_dir + '/theme/' + new_theme_name
|
theme_dir = base_dir + '/theme/' + new_theme_name
|
||||||
|
|
Loading…
Reference in New Issue