mirror of https://gitlab.com/bashrc2/epicyon
Finding text not in file
parent
9bab4c1684
commit
bc614fcd3c
4
blog.py
4
blog.py
|
@ -34,6 +34,7 @@ from utils import first_paragraph_from_string
|
|||
from utils import get_actor_property_url
|
||||
from utils import acct_dir
|
||||
from posts import create_blogs_timeline
|
||||
from utils import text_in_file
|
||||
from newswire import rss2header
|
||||
from newswire import rss2footer
|
||||
from cache import get_person_from_cache
|
||||
|
@ -929,8 +930,7 @@ def path_contains_blog_link(base_dir: str,
|
|||
acct_dir(base_dir, nickname, domain) + '/tlblogs.index'
|
||||
if not os.path.isfile(blog_index_filename):
|
||||
return None, None
|
||||
if '#' + user_ending2[1] + '.' not in open(blog_index_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file('#' + user_ending2[1] + '.', blog_index_filename):
|
||||
return None, None
|
||||
message_id = local_actor_url(http_prefix, nickname, domain_full) + \
|
||||
'/statuses/' + user_ending2[1]
|
||||
|
|
|
@ -28,6 +28,7 @@ from utils import acct_dir
|
|||
from utils import local_actor_url
|
||||
from utils import has_actor
|
||||
from utils import has_object_string_type
|
||||
from utils import text_in_file
|
||||
from posts import get_person_box
|
||||
from session import post_json
|
||||
|
||||
|
@ -71,8 +72,7 @@ def undo_bookmarks_collection_entry(recent_posts_cache: {},
|
|||
else:
|
||||
bookmark_index = post_filename.strip()
|
||||
bookmark_index = bookmark_index.replace('\n', '').replace('\r', '')
|
||||
if bookmark_index not in open(bookmarks_index_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(bookmark_index, bookmarks_index_filename):
|
||||
return
|
||||
index_str = ''
|
||||
try:
|
||||
|
@ -238,8 +238,7 @@ def update_bookmarks_collection(recent_posts_cache: {},
|
|||
acct_dir(base_dir, nickname, domain) + '/bookmarks.index'
|
||||
bookmark_index = post_filename.split('/')[-1]
|
||||
if os.path.isfile(bookmarks_index_filename):
|
||||
if bookmark_index not in open(bookmarks_index_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(bookmark_index, bookmarks_index_filename):
|
||||
try:
|
||||
with open(bookmarks_index_filename, 'r+',
|
||||
encoding='utf-8') as bmi_file:
|
||||
|
|
|
@ -11,6 +11,7 @@ import os
|
|||
from utils import has_object_dict
|
||||
from utils import acct_dir
|
||||
from utils import remove_id_ending
|
||||
from utils import text_in_file
|
||||
|
||||
|
||||
def _get_conversation_filename(base_dir: str, nickname: str, domain: str,
|
||||
|
@ -50,8 +51,7 @@ def update_conversation(base_dir: str, nickname: str, domain: str,
|
|||
except OSError:
|
||||
print('EX: update_conversation ' +
|
||||
'unable to write to ' + conversation_filename)
|
||||
elif post_id + '\n' not in open(conversation_filename,
|
||||
encoding='utf-8').read():
|
||||
elif not text_in_file(post_id + '\n', conversation_filename):
|
||||
try:
|
||||
with open(conversation_filename, 'a+',
|
||||
encoding='utf-8') as conv_file:
|
||||
|
|
|
@ -9,6 +9,7 @@ __module_group__ = "Moderation"
|
|||
|
||||
import os
|
||||
from utils import acct_dir
|
||||
from utils import text_in_file
|
||||
|
||||
|
||||
def add_filter(base_dir: str, nickname: str, domain: str, words: str) -> bool:
|
||||
|
@ -16,7 +17,7 @@ def add_filter(base_dir: str, nickname: str, domain: str, words: str) -> bool:
|
|||
"""
|
||||
filters_filename = acct_dir(base_dir, nickname, domain) + '/filters.txt'
|
||||
if os.path.isfile(filters_filename):
|
||||
if words in open(filters_filename, encoding='utf-8').read():
|
||||
if text_in_file(words, filters_filename):
|
||||
return False
|
||||
try:
|
||||
with open(filters_filename, 'a+',
|
||||
|
@ -37,7 +38,7 @@ def add_global_filter(base_dir: str, words: str) -> bool:
|
|||
return False
|
||||
filters_filename = base_dir + '/accounts/filters.txt'
|
||||
if os.path.isfile(filters_filename):
|
||||
if words in open(filters_filename, encoding='utf-8').read():
|
||||
if text_in_file(words, filters_filename):
|
||||
return False
|
||||
try:
|
||||
with open(filters_filename, 'a+', encoding='utf-8') as filters_file:
|
||||
|
@ -54,7 +55,7 @@ def remove_filter(base_dir: str, nickname: str, domain: str,
|
|||
filters_filename = acct_dir(base_dir, nickname, domain) + '/filters.txt'
|
||||
if not os.path.isfile(filters_filename):
|
||||
return False
|
||||
if words not in open(filters_filename, encoding='utf-8').read():
|
||||
if not text_in_file(words, filters_filename):
|
||||
return False
|
||||
new_filters_filename = filters_filename + '.new'
|
||||
try:
|
||||
|
@ -79,7 +80,7 @@ def remove_global_filter(base_dir: str, words: str) -> bool:
|
|||
filters_filename = base_dir + '/accounts/filters.txt'
|
||||
if not os.path.isfile(filters_filename):
|
||||
return False
|
||||
if words not in open(filters_filename, encoding='utf-8').read():
|
||||
if not text_in_file(words, filters_filename):
|
||||
return False
|
||||
new_filters_filename = filters_filename + '.new'
|
||||
try:
|
||||
|
|
31
follow.py
31
follow.py
|
@ -30,6 +30,7 @@ from utils import get_user_paths
|
|||
from utils import acct_dir
|
||||
from utils import has_group_type
|
||||
from utils import local_actor_url
|
||||
from utils import text_in_file
|
||||
from acceptreject import create_accept
|
||||
from acceptreject import create_reject
|
||||
from webfinger import webfinger_handle
|
||||
|
@ -94,8 +95,7 @@ def _pre_approved_follower(base_dir: str,
|
|||
account_dir = base_dir + '/accounts/' + handle
|
||||
approved_filename = account_dir + '/approved.txt'
|
||||
if os.path.isfile(approved_filename):
|
||||
if approve_handle in open(approved_filename,
|
||||
encoding='utf-8').read():
|
||||
if text_in_file(approve_handle, approved_filename):
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -115,8 +115,7 @@ def _remove_from_follow_base(base_dir: str,
|
|||
' to remove ' + handle + ' from')
|
||||
return
|
||||
accept_deny_actor = None
|
||||
if accept_or_deny_handle not in open(approve_follows_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(accept_or_deny_handle, approve_follows_filename):
|
||||
# is this stored in the file as an actor rather than a handle?
|
||||
accept_deny_nickname = accept_or_deny_handle.split('@')[0]
|
||||
accept_deny_domain = accept_or_deny_handle.split('@')[1]
|
||||
|
@ -127,8 +126,7 @@ def _remove_from_follow_base(base_dir: str,
|
|||
for users_name in users_paths:
|
||||
accept_deny_actor = \
|
||||
'://' + accept_deny_domain + users_name + accept_deny_nickname
|
||||
if accept_deny_actor in open(approve_follows_filename,
|
||||
encoding='utf-8').read():
|
||||
if text_in_file(accept_deny_actor, approve_follows_filename):
|
||||
actor_found = True
|
||||
break
|
||||
if not actor_found:
|
||||
|
@ -186,7 +184,8 @@ def is_following_actor(base_dir: str,
|
|||
return False
|
||||
if actor.startswith('@'):
|
||||
actor = actor[1:]
|
||||
if actor.lower() in open(following_file, encoding='utf-8').read().lower():
|
||||
actor_lower = actor.lower()
|
||||
if text_in_file(actor_lower, following_file).lower():
|
||||
return True
|
||||
following_nickname = get_nickname_from_actor(actor)
|
||||
if not following_nickname:
|
||||
|
@ -196,8 +195,8 @@ def is_following_actor(base_dir: str,
|
|||
following_handle = \
|
||||
get_full_domain(following_nickname + '@' + following_domain,
|
||||
following_port)
|
||||
if following_handle.lower() in open(following_file,
|
||||
encoding='utf-8').read().lower():
|
||||
following_handle_lower = following_handle.lower()
|
||||
if text_in_file(following_handle_lower, following_file).lower():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
@ -317,8 +316,7 @@ def unfollow_account(base_dir: str, nickname: str, domain: str,
|
|||
print('DEBUG: follow file ' + filename + ' was not found')
|
||||
return False
|
||||
handle_to_unfollow_lower = handle_to_unfollow.lower()
|
||||
if handle_to_unfollow_lower not in open(filename,
|
||||
encoding='utf-8').read().lower():
|
||||
if not text_in_file(handle_to_unfollow_lower, filename):
|
||||
if debug:
|
||||
print('DEBUG: handle to unfollow ' + handle_to_unfollow +
|
||||
' is not in ' + filename)
|
||||
|
@ -688,8 +686,7 @@ def store_follow_request(base_dir: str,
|
|||
# should this follow be denied?
|
||||
deny_follows_filename = accounts_dir + '/followrejects.txt'
|
||||
if os.path.isfile(deny_follows_filename):
|
||||
if approve_handle in open(deny_follows_filename,
|
||||
encoding='utf-8').read():
|
||||
if text_in_file(approve_handle, deny_follows_filename):
|
||||
remove_from_follow_requests(base_dir, nickname_to_follow,
|
||||
domain_to_follow, approve_handle,
|
||||
debug)
|
||||
|
@ -708,8 +705,7 @@ def store_follow_request(base_dir: str,
|
|||
approve_handle = '!' + approve_handle
|
||||
|
||||
if os.path.isfile(approve_follows_filename):
|
||||
if approve_handle not in open(approve_follows_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(approve_handle, approve_follows_filename):
|
||||
try:
|
||||
with open(approve_follows_filename, 'a+',
|
||||
encoding='utf-8') as fp_approve:
|
||||
|
@ -924,8 +920,7 @@ def send_follow_request(session, base_dir: str,
|
|||
unfollowed_filename = \
|
||||
acct_dir(base_dir, nickname, domain) + '/unfollowed.txt'
|
||||
if os.path.isfile(unfollowed_filename):
|
||||
if follow_handle in open(unfollowed_filename,
|
||||
encoding='utf-8').read():
|
||||
if text_in_file(follow_handle, unfollowed_filename):
|
||||
unfollowed_file = None
|
||||
try:
|
||||
with open(unfollowed_filename, 'r',
|
||||
|
@ -1404,7 +1399,7 @@ def get_followers_of_actor(base_dir: str, actor: str, debug: bool) -> {}:
|
|||
if debug:
|
||||
print('DEBUG: checking if ' + actor_handle +
|
||||
' in ' + following_filename)
|
||||
if actor_handle in open(following_filename).read():
|
||||
if text_in_file(actor_handle, following_filename):
|
||||
if debug:
|
||||
print('DEBUG: ' + account +
|
||||
' follows ' + actor_handle)
|
||||
|
|
|
@ -10,6 +10,20 @@ __module_group__ = "Calendar"
|
|||
import os
|
||||
|
||||
|
||||
def _text_in_file2(text: str, filename: str) -> bool:
|
||||
"""is the given text in the given file?
|
||||
"""
|
||||
try:
|
||||
with open(filename, 'r', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
if content:
|
||||
if text in content:
|
||||
return True
|
||||
except OSError:
|
||||
print('EX: unable to find text in missing file ' + filename)
|
||||
return False
|
||||
|
||||
|
||||
def _dir_acct(base_dir: str, nickname: str, domain: str) -> str:
|
||||
"""Returns the directory of an account
|
||||
"""
|
||||
|
@ -60,8 +74,7 @@ def receiving_calendar_events(base_dir: str, nickname: str, domain: str,
|
|||
fp_cal.write(following_handles)
|
||||
except OSError:
|
||||
print('EX: receiving_calendar_events 2 ' + calendar_filename)
|
||||
return handle + '\n' in open(calendar_filename,
|
||||
encoding='utf-8').read()
|
||||
return _text_in_file2(handle + '\n', calendar_filename)
|
||||
|
||||
|
||||
def _receive_calendar_events(base_dir: str, nickname: str, domain: str,
|
||||
|
@ -82,8 +95,7 @@ def _receive_calendar_events(base_dir: str, nickname: str, domain: str,
|
|||
handle = following_nickname + '@' + following_domain
|
||||
|
||||
# check that you are following this handle
|
||||
if handle + '\n' not in open(following_filename,
|
||||
encoding='utf-8').read():
|
||||
if not _text_in_file2(handle + '\n', following_filename):
|
||||
print('WARN: ' + handle + ' is not in ' + following_filename)
|
||||
return
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ from utils import get_display_name
|
|||
from utils import delete_post
|
||||
from utils import get_status_number
|
||||
from utils import get_full_domain
|
||||
from utils import text_in_file
|
||||
from filters import is_filtered
|
||||
from context import get_individual_post_context
|
||||
from session import get_method
|
||||
|
@ -70,8 +71,7 @@ def _remove_event_from_timeline(event_id: str,
|
|||
tl_events_filename: str) -> None:
|
||||
"""Removes the given event Id from the timeline
|
||||
"""
|
||||
if event_id + '\n' not in open(tl_events_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(event_id + '\n', tl_events_filename):
|
||||
return
|
||||
with open(tl_events_filename, 'r',
|
||||
encoding='utf-8') as fp_tl:
|
||||
|
@ -166,8 +166,7 @@ def save_event_post(base_dir: str, handle: str, post_id: str,
|
|||
|
||||
# Does this event post already exist within the calendar month?
|
||||
if os.path.isfile(calendar_filename):
|
||||
if post_id in open(calendar_filename,
|
||||
encoding='utf-8').read():
|
||||
if text_in_file(post_id, calendar_filename):
|
||||
# Event post already exists
|
||||
return False
|
||||
|
||||
|
@ -760,7 +759,7 @@ def remove_calendar_event(base_dir: str, nickname: str, domain: str,
|
|||
return
|
||||
if '/' in message_id:
|
||||
message_id = message_id.replace('/', '#')
|
||||
if message_id not in open(calendar_filename, encoding='utf-8').read():
|
||||
if not text_in_file(message_id, calendar_filename):
|
||||
return
|
||||
lines = None
|
||||
with open(calendar_filename, 'r', encoding='utf-8') as fp_cal:
|
||||
|
|
10
inbox.py
10
inbox.py
|
@ -18,6 +18,7 @@ from languages import understood_post_language
|
|||
from like import update_likes_collection
|
||||
from reaction import update_reaction_collection
|
||||
from reaction import valid_emoji_content
|
||||
from utils import text_in_file
|
||||
from utils import get_media_descriptions_from_post
|
||||
from utils import get_summary_from_post
|
||||
from utils import delete_cached_html
|
||||
|
@ -2557,8 +2558,7 @@ def populate_replies(base_dir: str, http_prefix: str, domain: str,
|
|||
encoding='utf-8'))
|
||||
if num_lines > max_replies:
|
||||
return False
|
||||
if message_id not in open(post_replies_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(message_id, post_replies_filename):
|
||||
try:
|
||||
with open(post_replies_filename, 'a+',
|
||||
encoding='utf-8') as replies_file:
|
||||
|
@ -2875,7 +2875,7 @@ def _like_notify(base_dir: str, domain: str, onion_domain: str,
|
|||
|
||||
like_file = account_dir + '/.newLike'
|
||||
if os.path.isfile(like_file):
|
||||
if '##sent##' not in open(like_file).read():
|
||||
if not text_in_file('##sent##', like_file):
|
||||
return
|
||||
|
||||
liker_nickname = get_nickname_from_actor(actor)
|
||||
|
@ -2937,7 +2937,7 @@ def _reaction_notify(base_dir: str, domain: str, onion_domain: str,
|
|||
|
||||
reaction_file = account_dir + '/.newReaction'
|
||||
if os.path.isfile(reaction_file):
|
||||
if '##sent##' not in open(reaction_file, encoding='utf-8').read():
|
||||
if not text_in_file('##sent##', reaction_file):
|
||||
return
|
||||
|
||||
reaction_nickname = get_nickname_from_actor(actor)
|
||||
|
@ -4816,7 +4816,7 @@ def _receive_follow_request(session, session_onion, session_i2p,
|
|||
print('Updating followers file: ' +
|
||||
followers_filename + ' adding ' + approve_handle)
|
||||
if os.path.isfile(followers_filename):
|
||||
if approve_handle not in open(followers_filename).read():
|
||||
if not text_in_file(approve_handle, followers_filename):
|
||||
group_account = \
|
||||
has_group_type(base_dir,
|
||||
message_json['actor'], person_cache)
|
||||
|
|
|
@ -16,6 +16,7 @@ from utils import remove_domain_port
|
|||
from utils import get_port_from_domain
|
||||
from utils import get_user_paths
|
||||
from utils import acct_dir
|
||||
from utils import text_in_file
|
||||
from threads import thread_with_trace
|
||||
from session import create_session
|
||||
|
||||
|
@ -115,7 +116,7 @@ def _approve_follower_handle(account_dir: str, approve_handle: str) -> None:
|
|||
"""
|
||||
approved_filename = account_dir + '/approved.txt'
|
||||
if os.path.isfile(approved_filename):
|
||||
if approve_handle not in open(approved_filename).read():
|
||||
if not text_in_file(approve_handle, approved_filename):
|
||||
try:
|
||||
with open(approved_filename, 'a+') as approved_file:
|
||||
approved_file.write(approve_handle + '\n')
|
||||
|
@ -280,8 +281,7 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
|
|||
# update the followers
|
||||
print('Manual follow accept: updating ' + followers_filename)
|
||||
if os.path.isfile(followers_filename):
|
||||
if approve_handle_full not in open(followers_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(approve_handle_full, followers_filename):
|
||||
try:
|
||||
with open(followers_filename, 'r+',
|
||||
encoding='utf-8') as followers_file:
|
||||
|
|
|
@ -34,6 +34,7 @@ from utils import get_status_number
|
|||
from utils import clear_from_post_caches
|
||||
from utils import dangerous_markup
|
||||
from utils import local_actor_url
|
||||
from utils import text_in_file
|
||||
from inbox import store_hash_tags
|
||||
from session import create_session
|
||||
|
||||
|
@ -46,7 +47,7 @@ def _update_feeds_outbox_index(base_dir: str, domain: str,
|
|||
index_filename = base_path + '/outbox.index'
|
||||
|
||||
if os.path.isfile(index_filename):
|
||||
if post_id not in open(index_filename, encoding='utf-8').read():
|
||||
if not text_in_file(post_id, index_filename):
|
||||
try:
|
||||
with open(index_filename, 'r+') as feeds_file:
|
||||
content = feeds_file.read()
|
||||
|
|
|
@ -10,6 +10,7 @@ __module_group__ = "Calendar"
|
|||
import os
|
||||
from utils import remove_domain_port
|
||||
from utils import acct_dir
|
||||
from utils import text_in_file
|
||||
|
||||
|
||||
def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
|
||||
|
@ -30,8 +31,7 @@ def _notify_on_post_arrival(base_dir: str, nickname: str, domain: str,
|
|||
handle = following_nickname + '@' + following_domain
|
||||
|
||||
# check that you are following this handle
|
||||
if handle + '\n' not in open(following_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(handle + '\n', following_filename):
|
||||
print('WARN: ' + handle + ' is not in ' + following_filename)
|
||||
return
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ from roles import set_role
|
|||
from roles import set_rolesFromList
|
||||
from roles import get_actor_roles_list
|
||||
from media import process_meta_data
|
||||
from utils import text_in_file
|
||||
from utils import get_attachment_property_value
|
||||
from utils import get_nickname_from_actor
|
||||
from utils import remove_html
|
||||
|
@ -1207,7 +1208,7 @@ def _remove_tags_for_nickname(base_dir: str, nickname: str,
|
|||
continue
|
||||
if not os.path.isfile(tag_filename):
|
||||
continue
|
||||
if match_str not in open(tag_filename, encoding='utf-8').read():
|
||||
if not text_in_file(match_str, tag_filename):
|
||||
continue
|
||||
lines = []
|
||||
with open(tag_filename, 'r', encoding='utf-8') as fp_tag:
|
||||
|
@ -1358,8 +1359,7 @@ def is_person_snoozed(base_dir: str, nickname: str, domain: str,
|
|||
snoozed_filename = acct_dir(base_dir, nickname, domain) + '/snoozed.txt'
|
||||
if not os.path.isfile(snoozed_filename):
|
||||
return False
|
||||
if snooze_actor + ' ' not in open(snoozed_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(snooze_actor + ' ', snoozed_filename):
|
||||
return False
|
||||
# remove the snooze entry if it has timed out
|
||||
replace_str = None
|
||||
|
@ -1428,8 +1428,7 @@ def person_unsnooze(base_dir: str, nickname: str, domain: str,
|
|||
snoozed_filename = account_dir + '/snoozed.txt'
|
||||
if not os.path.isfile(snoozed_filename):
|
||||
return
|
||||
if snooze_actor + ' ' not in open(snoozed_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(snooze_actor + ' ', snoozed_filename):
|
||||
return
|
||||
replace_str = None
|
||||
with open(snoozed_filename, 'r', encoding='utf-8') as snoozed_file:
|
||||
|
|
6
posts.py
6
posts.py
|
@ -32,6 +32,7 @@ from webfinger import webfinger_handle
|
|||
from httpsig import create_signed_header
|
||||
from siteactive import site_is_active
|
||||
from languages import understood_post_language
|
||||
from utils import text_in_file
|
||||
from utils import get_media_descriptions_from_post
|
||||
from utils import valid_hash_tag
|
||||
from utils import get_audio_extensions
|
||||
|
@ -968,7 +969,7 @@ def _update_hashtags_index(base_dir: str, tag: {}, new_post_id: str) -> None:
|
|||
tags_filename)
|
||||
else:
|
||||
# prepend to tags index file
|
||||
if tagline not in open(tags_filename, encoding='utf-8').read():
|
||||
if not text_in_file(tagline, tags_filename):
|
||||
try:
|
||||
with open(tags_filename, 'r+', encoding='utf-8') as tags_file:
|
||||
content = tags_file.read()
|
||||
|
@ -990,8 +991,7 @@ def _add_schedule_post(base_dir: str, nickname: str, domain: str,
|
|||
|
||||
index_str = event_date_str + ' ' + post_id.replace('/', '#')
|
||||
if os.path.isfile(schedule_index_filename):
|
||||
if index_str not in open(schedule_index_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(index_str, schedule_index_filename):
|
||||
try:
|
||||
with open(schedule_index_filename, 'r+',
|
||||
encoding='utf-8') as schedule_file:
|
||||
|
|
|
@ -12,6 +12,7 @@ from utils import locate_post
|
|||
from utils import load_json
|
||||
from utils import save_json
|
||||
from utils import has_object_dict
|
||||
from utils import text_in_file
|
||||
|
||||
|
||||
def question_update_votes(base_dir: str, nickname: str, domain: str,
|
||||
|
@ -74,8 +75,7 @@ def question_update_votes(base_dir: str, nickname: str, domain: str,
|
|||
except OSError:
|
||||
print('EX: unable to write voters file ' + voters_filename)
|
||||
else:
|
||||
if reply_json['actor'] not in open(voters_filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file(reply_json['actor'], voters_filename):
|
||||
# append to the voters file
|
||||
try:
|
||||
with open(voters_filename, 'a+',
|
||||
|
|
4
roles.py
4
roles.py
|
@ -13,6 +13,7 @@ from utils import save_json
|
|||
from utils import get_status_number
|
||||
from utils import remove_domain_port
|
||||
from utils import acct_dir
|
||||
from utils import text_in_file
|
||||
|
||||
|
||||
def _clear_role_status(base_dir: str, role: str) -> None:
|
||||
|
@ -28,8 +29,7 @@ def _clear_role_status(base_dir: str, role: str) -> None:
|
|||
if not filename.endswith(".json"):
|
||||
continue
|
||||
filename = os.path.join(base_dir + '/accounts/', filename)
|
||||
if '"' + role + '"' not in open(filename,
|
||||
encoding='utf-8').read():
|
||||
if not text_in_file('"' + role + '"', filename):
|
||||
continue
|
||||
actor_json = load_json(filename)
|
||||
if not actor_json:
|
||||
|
|
27
tests.py
27
tests.py
|
@ -54,6 +54,7 @@ from follow import clear_followers
|
|||
from follow import send_follow_request_via_server
|
||||
from follow import send_unfollow_request_via_server
|
||||
from siteactive import site_is_active
|
||||
from utils import text_in_file
|
||||
from utils import convert_published_to_local_timezone
|
||||
from utils import convert_to_snake_case
|
||||
from utils import get_sha_256
|
||||
|
@ -2324,8 +2325,7 @@ def test_group_follow(base_dir: str) -> None:
|
|||
alice_domain, alice_port)
|
||||
assert 'alice@' + alice_domain in open(testgroup_followers_filename,
|
||||
encoding='utf-8').read()
|
||||
assert '!alice@' + alice_domain not in \
|
||||
open(testgroup_followers_filename, encoding='utf-8').read()
|
||||
assert not text_in_file('!alice@' + alice_domain, testgroup_followers_filename)
|
||||
|
||||
testgroup_webfinger_filename = \
|
||||
testgroup_dir + '/wfendpoints/testgroup@' + \
|
||||
|
@ -2404,10 +2404,9 @@ def test_group_follow(base_dir: str) -> None:
|
|||
assert valid_inbox(testgroup_dir, 'testgroup', testgroup_domain)
|
||||
assert valid_inbox_filenames(testgroup_dir, 'testgroup', testgroup_domain,
|
||||
bob_domain, bob_port)
|
||||
assert 'bob@' + bob_domain in open(testgroup_followers_filename,
|
||||
encoding='utf-8').read()
|
||||
assert '!bob@' + bob_domain not in \
|
||||
open(testgroup_followers_filename, encoding='utf-8').read()
|
||||
assert text_in_file('bob@' + bob_domain, testgroup_followers_filename)
|
||||
assert not text_in_file('!bob@' + bob_domain,
|
||||
testgroup_followers_filename)
|
||||
|
||||
testgroup_webfinger_filename = \
|
||||
testgroup_dir + '/wfendpoints/testgroup@' + \
|
||||
|
@ -3458,19 +3457,19 @@ def test_client_to_server(base_dir: str):
|
|||
cached_webfingers, person_cache,
|
||||
True, __version__, signing_priv_key_pem)
|
||||
for _ in range(10):
|
||||
if 'alice@' + alice_domain + ':' + str(alice_port) not in \
|
||||
open(bob_followers_filename, encoding='utf-8').read():
|
||||
if 'bob@' + bob_domain + ':' + str(bob_port) not in \
|
||||
open(alice_following_filename, encoding='utf-8').read():
|
||||
test_str = 'alice@' + alice_domain + ':' + str(alice_port)
|
||||
if not text_in_file(test_str, bob_followers_filename):
|
||||
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
||||
if not text_in_file(test_str, alice_following_filename):
|
||||
break
|
||||
time.sleep(1)
|
||||
|
||||
assert os.path.isfile(bob_followers_filename)
|
||||
assert os.path.isfile(alice_following_filename)
|
||||
assert 'alice@' + alice_domain + ':' + str(alice_port) \
|
||||
not in open(bob_followers_filename, encoding='utf-8').read()
|
||||
assert 'bob@' + bob_domain + ':' + str(bob_port) \
|
||||
not in open(alice_following_filename, encoding='utf-8').read()
|
||||
test_str = 'alice@' + alice_domain + ':' + str(alice_port)
|
||||
assert not text_in_file(test_str, bob_followers_filename)
|
||||
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
||||
assert not text_in_file(test_str, alice_following_filename)
|
||||
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
||||
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
||||
alice_domain, alice_port)
|
||||
|
|
Loading…
Reference in New Issue