diff --git a/webapp_profile.py b/webapp_profile.py index 7a187a6ab..8638b46a5 100644 --- a/webapp_profile.py +++ b/webapp_profile.py @@ -146,7 +146,7 @@ BLOCKFILE_FORMATS = '.csv' def _import_export_blocks(translate: {}) -> str: """ import and export blocks on edit profile screen """ - edit_profile_form = \ + edit_profile_form: str = \ ' \n' edit_profile_form += ' str: def _get_profile_short_description(profile_description: str) -> str: """Returns a short version of the profile description """ - profile_description_short = profile_description + profile_description_short: str = profile_description if '\n' in profile_description: if len(profile_description.split('\n')) > 6: profile_description_short: str = '' @@ -206,7 +206,7 @@ def _valid_profile_preview_post(post_json_object: {}, cc_list: list[str] = [] if post_json_object.get('cc'): cc_list = post_json_object['cc'] - new_post_json_object = { + new_post_json_object: dict = { 'object': post_json_object, 'to': post_json_object['to'], 'cc': cc_list, @@ -225,14 +225,14 @@ def _valid_profile_preview_post(post_json_object: {}, if has_object_dict(post_json_object): # convert attributedTo actor back to id if post_json_object['object'].get('attributedTo'): - attrib_field = post_json_object['object']['attributedTo'] + attrib_field: str = post_json_object['object']['attributedTo'] if attrib_field: if isinstance(attrib_field, dict): - attrib = get_attributed_to(attrib_field) + attrib: str = get_attributed_to(attrib_field) if attrib: post_json_object['object']['attributedTo'] = attrib if not is_announced_feed_item: - actor_url = get_actor_from_post(post_json_object) + actor_url: str = get_actor_from_post(post_json_object) if actor_url != person_url and \ post_json_object['object']['type'] != 'Page': return False, None @@ -289,7 +289,7 @@ def html_profile_after_search(authorized: bool, ipfs = True elif http_prefix == 'ipns': ipns = True - from_domain = domain + from_domain: str = domain if onion_domain: if '.onion/' in profile_handle or profile_handle.endswith('.onion'): from_domain = onion_domain @@ -320,21 +320,21 @@ def html_profile_after_search(authorized: bool, if not profile_json.get('id'): return None - person_url = profile_json['id'] - person_url2 = person_url + person_url: str = profile_json['id'] + person_url2: str = person_url if profile_json.get('url'): if isinstance(profile_json['url'], str): person_url2 = remove_html(profile_json['url']) search_domain, search_port = get_domain_from_actor(person_url) if not search_domain: return None - search_nickname = get_nickname_from_actor(person_url) + search_nickname: str = get_nickname_from_actor(person_url) if not search_nickname: return None - search_domain_full = get_full_domain(search_domain, search_port) + search_domain_full: str = get_full_domain(search_domain, search_port) profile_str: str = '' - css_filename = base_dir + '/epicyon-profile.css' + css_filename: str = base_dir + '/epicyon-profile.css' if is_a_file(base_dir + '/epicyon.css'): css_filename = base_dir + '/epicyon.css' @@ -345,17 +345,17 @@ def html_profile_after_search(authorized: bool, # shared items attached to the actor # https://codeberg.org/fediverse/fep/src/branch/main/fep/0837/fep-0837.md - attached_shared_items = \ + attached_shared_items: str = \ actor_attached_shares_as_html(profile_json, max_shares_on_profile) avatar_url: str = '' if profile_json.get('icon'): - url_str = get_person_icon(profile_json) + url_str: str = get_person_icon(profile_json) if url_str: avatar_url = remove_html(url_str) if not avatar_url: avatar_url = get_person_avatar_url(base_dir, person_url, person_cache) - display_name = search_nickname + display_name: str = search_nickname if profile_json.get('name'): display_name = profile_json['name'] display_name = remove_html(display_name) @@ -365,29 +365,29 @@ def html_profile_after_search(authorized: bool, nickname, domain, display_name, False, translate) - locked_account = get_locked_account(profile_json) + locked_account: bool = get_locked_account(profile_json) if locked_account: display_name += '🔒' # is this a bot account? if profile_json.get('type'): if isinstance(profile_json['type'], str): - bot_prefix = get_display_name_prefix(profile_json['type'], - search_nickname, - translate) + bot_prefix: str = \ + get_display_name_prefix(profile_json['type'], search_nickname, + translate) if bot_prefix: display_name = bot_prefix + ' ' + display_name - pronouns = get_pronouns(profile_json) - discord = get_discord(profile_json) - art_site_url = get_art_site_url(profile_json) - music_site_url = get_music_site_url(profile_json) - youtube = get_youtube(profile_json) - peertube = get_peertube(profile_json) - pixelfed = get_pixelfed(profile_json) - donate_url = get_donation_url(profile_json) - blog_url = get_blog_address(profile_json) - lxmf_address = get_lxmf_address(profile_json) + pronouns: str = get_pronouns(profile_json) + discord: str = get_discord(profile_json) + art_site_url: str = get_art_site_url(profile_json) + music_site_url: str = get_music_site_url(profile_json) + youtube: str = get_youtube(profile_json) + peertube: str = get_peertube(profile_json) + pixelfed: str = get_pixelfed(profile_json) + donate_url: str = get_donation_url(profile_json) + blog_url: str = get_blog_address(profile_json) + lxmf_address: str = get_lxmf_address(profile_json) moved_to: str = '' if profile_json.get('movedTo') or profile_json.get('copiedTo'): @@ -402,17 +402,17 @@ def html_profile_after_search(authorized: bool, moved_to = moved_to.split('"')[1] display_name += ' ⌂' - you_follow = \ + you_follow: str = \ is_following_actor(base_dir, nickname, domain, person_url) - follows_you = \ + follows_you: str = \ is_follower_of_person(base_dir, nickname, domain, search_nickname, search_domain_full) - profile_status = get_actor_status(profile_json) + profile_status: str = get_actor_status(profile_json) if profile_status: if actor_status_expired(profile_json['sm:status']): profile_status: str = '' @@ -436,9 +436,9 @@ def html_profile_after_search(authorized: bool, add_emoji_to_display_name(session, base_dir, http_prefix, nickname, domain, profile_description, False, translate) - featured_hashtags = \ + featured_hashtags: str = \ get_featured_hashtags_as_html(profile_json, profile_description) - outbox_url = None + outbox_url: str = None if not profile_json.get('outbox'): if debug: pprint(profile_json) @@ -453,11 +453,11 @@ def html_profile_after_search(authorized: bool, # profileBackgroundImage = remove_html(url_str) # url to return to - back_url = path + back_url: str = path if not back_url.endswith('/inbox'): back_url += '/inbox' - profile_description_short = \ + profile_description_short: str = \ _get_profile_short_description(profile_description) # remove formatting from profile description used on title avatar_description: str = '' @@ -473,26 +473,26 @@ def html_profile_after_search(authorized: bool, image_url: str = '' if profile_json.get('image'): if profile_json['image'].get('url'): - url_str = get_url_from_post(profile_json['image']['url']) + url_str: str = get_url_from_post(profile_json['image']['url']) image_url = remove_html(url_str) - also_known_as = None + also_known_as: str = None if profile_json.get('alsoKnownAs'): also_known_as = remove_html(profile_json['alsoKnownAs']) elif profile_json.get('sameAs'): also_known_as = remove_html(profile_json['sameAs']) - joined_date = None + joined_date: str = None if profile_json.get('published'): if 'T' in profile_json['published']: joined_date = remove_html(profile_json['published']) - available = get_availability(base_dir, nickname, domain, profile_json) + available: str = get_availability(base_dir, nickname, domain, profile_json) - actor_proxied = ap_proxy_type(profile_json) + actor_proxied: str = ap_proxy_type(profile_json) - website_url = get_website(profile_json, translate) - repo_url = get_repo_url(profile_json) + website_url: str = get_website(profile_json, translate) + repo_url: str = get_repo_url(profile_json) # is sending posts to this account blocked? send_blocks_str: str = '' @@ -511,7 +511,7 @@ def html_profile_after_search(authorized: bool, if profile_json.get('vcard:bday'): birth_date = profile_json['vcard:bday'] - profile_str = \ + profile_str: str = \ _get_profile_header_after_search(base_dir, nickname, domain, default_timeline, search_nickname, @@ -539,7 +539,7 @@ def html_profile_after_search(authorized: bool, art_site_url, donate_url) - domain_full = get_full_domain(domain, port) + domain_full: str = get_full_domain(domain, port) follow_is_permitted: bool = True if not profile_json.get('followers'): @@ -552,12 +552,12 @@ def html_profile_after_search(authorized: bool, # don't follow yourself! follow_is_permitted = False - blocked = \ + blocked: bool = \ is_blocked(base_dir, nickname, domain, search_nickname, search_domain, None, None) if follow_is_permitted: - follow_str = 'Follow' + follow_str: str = 'Follow' if is_group: follow_str = 'Join' @@ -615,9 +615,9 @@ def html_profile_after_search(authorized: bool, ' \n' + \ '\n' - text_mode_separator = '

