windows fails to open utf-8 files as utf-8

This commit is contained in:
j 2019-02-20 18:22:20 +05:30
parent b4b66f9bd5
commit 41d90e1736
2 changed files with 5 additions and 4 deletions

View File

@ -36,14 +36,14 @@ def add_record(action, *args, **kwargs):
revision = next_revision()
data = [revision, timestamp, [action] + list(args)]
data = json.dumps(data, ensure_ascii=False)
data = json.dumps(data, ensure_ascii=False).encode('utf-8')
path = changelog_path()
if os.path.exists(path):
mode = 'a'
mode = 'ab'
state.changelog_size = os.path.getsize(path)
else:
mode = 'w'
mode = 'wb'
state.changelog_size = 0
makefolder(path)
with open(path, mode) as fd:

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
import codecs
import json
import os
import time
@ -52,7 +53,7 @@ class Peer(object):
def apply_log(self):
changes = []
if os.path.exists(self._logpath):
with open(self._logpath) as fd:
with codecs.open(self._logpath, 'r', encoding='utf-8') as fd:
for line in fd:
if line:
try: