diff --git a/daemon.py b/daemon.py index fff0482a0..943bc06b7 100644 --- a/daemon.py +++ b/daemon.py @@ -2922,7 +2922,8 @@ class PubServer(BaseHTTPRequestHandler): nw_filename = newswire_blocked_filename nw_written = False try: - with open(nw_filename, 'w+') as nofile: + with open(nw_filename, 'w+', + encoding='utf-8') as nofile: nofile.write('\n') nw_written = True except OSError as ex: @@ -5672,7 +5673,8 @@ class PubServer(BaseHTTPRequestHandler): city_filename = \ acct_dir(base_dir, nickname, domain) + '/city.txt' try: - with open(city_filename, 'w+') as fp_city: + with open(city_filename, 'w+', + encoding='utf-8') as fp_city: fp_city.write(fields['cityDropdown']) except OSError: print('EX: unable to write city ' + city_filename) @@ -6403,7 +6405,8 @@ class PubServer(BaseHTTPRequestHandler): # if the list was given as comma separated eds = fields['editors'].split(',') try: - with open(editors_file, 'w+') as edfil: + with open(editors_file, 'w+', + encoding='utf-8') as edfil: for ed_nick in eds: ed_nick = ed_nick.strip() ed_dir = base_dir + \ @@ -6428,8 +6431,8 @@ class PubServer(BaseHTTPRequestHandler): # nicknames on separate lines eds = fields['editors'].split('\n') try: - with open(editors_file, - 'w+') as edfile: + with open(editors_file, 'w+', + encoding='utf-8') as edfile: for ed_nick in eds: ed_nick = ed_nick.strip() ed_dir = \ @@ -8106,7 +8109,8 @@ class PubServer(BaseHTTPRequestHandler): if os.path.isfile(ontology_filename): ontology_file = None try: - with open(ontology_filename, 'r') as fp_ont: + with open(ontology_filename, 'r', + encoding='utf-8') as fp_ont: ontology_file = fp_ont.read() except OSError: print('EX: unable to read ontology ' + ontology_filename) @@ -11509,7 +11513,7 @@ class PubServer(BaseHTTPRequestHandler): return True ssml_str = None try: - with open(ssml_filename, 'r') as fp_ssml: + with open(ssml_filename, 'r', encoding='utf-8') as fp_ssml: ssml_str = fp_ssml.read() except OSError: pass @@ -18639,7 +18643,8 @@ class PubServer(BaseHTTPRequestHandler): media_tag_filename = media_filename + '.etag' if os.path.isfile(media_tag_filename): try: - with open(media_tag_filename, 'r') as efile: + with open(media_tag_filename, 'r', + encoding='utf-8') as efile: etag = efile.read() except OSError: print('EX: do_HEAD unable to read ' + @@ -18655,7 +18660,8 @@ class PubServer(BaseHTTPRequestHandler): if media_binary: etag = md5(media_binary).hexdigest() # nosec try: - with open(media_tag_filename, 'w+') as efile: + with open(media_tag_filename, 'w+', + encoding='utf-8') as efile: efile.write(etag) except OSError: print('EX: do_HEAD unable to write ' + diff --git a/happening.py b/happening.py index ee2fae65f..5ae099f21 100644 --- a/happening.py +++ b/happening.py @@ -615,7 +615,7 @@ def get_this_weeks_events(base_dir: str, nickname: str, domain: str) -> {}: calendar_post_ids = [] recreate_events_file = False - with open(calendar_filename, 'r') as events_file: + with open(calendar_filename, 'r', encoding='utf-8') as events_file: for post_id in events_file: post_id = post_id.replace('\n', '').replace('\r', '') post_filename = locate_post(base_dir, nickname, domain, post_id) diff --git a/inbox.py b/inbox.py index 797989d4a..b89f87aee 100644 --- a/inbox.py +++ b/inbox.py @@ -4170,7 +4170,8 @@ def _inbox_after_initial(server, inbox_start_time, print('MUTE REPLY: ' + destination_filename) destination_filename_muted = destination_filename + '.muted' try: - with open(destination_filename_muted, 'w+') as mute_file: + with open(destination_filename_muted, 'w+', + encoding='utf-8') as mute_file: mute_file.write('\n') except OSError: print('EX: unable to write ' + destination_filename_muted) @@ -4592,7 +4593,8 @@ def _check_json_signature(base_dir: str, queue_json: {}) -> (bool, bool): if not already_unknown: try: - with open(unknown_signatures_file, 'a+') as unknown_file: + with open(unknown_signatures_file, 'a+', + encoding='utf-8') as unknown_file: unknown_file.write(jwebsig_type + '\n') except OSError: print('EX: unable to append ' + unknown_signatures_file) diff --git a/manualapprove.py b/manualapprove.py index 7977415ef..734547e0d 100644 --- a/manualapprove.py +++ b/manualapprove.py @@ -117,13 +117,15 @@ def _approve_follower_handle(account_dir: str, approve_handle: str) -> None: if os.path.isfile(approved_filename): if not text_in_file(approve_handle, approved_filename): try: - with open(approved_filename, 'a+') as approved_file: + with open(approved_filename, 'a+', + encoding='utf-8') as approved_file: approved_file.write(approve_handle + '\n') except OSError: print('EX: unable to append ' + approved_filename) else: try: - with open(approved_filename, 'w+') as approved_file: + with open(approved_filename, 'w+', + encoding='utf-8') as approved_file: approved_file.write(approve_handle + '\n') except OSError: print('EX: unable to write ' + approved_filename) diff --git a/media.py b/media.py index c87a34dcd..ced8866c6 100644 --- a/media.py +++ b/media.py @@ -318,12 +318,13 @@ def _spoof_meta_data(base_dir: str, nickname: str, domain: str, decoy_seed_filename = acct_dir(base_dir, nickname, domain) + '/decoyseed' decoy_seed = 63725 if os.path.isfile(decoy_seed_filename): - with open(decoy_seed_filename, 'r') as fp_seed: + with open(decoy_seed_filename, 'r', encoding='utf-8') as fp_seed: decoy_seed = int(fp_seed.read()) else: decoy_seed = randint(10000, 10000000000000000) try: - with open(decoy_seed_filename, 'w+') as fp_seed: + with open(decoy_seed_filename, 'w+', + encoding='utf-8') as fp_seed: fp_seed.write(str(decoy_seed)) except OSError: print('EX: unable to write ' + decoy_seed_filename) diff --git a/person.py b/person.py index 5afced652..79899ba7d 100644 --- a/person.py +++ b/person.py @@ -522,7 +522,7 @@ def _create_person_base(base_dir: str, nickname: str, domain: str, port: int, os.mkdir(base_dir + private_keys_subdir) filename = base_dir + private_keys_subdir + '/' + handle + '.key' try: - with open(filename, 'w+') as text_file: + with open(filename, 'w+', encoding='utf-8') as text_file: print(private_key_pem, file=text_file) except OSError: print('EX: unable to save ' + filename) @@ -533,7 +533,7 @@ def _create_person_base(base_dir: str, nickname: str, domain: str, port: int, os.mkdir(base_dir + public_keys_subdir) filename = base_dir + public_keys_subdir + '/' + handle + '.pem' try: - with open(filename, 'w+') as text_file: + with open(filename, 'w+', encoding='utf-8') as text_file: print(public_key_pem, file=text_file) except OSError: print('EX: unable to save 2 ' + filename) diff --git a/webapp_column_left.py b/webapp_column_left.py index 94254b6e0..40897ce63 100644 --- a/webapp_column_left.py +++ b/webapp_column_left.py @@ -487,7 +487,7 @@ def html_edit_links(css_cache: {}, translate: {}, base_dir: str, path: str, links_filename = base_dir + '/accounts/links.txt' links_str = '' if os.path.isfile(links_filename): - with open(links_filename, 'r') as fp_links: + with open(links_filename, 'r', encoding='utf-8') as fp_links: links_str = fp_links.read() edit_links_form += \ @@ -512,7 +512,7 @@ def html_edit_links(css_cache: {}, translate: {}, base_dir: str, path: str, about_filename = base_dir + '/accounts/about.md' about_str = '' if os.path.isfile(about_filename): - with open(about_filename, 'r') as fp_about: + with open(about_filename, 'r', encoding='utf-8') as fp_about: about_str = fp_about.read() edit_links_form += \ @@ -531,7 +531,7 @@ def html_edit_links(css_cache: {}, translate: {}, base_dir: str, path: str, tos_filename = base_dir + '/accounts/tos.md' tos_str = '' if os.path.isfile(tos_filename): - with open(tos_filename, 'r') as fp_tos: + with open(tos_filename, 'r', encoding='utf-8') as fp_tos: tos_str = fp_tos.read() edit_links_form += \