' + text_mode_separator: str = '

' - user_feed = \ + user_feed: list[dict] = \ parse_user_feed(signing_priv_key_pem, session, outbox_url, as_header, project_version, http_prefix, from_domain, debug, 0, @@ -637,13 +637,13 @@ def html_profile_after_search(authorized: bool, if str(item['type']) == 'Announce' and \ isinstance(item['object'], str): # resolve the announce - profile_str2 = 'https://www.w3.org/ns/activitystreams' - as_header2_str = 'application/ld+json; profile="' + \ + profile_str2: str = 'https://www.w3.org/ns/activitystreams' + as_header2_str: str = 'application/ld+json; profile="' + \ profile_str2 + '"' - as_header2 = { + as_header2: dict = { 'Accept': as_header2_str } - item = \ + item: dict = \ get_json(signing_priv_key_pem, session, item['object'], as_header2, None, debug, mitm_servers, __version__, http_prefix, from_domain) @@ -665,9 +665,10 @@ def html_profile_after_search(authorized: bool, continue # get the list of mutuals for the current account - mutuals_list = get_mutuals_of_person(base_dir, nickname, domain) + mutuals_list: list[str] = \ + get_mutuals_of_person(base_dir, nickname, domain) - profile_post_html = \ + profile_post_html: str = \ individual_post_as_html(signing_priv_key_pem, True, recent_posts_cache, max_recent_posts, @@ -716,7 +717,7 @@ def html_profile_after_search(authorized: bool, elif is_private_browser(ua_str): profile_str = replace_embedded_map_with_link(profile_str, translate) - instance_title = get_config_param(base_dir, 'instanceTitle') + instance_title: str = get_config_param(base_dir, 'instanceTitle') preload_images: list[str] = [] return html_header_with_external_style(css_filename, instance_title, None, @@ -760,7 +761,7 @@ def _get_profile_header(base_dir: str, http_prefix: str, nickname: str, """ banner_file, _ = \ get_profile_background_file(base_dir, nickname, domain, theme) - html_str = \ + html_str: str = \ '\n\n
\n' + \ ' @' + \ new_nickname + '@' + new_domain_full + '
\n' elif also_known_as: - other_accounts_html = \ + other_accounts_html: str = \ '

