diff --git a/daemon.py b/daemon.py index 3e2d766be..49a0f9491 100644 --- a/daemon.py +++ b/daemon.py @@ -2230,12 +2230,12 @@ class PubServer(BaseHTTPRequestHandler): moderation_text = None moderation_button = None # get the moderation text first - actStr = 'moderationAction=' + act_str = 'moderationAction=' for moderation_str in moderation_params.split('&'): - if moderation_str.startswith(actStr): - if actStr in moderation_str: + if moderation_str.startswith(act_str): + if act_str in moderation_str: moderation_text = \ - moderation_str.split(actStr)[1].strip() + moderation_str.split(act_str)[1].strip() mod_text = moderation_text.replace('+', ' ') moderation_text = \ urllib.parse.unquote_plus(mod_text.strip()) @@ -4672,7 +4672,7 @@ class PubServer(BaseHTTPRequestHandler): print('origin_path_str: ' + origin_path_str) print('remove_post_actor: ' + remove_post_actor) if origin_path_str in remove_post_actor: - toList = [ + to_list = [ 'https://www.w3.org/ns/activitystreams#Public', remove_post_actor ] @@ -4680,7 +4680,7 @@ class PubServer(BaseHTTPRequestHandler): "@context": "https://www.w3.org/ns/activitystreams", 'actor': remove_post_actor, 'object': remove_message_id, - 'to': toList, + 'to': to_list, 'cc': [remove_post_actor + '/followers'], 'type': 'Delete' } @@ -5461,7 +5461,7 @@ class PubServer(BaseHTTPRequestHandler): acct_dir(base_dir, nickname, domain) + \ '/' + m_type + '.temp' - filename, attachment_media_type = \ + filename, _ = \ save_media_in_form_post(media_bytes, debug, filename_base) if filename: @@ -14956,16 +14956,16 @@ class PubServer(BaseHTTPRequestHandler): calling_domain: str, referer_domain: str, http_prefix: str, domain: str, port: int, - followingItemsPerPage: int, - debug: bool, listName='following') -> None: + following_items_per_page: int, + debug: bool, list_name: str = 'following') -> None: """Returns json collection for following.txt """ following_json = \ get_following_feed(base_dir, domain, port, path, http_prefix, - True, followingItemsPerPage, listName) + True, following_items_per_page, list_name) if not following_json: if debug: - print(listName + ' json feed not found for ' + path) + print(list_name + ' json feed not found for ' + path) self._404() return msg_str = json.dumps(following_json, @@ -15280,7 +15280,6 @@ class PubServer(BaseHTTPRequestHandler): known_bots_str = '' for bot_name in self.server.known_bots: known_bots_str += bot_name + '\n' - # TODO msg = known_bots_str.encode('utf-8') msglen = len(msg) self._set_headers('text/plain; charset=utf-8', @@ -16395,8 +16394,7 @@ class PubServer(BaseHTTPRequestHandler): '_GET', 'show welcome screen', self.server.debug) return - else: - self.path = self.path.replace('/welcome', '') + self.path = self.path.replace('/welcome', '') # the welcome screen which allows you to set an avatar image if html_getreq and authorized and \ @@ -18556,10 +18554,11 @@ class PubServer(BaseHTTPRequestHandler): return if response_str == 'Not modified': if endpoint_type == 'put': - return self._200() - else: - return self._304() - elif response_str.startswith('ETag:') and endpoint_type == 'put': + self._200() + return + self._304() + return + if response_str.startswith('ETag:') and endpoint_type == 'put': response_etag = response_str.split('ETag:', 1)[1] self._201(response_etag) elif response_str != 'Ok': @@ -19483,7 +19482,7 @@ class PubServer(BaseHTTPRequestHandler): curr_session, proxy_type): return 1 return -1 - elif post_type == 'newshare' or post_type == 'newwanted': + elif post_type in ('newshare', 'newwanted'): if not fields.get('itemQty'): print(post_type + ' no itemQty') return -1 diff --git a/utils.py b/utils.py index 6fc1adf7d..e9e985d13 100644 --- a/utils.py +++ b/utils.py @@ -2050,7 +2050,7 @@ def _is_valid_language(text: str) -> bool: "Phonetic Extensions": [7467, 7544], "Combining Half Marks": [65070, 65071] } - for lang_name, lang_range in natural_languages.items(): + for _, lang_range in natural_languages.items(): ok_lang = True for char in text: if char.isdigit() or char == '_': @@ -2134,7 +2134,7 @@ def no_of_accounts(base_dir: str) -> bool: """Returns the number of accounts on the system """ account_ctr = 0 - for subdir, dirs, files in os.walk(base_dir + '/accounts'): + for _, dirs, _ in os.walk(base_dir + '/accounts'): for account in dirs: if is_account_dir(account): account_ctr += 1 @@ -2148,7 +2148,7 @@ def no_of_active_accounts_monthly(base_dir: str, months: int) -> bool: account_ctr = 0 curr_time = int(time.time()) month_seconds = int(60*60*24*30*months) - for subdir, dirs, files in os.walk(base_dir + '/accounts'): + for _, dirs, _ in os.walk(base_dir + '/accounts'): for account in dirs: if not is_account_dir(account): continue @@ -2427,7 +2427,7 @@ def search_box_posts(base_dir: str, nickname: str, domain: str, search_words = [search_str] res = [] - for root, dirs, fnames in os.walk(path): + for root, _, fnames in os.walk(path): for fname in fnames: file_path = os.path.join(root, fname) with open(file_path, 'r') as post_file: @@ -3485,7 +3485,7 @@ def has_object_string_object(post_json_object: {}, debug: bool) -> bool: if post_json_object['object'].get('object'): if isinstance(post_json_object['object']['object'], str): return True - elif debug: + if debug: if post_json_object.get('type'): print('DEBUG: ' + post_json_object['type'] + ' object within dict is not a string') @@ -3566,14 +3566,14 @@ def load_account_timezones(base_dir: str) -> {}: """Returns a dictionary containing the preferred timezone for each account """ account_timezone = {} - for subdir, dirs, files in os.walk(base_dir + '/accounts'): + for _, dirs, _ in os.walk(base_dir + '/accounts'): for acct in dirs: if '@' not in acct: continue if acct.startswith('inbox@') or acct.startswith('Actor@'): continue - acct_dir = os.path.join(base_dir + '/accounts', acct) - tz_filename = acct_dir + '/timezone.txt' + acct_directory = os.path.join(base_dir + '/accounts', acct) + tz_filename = acct_directory + '/timezone.txt' if not os.path.isfile(tz_filename): continue timezone = None @@ -3590,7 +3590,7 @@ def load_bold_reading(base_dir: str) -> {}: """Returns a dictionary containing the bold reading status for each account """ bold_reading = {} - for subdir, dirs, files in os.walk(base_dir + '/accounts'): + for _, dirs, _ in os.walk(base_dir + '/accounts'): for acct in dirs: if '@' not in acct: continue @@ -3601,6 +3601,7 @@ def load_bold_reading(base_dir: str) -> {}: if os.path.isfile(bold_reading_filename): nickname = acct.split('@')[0] bold_reading[nickname] = True + break return bold_reading diff --git a/webapp_profile.py b/webapp_profile.py index 453a75673..bfa7daca4 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -1174,7 +1174,7 @@ def _html_profile_following(translate: {}, base_dir: str, http_prefix: str, session, cached_webfingers: {}, person_cache: {}, following_json: {}, project_version: str, buttons: [], - feedName: str, actor: str, + feed_name: str, actor: str, page_number: int, max_items_per_page: int, dormant_months: int, debug: bool, @@ -1188,7 +1188,7 @@ def _html_profile_following(translate: {}, base_dir: str, http_prefix: str, # page up arrow profile_str += \ '