data = doc.read() if not data: return ActionPayload() try: params = json.loads(data) except ValueError, e: raise document.DocumentFormatError("Invalid JSON document: %s" % (e, )) if not isinstance(params, dict): return ActionPayload([(u"value", params)]) return ActionPayload(params) document.register_writer(write_model, MIME_TYPE, IModel) document.register_writer(write_error, MIME_TYPE, IErrorPayload) document.register_writer(write_reference, MIME_TYPE, IReference) # document.register_writer(write_serializable, MIME_TYPE, # serialization.ISerializable) document.register_writer(write_anything, MIME_TYPE, None) document.register_writer(write_query_model, MIME_TYPE, IQueryModel) document.register_reader(read_action, MIME_TYPE, IActionPayload) ### private ### class CustomJSONEncoder(json.JSONEncoder):
if obj.query_target == 'view': instance = model_factory(obj.source) d = instance.initiate(view=child) else: instance = model_factory(child) d = instance.initiate(view=obj.view) d.addCallback(applicationjson.render_inline_model, *args, **kwargs) result.append(d) r = applicationjson.AsyncDict() d = defer.DeferredList(result) d.addCallback(applicationjson.unpack_deferred_list_result) d.addCallback(list) r.add('rows', d) r.add('total_count', items.total_count) r.add('aggregations', items.aggregations) d = r.wait() d.addCallback(applicationjson.render_json, doc) d.addCallback(defer.override_result, None) return d document.register_writer(write_query_result, applicationjson.MIME_TYPE, QueryResult) # This used to be defined in this module, prevent all code from # failing with ImportError FixedValues = value.FixedValues
stdin += 'e\n' return stdin def get_png(script): gnuplot = subprocess.Popen(['gnuplot'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = gnuplot.communicate(script) if output[1]: log.error('gnuplot', "Failed to generate the graph. " "Error returned by gnuplot: \n%s", output[1]) return output[0] def write_graph(doc, obj, *args, **kwargs): doc.write(get_png(obj.to_gnuplot())) def write_data(doc, obj, *args, **kwargs): doc.write(json.dumps(obj.data)) def write_script(doc, obj, *args, **kwargs): doc.write(obj.to_gnuplot()) document.register_writer(write_graph, 'image/png', IGraph) document.register_writer(write_data, 'application/json', IGraph) document.register_writer(write_script, 'application/gnuplot', IGraph)
self.log("Rendering html error: %s", obj.message) context = kwargs['context'] markup = ErrorLayout("Error", context) s = markup.span(_class="error")("ERROR") if obj.error_code is not None: s.content.append(" ") s.content.append(str(obj.error_code)) if obj.message is not None: s.content.append(": ") s.content.append(obj.message) s.close() if obj.debug is not None: markup.br() markup.span(_class="debug")(obj.debug).close() if obj.trace is not None: markup.br() markup.pre(_class="trace")(obj.trace).close() return markup.render(doc) model_writer = ModelWriter() error_writer = ErrorWriter() document.register_writer(QueryModelWriter(), MIME_TYPE, IQueryModel) document.register_writer(model_writer, MIME_TYPE, IModel) document.register_writer(error_writer, MIME_TYPE, IErrorPayload)
def get_png(script): gnuplot = subprocess.Popen(['gnuplot'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) output = gnuplot.communicate(script) if output[1]: log.error( 'gnuplot', "Failed to generate the graph. " "Error returned by gnuplot: \n%s", output[1]) return output[0] def write_graph(doc, obj, *args, **kwargs): doc.write(get_png(obj.to_gnuplot())) def write_data(doc, obj, *args, **kwargs): doc.write(json.dumps(obj.data)) def write_script(doc, obj, *args, **kwargs): doc.write(obj.to_gnuplot()) document.register_writer(write_graph, 'image/png', IGraph) document.register_writer(write_data, 'application/json', IGraph) document.register_writer(write_script, 'application/gnuplot', IGraph)