Skip to content

Commit addd2a2

Browse files
committed
Avoid encapsulation
1 parent 9267dbb commit addd2a2

7 files changed

+103
-97
lines changed

README_coding_style.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Procedural style. Think "C style in Python". Avoid classes and objects as far as
1010

1111
Declare all called functions individually at the top of each module. This avoids any possible mistakes with colliding function names, and allows static analysis to explicitly check all dependencies.
1212

13+
Avoid too much encapsulation. Prefer passing a variable as a function argument rather than using "self.server.variable". This makes static checking of everything easier, before it goes into production.
14+
1315
Don't use any features of Python which are not supported by the version of Python within the current Debian stable release. Don't assume that all users are running the latest cutting-edge Python release.
1416

1517
Before doing a commit run all the unit tests. There are three layers of testing. The first just checks PEP8 compliance. The second runs a more thorough static analysis and unit tests. The third simulates instances communicating with each other.

daemon_post.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ def daemon_http_post(self) -> None:
663663
receive_new_post(self, curr_post_type, self.path,
664664
calling_domain, cookie,
665665
self.server.content_license_url,
666-
curr_session, proxy_type)
666+
curr_session, proxy_type,
667+
self.server.base_dir)
667668
if page_number:
668669
print(curr_post_type + ' post received')
669670
nickname = self.path.split('/users/')[1]