' + translate['Other accounts'] + ': ' - actor = local_actor_url(http_prefix, nickname, domain_full) + actor: str = local_actor_url(http_prefix, nickname, domain_full) ctr: int = 0 if isinstance(also_known_as, list): for alt_actor in also_known_as: @@ -870,7 +871,7 @@ def _get_profile_header(base_dir: str, http_prefix: str, nickname: str, if ctr > 0: html_str += other_accounts_html if is_valid_date(birth_date): - birth_date = remove_html(birth_date) + birth_date: str = remove_html(birth_date) html_str += \ '

' + translate['Birthday'] + ': ' + \ birth_date + '

\n' @@ -885,7 +886,7 @@ def _get_profile_header(base_dir: str, http_prefix: str, nickname: str, if profile_status: # https://codeberg.org/fediverse/fep/src/branch/main/ # fep/82f6/fep-82f6.md - status_str = 'Status' + status_str: str = 'Status' if translate.get('Status'): status_str = translate['Status'] html_str += \ @@ -962,7 +963,7 @@ def _get_profile_header_after_search(base_dir: str, """ if not image_url: image_url = '/defaultprofilebackground' - html_str = \ + html_str: str = \ '\n\n
\n' + \ '
\n' if joined_date: - joined_str = translate['Joined'] + joined_str: str = translate['Joined'] if time_days_ago(joined_date) < 7: joined_str = '' + translate['New account'] + '' html_str += '

' + joined_str + ' ' + \ @@ -1027,15 +1028,15 @@ def _get_profile_header_after_search(base_dir: str, if send_blocks_str: html_str += '

' + send_blocks_str + '

\n' if moved_to: - new_nickname = get_nickname_from_actor(moved_to) + new_nickname: str = get_nickname_from_actor(moved_to) new_domain, new_port = get_domain_from_actor(moved_to) if new_nickname and new_domain: - new_domain_full = get_full_domain(new_domain, new_port) - new_handle = new_nickname + '@' + new_domain_full + new_domain_full: str = get_full_domain(new_domain, new_port) + new_handle: str = new_nickname + '@' + new_domain_full html_str += '

' + translate['New account'] + \ ': @' + new_handle + '

\n' elif also_known_as: - other_accounts_html = \ + other_accounts_html: str = \ '

' + translate['Other accounts'] + ': ' ctr: int = 0 @@ -1064,7 +1065,7 @@ def _get_profile_header_after_search(base_dir: str, if ctr > 0: html_str += other_accounts_html if is_valid_date(birth_date): - birth_date = remove_html(birth_date) + birth_date: str = remove_html(birth_date) html_str += \ '

' + translate['Birthday'] + ': ' + \ birth_date + '

\n' @@ -1074,7 +1075,7 @@ def _get_profile_header_after_search(base_dir: str, html_str += '

🌐 ' + \ website_url + '

\n' if blog_url: - blog_str = 'Blog' + blog_str: str = 'Blog' if translate.get('Blog'): blog_str = translate['Blog'] html_str += '

' + blog_str + ': ' + \ @@ -1095,7 +1096,7 @@ def _get_profile_header_after_search(base_dir: str, html_str += '

Discord: ' + \ discord + '

