Mercurial > hg > webaudioevaluationtool
changeset 2376:c41caaa96633
Some fixes for #90. Also a failsafe loop if the server never responds with meaningul information from saves (for instance, running only on apache or basic http servers). More changes to pythonServer for python 3.5. Please check if still valid on 2.7
author | Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk> |
---|---|
date | Thu, 19 May 2016 10:44:19 +0100 |
parents | a6670226df24 |
children | e04f0f8b6f8f |
files | js/core.js python/pythonServer.py |
diffstat | 2 files changed, 18 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/js/core.js Wed May 18 15:34:20 2016 +0100 +++ b/js/core.js Thu May 19 10:44:19 2016 +0100 @@ -562,7 +562,13 @@ } function randomString(length) { - return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1); + var str = "" + for (var i=0; i<length; i+=2) { + var num = Math.floor(Math.random()*1295); + str += num.toString(36); + } + return str; + //return Math.round((Math.pow(36, length + 1) - Math.random() * Math.pow(36, length))).toString(36).slice(1); } function randomiseOrder(input) @@ -2995,7 +3001,7 @@ if (existingStore == undefined) { // We need to get the sessionKey this.SessionKey.generateKey(); - this.document = document.implementation.createDocument(null,"waetresult"); + this.document = document.implementation.createDocument(null,"waetresult",null); this.root = this.document.childNodes[0]; var projectDocument = specification.projectXML; projectDocument.setAttribute('file-name',url); @@ -3020,8 +3026,12 @@ var parse = new DOMParser(); var xml = parse.parseFromString(this.request.response,"text/xml"); var shouldGenerateKey = true; - if(xml.getAllElementsByTagName("state").length > 0){ - if (xml.getAllElementsByTagName("state")[0].textContent == "OK") { + if (this.request.response.length == 0) { + console.log("Error: Server did not respond"); + return; + } + if(xml.getElementsByTagName("state").length > 0){ + if (xml.getElementsByTagName("state")[0].textContent == "OK") { this.key = xml.getAllElementsByTagName("key")[0].textContent; this.parent.root.setAttribute("key",this.key); this.parent.root.setAttribute("state","empty");
--- a/python/pythonServer.py Wed May 18 15:34:20 2016 +0100 +++ b/python/pythonServer.py Thu May 19 10:44:19 2016 +0100 @@ -122,7 +122,7 @@ s.send_response(200) s.send_header("Content-type", "application/xml") s.end_headers() - s.wfile.write(reply) + s.wfile.write(bytes(reply, "utf-8")) file = open("../saves/save-"+key+".xml",'w') file.write("<waetresult key="+key+"/>") file.close(); @@ -136,7 +136,7 @@ varLen = int(self.headers['Content-Length']) postVars = self.rfile.read(varLen) print("Saving file key "+key) - file = open('../saves/save-'+key+'.xml','w') + file = open('../saves/save-'+key+'.xml','wb') file.write(postVars) file.close() try: @@ -149,7 +149,8 @@ self.send_response(200) self.send_header("Content-type", "text/xml") self.end_headers() - self.wfile.write('<response state="OK"><message>OK</message><file bytes="'+str(wbytes)+'">"saves/'+curFileName+'"</file></response>') + reply = '<response state="OK"><message>OK</message><file bytes="'+str(wbytes)+'">"saves/'+curFileName+'"</file></response>' + self.wfile.write(bytes(reply, "utf-8")) curSaveIndex += 1 curFileName = 'test-'+str(curSaveIndex)+'.xml'