it('uri', () => { var u = '中文测试'; var u1 = escape(u); assert.equal(encoding.decodeURI(u1), u); u1 = u1.replace(/%/g, '\\'); assert.equal(encoding.decodeURI(u1), u); for (var i = 32; i < 128; i++) u += String.fromCharCode(i); assert.equal(encodeURI(u), encoding.encodeURI(u)); assert.equal(encodeURIComponent(u), encoding.encodeURIComponent(u)); assert.equal(encoding.decodeURI(encodeURI(u)), u); assert.equal(encoding.decodeURI(encodeURIComponent(u)), u); });
rename: function(name, newname) { var id = ids.get(encoding.decodeURI(name)); if (!id) { return { name: "notexists" } } if (ids.check(newname)) { return { newname: "exists" } } var r = ids.put(id, newname); if (!r) { return { newname: "puterrro" } } //change app var appids = apploader[id].root.object.appids(); for (var appId in appids) { var appName = appManage.id2name(appId); var app = apploader[id][appName].object; if (app.rename && util.isFunction(app.rename)) app.rename(newname); } ids.remove(id, name); return true; },
function set(e) { var id = e["id"], type = e["type"]; if (is_numeric(id)) { id = Number(id); } else { id = ids.get(encoding.decodeURI(id)); if (!id) return { "result": { "error": { "msg": "id is null" } } }; } type = encoding.decodeURI((e["type"] || "").toLowerCase()); if (!object.getPower(id, type)) { return { error: "noPower" }; }; return object.set(id, type, e["e"]); }
function get(s, type, v) { var r, id = 0; if (is_numeric(s)) { id = Number(s); if (id < 0) r = "id is error"; } else { id = ids.get(encoding.decodeURI(s)); if (!id) r = "id is null"; } if (!util.isString(type)) r = "type is not string"; if (r) return { "result": { "error": { "msg": r } } }; type = encoding.decodeURI((type || "").toLowerCase()); if (!stats.call(this, object.getPower, id, type)) { return { error: "noPower" }; }; var k = type + "_" + id, locker = Locker[k]; if (!locker) locker = Locker[k] = { lock: new coroutine.Lock(), waits: 0 }; locker.waits++; locker.lock.acquire(); try { if (!locker.data) { var status = {}, k = type + "_" + id; locker.data = stats.call(this, _get, [ [type, id] ], status); if (v && status[k] && status[k].lastModified) { var ifmod = v.firstHeader('If-Modified-Since'); if (ifmod && new Date(ifmod).toString() === new Date(status[k].lastModified).toString()) { v.response.status = 304; } v.response.addHeader('Last-Modified', new Date(status[k].lastModified)); v.response.addHeader('Cache-Control', "max-age=0"); } } return locker.data[k]; } finally { locker.lock.release(); locker.waits--; if (locker.waits === 0) delete Locker[k]; } }