From 1085f9707014fdb3ab97a8adea350df079b08972 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 8 Jan 2022 10:58:54 +0000 Subject: [PATCH] Use enumerations --- blocking.py | 2 +- outbox.py | 2 +- person.py | 2 +- roles.py | 2 +- speaker.py | 2 +- utils.py | 10 +++++----- webapp_search.py | 5 ++--- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/blocking.py b/blocking.py index 045f6c70b..19ee64470 100644 --- a/blocking.py +++ b/blocking.py @@ -290,7 +290,7 @@ def update_blocked_cache(base_dir: str, with open(global_blocking_filename, 'r') as fp_blocked: blocked_lines = fp_blocked.readlines() # remove newlines - for index in range(len(blocked_lines)): + for index, _ in enumerate(blocked_lines): blocked_lines[index] = blocked_lines[index].replace('\n', '') # update the cache blocked_cache.clear() diff --git a/outbox.py b/outbox.py index ed4f0f1b0..1a8945ba8 100644 --- a/outbox.py +++ b/outbox.py @@ -143,7 +143,7 @@ def _person_receive_update_outbox(recent_posts_cache: {}, if 'attachment' not in actor_json: continue found = False - for attach_idx in range(len(actor_json['attachment'])): + for attach_idx, _ in enumerate(actor_json['attachment']): if actor_json['attachment'][attach_idx]['type'] != \ 'PropertyValue': continue diff --git a/person.py b/person.py index f0f2406d5..da54a191f 100644 --- a/person.py +++ b/person.py @@ -797,7 +797,7 @@ def person_upgrade_actor(base_dir: str, person_json: {}, update_actor = True else: # add location if it is missing - for index in range(len(person_json['hasOccupation'])): + for index, _ in enumerate(person_json['hasOccupation']): oc_item = person_json['hasOccupation'][index] if oc_item.get('hasOccupation'): oc_item = oc_item['hasOccupation'] diff --git a/roles.py b/roles.py index 770f0c1c3..f638d15db 100644 --- a/roles.py +++ b/roles.py @@ -163,7 +163,7 @@ def _set_actor_role(actor_json: {}, role_name: str) -> bool: if not category: return False - for index in range(len(actor_json['hasOccupation'])): + for index, _ in enumerate(actor_json['hasOccupation']): occupation_item = actor_json['hasOccupation'][index] if not isinstance(occupation_item, dict): continue diff --git a/speaker.py b/speaker.py index 5bb896f90..984f30a62 100644 --- a/speaker.py +++ b/speaker.py @@ -503,7 +503,7 @@ def _post_to_speaker_json(base_dir: str, http_prefix: str, follows = fp_foll.readlines() if len(follows) > 0: follow_requests_exist = True - for i in range(len(follows)): + for i, _ in enumerate(follows): follows[i] = follows[i].strip() follow_requests_list = follows post_dm = False diff --git a/utils.py b/utils.py index 5d0b7f565..3e1930464 100644 --- a/utils.py +++ b/utils.py @@ -559,7 +559,7 @@ def get_followers_list(base_dir: str, with open(filename, 'r') as foll_file: lines = foll_file.readlines() - for i in range(len(lines)): + for i, _ in enumerate(lines): lines[i] = lines[i].strip() return lines return [] @@ -2126,7 +2126,7 @@ def _search_virtual_box_posts(base_dir: str, nickname: str, domain: str, if '+' in search_str: search_words = search_str.split('+') - for index in range(len(search_words)): + for index, _ in enumerate(search_words): search_words[index] = search_words[index].strip() print('SEARCH: ' + str(search_words)) else: @@ -2178,7 +2178,7 @@ def search_box_posts(base_dir: str, nickname: str, domain: str, if '+' in search_str: search_words = search_str.split('+') - for index in range(len(search_words)): + for index, _ in enumerate(search_words): search_words[index] = search_words[index].strip() print('SEARCH: ' + str(search_words)) else: @@ -2811,7 +2811,7 @@ def set_occupation_name(actor_json: {}, name: str) -> bool: return False if not isinstance(actor_json['hasOccupation'], list): return False - for index in range(len(actor_json['hasOccupation'])): + for index, _ in enumerate(actor_json['hasOccupation']): occupation_item = actor_json['hasOccupation'][index] if not isinstance(occupation_item, dict): continue @@ -2831,7 +2831,7 @@ def set_occupation_skills_list(actor_json: {}, skills_list: []) -> bool: return False if not isinstance(actor_json['hasOccupation'], list): return False - for index in range(len(actor_json['hasOccupation'])): + for index, _ in enumerate(actor_json['hasOccupation']): occupation_item = actor_json['hasOccupation'][index] if not isinstance(occupation_item, dict): continue diff --git a/webapp_search.py b/webapp_search.py index d8f3df883..32b3ec17d 100644 --- a/webapp_search.py +++ b/webapp_search.py @@ -941,9 +941,8 @@ def rss_hashtag_search(nickname: str, domain: str, port: int, domain_full = get_full_domain(domain, port) max_feed_length = 10 - hashtag_feed = \ - rss2tag_header(hashtag, http_prefix, domain_full) - for index in range(len(lines)): + hashtag_feed = rss2tag_header(hashtag, http_prefix, domain_full) + for index, _ in enumerate(lines): post_id = lines[index].strip('\n').strip('\r') if ' ' not in post_id: nickname = get_nickname_from_actor(post_id)