Compare commits
1 Commits
nilmrun-1.
...
nilmrun-1.
Author | SHA1 | Date | |
---|---|---|---|
5b878378f3 |
@@ -60,12 +60,16 @@ class AppProcess(object):
|
||||
self.manager = manager
|
||||
|
||||
def process_status(self, pid):
|
||||
# We need to convert the log (which is bytes) to Unicode
|
||||
# characters, in order to send it via JSON. Treat it as UTF-8
|
||||
# but replace invalid characters with markers.
|
||||
log = self.manager[pid].log.decode('utf-8', errors='replace')
|
||||
return {
|
||||
"pid": pid,
|
||||
"alive": self.manager[pid].alive,
|
||||
"exitcode": self.manager[pid].exitcode,
|
||||
"start_time": self.manager[pid].start_time,
|
||||
"log": self.manager[pid].log,
|
||||
"log": log
|
||||
}
|
||||
|
||||
# /process/status
|
||||
|
@@ -372,3 +372,21 @@ class TestClient(object):
|
||||
# kill all processes
|
||||
for pid in client.get("process/list"):
|
||||
client.post("process/remove", { "pid": pid })
|
||||
|
||||
def test_client_10_unicode(self):
|
||||
client = HTTPClient(baseurl = testurl, post_json = True)
|
||||
eq_(client.get("process/list"), [])
|
||||
def verify(cmd, result):
|
||||
pid = client.post("run/command", { "argv": [ "sh", "-c", cmd ] })
|
||||
eq_(client.get("process/list"), [pid])
|
||||
status = self.wait_end(client, pid)
|
||||
eq_(result, status["log"])
|
||||
|
||||
# Unicode should work
|
||||
verify("echo -n hello", "hello")
|
||||
verify(u"echo -n ☠", u"☠")
|
||||
verify("echo -ne \\\\xe2\\\\x98\\\\xa0", u"☠")
|
||||
|
||||
# Programs that spit out invalid UTF-8 should get replacement
|
||||
# markers
|
||||
verify("echo -ne \\\\xae", u"\ufffd")
|
||||
|
Reference in New Issue
Block a user