\n' if donate_url: - donate_str = 'Donate' + donate_str: str = 'Donate' if translate.get('Donate'): donate_str = translate['Donate'] html_str += '

' + donate_str + ': ' + \ repo_url + '

\n' if profile_status: - status_str = 'Status' + status_str: str = 'Status' if translate.get('Status'): status_str = translate['Status'] html_str += \ @@ -1120,11 +1121,11 @@ def _get_profile_header_after_search(base_dir: str, featured_hashtags # show any notes about this account if authorized: - handle = search_nickname + '@' + search_domain_full - person_notes = \ + handle: str = search_nickname + '@' + search_domain_full + person_notes: str = \ get_person_notes(base_dir, nickname, domain, handle) if person_notes: - person_notes_html = person_notes.replace('\n', '
') + person_notes_html: str = person_notes.replace('\n', '
') html_str += '

' + \ translate['Notes'].upper() + ': ' + \ person_notes_html + '

\n' @@ -1184,11 +1185,11 @@ def html_profile(signing_priv_key_pem: str, """ show_moved_accounts: bool = False if authorized: - moved_accounts_filename = data_dir(base_dir) + '/actors_moved.txt' + moved_accounts_filename: str = data_dir(base_dir) + '/actors_moved.txt' if is_a_file(moved_accounts_filename): show_moved_accounts = True - nickname = profile_json['preferredUsername'] + nickname: str = profile_json['preferredUsername'] if not nickname: return "" if is_system_account(nickname): @@ -1221,7 +1222,7 @@ def html_profile(signing_priv_key_pem: str, domain, port = get_domain_from_actor(profile_json['id']) if not domain: return "" - display_name = remove_html(profile_json['name']) + display_name: str = remove_html(profile_json['name']) display_name = standardize_text(display_name) display_name = \ add_emoji_to_display_name(session, base_dir, http_prefix, @@ -1236,8 +1237,8 @@ def html_profile(signing_priv_key_pem: str, if bot_prefix: display_name = bot_prefix + ' ' + display_name - domain_full = get_full_domain(domain, port) - profile_status = get_actor_status(profile_json) + domain_full: str = get_full_domain(domain, port) + profile_status: str = get_actor_status(profile_json) if profile_status: if actor_status_expired(profile_json['sm:status']): profile_status: str = '' @@ -1260,16 +1261,16 @@ def html_profile(signing_priv_key_pem: str, profile_description, False, translate) if profile_description: profile_description = standardize_text(profile_description) - featured_hashtags = \ + featured_hashtags: str = \ get_featured_hashtags_as_html(profile_json, profile_description) - posts_button = 'button' - following_button = 'button' - moved_button = 'button' - moved_button = 'button' - inactive_button = 'button' - followers_button = 'button' - roles_button = 'button' - skills_button = 'button' + posts_button: str = 'button' + following_button: str = 'button' + moved_button: str = 'button' + moved_button: str = 'button' + inactive_button: str = 'button' + followers_button: str = 'button' + roles_button: str = 'button' + skills_button: str = 'button' # shares_button = 'button' # wanted_button = 'button' if selected == 'posts': @@ -1296,36 +1297,36 @@ def html_profile(signing_priv_key_pem: str, follow_approvals: bool = False edit_profile_str: str = '' logout_str: str = '' - actor = profile_json['id'] - users_path = '/users/' + actor.split('/users/')[1] + actor: str = profile_json['id'] + users_path: str = '/users/' + actor.split('/users/')[1] donate_section: str = '' - donate_url = get_donation_url(profile_json) - website_url = get_website(profile_json, translate) - repo_url = get_repo_url(profile_json) - gemini_link = get_gemini_link(profile_json) - blog_address = get_blog_address(profile_json) - enigma_pub_key = get_enigma_pub_key(profile_json) - pgp_pub_key = get_pgp_pub_key(profile_json) - pgp_fingerprint = get_pgp_fingerprint(profile_json) - email_address = get_email_address(profile_json) - deltachat_invite = get_deltachat_invite(profile_json, translate) - pronouns = get_pronouns(profile_json) - pixelfed = get_pixelfed(profile_json) - discord = get_discord(profile_json) - art_site_url = get_art_site_url(profile_json) - music_site_url = get_music_site_url(profile_json) - youtube = get_youtube(profile_json) - peertube = get_peertube(profile_json) - xmpp_address = get_xmpp_address(profile_json) - matrix_address = get_matrix_address(profile_json) - ssb_address = get_ssb_address(profile_json) - tox_address = get_tox_address(profile_json) - lxmf_address = get_lxmf_address(profile_json) - briar_address = get_briar_address(profile_json) - cwtch_address = get_cwtch_address(profile_json) - verified_site_checkmark = '✔' - premium = is_premium_account(base_dir, nickname, domain) + donate_url: str = get_donation_url(profile_json) + website_url: str = get_website(profile_json, translate) + repo_url: str = get_repo_url(profile_json) + gemini_link: str = get_gemini_link(profile_json) + blog_address: str = get_blog_address(profile_json) + enigma_pub_key: str = get_enigma_pub_key(profile_json) + pgp_pub_key: str = get_pgp_pub_key(profile_json) + pgp_fingerprint: str = get_pgp_fingerprint(profile_json) + email_address: str = get_email_address(profile_json) + deltachat_invite: str = get_deltachat_invite(profile_json, translate) + pronouns: str = get_pronouns(profile_json) + pixelfed: str = get_pixelfed(profile_json) + discord: str = get_discord(profile_json) + art_site_url: str = get_art_site_url(profile_json) + music_site_url: str = get_music_site_url(profile_json) + youtube: str = get_youtube(profile_json) + peertube: str = get_peertube(profile_json) + xmpp_address: str = get_xmpp_address(profile_json) + matrix_address: str = get_matrix_address(profile_json) + ssb_address: str = get_ssb_address(profile_json) + tox_address: str = get_tox_address(profile_json) + lxmf_address: str = get_lxmf_address(profile_json) + briar_address: str = get_briar_address(profile_json) + cwtch_address: str = get_cwtch_address(profile_json) + verified_site_checkmark: str = '✔' + premium: bool = is_premium_account(base_dir, nickname, domain) if donate_url or website_url or repo_url or pronouns or discord or \ art_site_url or music_site_url or youtube or peertube or pixelfed or \ xmpp_address or matrix_address or \ @@ -1335,7 +1336,7 @@ def html_profile(signing_priv_key_pem: str, donate_section = '
\n' donate_section += '
\n' if donate_url and not is_system_account(nickname): - donate_str = translate['Donate'] + donate_str: str = translate['Donate'] if premium: donate_str = translate['Subscribe'] donate_section += \ @@ -1482,14 +1483,14 @@ def html_profile(signing_priv_key_pem: str, donate_section += '
\n' if authorized: - edit_profile_str = \ + edit_profile_str: str = \ '' + \ '| ' + translate['Edit'] + '\n' - logout_str = \ + logout_str: str = \ '' + \ '\n' # are there any follow requests? - follow_requests_filename = \ + follow_requests_filename: str = \ acct_dir(base_dir, nickname, domain) + '/followrequests.txt' if is_a_file(follow_requests_filename): follow_requests_list: list[str] = \ @@ -1515,7 +1516,7 @@ def html_profile(signing_priv_key_pem: str, break if selected == 'followers': if follow_approvals: - curr_follower_domains = \ + curr_follower_domains: str = \ get_follower_domains(base_dir, nickname, domain) follow_requests_list: list[str] = \ load_list(follow_requests_filename, @@ -1525,13 +1526,13 @@ def html_profile(signing_priv_key_pem: str, for follower_handle in follow_requests_list: if not follower_handle: continue - follower_handle = remove_eol(follower_handle) + follower_handle: str = remove_eol(follower_handle) if '://' in follower_handle: - follower_actor = follower_handle + follower_actor: str = follower_handle else: - nick = follower_handle.split('@')[0] - dom = follower_handle.split('@')[1] - follower_actor = \ + nick: str = follower_handle.split('@')[0] + dom: str = follower_handle.split('@')[1] + follower_actor: str = \ local_actor_url(http_prefix, nick, dom) # is this a new domain? @@ -1544,7 +1545,7 @@ def html_profile(signing_priv_key_pem: str, # Show the handle of the potential follower # being approved, linking to search on that handle - base_path = '/users/' + nickname + base_path: str = '/users/' + nickname follow_approvals_section += \ '
\n' + \ '
\n' @@ -1808,11 +1810,11 @@ def html_profile(signing_priv_key_pem: str, profile_str += follow_approvals_section - css_filename = base_dir + '/epicyon-profile.css' + css_filename: str = base_dir + '/epicyon-profile.css' if is_a_file(base_dir + '/epicyon.css'): css_filename = base_dir + '/epicyon.css' - license_str = \ + license_str: str = \ '' + \ '' + \
         translate['Get the source code'] + ' bool: """Is grayscale UI enabled? """ - dir_str = data_dir(base_dir) + dir_str: str = data_dir(base_dir) return is_a_file(dir_str + '/.grayscale') @@ -2199,20 +2200,20 @@ def _html_themes_dropdown(base_dir: str, translate: {}) -> str: """Returns the html for theme selection dropdown """ # Themes section - themes = get_themes_list(base_dir) + themes: list[str] = get_themes_list(base_dir) themes_dropdown = '
