def runTask(name, data = []): s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) s.connect("socket") s.send(jsonify.encode([name, data])) data = jsonify.encode("done") if name != "kill": data = s.recv(4096) s.close() return jsonify.decode(data)
def test_simple_nested_object_encode(self): obj = Person("Sergio", 21) fullobj = [1, 2, obj] picklestring = jsonpickle.encode(obj) jsonobj = [1, 2, picklestring] string = json.dumps(jsonobj) self.assertEqual(string, jsonify.encode(fullobj)) obj = Person("Sergio", 21) fullobj = [obj, [1,2,obj], obj, (obj, (obj))] os = jsonpickle.encode(obj) jsonos = [os, [1,2,os], os, (os, (os))] string = json.dumps(jsonos) self.assertEqual(string, jsonify.encode(fullobj))
def render(self, template_path, namespace): from jsonify import encode return encode(namespace)
def ed_test(self, obj): string = jsonify.encode(obj) decodeobj = jsonify.decode(string) self.assertEqual(obj, decodeobj)
def test_simple_object_encode(self): obj = Person("Sergio", 21) string = json.dumps(jsonpickle.encode(obj)) self.assertEqual(string, jsonify.encode(obj))
def encode_test(self, obj): string = jsonify.encode(obj) self.assertEqual(string, json.dumps(obj))
def recv(self, client, data): error, task, args = self.verify_data(data) if error != None: return client.send(jsonify.encode(error)) client.send(jsonify.encode(getattr(self, task)(*args)))
def finish(self, **params): self.connect_to_coord() self.coord_socket.sendall("finish:" + jsonify.encode(params)) self.coord_socket.close()
def kill_task(self, **params): self.connect_to_coord() self.coord_socket.sendall("kill_task:" + jsonify.encode(params)) self.coord_socket.close()
def start_task(self, **params): self.connect_to_coord() self.coord_socket.sendall("start_task:" + jsonify.encode(params)) result = self.coord_socket.recv(256) self.coord_socket.close() return jsonify.decode(result)["tid"]
def render(self, template_path, namespace): ''' Implements ``JSON`` rendering. ''' from jsonify import encode return encode(namespace)