fix unicode/json on py3
This commit is contained in:
parent
2e0c97cea8
commit
a1333e51cd
|
@ -9,7 +9,7 @@ class UsageLog(unittest.TestCase):
|
||||||
os.mkdir(d)
|
os.mkdir(d)
|
||||||
usage_logfile = os.path.join(d, "usage.log")
|
usage_logfile = os.path.join(d, "usage.log")
|
||||||
def read():
|
def read():
|
||||||
with open(usage_logfile, "rb") as f:
|
with open(usage_logfile, "r") as f:
|
||||||
return [json.loads(line) for line in f.readlines()]
|
return [json.loads(line) for line in f.readlines()]
|
||||||
t = Transit(None, usage_logfile, None)
|
t = Transit(None, usage_logfile, None)
|
||||||
t.recordUsage(started=123, result="happy", total_bytes=100,
|
t.recordUsage(started=123, result="happy", total_bytes=100,
|
||||||
|
|
|
@ -300,7 +300,7 @@ class Transit(protocol.ServerFactory):
|
||||||
|
|
||||||
def _update_stats(self, total_bytes, mood):
|
def _update_stats(self, total_bytes, mood):
|
||||||
try:
|
try:
|
||||||
with open(self._stats_file, "rb") as f:
|
with open(self._stats_file, "r") as f:
|
||||||
stats = json.load(f)
|
stats = json.load(f)
|
||||||
except (EnvironmentError, ValueError):
|
except (EnvironmentError, ValueError):
|
||||||
stats = {}
|
stats = {}
|
||||||
|
@ -332,7 +332,7 @@ class Transit(protocol.ServerFactory):
|
||||||
um[m] = 0
|
um[m] = 0
|
||||||
um[mood] += 1
|
um[mood] += 1
|
||||||
tmpfile = self._stats_file + ".tmp"
|
tmpfile = self._stats_file + ".tmp"
|
||||||
with open(tmpfile, "wb") as f:
|
with open(tmpfile, "w") as f:
|
||||||
f.write(json.dumps(stats))
|
f.write(json.dumps(stats))
|
||||||
f.write("\n")
|
f.write("\n")
|
||||||
os.rename(tmpfile, self._stats_file)
|
os.rename(tmpfile, self._stats_file)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user