\n' - grayscale = _grayscale_enabled(base_dir) + grayscale: bool = _grayscale_enabled(base_dir) themes_dropdown += \ edit_check_box(translate['Grayscale'], 'grayscale', grayscale) - dyslexic_font = get_config_param(base_dir, 'dyslexicFont') + dyslexic_font: bool = get_config_param(base_dir, 'dyslexicFont') themes_dropdown += \ edit_check_box(translate['Dyslexic font'], 'dyslexicFont', dyslexic_font) themes_dropdown += '

\n' @@ -2746,7 +2747,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, '
\n' city: str = '' - city_filename = acct_dir(base_dir, nickname, domain) + '/city.txt' + city_filename: str = acct_dir(base_dir, nickname, domain) + '/city.txt' if is_a_file(city_filename): city1 = \ load_string(city_filename, @@ -2754,7 +2755,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, city_filename) if city1: city = remove_eol(city1) - locations_filename = base_dir + '/custom_locations.txt' + locations_filename: str = base_dir + '/custom_locations.txt' if not is_a_file(locations_filename): locations_filename = base_dir + '/locations.txt' cities: list[str] = \ @@ -2814,7 +2815,7 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, ' \n' - idx = 'Blocked accounts, one per line, in the form ' + \ + idx: str = 'Blocked accounts, one per line, in the form ' + \ 'nickname@domain or *@blockeddomain' edit_profile_form += \ edit_text_area(translate['Blocked accounts'], None, 'blocked', @@ -2823,13 +2824,13 @@ def _html_edit_profile_filtering(base_dir: str, nickname: str, domain: str, # import and export blocks edit_profile_form += _import_export_blocks(translate) - idx = 'Direct messages are always allowed from these instances.' + idx: str = 'Direct messages are always allowed from these instances.' edit_profile_form += \ edit_text_area(translate['Direct Message permitted instances'], None, 'dmAllowedInstances', dm_allowed_instances_str, 200, '', False) - idx = 'Federate only with a defined set of instances. ' + \ + idx: str = 'Federate only with a defined set of instances. ' + \ 'One domain name per line.' edit_profile_form += \ '

