Replace repeated replacements

main
Bob Mottram 2024-08-09 13:29:22 +01:00
parent d2251eb173
commit f486eecaa7
8 changed files with 73 additions and 23 deletions

View File

@ -87,6 +87,7 @@ from httpcodes import http_304
from httpcodes import http_400
from httpcodes import http_503
from httpcodes import write2
from utils import replace_strings
from utils import contains_invalid_chars
from utils import save_json
from utils import data_dir
@ -1565,8 +1566,11 @@ def daemon_http_get(self) -> None:
if '/' in nickname:
nickname = nickname.split('/')[0]
episode_timestamp = self.path.split('?podepisode=')[1].strip()
episode_timestamp = episode_timestamp.replace('__', ' ')
episode_timestamp = episode_timestamp.replace('aa', ':')
replacements = {
'__': ' ',
'aa': ':'
}
episode_timestamp = replace_strings(episode_timestamp, replacements)
if self.server.newswire.get(episode_timestamp):
pod_episode = self.server.newswire[episode_timestamp]
html_str = \

View File

@ -11,6 +11,7 @@ import os
import errno
import urllib.parse
from socket import error as SocketError
from utils import replace_strings
from utils import remove_post_from_cache
from utils import get_cached_post_filename
from utils import load_json
@ -124,8 +125,11 @@ def receive_vote(self, calling_domain: str, cookie: str,
self.server.postreq_busy = False
return
question_params = question_params.replace('+', ' ')
question_params = question_params.replace('%3F', '')
replacements = {
'+': ' ',
'%3F': ''
}
question_params = replace_strings(question_params, replacements)
question_params = \
urllib.parse.unquote_plus(question_params.strip())

View File

@ -1312,9 +1312,13 @@ def _desktop_show_box(indent: str,
# say the post number range
say_str = indent + box_name_str + ' page ' + str(page_number) + \
' containing ' + str(ctr - 1) + ' posts. '
say_str2 = say_str.replace('\33[3m', '').replace('\33[0m', '')
say_str2 = say_str2.replace('show dm', 'show DM')
say_str2 = say_str2.replace('dm post', 'Direct message post')
replacements = {
'\33[3m': '',
'\33[0m': '',
'show dm': 'show DM',
'dm post': 'Direct message post'
}
say_str2 = replace_strings(say_str, replacements)
_say_command(say_str, say_str2, screenreader, system_language, espeak)
print('')
return True

View File

@ -55,6 +55,7 @@ from follow import clear_followers
from follow import send_follow_request_via_server
from follow import send_unfollow_request_via_server
from siteactive import site_is_active
from utils import replace_strings
from utils import valid_content_warning
from utils import data_dir
from utils import data_dir_testing
@ -5288,6 +5289,10 @@ def _test_checkbox_names():
print('test_checkbox_names')
fnames = ['edit_text_field', 'edit_check_box', 'edit_text_area']
replacements = {
'"': '',
"'": ''
}
for _, _, files in os.walk('.'):
for source_file in files:
if not source_file.endswith('.py'):
@ -5315,8 +5320,8 @@ def _test_checkbox_names():
if len(allparams_list) < 2:
continue
param_var_name = allparams_list[1].strip()
param_var_name = param_var_name.replace('"', '')
param_var_name = param_var_name.replace("'", '')
param_var_name = \
replace_strings(param_var_name, replacements)
if ' ' in param_var_name:
continue
if '/' in param_var_name:

View File

@ -8,6 +8,7 @@ __status__ = "Production"
__module_group__ = "Web Interface Columns"
import os
from utils import replace_strings
from utils import data_dir
from utils import get_config_param
from utils import get_nickname_from_actor
@ -440,8 +441,14 @@ def html_edit_links(translate: {}, base_dir: str, path: str,
"""
if '/users/' not in path:
return ''
path = path.replace('/inbox', '').replace('/outbox', '')
path = path.replace('/shares', '').replace('/wanted', '')
replacements = {
'/inbox': '',
'/outbox': '',
'/shares': '',
'/wanted': ''
}
path = replace_strings(path, replacements)
nickname = get_nickname_from_actor(path)
if not nickname:

View File

@ -10,6 +10,7 @@ __module_group__ = "Web Interface Columns"
import os
from content import remove_long_words
from content import limit_repeated_words
from utils import replace_strings
from utils import data_dir
from utils import get_image_extensions
from utils import get_fav_filename_from_url
@ -234,6 +235,14 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
"""
separator_str = html_post_separator(base_dir, 'right')
html_str = ''
replacements1 = {
'T': ' ',
'Z': ''
}
replacements2 = {
' ': '__',
':': 'aa'
}
for date_str, item in newswire.items():
item[0] = remove_html(item[0]).strip()
if not item[0]:
@ -251,8 +260,7 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
continue
date_shown = published_date.strftime("%Y-%m-%d %H:%M")
date_str_link = date_str.replace('T', ' ')
date_str_link = date_str_link.replace('Z', '')
date_str_link = replace_strings(date_str, replacements1)
url = item[1]
favicon_url = get_newswire_favicon_url(url)
favicon_link = ''
@ -286,8 +294,7 @@ def _html_newswire(base_dir: str, newswire: {}, nickname: str, moderator: bool,
podcast_properties = item[8]
if podcast_properties:
if podcast_properties.get('image'):
episode_id = date_str.replace(' ', '__')
episode_id = episode_id.replace(':', 'aa')
episode_id = replace_strings(date_str, replacements2)
link_url = \
'/users/' + nickname + '/?podepisode=' + episode_id
@ -565,8 +572,14 @@ def html_edit_newswire(translate: {}, base_dir: str, path: str,
"""
if '/users/' not in path:
return ''
path = path.replace('/inbox', '').replace('/outbox', '')
path = path.replace('/shares', '').replace('/wanted', '')
replacements = {
'/inbox': '',
'/outbox': '',
'/shares': '',
'/wanted': ''
}
path = replace_strings(path, replacements)
nickname = get_nickname_from_actor(path)
if not nickname:

View File

@ -10,6 +10,7 @@ __module_group__ = "Web Interface"
import os
from pprint import pprint
from webfinger import webfinger_handle
from utils import replace_strings
from utils import data_dir
from utils import is_premium_account
from utils import time_days_ago
@ -1294,8 +1295,11 @@ def html_profile(signing_priv_key_pem: str,
avatar_description = ''
if profile_json.get('summary'):
avatar_description = profile_json['summary'].replace('<br>', '\n')
avatar_description = avatar_description.replace('<p>', '')
avatar_description = avatar_description.replace('</p>', '')
replacements = {
'<p>': '',
'</p>': ''
}
avatar_description = replace_strings(avatar_description, replacements)
moved_to = ''
if profile_json.get('movedTo'):
@ -3119,8 +3123,13 @@ def html_edit_profile(server, translate: {},
block_federated_endpoints: []) -> str:
"""Shows the edit profile screen
"""
path = path.replace('/inbox', '').replace('/outbox', '')
path = path.replace('/shares', '').replace('/wanted', '')
replacements = {
'/inbox': '',
'/outbox': '',
'/shares': '',
'/wanted': ''
}
path = replace_strings(path, replacements)
nickname = get_nickname_from_actor(path)
if not nickname:
return ''

View File

@ -9,6 +9,7 @@ __module_group__ = "Onboarding"
import os
from shutil import copyfile
from utils import replace_strings
from utils import data_dir
from utils import remove_html
from utils import load_json
@ -118,8 +119,11 @@ def html_welcome_profile(base_dir: str, nickname: str, domain: str,
bio_str = ''
if actor_json.get('summary'):
bio_str = \
actor_json['summary'].replace('<p>', '').replace('</p>', '')
replacements = {
'<p>': '',
'</p>': ''
}
bio_str = replace_strings(actor_json['summary'], replacements)
if not bio_str:
bio_str = translate['Your bio']
profile_form += ' <label class="labels">' + \