daemon_post_confirm.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def unfollow_confirm(self, calling_domain: str, cookie: str,
117117
self.post_to_nickname = path_users_section.split('/')[0]
118118
group_account = has_group_type(base_dir, following_actor,
119119
self.server.person_cache)
120-
unfollow_account(self.server.base_dir, self.post_to_nickname,
120+
unfollow_account(base_dir, self.post_to_nickname,
121121
self.server.domain,
122122
following_nickname, following_domain_full,
123123
self.server.debug, group_account,
@@ -333,7 +333,7 @@ def follow_confirm2(self, calling_domain: str, cookie: str,
333333
blocked_cache_last_updated = \
334334
self.server.blocked_cache_last_updated
335335
self.server.blocked_cache_last_updated = \
336-
update_blocked_cache(self.server.base_dir,
336+
update_blocked_cache(base_dir,
337337
self.server.blocked_cache,
338338
blocked_cache_last_updated, 0)
339339

@@ -519,7 +519,7 @@ def unblock_confirm(self, calling_domain: str, cookie: str,
519519
blocked_cache_last_updated = \
520520
self.server.blocked_cache_last_updated
521521
self.server.blocked_cache_last_updated = \
522-
update_blocked_cache(self.server.base_dir,
522+
update_blocked_cache(base_dir,
523523
self.server.blocked_cache,
524524
blocked_cache_last_updated, 0)
525525
if calling_domain.endswith('.onion') and onion_domain:

daemon_post_moderator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
4949
self.server.onion_domain,
5050
self.server.i2p_domain) + \
5151
users_path
52-
if not is_moderator(self.server.base_dir, nickname):
52+
if not is_moderator(base_dir, nickname):
5353
redirect_headers(self, actor_str + '/moderation',
5454
cookie, calling_domain)
5555
self.server.postreq_busy = False
@@ -138,7 +138,7 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
138138
# is this a local nickname on this instance?
139139
local_handle = \
140140
search_handle + '@' + self.server.domain
141-
if os.path.isdir(self.server.base_dir +
141+
if os.path.isdir(base_dir +
142142
'/accounts/' + local_handle):
143143
search_handle = local_handle
144144
else:
@@ -249,7 +249,7 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
249249
blocked_cache_last_updated = \
250250
self.server.blocked_cache_last_updated
251251
self.server.blocked_cache_last_updated = \
252-
update_blocked_cache(self.server.base_dir,
252+
update_blocked_cache(base_dir,
253253
self.server.blocked_cache,
254254
blocked_cache_last_updated, 0)
255255
if moderation_button == 'unblock':
@@ -284,7 +284,7 @@ def moderator_actions(self, path: str, calling_domain: str, cookie: str,
284284
blocked_cache_last_updated = \
285285
self.server.blocked_cache_last_updated
286286
self.server.blocked_cache_last_updated = \
287-
update_blocked_cache(self.server.base_dir,
287+
update_blocked_cache(base_dir,
288288
self.server.blocked_cache,
289289
blocked_cache_last_updated, 0)
290290
if moderation_button == 'remove':

daemon_post_person_options.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -452,18 +452,18 @@ def person_options2(self, path: str,
452452
# person options screen, permission to post to newswire
453453
# See html_person_options
454454
if '&submitPostToNews=' in options_confirm_params:
455-
admin_nickname = get_config_param(self.server.base_dir, 'admin')
455+
admin_nickname = get_config_param(base_dir, 'admin')
456456
if (chooser_nickname != options_nickname and
457457
(chooser_nickname == admin_nickname or
458-
(is_moderator(self.server.base_dir, chooser_nickname) and
459-
not is_moderator(self.server.base_dir, options_nickname)))):
458+
(is_moderator(base_dir, chooser_nickname) and
459+
not is_moderator(base_dir, options_nickname)))):
460460
posts_to_news = None
461461
if 'postsToNews=' in options_confirm_params:
462462
posts_to_news = \
463463
options_confirm_params.split('postsToNews=')[1]
464464
if '&' in posts_to_news:
465465
posts_to_news = posts_to_news.split('&')[0]
466-
account_dir = acct_dir(self.server.base_dir,
466+
account_dir = acct_dir(base_dir,
467467
options_nickname, options_domain)
468468
newswire_blocked_filename = account_dir + '/.nonewswire'
469469
if posts_to_news == 'on':
@@ -473,7 +473,7 @@ def person_options2(self, path: str,
473473
except OSError:
474474
print('EX: _person_options unable to delete ' +
475475
newswire_blocked_filename)
476-
refresh_newswire(self.server.base_dir)
476+
refresh_newswire(base_dir)
477477
else:
478478
if os.path.isdir(account_dir):
479479
nw_filename = newswire_blocked_filename
@@ -487,7 +487,7 @@ def person_options2(self, path: str,
487487
print('EX: unable to write ' + nw_filename +
488488
' ' + str(ex))
489489
if nw_written:
490-
refresh_newswire(self.server.base_dir)
490+
refresh_newswire(base_dir)
491491
users_path_str = \
492492
users_path + '/' + self.server.default_timeline + \
493493
'?page=' + str(page_number)
@@ -499,18 +499,18 @@ def person_options2(self, path: str,
499499
# person options screen, permission to post to featured articles
500500
# See html_person_options
501501
if '&submitPostToFeatures=' in options_confirm_params:
502-
admin_nickname = get_config_param(self.server.base_dir, 'admin')
502+
admin_nickname = get_config_param(base_dir, 'admin')
503503
if (chooser_nickname != options_nickname and
504504
(chooser_nickname == admin_nickname or
505-
(is_moderator(self.server.base_dir, chooser_nickname) and
506-
not is_moderator(self.server.base_dir, options_nickname)))):
505+
(is_moderator(base_dir, chooser_nickname) and
506+
not is_moderator(base_dir, options_nickname)))):
507507
posts_to_features = None
508508
if 'postsToFeatures=' in options_confirm_params:
509509
posts_to_features = \
510510
options_confirm_params.split('postsToFeatures=')[1]
511511
if '&' in posts_to_features:
512512
posts_to_features = posts_to_features.split('&')[0]
513-
account_dir = acct_dir(self.server.base_dir,
513+
account_dir = acct_dir(base_dir,
514514
options_nickname, options_domain)
515515
features_blocked_filename = account_dir + '/.nofeatures'
516516
if posts_to_features == 'on':
@@ -520,7 +520,7 @@ def person_options2(self, path: str,
520520
except OSError:
521521
print('EX: _person_options unable to delete ' +
522522
features_blocked_filename)
523-
refresh_newswire(self.server.base_dir)
523+
refresh_newswire(base_dir)
524524
else:
525525
if os.path.isdir(account_dir):
526526
feat_filename = features_blocked_filename
@@ -534,7 +534,7 @@ def person_options2(self, path: str,
534534
print('EX: unable to write ' + feat_filename +
535535
' ' + str(ex))
536536
if feat_written:
537-
refresh_newswire(self.server.base_dir)
537+
refresh_newswire(base_dir)
538538
users_path_str = \
539539
users_path + '/' + self.server.default_timeline + \
540540
'?page=' + str(page_number)
@@ -546,18 +546,18 @@ def person_options2(self, path: str,
546546
# person options screen, permission to post to newswire
547547
# See html_person_options
548548
if '&submitModNewsPosts=' in options_confirm_params:
549-
admin_nickname = get_config_param(self.server.base_dir, 'admin')
549+
admin_nickname = get_config_param(base_dir, 'admin')
550550
if (chooser_nickname != options_nickname and
551551
(chooser_nickname == admin_nickname or
552-
(is_moderator(self.server.base_dir, chooser_nickname) and
553-
not is_moderator(self.server.base_dir, options_nickname)))):
552+
(is_moderator(base_dir, chooser_nickname) and
553+
not is_moderator(base_dir, options_nickname)))):
554554
mod_posts_to_news = None
555555
if 'modNewsPosts=' in options_confirm_params:
556556
mod_posts_to_news = \
557557
options_confirm_params.split('modNewsPosts=')[1]
558558
if '&' in mod_posts_to_news:
559559
mod_posts_to_news = mod_posts_to_news.split('&')[0]
560-
account_dir = acct_dir(self.server.base_dir,
560+
account_dir = acct_dir(base_dir,
561561
options_nickname, options_domain)
562562
newswire_mod_filename = account_dir + '/.newswiremoderated'
563563
if mod_posts_to_news != 'on':
@@ -771,7 +771,7 @@ def person_options2(self, path: str,
771771
# person options screen, Info button
772772
# See html_person_options
773773
if '&submitPersonInfo=' in options_confirm_params:
774-
if is_moderator(self.server.base_dir, chooser_nickname):
774+
if is_moderator(base_dir, chooser_nickname):
775775
if debug:
776776
print('Showing info for ' + options_actor)
777777
signing_priv_key_pem = self.server.signing_priv_key_pem

daemon_post_profile.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
24562456
self.server.postreq_busy = False
24572457
return
24582458

2459-
admin_nickname = get_config_param(self.server.base_dir, 'admin')
2459+
admin_nickname = get_config_param(base_dir, 'admin')
24602460

24612461
if not boundary:
24622462
if b'--LYNX' in post_bytes:
@@ -2602,13 +2602,13 @@ def profile_edit(self, calling_domain: str, cookie: str,
26022602
redirect_path = '/welcome_final'
26032603
elif 'name="welcomeCompleteButton"' in post_bytes_str:
26042604
redirect_path = '/' + self.server.default_timeline
2605-
welcome_screen_is_complete(self.server.base_dir, nickname,
2605+
welcome_screen_is_complete(base_dir, nickname,
26062606
self.server.domain)
26072607
on_final_welcome_screen = True
26082608
elif 'name="submitExportTheme"' in post_bytes_str:
26092609
print('submitExportTheme')
26102610
theme_download_path = actor_str
2611-
if export_theme(self.server.base_dir,
2611+
if export_theme(base_dir,
26122612
self.server.theme_name):
26132613
theme_download_path += \
26142614
'/exports/' + self.server.theme_name + '.zip'
@@ -2691,7 +2691,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
26912691
_profile_post_media_instance_status(base_dir, fields, self)
26922692

26932693
# is this a news theme?
2694-
if is_news_theme_name(self.server.base_dir,
2694+
if is_news_theme_name(base_dir,
26952695
self.server.theme_name):
26962696
fields['newsInstance'] = 'on'
26972697

@@ -2745,7 +2745,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
27452745

27462746
actor_changed = \
27472747
_profile_post_blog_address(curr_session,
2748-
self.server.base_dir,
2748+
base_dir,
27492749
self.server.http_prefix,
27502750
nickname, domain,
27512751
actor_json, fields,
@@ -2803,7 +2803,7 @@ def profile_edit(self, calling_domain: str, cookie: str,
28032803

28042804
actor_changed = \
28052805
_profile_post_website(curr_session,
2806-
self.server.base_dir,
2806+
base_dir,
28072807
self.server.http_prefix,
28082808
nickname, domain,
28092809
actor_json, fields,

0 commit comments

Comments
 (0)