mirror of https://gitlab.com/bashrc2/epicyon
Replacing open statements
parent
f86560e8da
commit
f0f612fba1
|
@ -251,6 +251,7 @@ from languages import set_actor_languages
|
||||||
from languages import get_understood_languages
|
from languages import get_understood_languages
|
||||||
from like import update_likes_collection
|
from like import update_likes_collection
|
||||||
from reaction import update_reaction_collection
|
from reaction import update_reaction_collection
|
||||||
|
from utils import text_in_file
|
||||||
from utils import is_onion_request
|
from utils import is_onion_request
|
||||||
from utils import is_i2p_request
|
from utils import is_i2p_request
|
||||||
from utils import get_account_timezone
|
from utils import get_account_timezone
|
||||||
|
@ -510,7 +511,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
|
|
||||||
if os.path.isfile(votes_filename):
|
if os.path.isfile(votes_filename):
|
||||||
# have we already voted on this?
|
# have we already voted on this?
|
||||||
if message_id in open(votes_filename, encoding='utf-8').read():
|
if text_in_file(message_id, votes_filename):
|
||||||
print('Already voted on message ' + message_id)
|
print('Already voted on message ' + message_id)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ import webbrowser
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from random import randint
|
from random import randint
|
||||||
|
from utils import text_in_file
|
||||||
from utils import disallow_announce
|
from utils import disallow_announce
|
||||||
from utils import disallow_reply
|
from utils import disallow_reply
|
||||||
from utils import get_base_content_from_post
|
from utils import get_base_content_from_post
|
||||||
|
@ -169,8 +170,7 @@ def _mark_post_as_read(actor: str, post_id: str, post_category: str) -> None:
|
||||||
read_posts_dir = home_dir + '/.config/epicyon/' + handle
|
read_posts_dir = home_dir + '/.config/epicyon/' + handle
|
||||||
read_posts_filename = read_posts_dir + '/' + post_category + '.txt'
|
read_posts_filename = read_posts_dir + '/' + post_category + '.txt'
|
||||||
if os.path.isfile(read_posts_filename):
|
if os.path.isfile(read_posts_filename):
|
||||||
if post_id in open(read_posts_filename,
|
if text_in_file(post_id, read_posts_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
# prepend to read posts file
|
# prepend to read posts file
|
||||||
|
@ -201,7 +201,7 @@ def _has_read_post(actor: str, post_id: str, post_category: str) -> bool:
|
||||||
read_posts_dir = home_dir + '/.config/epicyon/' + handle
|
read_posts_dir = home_dir + '/.config/epicyon/' + handle
|
||||||
read_posts_filename = read_posts_dir + '/' + post_category + '.txt'
|
read_posts_filename = read_posts_dir + '/' + post_category + '.txt'
|
||||||
if os.path.isfile(read_posts_filename):
|
if os.path.isfile(read_posts_filename):
|
||||||
if post_id in open(read_posts_filename).read():
|
if text_in_file(post_id, read_posts_filename):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,7 @@ from tests import test_update_actor
|
||||||
from tests import run_all_tests
|
from tests import run_all_tests
|
||||||
from auth import store_basic_credentials
|
from auth import store_basic_credentials
|
||||||
from auth import create_password
|
from auth import create_password
|
||||||
|
from utils import text_in_file
|
||||||
from utils import remove_domain_port
|
from utils import remove_domain_port
|
||||||
from utils import get_port_from_domain
|
from utils import get_port_from_domain
|
||||||
from utils import has_users_path
|
from utils import has_users_path
|
||||||
|
@ -2748,7 +2749,7 @@ def _command_options() -> None:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
password_file = base_dir + '/accounts/passwords'
|
password_file = base_dir + '/accounts/passwords'
|
||||||
if os.path.isfile(password_file):
|
if os.path.isfile(password_file):
|
||||||
if nickname + ':' in open(password_file).read():
|
if text_in_file(nickname + ':', password_file):
|
||||||
store_basic_credentials(base_dir, nickname, new_password)
|
store_basic_credentials(base_dir, nickname, new_password)
|
||||||
print('Password for ' + nickname + ' was changed')
|
print('Password for ' + nickname + ' was changed')
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -17,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'
|
filters_filename = acct_dir(base_dir, nickname, domain) + '/filters.txt'
|
||||||
if os.path.isfile(filters_filename):
|
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
|
return False
|
||||||
try:
|
try:
|
||||||
with open(filters_filename, 'a+',
|
with open(filters_filename, 'a+',
|
||||||
|
@ -38,7 +38,7 @@ def add_global_filter(base_dir: str, words: str) -> bool:
|
||||||
return False
|
return False
|
||||||
filters_filename = base_dir + '/accounts/filters.txt'
|
filters_filename = base_dir + '/accounts/filters.txt'
|
||||||
if os.path.isfile(filters_filename):
|
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
|
return False
|
||||||
try:
|
try:
|
||||||
with open(filters_filename, 'a+', encoding='utf-8') as filters_file:
|
with open(filters_filename, 'a+', encoding='utf-8') as filters_file:
|
||||||
|
|
19
follow.py
19
follow.py
|
@ -95,8 +95,7 @@ def _pre_approved_follower(base_dir: str,
|
||||||
account_dir = base_dir + '/accounts/' + handle
|
account_dir = base_dir + '/accounts/' + handle
|
||||||
approved_filename = account_dir + '/approved.txt'
|
approved_filename = account_dir + '/approved.txt'
|
||||||
if os.path.isfile(approved_filename):
|
if os.path.isfile(approved_filename):
|
||||||
if approve_handle in open(approved_filename,
|
if text_in_file(approve_handle, approved_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -127,8 +126,7 @@ def _remove_from_follow_base(base_dir: str,
|
||||||
for users_name in users_paths:
|
for users_name in users_paths:
|
||||||
accept_deny_actor = \
|
accept_deny_actor = \
|
||||||
'://' + accept_deny_domain + users_name + accept_deny_nickname
|
'://' + accept_deny_domain + users_name + accept_deny_nickname
|
||||||
if accept_deny_actor in open(approve_follows_filename,
|
if text_in_file(accept_deny_actor, approve_follows_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
actor_found = True
|
actor_found = True
|
||||||
break
|
break
|
||||||
if not actor_found:
|
if not actor_found:
|
||||||
|
@ -186,7 +184,7 @@ def is_following_actor(base_dir: str,
|
||||||
return False
|
return False
|
||||||
if actor.startswith('@'):
|
if actor.startswith('@'):
|
||||||
actor = actor[1:]
|
actor = actor[1:]
|
||||||
if actor.lower() in open(following_file, encoding='utf-8').read().lower():
|
if text_in_file(actor, following_file, False):
|
||||||
return True
|
return True
|
||||||
following_nickname = get_nickname_from_actor(actor)
|
following_nickname = get_nickname_from_actor(actor)
|
||||||
if not following_nickname:
|
if not following_nickname:
|
||||||
|
@ -196,8 +194,7 @@ def is_following_actor(base_dir: str,
|
||||||
following_handle = \
|
following_handle = \
|
||||||
get_full_domain(following_nickname + '@' + following_domain,
|
get_full_domain(following_nickname + '@' + following_domain,
|
||||||
following_port)
|
following_port)
|
||||||
if following_handle.lower() in open(following_file,
|
if text_in_file(following_handle, following_file, False):
|
||||||
encoding='utf-8').read().lower():
|
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -687,8 +684,7 @@ def store_follow_request(base_dir: str,
|
||||||
# should this follow be denied?
|
# should this follow be denied?
|
||||||
deny_follows_filename = accounts_dir + '/followrejects.txt'
|
deny_follows_filename = accounts_dir + '/followrejects.txt'
|
||||||
if os.path.isfile(deny_follows_filename):
|
if os.path.isfile(deny_follows_filename):
|
||||||
if approve_handle in open(deny_follows_filename,
|
if text_in_file(approve_handle, deny_follows_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
remove_from_follow_requests(base_dir, nickname_to_follow,
|
remove_from_follow_requests(base_dir, nickname_to_follow,
|
||||||
domain_to_follow, approve_handle,
|
domain_to_follow, approve_handle,
|
||||||
debug)
|
debug)
|
||||||
|
@ -922,8 +918,7 @@ def send_follow_request(session, base_dir: str,
|
||||||
unfollowed_filename = \
|
unfollowed_filename = \
|
||||||
acct_dir(base_dir, nickname, domain) + '/unfollowed.txt'
|
acct_dir(base_dir, nickname, domain) + '/unfollowed.txt'
|
||||||
if os.path.isfile(unfollowed_filename):
|
if os.path.isfile(unfollowed_filename):
|
||||||
if follow_handle in open(unfollowed_filename,
|
if text_in_file(follow_handle, unfollowed_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
unfollowed_file = None
|
unfollowed_file = None
|
||||||
try:
|
try:
|
||||||
with open(unfollowed_filename, 'r',
|
with open(unfollowed_filename, 'r',
|
||||||
|
@ -1402,7 +1397,7 @@ def get_followers_of_actor(base_dir: str, actor: str, debug: bool) -> {}:
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: checking if ' + actor_handle +
|
print('DEBUG: checking if ' + actor_handle +
|
||||||
' in ' + following_filename)
|
' in ' + following_filename)
|
||||||
if actor_handle in open(following_filename).read():
|
if text_in_file(actor_handle, following_filename):
|
||||||
if debug:
|
if debug:
|
||||||
print('DEBUG: ' + account +
|
print('DEBUG: ' + account +
|
||||||
' follows ' + actor_handle)
|
' follows ' + actor_handle)
|
||||||
|
|
3
git.py
3
git.py
|
@ -11,6 +11,7 @@ import os
|
||||||
import html
|
import html
|
||||||
from utils import acct_dir
|
from utils import acct_dir
|
||||||
from utils import has_object_string_type
|
from utils import has_object_string_type
|
||||||
|
from utils import text_in_file
|
||||||
|
|
||||||
|
|
||||||
def _git_format_content(content: str) -> str:
|
def _git_format_content(content: str) -> str:
|
||||||
|
@ -38,7 +39,7 @@ def _get_git_project_name(base_dir: str, nickname: str, domain: str,
|
||||||
return None
|
return None
|
||||||
subject_line_words = subject.lower().split(' ')
|
subject_line_words = subject.lower().split(' ')
|
||||||
for word in subject_line_words:
|
for word in subject_line_words:
|
||||||
if word in open(git_projects_filename, encoding='utf-8').read():
|
if text_in_file(word, git_projects_filename):
|
||||||
return word
|
return word
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
|
@ -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?
|
# Does this event post already exist within the calendar month?
|
||||||
if os.path.isfile(calendar_filename):
|
if os.path.isfile(calendar_filename):
|
||||||
if post_id in open(calendar_filename,
|
if text_in_file(post_id, calendar_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
# Event post already exists
|
# Event post already exists
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
2
inbox.py
2
inbox.py
|
@ -449,7 +449,7 @@ def valid_inbox(base_dir: str, nickname: str, domain: str) -> bool:
|
||||||
if not os.path.isfile(filename):
|
if not os.path.isfile(filename):
|
||||||
print('filename: ' + filename)
|
print('filename: ' + filename)
|
||||||
return False
|
return False
|
||||||
if 'postNickname' in open(filename, encoding='utf-8').read():
|
if text_in_file('postNickname', filename):
|
||||||
print('queue file incorrectly saved to ' + filename)
|
print('queue file incorrectly saved to ' + filename)
|
||||||
return False
|
return False
|
||||||
break
|
break
|
||||||
|
|
|
@ -39,8 +39,7 @@ def manual_deny_follow_request(session, session_onion, session_i2p,
|
||||||
# has this handle already been rejected?
|
# has this handle already been rejected?
|
||||||
rejected_follows_filename = accounts_dir + '/followrejects.txt'
|
rejected_follows_filename = accounts_dir + '/followrejects.txt'
|
||||||
if os.path.isfile(rejected_follows_filename):
|
if os.path.isfile(rejected_follows_filename):
|
||||||
if deny_handle in open(rejected_follows_filename,
|
if text_in_file(deny_handle, rejected_follows_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
remove_from_follow_requests(base_dir, nickname, domain,
|
remove_from_follow_requests(base_dir, nickname, domain,
|
||||||
deny_handle, debug)
|
deny_handle, debug)
|
||||||
print(deny_handle +
|
print(deny_handle +
|
||||||
|
@ -308,8 +307,7 @@ def manual_approve_follow_request(session, session_onion, session_i2p,
|
||||||
|
|
||||||
# only update the follow requests file if the follow is confirmed to be
|
# only update the follow requests file if the follow is confirmed to be
|
||||||
# in followers.txt
|
# in followers.txt
|
||||||
if approve_handle_full in open(followers_filename,
|
if text_in_file(approve_handle_full, followers_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
# mark this handle as approved for following
|
# mark this handle as approved for following
|
||||||
_approve_follower_handle(account_dir, approve_handle)
|
_approve_follower_handle(account_dir, approve_handle)
|
||||||
# update the follow requests with the handles not yet approved
|
# update the follow requests with the handles not yet approved
|
||||||
|
|
|
@ -113,5 +113,4 @@ def notify_when_person_posts(base_dir: str, nickname: str, domain: str,
|
||||||
with open(notify_on_post_filename, 'w+',
|
with open(notify_on_post_filename, 'w+',
|
||||||
encoding='utf-8') as fp_notify:
|
encoding='utf-8') as fp_notify:
|
||||||
fp_notify.write('')
|
fp_notify.write('')
|
||||||
return handle + '\n' in open(notify_on_post_filename,
|
return text_in_file(handle + '\n', notify_on_post_filename)
|
||||||
encoding='utf-8').read()
|
|
||||||
|
|
|
@ -1391,7 +1391,7 @@ def is_person_snoozed(base_dir: str, nickname: str, domain: str,
|
||||||
except OSError:
|
except OSError:
|
||||||
print('EX: unable to write ' + snoozed_filename)
|
print('EX: unable to write ' + snoozed_filename)
|
||||||
|
|
||||||
if snooze_actor + ' ' in open(snoozed_filename, encoding='utf-8').read():
|
if text_in_file(snooze_actor + ' ', snoozed_filename):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -1406,8 +1406,7 @@ def person_snooze(base_dir: str, nickname: str, domain: str,
|
||||||
return
|
return
|
||||||
snoozed_filename = account_dir + '/snoozed.txt'
|
snoozed_filename = account_dir + '/snoozed.txt'
|
||||||
if os.path.isfile(snoozed_filename):
|
if os.path.isfile(snoozed_filename):
|
||||||
if snooze_actor + ' ' in open(snoozed_filename,
|
if text_in_file(snooze_actor + ' ', snoozed_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
with open(snoozed_filename, 'a+', encoding='utf-8') as snoozed_file:
|
with open(snoozed_filename, 'a+', encoding='utf-8') as snoozed_file:
|
||||||
|
|
6
posts.py
6
posts.py
|
@ -4751,8 +4751,7 @@ def populate_replies_json(base_dir: str, nickname: str, domain: str,
|
||||||
message_id2.replace('/', '#') + '.json'
|
message_id2.replace('/', '#') + '.json'
|
||||||
if os.path.isfile(search_filename):
|
if os.path.isfile(search_filename):
|
||||||
if authorized or \
|
if authorized or \
|
||||||
pub_str in open(search_filename,
|
text_in_file(pub_str, search_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
post_json_object = load_json(search_filename)
|
post_json_object = load_json(search_filename)
|
||||||
if post_json_object:
|
if post_json_object:
|
||||||
if post_json_object['object'].get('cc'):
|
if post_json_object['object'].get('cc'):
|
||||||
|
@ -4779,8 +4778,7 @@ def populate_replies_json(base_dir: str, nickname: str, domain: str,
|
||||||
message_id2.replace('/', '#') + '.json'
|
message_id2.replace('/', '#') + '.json'
|
||||||
if os.path.isfile(search_filename):
|
if os.path.isfile(search_filename):
|
||||||
if authorized or \
|
if authorized or \
|
||||||
pub_str in open(search_filename,
|
text_in_file(pub_str, search_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
# get the json of the reply and append it to
|
# get the json of the reply and append it to
|
||||||
# the collection
|
# the collection
|
||||||
post_json_object = load_json(search_filename)
|
post_json_object = load_json(search_filename)
|
||||||
|
|
143
tests.py
143
tests.py
|
@ -1419,7 +1419,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
||||||
bob_domain, None, None)
|
bob_domain, None, None)
|
||||||
|
|
||||||
for _ in range(20):
|
for _ in range(20):
|
||||||
if 'likes' in open(outbox_post_filename, encoding='utf-8').read():
|
if text_in_file('likes', outbox_post_filename):
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -1427,7 +1427,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
||||||
if alice_post_json:
|
if alice_post_json:
|
||||||
pprint(alice_post_json)
|
pprint(alice_post_json)
|
||||||
|
|
||||||
assert 'likes' in open(outbox_post_filename, encoding='utf-8').read()
|
assert text_in_file('likes', outbox_post_filename)
|
||||||
|
|
||||||
print('\n\n*******************************************************')
|
print('\n\n*******************************************************')
|
||||||
print("Bob reacts to Alice's post")
|
print("Bob reacts to Alice's post")
|
||||||
|
@ -1442,7 +1442,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
||||||
bob_domain, None, None)
|
bob_domain, None, None)
|
||||||
|
|
||||||
for _ in range(20):
|
for _ in range(20):
|
||||||
if 'reactions' in open(outbox_post_filename, encoding='utf-8').read():
|
if text_in_file('reactions', outbox_post_filename):
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -1451,7 +1451,7 @@ def test_post_message_between_servers(base_dir: str) -> None:
|
||||||
pprint(alice_post_json)
|
pprint(alice_post_json)
|
||||||
|
|
||||||
# TODO: fix reactions unit test
|
# TODO: fix reactions unit test
|
||||||
# assert 'reactions' in open(outbox_post_filename, encoding='utf-8').read()
|
# assert text_in_file('reactions', outbox_post_filename)
|
||||||
|
|
||||||
print('\n\n*******************************************************')
|
print('\n\n*******************************************************')
|
||||||
print("Bob repeats Alice's post")
|
print("Bob repeats Alice's post")
|
||||||
|
@ -1638,17 +1638,14 @@ def test_follow_between_servers(base_dir: str) -> None:
|
||||||
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
||||||
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
||||||
alice_domain, alice_port)
|
alice_domain, alice_port)
|
||||||
assert 'alice@' + alice_domain in open(bob_dir + '/accounts/bob@' +
|
assert text_in_file('alice@' + alice_domain, bob_dir + '/accounts/bob@' +
|
||||||
bob_domain +
|
bob_domain + '/followers.txt')
|
||||||
'/followers.txt',
|
assert text_in_file('bob@' + bob_domain,
|
||||||
encoding='utf-8').read()
|
alice_dir + '/accounts/alice@' +
|
||||||
assert 'bob@' + bob_domain in open(alice_dir + '/accounts/alice@' +
|
alice_domain + '/following.txt')
|
||||||
alice_domain + '/following.txt',
|
assert text_in_file('bob@' + bob_domain,
|
||||||
encoding='utf-8').read()
|
alice_dir + '/accounts/alice@' +
|
||||||
assert 'bob@' + bob_domain in open(alice_dir + '/accounts/alice@' +
|
alice_domain + '/followingCalendar.txt')
|
||||||
alice_domain +
|
|
||||||
'/followingCalendar.txt',
|
|
||||||
encoding='utf-8').read()
|
|
||||||
assert not is_group_actor(alice_dir, bob_actor, alice_person_cache)
|
assert not is_group_actor(alice_dir, bob_actor, alice_person_cache)
|
||||||
assert not is_group_account(alice_dir, 'alice', alice_domain)
|
assert not is_group_account(alice_dir, 'alice', alice_domain)
|
||||||
|
|
||||||
|
@ -1862,17 +1859,15 @@ def test_shared_items_federation(base_dir: str) -> None:
|
||||||
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
||||||
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
||||||
alice_domain, alice_port)
|
alice_domain, alice_port)
|
||||||
assert 'alice@' + alice_domain in open(bob_dir + '/accounts/bob@' +
|
assert text_in_file('alice@' + alice_domain,
|
||||||
bob_domain +
|
bob_dir + '/accounts/bob@' +
|
||||||
'/followers.txt',
|
bob_domain + '/followers.txt')
|
||||||
encoding='utf-8').read()
|
assert text_in_file('bob@' + bob_domain,
|
||||||
assert 'bob@' + bob_domain in open(alice_dir + '/accounts/alice@' +
|
alice_dir + '/accounts/alice@' +
|
||||||
alice_domain + '/following.txt',
|
alice_domain + '/following.txt')
|
||||||
encoding='utf-8').read()
|
assert text_in_file('bob@' + bob_domain,
|
||||||
assert 'bob@' + bob_domain in open(alice_dir + '/accounts/alice@' +
|
alice_dir + '/accounts/alice@' +
|
||||||
alice_domain +
|
alice_domain + '/followingCalendar.txt')
|
||||||
'/followingCalendar.txt',
|
|
||||||
encoding='utf-8').read()
|
|
||||||
assert not is_group_actor(alice_dir, bob_actor, alice_person_cache)
|
assert not is_group_actor(alice_dir, bob_actor, alice_person_cache)
|
||||||
assert not is_group_account(bob_dir, 'bob', bob_domain)
|
assert not is_group_account(bob_dir, 'bob', bob_domain)
|
||||||
|
|
||||||
|
@ -2323,17 +2318,15 @@ def test_group_follow(base_dir: str) -> None:
|
||||||
assert valid_inbox(testgroup_dir, 'testgroup', testgroup_domain)
|
assert valid_inbox(testgroup_dir, 'testgroup', testgroup_domain)
|
||||||
assert valid_inbox_filenames(testgroup_dir, 'testgroup', testgroup_domain,
|
assert valid_inbox_filenames(testgroup_dir, 'testgroup', testgroup_domain,
|
||||||
alice_domain, alice_port)
|
alice_domain, alice_port)
|
||||||
assert 'alice@' + alice_domain in open(testgroup_followers_filename,
|
assert text_in_file('alice@' + alice_domain, testgroup_followers_filename)
|
||||||
encoding='utf-8').read()
|
assert not text_in_file('!alice@' + alice_domain,
|
||||||
assert '!alice@' + alice_domain not in \
|
testgroup_followers_filename)
|
||||||
open(testgroup_followers_filename, encoding='utf-8').read()
|
|
||||||
|
|
||||||
testgroup_webfinger_filename = \
|
testgroup_webfinger_filename = \
|
||||||
testgroup_dir + '/wfendpoints/testgroup@' + \
|
testgroup_dir + '/wfendpoints/testgroup@' + \
|
||||||
testgroup_domain + ':' + str(testgroupPort) + '.json'
|
testgroup_domain + ':' + str(testgroupPort) + '.json'
|
||||||
assert os.path.isfile(testgroup_webfinger_filename)
|
assert os.path.isfile(testgroup_webfinger_filename)
|
||||||
assert 'acct:testgroup@' in open(testgroup_webfinger_filename,
|
assert text_in_file('acct:testgroup@', testgroup_webfinger_filename)
|
||||||
encoding='utf-8').read()
|
|
||||||
print('acct: exists within the webfinger endpoint for testgroup')
|
print('acct: exists within the webfinger endpoint for testgroup')
|
||||||
|
|
||||||
testgroup_handle = 'testgroup@' + testgroup_domain
|
testgroup_handle = 'testgroup@' + testgroup_domain
|
||||||
|
@ -2348,10 +2341,8 @@ def test_group_follow(base_dir: str) -> None:
|
||||||
assert not is_group_account(alice_dir, 'alice', alice_domain)
|
assert not is_group_account(alice_dir, 'alice', alice_domain)
|
||||||
assert is_group_account(testgroup_dir, 'testgroup', testgroup_domain)
|
assert is_group_account(testgroup_dir, 'testgroup', testgroup_domain)
|
||||||
assert '!testgroup' in following_str
|
assert '!testgroup' in following_str
|
||||||
assert testgroup_handle in open(alice_following_filename,
|
assert text_in_file(testgroup_handle, alice_following_filename)
|
||||||
encoding='utf-8').read()
|
assert text_in_file(testgroup_handle, alice_following_calendar_filename)
|
||||||
assert testgroup_handle in open(alice_following_calendar_filename,
|
|
||||||
encoding='utf-8').read()
|
|
||||||
print('\n\n*********************************************************')
|
print('\n\n*********************************************************')
|
||||||
print('Alice follows the test group')
|
print('Alice follows the test group')
|
||||||
|
|
||||||
|
@ -2405,17 +2396,15 @@ def test_group_follow(base_dir: str) -> None:
|
||||||
assert valid_inbox(testgroup_dir, 'testgroup', testgroup_domain)
|
assert valid_inbox(testgroup_dir, 'testgroup', testgroup_domain)
|
||||||
assert valid_inbox_filenames(testgroup_dir, 'testgroup', testgroup_domain,
|
assert valid_inbox_filenames(testgroup_dir, 'testgroup', testgroup_domain,
|
||||||
bob_domain, bob_port)
|
bob_domain, bob_port)
|
||||||
assert 'bob@' + bob_domain in open(testgroup_followers_filename,
|
assert text_in_file('bob@' + bob_domain, testgroup_followers_filename)
|
||||||
encoding='utf-8').read()
|
assert not text_in_file('!bob@' + bob_domain,
|
||||||
assert '!bob@' + bob_domain not in \
|
testgroup_followers_filename)
|
||||||
open(testgroup_followers_filename, encoding='utf-8').read()
|
|
||||||
|
|
||||||
testgroup_webfinger_filename = \
|
testgroup_webfinger_filename = \
|
||||||
testgroup_dir + '/wfendpoints/testgroup@' + \
|
testgroup_dir + '/wfendpoints/testgroup@' + \
|
||||||
testgroup_domain + ':' + str(testgroupPort) + '.json'
|
testgroup_domain + ':' + str(testgroupPort) + '.json'
|
||||||
assert os.path.isfile(testgroup_webfinger_filename)
|
assert os.path.isfile(testgroup_webfinger_filename)
|
||||||
assert 'acct:testgroup@' in open(testgroup_webfinger_filename,
|
assert text_in_file('acct:testgroup@', testgroup_webfinger_filename)
|
||||||
encoding='utf-8').read()
|
|
||||||
print('acct: exists within the webfinger endpoint for testgroup')
|
print('acct: exists within the webfinger endpoint for testgroup')
|
||||||
|
|
||||||
testgroup_handle = 'testgroup@' + testgroup_domain
|
testgroup_handle = 'testgroup@' + testgroup_domain
|
||||||
|
@ -2428,10 +2417,8 @@ def test_group_follow(base_dir: str) -> None:
|
||||||
testgroup_domain + ':' + str(testgroupPort))
|
testgroup_domain + ':' + str(testgroupPort))
|
||||||
assert is_group_actor(bob_dir, testgroup_actor, bob_person_cache)
|
assert is_group_actor(bob_dir, testgroup_actor, bob_person_cache)
|
||||||
assert '!testgroup' in following_str
|
assert '!testgroup' in following_str
|
||||||
assert testgroup_handle in open(bob_following_filename,
|
assert text_in_file(testgroup_handle, bob_following_filename)
|
||||||
encoding='utf-8').read()
|
assert text_in_file(testgroup_handle, bob_following_calendar_filename)
|
||||||
assert testgroup_handle in open(bob_following_calendar_filename,
|
|
||||||
encoding='utf-8').read()
|
|
||||||
print('Bob follows the test group')
|
print('Bob follows the test group')
|
||||||
|
|
||||||
print('\n\n*********************************************************')
|
print('\n\n*********************************************************')
|
||||||
|
@ -3188,30 +3175,27 @@ def test_client_to_server(base_dir: str):
|
||||||
bob_dir + '/accounts/bob@' + bob_domain + '/followers.txt'
|
bob_dir + '/accounts/bob@' + bob_domain + '/followers.txt'
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
if os.path.isfile(bob_followers_filename):
|
if os.path.isfile(bob_followers_filename):
|
||||||
if 'alice@' + alice_domain + ':' + str(alice_port) in \
|
test_str = 'alice@' + alice_domain + ':' + str(alice_port)
|
||||||
open(bob_followers_filename,
|
if text_in_file(test_str, bob_followers_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
if os.path.isfile(alice_following_filename) and \
|
if os.path.isfile(alice_following_filename) and \
|
||||||
os.path.isfile(alice_petnames_filename):
|
os.path.isfile(alice_petnames_filename):
|
||||||
if 'bob@' + bob_domain + ':' + str(bob_port) in \
|
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
||||||
open(alice_following_filename,
|
if text_in_file(test_str, alice_following_filename):
|
||||||
encoding='utf-8').read():
|
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
assert os.path.isfile(bob_followers_filename)
|
assert os.path.isfile(bob_followers_filename)
|
||||||
assert os.path.isfile(alice_following_filename)
|
assert os.path.isfile(alice_following_filename)
|
||||||
assert os.path.isfile(alice_petnames_filename)
|
assert os.path.isfile(alice_petnames_filename)
|
||||||
assert 'bob bob@' + bob_domain in \
|
assert text_in_file('bob bob@' + bob_domain, alice_petnames_filename)
|
||||||
open(alice_petnames_filename, encoding='utf-8').read()
|
|
||||||
print('alice@' + alice_domain + ':' + str(alice_port) + ' in ' +
|
print('alice@' + alice_domain + ':' + str(alice_port) + ' in ' +
|
||||||
bob_followers_filename)
|
bob_followers_filename)
|
||||||
assert 'alice@' + alice_domain + ':' + str(alice_port) in \
|
test_str = 'alice@' + alice_domain + ':' + str(alice_port)
|
||||||
open(bob_followers_filename, encoding='utf-8').read()
|
assert text_in_file(test_str, bob_followers_filename)
|
||||||
print('bob@' + bob_domain + ':' + str(bob_port) + ' in ' +
|
print('bob@' + bob_domain + ':' + str(bob_port) + ' in ' +
|
||||||
alice_following_filename)
|
alice_following_filename)
|
||||||
assert 'bob@' + bob_domain + ':' + str(bob_port) in \
|
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
||||||
open(alice_following_filename, encoding='utf-8').read()
|
assert text_in_file(test_str, alice_following_filename)
|
||||||
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
assert valid_inbox(bob_dir, 'bob', bob_domain)
|
||||||
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
assert valid_inbox_filenames(bob_dir, 'bob', bob_domain,
|
||||||
alice_domain, alice_port)
|
alice_domain, alice_port)
|
||||||
|
@ -3227,23 +3211,25 @@ def test_client_to_server(base_dir: str):
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
if os.path.isfile(alice_dir + '/accounts/alice@' + alice_domain +
|
if os.path.isfile(alice_dir + '/accounts/alice@' + alice_domain +
|
||||||
'/followers.txt'):
|
'/followers.txt'):
|
||||||
if 'bob@' + bob_domain + ':' + str(bob_port) in \
|
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
||||||
open(alice_dir + '/accounts/alice@' + alice_domain +
|
test_filename = \
|
||||||
'/followers.txt', encoding='utf-8').read():
|
alice_dir + '/accounts/alice@' + \
|
||||||
|
alice_domain + '/followers.txt'
|
||||||
|
if text_in_file(test_str, test_filename):
|
||||||
if os.path.isfile(bob_dir + '/accounts/bob@' + bob_domain +
|
if os.path.isfile(bob_dir + '/accounts/bob@' + bob_domain +
|
||||||
'/following.txt'):
|
'/following.txt'):
|
||||||
alice_handle_str = \
|
alice_handle_str = \
|
||||||
'alice@' + alice_domain + ':' + str(alice_port)
|
'alice@' + alice_domain + ':' + str(alice_port)
|
||||||
if alice_handle_str in \
|
if text_in_file(alice_handle_str,
|
||||||
open(bob_dir + '/accounts/bob@' + bob_domain +
|
bob_dir + '/accounts/bob@' + bob_domain +
|
||||||
'/following.txt', encoding='utf-8').read():
|
'/following.txt'):
|
||||||
if os.path.isfile(bob_dir + '/accounts/bob@' +
|
if os.path.isfile(bob_dir + '/accounts/bob@' +
|
||||||
bob_domain +
|
bob_domain +
|
||||||
'/followingCalendar.txt'):
|
'/followingCalendar.txt'):
|
||||||
if alice_handle_str in \
|
if text_in_file(alice_handle_str,
|
||||||
open(bob_dir + '/accounts/bob@' + bob_domain +
|
bob_dir + '/accounts/bob@' +
|
||||||
'/followingCalendar.txt',
|
bob_domain +
|
||||||
encoding='utf-8').read():
|
'/followingCalendar.txt'):
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -3251,12 +3237,13 @@ def test_client_to_server(base_dir: str):
|
||||||
'/followers.txt')
|
'/followers.txt')
|
||||||
assert os.path.isfile(bob_dir + '/accounts/bob@' + bob_domain +
|
assert os.path.isfile(bob_dir + '/accounts/bob@' + bob_domain +
|
||||||
'/following.txt')
|
'/following.txt')
|
||||||
assert 'bob@' + bob_domain + ':' + str(bob_port) in \
|
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
||||||
open(alice_dir + '/accounts/alice@' + alice_domain +
|
assert text_in_file(test_str, alice_dir + '/accounts/alice@' +
|
||||||
'/followers.txt', encoding='utf-8').read()
|
alice_domain + '/followers.txt')
|
||||||
assert 'alice@' + alice_domain + ':' + str(alice_port) in \
|
test_str = 'alice@' + alice_domain + ':' + str(alice_port)
|
||||||
open(bob_dir + '/accounts/bob@' + bob_domain + '/following.txt',
|
assert text_in_file(test_str,
|
||||||
encoding='utf-8').read()
|
bob_dir + '/accounts/bob@' +
|
||||||
|
bob_domain + '/following.txt')
|
||||||
|
|
||||||
session_bob = create_session(proxy_type)
|
session_bob = create_session(proxy_type)
|
||||||
password = 'bobpass'
|
password = 'bobpass'
|
||||||
|
@ -3459,10 +3446,10 @@ def test_client_to_server(base_dir: str):
|
||||||
cached_webfingers, person_cache,
|
cached_webfingers, person_cache,
|
||||||
True, __version__, signing_priv_key_pem)
|
True, __version__, signing_priv_key_pem)
|
||||||
for _ in range(10):
|
for _ in range(10):
|
||||||
if 'alice@' + alice_domain + ':' + str(alice_port) not in \
|
test_str = 'alice@' + alice_domain + ':' + str(alice_port)
|
||||||
open(bob_followers_filename, encoding='utf-8').read():
|
if not text_in_file(test_str, bob_followers_filename):
|
||||||
if 'bob@' + bob_domain + ':' + str(bob_port) not in \
|
test_str = 'bob@' + bob_domain + ':' + str(bob_port)
|
||||||
open(alice_following_filename, encoding='utf-8').read():
|
if not text_in_file(test_str, alice_following_filename):
|
||||||
break
|
break
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
27
utils.py
27
utils.py
|
@ -40,7 +40,8 @@ INVALID_CHARACTERS = (
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def text_in_file(text: str, filename: str, case_sensitive: bool = True) -> bool:
|
def text_in_file(text: str, filename: str,
|
||||||
|
case_sensitive: bool = True) -> bool:
|
||||||
"""is the given text in the given file?
|
"""is the given text in the given file?
|
||||||
"""
|
"""
|
||||||
if not case_sensitive:
|
if not case_sensitive:
|
||||||
|
@ -127,32 +128,32 @@ def has_object_dict(post_json_object: {}) -> bool:
|
||||||
|
|
||||||
def get_content_from_post(post_json_object: {}, system_language: str,
|
def get_content_from_post(post_json_object: {}, system_language: str,
|
||||||
languages_understood: [],
|
languages_understood: [],
|
||||||
contentType: str = "content") -> str:
|
content_type: str = "content") -> str:
|
||||||
"""Returns the content from the post in the given language
|
"""Returns the content from the post in the given language
|
||||||
including searching for a matching entry within contentMap
|
including searching for a matching entry within contentMap
|
||||||
"""
|
"""
|
||||||
this_post_json = post_json_object
|
this_post_json = post_json_object
|
||||||
if has_object_dict(post_json_object):
|
if has_object_dict(post_json_object):
|
||||||
this_post_json = post_json_object['object']
|
this_post_json = post_json_object['object']
|
||||||
if not this_post_json.get(contentType):
|
if not this_post_json.get(content_type):
|
||||||
return ''
|
return ''
|
||||||
content = ''
|
content = ''
|
||||||
mapDict = contentType + 'Map'
|
map_dict = content_type + 'Map'
|
||||||
if this_post_json.get(mapDict):
|
if this_post_json.get(map_dict):
|
||||||
if isinstance(this_post_json[mapDict], dict):
|
if isinstance(this_post_json[map_dict], dict):
|
||||||
if this_post_json[mapDict].get(system_language):
|
if this_post_json[map_dict].get(system_language):
|
||||||
sys_lang = this_post_json[mapDict][system_language]
|
sys_lang = this_post_json[map_dict][system_language]
|
||||||
if isinstance(sys_lang, str):
|
if isinstance(sys_lang, str):
|
||||||
return this_post_json[mapDict][system_language]
|
return this_post_json[map_dict][system_language]
|
||||||
else:
|
else:
|
||||||
# is there a contentMap/summaryMap entry for one of
|
# is there a contentMap/summaryMap entry for one of
|
||||||
# the understood languages?
|
# the understood languages?
|
||||||
for lang in languages_understood:
|
for lang in languages_understood:
|
||||||
if this_post_json[mapDict].get(lang):
|
if this_post_json[map_dict].get(lang):
|
||||||
return this_post_json[mapDict][lang]
|
return this_post_json[map_dict][lang]
|
||||||
else:
|
else:
|
||||||
if isinstance(this_post_json[contentType], str):
|
if isinstance(this_post_json[content_type], str):
|
||||||
content = this_post_json[contentType]
|
content = this_post_json[content_type]
|
||||||
return content
|
return content
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ import os
|
||||||
from question import is_question
|
from question import is_question
|
||||||
from utils import remove_id_ending
|
from utils import remove_id_ending
|
||||||
from utils import acct_dir
|
from utils import acct_dir
|
||||||
|
from utils import text_in_file
|
||||||
|
|
||||||
|
|
||||||
def insert_question(base_dir: str, translate: {},
|
def insert_question(base_dir: str, translate: {},
|
||||||
|
@ -34,7 +35,7 @@ def insert_question(base_dir: str, translate: {},
|
||||||
|
|
||||||
show_question_results = False
|
show_question_results = False
|
||||||
if os.path.isfile(votes_filename):
|
if os.path.isfile(votes_filename):
|
||||||
if message_id in open(votes_filename, encoding='utf-8').read():
|
if text_in_file(message_id, votes_filename):
|
||||||
show_question_results = True
|
show_question_results = True
|
||||||
|
|
||||||
if not show_question_results:
|
if not show_question_results:
|
||||||
|
|
|
@ -26,6 +26,7 @@ from utils import get_audio_extensions
|
||||||
from utils import get_video_extensions
|
from utils import get_video_extensions
|
||||||
from utils import get_image_extensions
|
from utils import get_image_extensions
|
||||||
from utils import local_actor_url
|
from utils import local_actor_url
|
||||||
|
from utils import text_in_file
|
||||||
from cache import store_person_in_cache
|
from cache import store_person_in_cache
|
||||||
from content import add_html_tags
|
from content import add_html_tags
|
||||||
from content import replace_emoji_from_tags
|
from content import replace_emoji_from_tags
|
||||||
|
@ -362,7 +363,7 @@ def scheduled_posts_exist(base_dir: str, nickname: str, domain: str) -> bool:
|
||||||
acct_dir(base_dir, nickname, domain) + '/schedule.index'
|
acct_dir(base_dir, nickname, domain) + '/schedule.index'
|
||||||
if not os.path.isfile(schedule_index_filename):
|
if not os.path.isfile(schedule_index_filename):
|
||||||
return False
|
return False
|
||||||
if '#users#' in open(schedule_index_filename, encoding='utf-8').read():
|
if text_in_file('#users#', schedule_index_filename):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue