Added file support to jots, fixed bug in socket client

This commit is contained in:
aewens 2019-05-18 15:00:52 -05:00
parent 075bebc8c8
commit d271de75dc
2 changed files with 6 additions and 4 deletions

View File

@ -1,10 +1,10 @@
from json import dumps, loads
from json import dump, dumps, loads
from codecs import encode as c_encode, decode as c_decode
from base64 import b64encode, b64decode
from re import compile as regex
# JSON encoder, converts a python object to a string
def jots(data, readable=False):
def jots(data, readable=False, dest=None):
kwargs = dict()
# If readable is set, it pretty prints the JSON to be more human-readable
@ -13,7 +13,9 @@ def jots(data, readable=False):
kwargs["indent"] = 4
kwargs["separators"] = (",", ":")
try:
return dumps(data, encoding="utf-8", **kwargs)
if dest:
return dump(data, dest, ensure_ascii=False, **kwargs)
return dumps(data, ensure_ascii=False, **kwargs)
except ValueError as e:
return None

View File

@ -151,7 +151,7 @@ class SocketClient(Thread):
def send(self, message):
self._inbox.put(message)
cast(self._bridge, "send" ("inbox", message))
cast(self._bridge, "send", ("inbox", message))
def connect(self, bridge):
self._bridge = bridge()