' + \ '


\n' - followers_str = translate['Followers'] + followers_str: str = translate['Followers'] if premium: followers_str = translate['Fans'] edit_profile_form += \ @@ -3189,9 +3190,9 @@ def _html_edit_profile_encryption_keys(pgp_fingerprint: str, translate: {}) -> str: """Contact Information section of edit profile screen """ - edit_profile_form = begin_edit_section(translate['Encryption Keys']) + edit_profile_form: str = begin_edit_section(translate['Encryption Keys']) - enigma_url = 'https://github.com/enigma-reloaded/enigma-reloaded' + enigma_url: str = 'https://github.com/enigma-reloaded/enigma-reloaded' edit_profile_form += \ edit_text_field('Enigma', 'enigmapubkey', enigma_pub_key) @@ -3213,24 +3214,26 @@ def _html_edit_profile_reply_controls(translate: {}, no_reply_boosts: bool) -> str: """option checkboxes for reply controls """ - edit_profile_form = begin_edit_section(translate['Reply Controls']) + edit_profile_form: str = begin_edit_section(translate['Reply Controls']) edit_profile_form += \ edit_check_box(translate['Only people I follow can send me DMs'], 'followDMs', follow_dms) - show_replies_followers_str = translate['Only allow replies from followers'] + show_replies_followers_str: str = \ + translate['Only allow replies from followers'] if premium: show_replies_followers_str = translate['Only allow replies from fans'] edit_profile_form += \ edit_check_box(show_replies_followers_str, 'repliesFromFollowersOnly', show_replies_followers) - show_replies_mutuals_str = translate['Only allow replies from mutuals'] + show_replies_mutuals_str: str = \ + translate['Only allow replies from mutuals'] edit_profile_form += \ edit_check_box(show_replies_mutuals_str, 'repliesFromMutualsOnly', show_replies_mutuals) - no_reply_boosts_str = translate["Don't show boosted replies"] + no_reply_boosts_str: str = translate["Don't show boosted replies"] edit_profile_form += \ edit_check_box(no_reply_boosts_str, 'noReplyBoosts', no_reply_boosts) edit_profile_form += end_edit_section() @@ -3258,10 +3261,10 @@ def _html_edit_profile_options(is_admin: bool, watermark_enabled: bool) -> str: """option checkboxes section of edit profile screen """ - edit_profile_form = '
\n' + edit_profile_form: str = '
\n' edit_profile_form += \ edit_check_box(translate['Premium account'], 'premiumAccount', premium) - approve_followers_str = translate['Approve follower requests'] + approve_followers_str: str = translate['Approve follower requests'] if premium: approve_followers_str = translate['Approve fans'] edit_profile_form += \ @@ -3293,14 +3296,14 @@ def _html_edit_profile_options(is_admin: bool, edit_check_box(translate["Don't show the Reaction button"], 'hideReactionButton', hide_reaction_button) - bold_str = bold_reading_string(translate['Bold reading']) + bold_str: str = bold_reading_string(translate['Bold reading']) edit_profile_form += \ edit_check_box(bold_str, 'boldReading', bold_reading) minimize_all_images: bool = False if nickname in min_images_for_accounts: minimize_all_images = True - minimize_all_images_str = translate['Minimize all images'] + minimize_all_images_str: str = translate['Minimize all images'] edit_profile_form += \ edit_check_box(minimize_all_images_str, 'minimizeAllImages', minimize_all_images) @@ -3308,35 +3311,35 @@ def _html_edit_profile_options(is_admin: bool, reverse: bool = False if nickname in reverse_sequence: reverse = True - reverse_str = translate['Reverse timelines'] + reverse_str: str = translate['Reverse timelines'] edit_profile_form += \ edit_check_box(reverse_str, 'reverseTimelines', reverse) - show_quote_toots_str = translate['Show quote posts'] + show_quote_toots_str: str = translate['Show quote posts'] edit_profile_form += \ edit_check_box(show_quote_toots_str, 'showQuotes', show_quote_toots) - show_vote_posts_str = translate['Show vote posts'] + show_vote_posts_str: str = translate['Show vote posts'] edit_profile_form += \ edit_check_box(show_vote_posts_str, 'showVotes', show_vote_posts) - hide_follows_str = translate['Do not show follows on your profile'] + hide_follows_str: str = translate['Do not show follows on your profile'] if premium: hide_follows_str = translate['Do not show fans on your profile'] edit_profile_form += \ edit_check_box(hide_follows_str, 'hideFollows', hide_follows) - hide_recent_posts_str = \ + hide_recent_posts_str: str = \ translate["Don't show recent public posts on your profile"] edit_profile_form += \ edit_check_box(hide_recent_posts_str, 'hideRecentPosts', hide_recent_posts) - no_seen_posts_str = translate["Don't show already seen posts"] + no_seen_posts_str: str = translate["Don't show already seen posts"] edit_profile_form += \ edit_check_box(no_seen_posts_str, 'noSeenPosts', no_seen_posts) - watermark_str = translate["Apply a watermark to uploaded images"] + watermark_str: str = translate["Apply a watermark to uploaded images"] edit_profile_form += \ edit_check_box(watermark_str, 'watermarkEnabled', watermark_enabled) @@ -3370,9 +3373,9 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, featured_hashtags: str) -> str: """main info on edit profile screen """ - image_formats = get_image_formats() + image_formats: list[str] = get_image_formats() - edit_profile_form = '
\n' + edit_profile_form: str = '
\n' edit_profile_form += \ edit_text_field(translate['Nickname'], 'displayNickname', @@ -3387,7 +3390,7 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, 200, '', True) birth_date: str = '' - birth_date_field = 'vcard:bday' + birth_date_field: str = 'vcard:bday' if actor_json.get(birth_date_field): if '-' in actor_json[birth_date_field]: if len(actor_json[birth_date_field].split('-')) == 3: @@ -3420,7 +3423,7 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, also_known_as_str: str = '' if actor_json.get('alsoKnownAs'): - also_known_as = actor_json['alsoKnownAs'] + also_known_as: str = actor_json['alsoKnownAs'] ctr: int = 0 for alt_actor in also_known_as: if ctr > 0: @@ -3436,7 +3439,7 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, edit_text_field(translate['Moved to new account address'], 'movedTo', moved_to, 'https://...') - donate_str = translate['Donations link'] + donate_str: str = translate['Donations link'] if is_premium_account(base_dir, nickname, domain): donate_str = translate['Premium account subscription link'] edit_profile_form += \ @@ -3453,30 +3456,30 @@ def _html_edit_profile_main(base_dir: str, display_nickname: str, edit_profile_form += \ edit_text_field('Blog', 'blogAddress', blog_address, 'https://...') - languages_list_str = _get_supported_languagesSorted(base_dir) - show_languages = get_actor_languages(actor_json) + languages_list_str: str = _get_supported_languagesSorted(base_dir) + show_languages: str = get_actor_languages(actor_json) edit_profile_form += \ edit_text_field(translate['Languages'], 'showLanguages', show_languages, languages_list_str) - timezone = get_account_timezone(base_dir, nickname, domain) + timezone: str = get_account_timezone(base_dir, nickname, domain) edit_profile_form += \ edit_text_field(translate['Time Zone'], 'timeZone', timezone, 'Europe/London') - keep_dms = get_post_expiry_keep_dms(base_dir, nickname, domain) + keep_dms: int = get_post_expiry_keep_dms(base_dir, nickname, domain) edit_profile_form += '
\n' + \ edit_check_box(translate['Keep DMs during post expiry'], 'expiryKeepDMs', keep_dms) - post_expiry_period_days = \ + post_expiry_period_days: int = \ get_post_expiry_days(base_dir, nickname, domain) edit_profile_form += '

