def export(self): exch = Exchange(Base.metadata, ignlist=['cpu_types', 'machine_types', 'nic_types']) fp = StringIO.StringIO() exch.export_xml() exch.write_xml(fp) resp = Response() resp.headerlist=[('Content-Type', 'text/html; charset=UTF-8'),] resp.text=fp.getvalue() resp.content_disposition = 'attachment; filename="qtubes_export.xml"' resp.charset='utf-8' return resp
def traduir(request): filename = request.storage.save(request.POST['meme'], randomize=True) path = request.storage.path(filename) api_result = detect(path) target_lang = request.POST['lang'] out = "/tmp/out-" + filename try: badly_translate = request.POST['bad'] == "true" except: badly_translate = False write_on_image(path, badly_translate, api_result, target_lang, out) _resp = Response() _resp.headerlist = [('Content-type', "image/png; 'charset=UTF-8'")] _resp.body = open(out, 'rb').read() request.storage.delete(path) request.storage.delete(out) return _resp
def createResponse( status, code, result, serialize, request, format='json', header=None, ): """ Create and format a response Available formats: JSON ('json'), XML ('xml') """ format = format.lower() # set status if status == False: status = 'failure' else: status = 'success' if serialize: output = [i.serialize for i in result] else: output = result res = Response('') # set header if format == 'xml': res.content_type = 'application/xml' else: # default - format = "json" format = 'json' res.content_type = 'application/json' if header != None: res.headerlist = header if format == 'xml': response = \ XMLDict.convert_dict_to_xml({'response': {'status': status, 'code': code, 'data': output}}) else: # default - format = "json": response = json.dumps({ 'status': status, 'code': code, 'data': output }) callback = request.params.get('callback', None) if callback: response = callback + '(' + response + ')' res.text = response else: res.body = response return res
def createResponse( status, code, result, serialize, request, format='json', header=None, ): """ Create and format a response Available formats: JSON ('json'), XML ('xml') """ format = format.lower() # set status if status == False: status = 'failure' else: status = 'success' if serialize: output = [i.serialize for i in result] else: output = result res = Response('') # set header if format == 'xml': res.content_type = 'application/xml' else: # default - format = "json" format = 'json' res.content_type = 'application/json' if header != None: res.headerlist = header if format == 'xml': response = \ XMLDict.convert_dict_to_xml({'response': {'status': status, 'code': code, 'data': output}}) else: # default - format = "json": response = json.dumps({'status': status, 'code': code, 'data': output}) callback = request.params.get('callback', None) if callback: response = callback + '(' + response + ')' res.text = response else: res.body = response return res
def homepage(request): _resp = Response() _resp.headerlist = [('Content-type', "text/html; 'charset=UTF-8'")] _resp.body = open('src/views/page.html', 'rb').read() return _resp