Skip to content

Commit

Permalink
utf-8 for files i know should be utf-8
Browse files Browse the repository at this point in the history
  • Loading branch information
ntaraujo committed Feb 18, 2022
1 parent c056b07 commit 1295649
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ def encoding_of(file_path):
return 'utf-8' if result == 'ascii' else result

def open(*args, **kwargs):
if len(args) > 3:
args[4] = encoding_of(args[0])
else:
if len(args) < 4 or 'encoding' not in kwargs:
kwargs['encoding'] = encoding_of(args[0] if args else kwargs['file'])

return default_open(*args, **kwargs)
Expand All @@ -36,7 +34,7 @@ def open(*args, **kwargs):
if not os.path.exists(data_dir_path):
os.mkdir(data_dir_path)

log_file = open(os.path.join(data_dir_path, 'last-log.txt'), 'w')
log_file = open(os.path.join(data_dir_path, 'last-log.txt'), 'w', encoding='utf-8')

locale.setlocale(locale.LC_TIME, 'pt_BR.UTF-8')

Expand Down Expand Up @@ -147,15 +145,15 @@ def new_func(*args, **kwargs):
def save_cache():
msg(f'Salvando cache em "{cache_file_path}"')

with open(cache_file_path, 'w') as cache_file:
with open(cache_file_path, 'w', encoding='utf-8') as cache_file:
cache.write(cache_file)


def load_cache():
msg(f'Carregando cache de "{cache_file_path}"')

if os.path.exists(cache_file_path):
cache.read(cache_file_path, encoding=encoding_of(cache_file_path))
cache.read(cache_file_path, encoding='utf-8')


def global_path(local_path, basename=None):
Expand Down

0 comments on commit 1295649

Please sign in to comment.