' + \ edit_number_field(translate['Post expiry period in days'], 'postExpiryPeriod', post_expiry_period_days, 0, 9999999999999999999999, 0) + '

\n' - max_profile_posts = \ + max_profile_posts: int = \ get_max_profile_posts(base_dir, nickname, domain, max_recent_posts) edit_profile_form += '

' + \ edit_number_field(translate['Preview posts on profile screen'], @@ -3494,7 +3497,7 @@ def _html_edit_profile_top_banner(base_dir: str, translate: {}) -> str: """top banner on edit profile screen """ - edit_profile_form = \ + edit_profile_form: str = \ '' + \ ' str: """An individual follow entry on the profile screen """ - follow_url_nickname = get_nickname_from_actor(follow_url) + follow_url_nickname: str = get_nickname_from_actor(follow_url) if not follow_url_nickname: return '' follow_url_domain, follow_url_port = get_domain_from_actor(follow_url) if not follow_url_domain: return '' - follow_url_domain_full = \ + follow_url_domain_full: str = \ get_full_domain(follow_url_domain, follow_url_port) - title_str = '@' + follow_url_nickname + '@' + follow_url_domain_full - avatar_url = \ + title_str: str = '@' + follow_url_nickname + '@' + follow_url_domain_full + avatar_url: str = \ get_person_avatar_url(base_dir, follow_url, person_cache) if not avatar_url: avatar_url = follow_url + '/avatar.png' - display_name = get_display_name(base_dir, follow_url, person_cache) + display_name: str = get_display_name(base_dir, follow_url, person_cache) is_group: bool = False if not display_name: # lookup the correct webfinger for the follow_url - follow_url_handle = follow_url_nickname + '@' + follow_url_domain_full + follow_url_handle: str = \ + follow_url_nickname + '@' + follow_url_domain_full follow_url_wf = \ webfinger_handle(session, follow_url_handle, http_prefix, cached_webfingers, @@ -3979,13 +3983,13 @@ def _individual_follow_as_html(signing_priv_key_pem: str, avatar_url = avatar_url2 if display_name: - display_name = \ + display_name: str = \ add_emoji_to_display_name(None, base_dir, http_prefix, actor_nickname, domain, display_name, False, translate) - actor_type = get_actor_type(base_dir, follow_url, person_cache) - bot_prefix = get_display_name_prefix(actor_type, - actor_nickname, translate) + actor_type: str = get_actor_type(base_dir, follow_url, person_cache) + bot_prefix: str = get_display_name_prefix(actor_type, + actor_nickname, translate) if bot_prefix: display_name = bot_prefix + ' ' + display_name diff --git a/webapp_pwa.py b/webapp_pwa.py index a3bb7e4f0..51f4e6997 100644 --- a/webapp_pwa.py +++ b/webapp_pwa.py @@ -17,7 +17,7 @@ def _get_variable_from_css(css_str: str, variable: str) -> str: """ if '--' + variable + ':' not in css_str: return None - value = css_str.split('--' + variable + ':')[1] + value: str = css_str.split('--' + variable + ':')[1] if ';' in value: value = value.split(';')[0].strip() value = remove_html(value) @@ -29,18 +29,18 @@ def _get_variable_from_css(css_str: str, variable: str) -> str: def get_pwa_theme_colors(css_filename: str) -> (str, str): """Gets the theme/statusbar color for progressive web apps """ - default_pwa_theme_color = 'apple-mobile-web-app-status-bar-style' - pwa_theme_color = default_pwa_theme_color + default_pwa_theme_color: str = 'apple-mobile-web-app-status-bar-style' + pwa_theme_color: str = default_pwa_theme_color - default_pwa_theme_background_color = 'black-translucent' - pwa_theme_background_color = default_pwa_theme_background_color + default_pwa_theme_background_color: str = 'black-translucent' + pwa_theme_background_color: str = default_pwa_theme_background_color if not is_a_file(css_filename): return pwa_theme_color, pwa_theme_background_color - css_str = load_string(css_filename, - 'EX: get_pwa_theme_colors unable to read ' + - css_filename) + css_str: str = load_string(css_filename, + 'EX: get_pwa_theme_colors unable to read ' + + css_filename) if css_str is None: css_str: str = '' @@ -60,13 +60,13 @@ def get_pwa_theme_colors(css_filename: str) -> (str, str): def pwa_manifest(base_dir: str) -> {}: """Returns progressive web app manifest """ - css_filename = base_dir + '/epicyon.css' + css_filename: str = base_dir + '/epicyon.css' pwa_theme_color, pwa_theme_background_color = \ get_pwa_theme_colors(css_filename) - app1 = "https://f-droid.org/en/packages/eu.siacs.conversations" - app2 = "https://staging.f-droid.org/en/packages/im.vector.app" - app3 = \ + app1: str = "https://f-droid.org/en/packages/eu.siacs.conversations" + app2: str = "https://staging.f-droid.org/en/packages/im.vector.app" + app3: str = \ "https://f-droid.org/en/packages/" + \ "com.stoutner.privacybrowser.standard" return {