diff --git a/oioioi/contests/fixtures/test_submission_python.json b/oioioi/contests/fixtures/test_submission_python.json new file mode 100644 index 000000000..3025f78ae --- /dev/null +++ b/oioioi/contests/fixtures/test_submission_python.json @@ -0,0 +1,279 @@ +[ + { + "pk": 1, + "model": "contests.submission", + "fields": { + "status": "OK", + "problem_instance": 1, + "kind": "NORMAL", + "comment": "", + "score": "int:0000000000000000034", + "user": 1001, + "date": "2012-06-03T22:07:07.516Z" + } + }, + { + "pk": 1, + "model": "contests.submissionreport", + "fields": { + "status": "ACTIVE", + "kind": "INITIAL", + "submission": 1, + "creation_date": "2012-08-03T22:07:29.547Z" + } + }, + { + "pk": 2, + "model": "contests.submissionreport", + "fields": { + "status": "ACTIVE", + "kind": "NORMAL", + "submission": 1, + "creation_date": "2012-08-03T22:07:39.662Z" + } + }, + { + "pk": 1, + "model": "contests.scorereport", + "fields": { + "status": "OK", + "comment": null, + "score": null, + "submission_report": 1, + "max_score": "int:0000000000000000100" + } + }, + { + "pk": 2, + "model": "contests.scorereport", + "fields": { + "status": "RE", + "comment": null, + "score": "int:0000000000000000034", + "submission_report": 2, + "max_score": "int:0000000000000000100" + } + }, + { + "pk": 1, + "model": "contests.userresultforproblem", + "fields": { + "status": "OK", + "problem_instance": 1, + "score": "int:0000000000000000034", + "user": 1001, + "submission_report": 2 + } + }, + { + "pk": 1, + "model": "contests.userresultforround", + "fields": { + "score": "int:0000000000000000034", + "user": 1001, + "round": 1 + } + }, + { + "pk": 1, + "model": "contests.userresultforcontest", + "fields": { + "score": "int:0000000000000000034", + "user": 1001, + "contest": "c" + } + }, + { + "pk": 1, + "model": "programs.programsubmission", + "fields": { + "source_file": "data:submissions/c/1.py:data:submissions/c/2.py:YSwgYiA9IGlucHV0KCkuc3BsaXQoKQoKcHJpbnQoaW50KGEpICsgaW50KGIpKQ==", + "source_length": 46 + } + }, + { + "pk": 1, + "model": "programs.compilationreport", + "fields": { + "status": "OK", + "compiler_output": "", + "submission_report": 1 + } + }, + { + "pk": 2, + "model": "programs.compilationreport", + "fields": { + "status": "OK", + "compiler_output": "", + "submission_report": 2 + } + }, + { + "pk": 1, + "model": "programs.testreport", + "fields": { + "status": "OK", + "comment": "", + "test_time_limit": 10000, + "submission_report": 1, + "time_used": 1, + "test_group": "0", + "score": "int:0000000000000000000", + "test_name": "0", + "test": 1 + } + }, + { + "pk": 2, + "model": "programs.testreport", + "fields": { + "status": "OK", + "comment": "", + "test_time_limit": 10000, + "submission_report": 1, + "time_used": 1, + "test_group": "1ocen", + "score": "int:0000000000000000000", + "test_name": "1ocen", + "test": 4 + } + }, + { + "pk": 3, + "model": "programs.testreport", + "fields": { + "status": "OK", + "comment": "", + "test_time_limit": 10000, + "submission_report": 2, + "time_used": 1, + "test_group": "1", + "score": "int:0000000000000000005", + "test_name": "1a", + "test": 2 + } + }, + { + "pk": 4, + "model": "programs.testreport", + "fields": { + "status": "OK", + "comment": "", + "test_time_limit": 10000, + "submission_report": 2, + "time_used": 1, + "test_group": "3", + "score": "int:0000000000000000034", + "test_name": "3", + "test": 6 + } + }, + { + "pk": 5, + "model": "programs.testreport", + "fields": { + "status": "WA", + "comment": "", + "test_time_limit": 10000, + "submission_report": 2, + "time_used": 0, + "test_group": "2", + "score": "int:0000000000000000000", + "test_name": "2", + "test": 5 + } + }, + { + "pk": 6, + "model": "programs.testreport", + "fields": { + "status": "RE", + "comment": "program exited with code 1", + "test_time_limit": 100, + "submission_report": 2, + "time_used": 0, + "test_group": "1", + "score": "int:0000000000000000000", + "test_name": "1b", + "test": 3 + } + }, + { + "pk": 1, + "model": "programs.groupreport", + "fields": { + "status": "OK", + "group": "0", + "score": "int:0000000000000000000", + "max_score": "int:0000000000000000000", + "submission_report": 1 + } + }, + { + "pk": 2, + "model": "programs.groupreport", + "fields": { + "status": "OK", + "group": "1ocen", + "score": "int:0000000000000000000", + "max_score": "int:0000000000000000000", + "submission_report": 1 + } + }, + { + "pk": 3, + "model": "programs.groupreport", + "fields": { + "status": "RE", + "group": "1", + "score": "int:0000000000000000000", + "max_score": "int:0000000000000000033", + "submission_report": 2 + } + }, + { + "pk": 4, + "model": "programs.groupreport", + "fields": { + "status": "OK", + "group": "0", + "score": "int:0000000000000000000", + "max_score": "int:0000000000000000000", + "submission_report": 2 + } + }, + { + "pk": 5, + "model": "programs.groupreport", + "fields": { + "status": "OK", + "group": "3", + "score": "int:0000000000000000034", + "max_score": "int:0000000000000000034", + "submission_report": 2 + } + }, + { + "pk": 6, + "model": "programs.groupreport", + "fields": { + "status": "OK", + "group": "1ocen", + "score": "int:0000000000000000000", + "max_score": "int:0000000000000000000", + "submission_report": 2 + } + }, + { + "pk": 7, + "model": "programs.groupreport", + "fields": { + "status": "WA", + "group": "2", + "score": "int:0000000000000000000", + "max_score": "int:0000000000000000033", + "submission_report": 2 + } + } +] diff --git a/oioioi/programs/static/code_formatter/clang-format.js b/oioioi/programs/static/code_formatter/clang-format.js new file mode 100644 index 000000000..9be0f8adb --- /dev/null +++ b/oioioi/programs/static/code_formatter/clang-format.js @@ -0,0 +1 @@ +let e;export default async function r(r){if(void 0!==e)return e;void 0===r&&(r=new URL("clang-format.wasm",import.meta.url)),("string"==typeof r||"function"==typeof Request&&r instanceof Request||"function"==typeof URL&&r instanceof URL)&&(r=fetch(r)),e=await async function(e){if("function"==typeof Response&&e instanceof Response){if("compileStreaming"in WebAssembly)try{return await WebAssembly.compileStreaming(e)}catch(r){if("application/wasm"==e.headers.get("Content-Type"))throw r;console.warn("`WebAssembly.compileStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",r)}return e.arrayBuffer()}return e}(await r).then((e=>n({wasm:e}))),version=e.version,t=e.format_with_style}function t(){throw Error("uninit")}export function version(){throw Error("uninit")}export function format(e,r="",n="LLVM"){const a=t(e,r,n);if("\0"===a[0])throw Error(a.slice(1));return a}var n=function(e={}){var r,t=e;t.ready=new Promise(((e,t)=>{r=e}));var n,a,o,i,u,s,l,c,f,h=e=>console.log(e),d=e=>console.error(e);function g(){var e=f.buffer;n=new Int8Array(e),a=new Int16Array(e),i=new Uint8Array(e),u=new Uint16Array(e),o=new Int32Array(e),s=new Uint32Array(e),l=new Float32Array(e),c=new Float64Array(e)}f=new WebAssembly.Memory({initial:256,maximum:32768}),g(),t.noExitRuntime;var m,v=e=>m.get(e);function y(e){this.excPtr=e,this.ptr=e-24,this.set_type=function(e){s[this.ptr+4>>2]=e},this.get_type=function(){return s[this.ptr+4>>2]},this.set_destructor=function(e){s[this.ptr+8>>2]=e},this.get_destructor=function(){return s[this.ptr+8>>2]},this.set_caught=function(e){e=e?1:0,n[this.ptr+12>>0]=e},this.get_caught=function(){return 0!=n[this.ptr+12>>0]},this.set_rethrown=function(e){e=e?1:0,n[this.ptr+13>>0]=e},this.get_rethrown=function(){return 0!=n[this.ptr+13>>0]},this.init=function(e,r){this.set_adjusted_ptr(0),this.set_type(e),this.set_destructor(r)},this.set_adjusted_ptr=function(e){s[this.ptr+16>>2]=e},this.get_adjusted_ptr=function(){return s[this.ptr+16>>2]},this.get_exception_ptr=function(){if(Te(this.get_type()))return s[this.excPtr>>2];var e=this.get_adjusted_ptr();return 0!==e?e:this.excPtr}}var p,w,b,_="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0,T=(e,r,t)=>{for(var n=r+t,a=r;e[a]&&!(a>=n);)++a;if(a-r>16&&e.buffer&&_)return _.decode(e.subarray(r,a));for(var o="";r>10,56320|1023&l)}}else o+=String.fromCharCode((31&i)<<6|u)}else o+=String.fromCharCode(i)}return o},A=(e,r)=>e?T(i,e,r):"",C={varargs:void 0,get(){var e=o[+C.varargs>>2];return C.varargs+=4,e},getp:()=>C.get(),getStr:e=>A(e)},D=e=>{for(var r=0,t=0;t=55296&&n<=57343?(r+=4,++t):r+=3}return r},F=(e,r,t,n)=>{if(!(n>0))return 0;for(var a=t,o=t+n-1,i=0;i=55296&&u<=57343&&(u=65536+((1023&u)<<10)|1023&e.charCodeAt(++i)),u<=127){if(t>=o)break;r[t++]=u}else if(u<=2047){if(t+1>=o)break;r[t++]=192|u>>6,r[t++]=128|63&u}else if(u<=65535){if(t+2>=o)break;r[t++]=224|u>>12,r[t++]=128|u>>6&63,r[t++]=128|63&u}else{if(t+3>=o)break;r[t++]=240|u>>18,r[t++]=128|u>>12&63,r[t++]=128|u>>6&63,r[t++]=128|63&u}}return r[t]=0,t-a},M=(e,r,t)=>F(e,i,r,t),E=e=>{for(var r="",t=e;i[t];)r+=p[i[t++]];return r},S={},O={},W={},P=e=>{throw new w(e)},U=e=>{throw new b(e)};function x(e,r,t={}){if(!("argPackAdvance"in r))throw new TypeError("registerType registeredInstance requires argPackAdvance");return function(e,r,t={}){var n=r.name;if(e||P(`type "${n}" must have a positive integer typeid pointer`),O.hasOwnProperty(e)){if(t.ignoreDuplicateRegistrations)return;P(`Cannot register type '${n}' twice`)}if(O[e]=r,delete W[e],S.hasOwnProperty(e)){var a=S[e];delete S[e],a.forEach((e=>e()))}}(e,r,t)}function Y(){this.allocated=[void 0],this.freelist=[]}var $=new Y;function k(e){return this.fromWireType(o[e>>2])}var I,j=(e,r)=>{switch(r){case 4:return function(e){return this.fromWireType(l[e>>2])};case 8:return function(e){return this.fromWireType(c[e>>3])};default:throw new TypeError(`invalid float width (${r}): ${e}`)}},R=(e,r)=>Object.defineProperty(r,"name",{value:e}),H=(e,r,t)=>{if(void 0===e[r].overloadTable){var n=e[r];e[r]=function(){return e[r].overloadTable.hasOwnProperty(arguments.length)||P(`Function '${t}' called with an invalid number of arguments (${arguments.length}) - expects one of (${e[r].overloadTable})!`),e[r].overloadTable[arguments.length].apply(this,arguments)},e[r].overloadTable=[],e[r].overloadTable[n.argCount]=n}},V=(e,r)=>{var t,n,a,o=(e=E(e)).includes("j")?(t=e,n=r,a=[],function(){return a.length=0,Object.assign(a,arguments),((e,r,t)=>e.includes("j")?((e,r,t)=>{var n=dynCalls[e];return t&&t.length?n.apply(null,[r].concat(t)):n.call(null,r)})(e,r,t):v(r).apply(null,t))(t,n,a)}):v(r);return"function"!=typeof o&&P(`unknown function pointer with signature ${e}: ${r}`),o},z=e=>{var r=be(e),t=E(r);return ye(r),t},L=(e,r,t)=>{switch(r){case 1:return t?e=>n[e>>0]:e=>i[e>>0];case 2:return t?e=>a[e>>1]:e=>u[e>>1];case 4:return t?e=>o[e>>2]:e=>s[e>>2];default:throw new TypeError(`invalid integer width (${r}): ${e}`)}};function N(e){return this.fromWireType(s[e>>2])}var B,G="undefined"!=typeof TextDecoder?new TextDecoder("utf-16le"):void 0,q=(e,r)=>{for(var t=e,n=t>>1,o=n+r/2;!(n>=o)&&u[n];)++n;if((t=n<<1)-e>32&&G)return G.decode(i.subarray(e,t));for(var s="",l=0;!(l>=r/2);++l){var c=a[e+2*l>>1];if(0==c)break;s+=String.fromCharCode(c)}return s},J=(e,r,t)=>{if(t??=2147483647,t<2)return 0;for(var n=r,o=(t-=2)<2*e.length?t/2:e.length,i=0;i>1]=u,r+=2}return a[r>>1]=0,r-n},X=e=>2*e.length,Z=(e,r)=>{for(var t=0,n="";!(t>=r/4);){var a=o[e+4*t>>2];if(0==a)break;if(++t,a>=65536){var i=a-65536;n+=String.fromCharCode(55296|i>>10,56320|1023&i)}else n+=String.fromCharCode(a)}return n},K=(e,r,t)=>{if(t??=2147483647,t<4)return 0;for(var n=r,a=n+t-4,i=0;i=55296&&u<=57343&&(u=65536+((1023&u)<<10)|1023&e.charCodeAt(++i)),o[r>>2]=u,(r+=4)+4>a)break}return o[r>>2]=0,r-n},Q=e=>{for(var r=0,t=0;t=55296&&n<=57343&&++t,r+=4}return r},ee=(e,r)=>r+2097152>>>0<4194305-!!e?(e>>>0)+4294967296*r:NaN,re=e=>e%4==0&&(e%100!=0||e%400==0),te=[0,31,60,91,121,152,182,213,244,274,305,335],ne=[0,31,59,90,120,151,181,212,243,273,304,334],ae={};B=()=>performance.now();var oe,ie,ue=e=>{var r=D(e)+1,t=we(r);return t&&M(e,t,r),t},se=e=>{var r=(e-f.buffer.byteLength+65535)/65536;try{return f.grow(r),g(),1}catch(e){}},le={},ce=()=>{if(!ce.strings){var e={USER:"web_user",LOGNAME:"web_user",PATH:"/",PWD:"/",HOME:"/home/web_user",LANG:("object"==typeof navigator&&navigator.languages&&navigator.languages[0]||"C").replace("-","_")+".UTF-8",_:"./this.program"};for(var r in le)void 0===le[r]?delete e[r]:e[r]=le[r];var t=[];for(var r in e)t.push(`${r}=${e[r]}`);ce.strings=t}return ce.strings},fe=e=>{throw`exit(${e})`},he=fe,de=[null,[],[]],ge=(e,r)=>{var t=de[e];0===r||10===r?((1===e?h:d)(T(t,0)),t.length=0):t.push(r)},me=[31,29,31,30,31,30,31,31,30,31,30,31],ve=[31,28,31,30,31,30,31,31,30,31,30,31];(()=>{for(var e=new Array(256),r=0;r<256;++r)e[r]=String.fromCharCode(r);p=e})(),w=t.BindingError=class extends Error{constructor(e){super(e),this.name="BindingError"}},b=t.InternalError=class extends Error{constructor(e){super(e),this.name="InternalError"}},Object.assign(Y.prototype,{get(e){return this.allocated[e]},has(e){return void 0!==this.allocated[e]},allocate(e){var r=this.freelist.pop()||this.allocated.length;return this.allocated[r]=e,r},free(e){this.allocated[e]=void 0,this.freelist.push(e)}}),$.allocated.push({value:void 0},{value:null},{value:!0},{value:!1}),$.reserved=$.allocated.length,t.count_emval_handles=()=>{for(var e=0,r=$.reserved;r<$.allocated.length;++r)void 0!==$.allocated[r]&&++e;return e},I=t.UnboundTypeError=(oe=Error,(ie=R("UnboundTypeError",(function(e){this.name="UnboundTypeError",this.message=e;var r=new Error(e).stack;void 0!==r&&(this.stack=this.toString()+"\n"+r.replace(/^Error(:[^\n]*)?\n/,""))}))).prototype=Object.create(oe.prototype),ie.prototype.constructor=ie,ie.prototype.toString=function(){return void 0===this.message?this.name:`${this.name}: ${this.message}`},ie);var ye,pe,we,be,_e,Te,Ae={G:(e,r)=>v(e)(r),j:(e,r,t)=>{throw new y(e).init(r,t),e},R:e=>{},S:(e,r,t,n)=>{},O:(e,r)=>{},K:(e,r)=>{},D:(e,r,t)=>{},M:(e,r)=>{},L:(e,r,t,n)=>{},I:function(e,r,t,n){C.varargs=n},C:(e,r,t,n)=>{},N:(e,r)=>{},z:(e,r,t)=>{},B:(e,r,t)=>{},s:(e,r,t,n,a)=>{},l:(e,r,t,n)=>{x(e,{name:r=E(r),fromWireType:function(e){return!!e},toWireType:function(e,r){return r?t:n},argPackAdvance:8,readValueFromPointer:function(e){return this.fromWireType(i[e])},destructorFunction:null})},k:(e,r)=>{x(e,{name:r=E(r),fromWireType:e=>{var r=(e=>(e||P("Cannot use deleted val. handle = "+e),$.get(e).value))(e);return(e=>{e>=$.reserved&&0==--$.get(e).refcount&&$.free(e)})(e),r},toWireType:(e,r)=>(e=>{switch(e){case void 0:return 1;case null:return 2;case!0:return 3;case!1:return 4;default:return $.allocate({refcount:1,value:e})}})(r),argPackAdvance:8,readValueFromPointer:k,destructorFunction:null})},i:(e,r,t)=>{x(e,{name:r=E(r),fromWireType:e=>e,toWireType:(e,r)=>r,argPackAdvance:8,readValueFromPointer:j(r,t),destructorFunction:null})},f:(e,r,n,a,o,i,u)=>{var l=((e,r)=>{for(var t=[],n=0;n>2]);return t})(r,n);e=(e=>{const r=(e=e.trim()).indexOf("(");return-1!==r?e.substr(0,r):e})(e=E(e)),o=V(a,o),((e,r,n)=>{t.hasOwnProperty(e)?((void 0===n||void 0!==t[e].overloadTable&&void 0!==t[e].overloadTable[n])&&P(`Cannot register public name '${e}' twice`),H(t,e,e),t.hasOwnProperty(n)&&P(`Cannot register multiple overloads of a function with the same number of arguments (${n})!`),t[e].overloadTable[n]=r):(t[e]=r,void 0!==n&&(t[e].numArguments=n))})(e,(function(){((e,r)=>{var t=[],n={};throw r.forEach((function e(r){n[r]||O[r]||(W[r]?W[r].forEach(e):(t.push(r),n[r]=!0))})),new I(`${e}: `+t.map(z).join([", "]))})(`Cannot call ${e} due to unbound types`,l)}),r-1),((n,a,u)=>{function s(a){var u=function(n){var a=[n[0],null].concat(n.slice(1));return((e,r,n)=>{t.hasOwnProperty(e)||U("Replacing nonexistant public symbol"),void 0!==t[e].overloadTable&&void 0!==n?t[e].overloadTable[n]=r:(t[e]=r,t[e].argCount=n)})(e,function(e,r,t,n,a,o){var i=r.length;i<2&&P("argTypes array size mismatch! Must at least get return value and 'this' types!");var u=null!==r[1]&&null!==t,s=function(e){for(var r=1;r{for(;e.length;){var r=e.pop();e.pop()(r)}})(d);else for(var n=u?1:2;n{O.hasOwnProperty(e)?l[r]=O[e]:(c.push(e),S.hasOwnProperty(e)||(S[e]=[]),S[e].push((()=>{l[r]=O[e],++f===c.length&&s(l)})))})),0===c.length&&s(l)})([],l)},d:(e,r,t,n,a)=>{r=E(r),-1===a&&(a=4294967295);var o=e=>e;if(0===n){var i=32-8*t;o=e=>e<>>i}var u=r.includes("unsigned");x(e,{name:r,fromWireType:o,toWireType:u?function(e,r){return this.name,r>>>0}:function(e,r){return this.name,r},argPackAdvance:8,readValueFromPointer:L(r,t,0!==n),destructorFunction:null})},c:(e,r,t)=>{var a=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array][r];function o(e){var r=s[e>>2],t=s[e+4>>2];return new a(n.buffer,t,r)}x(e,{name:t=E(t),fromWireType:o,argPackAdvance:8,readValueFromPointer:o},{ignoreDuplicateRegistrations:!0})},g:(e,r)=>{var t="std::string"===(r=E(r));x(e,{name:r,fromWireType(e){var r,n=s[e>>2],a=e+4;if(t)for(var o=a,u=0;u<=n;++u){var l=a+u;if(u==n||0==i[l]){var c=A(o,l-o);void 0===r?r=c:(r+=String.fromCharCode(0),r+=c),o=l+1}}else{var f=new Array(n);for(u=0;u>2]=n,t&&a)M(r,u,n+1);else if(a)for(var l=0;l255&&(ye(u),P("String has UTF-16 code units that do not fit in 8 bits")),i[u+l]=c}else for(l=0;l{var n,a,o,i,l;t=E(t),2===r?(n=q,a=J,i=X,o=()=>u,l=1):4===r&&(n=Z,a=K,i=Q,o=()=>s,l=2),x(e,{name:t,fromWireType:e=>{for(var t,a=s[e>>2],i=o(),u=e+4,c=0;c<=a;++c){var f=e+4+c*r;if(c==a||0==i[f>>l]){var h=n(u,f-u);void 0===t?t=h:(t+=String.fromCharCode(0),t+=h),u=f+r}}return ye(e),t},toWireType:(e,n)=>{"string"!=typeof n&&P(`Cannot pass non-string to C++ string type ${t}`);var o=i(n),u=we(4+o+r);return s[u>>2]=o>>l,a(n,u+4,o+r),null!==e&&e.push(ye,u),u},argPackAdvance:8,readValueFromPointer:k,destructorFunction(e){ye(e)}})},t:(e,r)=>{x(e,{isVoid:!0,name:r=E(r),argPackAdvance:0,fromWireType:()=>{},toWireType:(e,r)=>{}})},H:()=>{},p:function(e,r,t){var n=ee(e,r),a=new Date(1e3*n);o[t>>2]=a.getUTCSeconds(),o[t+4>>2]=a.getUTCMinutes(),o[t+8>>2]=a.getUTCHours(),o[t+12>>2]=a.getUTCDate(),o[t+16>>2]=a.getUTCMonth(),o[t+20>>2]=a.getUTCFullYear()-1900,o[t+24>>2]=a.getUTCDay();var i=Date.UTC(a.getUTCFullYear(),0,1,0,0,0,0),u=(a.getTime()-i)/864e5|0;o[t+28>>2]=u},q:function(e,r,t){var n=ee(e,r),a=new Date(1e3*n);o[t>>2]=a.getSeconds(),o[t+4>>2]=a.getMinutes(),o[t+8>>2]=a.getHours(),o[t+12>>2]=a.getDate(),o[t+16>>2]=a.getMonth(),o[t+20>>2]=a.getFullYear()-1900,o[t+24>>2]=a.getDay();var i=0|(e=>(re(e.getFullYear())?te:ne)[e.getMonth()]+e.getDate()-1)(a);o[t+28>>2]=i,o[t+36>>2]=-60*a.getTimezoneOffset();var u=new Date(a.getFullYear(),0,1),s=new Date(a.getFullYear(),6,1).getTimezoneOffset(),l=u.getTimezoneOffset(),c=0|(s!=l&&a.getTimezoneOffset()==Math.min(l,s));o[t+32>>2]=c},n:function(e,r,t,n,a,o,i,u){return ee(a,o),-52},o:function(e,r,t,n,a,o,i){ee(o,i)},A:(e,r)=>{if(ae[e]&&(clearTimeout(ae[e].id),delete ae[e]),!r)return 0;var t=setTimeout((()=>{delete ae[e],_e(e,B())}),r);return ae[e]={id:t,timeout_ms:r},0},w:(e,r,t)=>{var n=(new Date).getFullYear(),a=new Date(n,0,1),i=new Date(n,6,1),u=a.getTimezoneOffset(),l=i.getTimezoneOffset(),c=Math.max(u,l);function f(e){var r=e.toTimeString().match(/\(([A-Za-z ]+)\)$/);return r?r[1]:"GMT"}s[e>>2]=60*c,o[r>>2]=Number(u!=l);var h=f(a),d=f(i),g=ue(h),m=ue(d);l>2]=g,s[t+4>>2]=m):(s[t>>2]=m,s[t+4>>2]=g)},b:()=>{!function(e){throw""}()},P:()=>Date.now(),x:()=>2147483648,Q:(e,r,t)=>i.copyWithin(e,r,r+t),v:e=>{var r=i.length,t=2147483648;if((e>>>=0)>t)return!1;for(var n,a=1;a<=4;a*=2){var o=r*(1+.2/a);o=Math.min(o,e+100663296);var u=Math.min(t,(n=Math.max(e,o))+(65536-n%65536)%65536);if(se(u))return!0}return!1},T:(e,r)=>{var t=0;return ce().forEach(((a,o)=>{var i=r+t;s[e+4*o>>2]=i,((e,r)=>{for(var t=0;t>0]=e.charCodeAt(t);n[r>>0]=0})(a,i),t+=a.length+1})),0},U:(e,r)=>{var t=ce();s[e>>2]=t.length;var n=0;return t.forEach((e=>n+=e.length+1)),s[r>>2]=n,0},E:he,h:e=>52,J:(e,r)=>{var t=0;return 0==e?t=2:1!=e&&2!=e||(t=64),n[r>>0]=2,a[r+2>>1]=1,tempI64=[t>>>0,(tempDouble=t,+Math.abs(tempDouble)>=1?tempDouble>0?+Math.floor(tempDouble/4294967296)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],o[r+8>>2]=tempI64[0],o[r+12>>2]=tempI64[1],tempI64=[0,(tempDouble=0,+Math.abs(tempDouble)>=1?tempDouble>0?+Math.floor(tempDouble/4294967296)>>>0:~~+Math.ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],o[r+16>>2]=tempI64[0],o[r+20>>2]=tempI64[1],0},m:function(e,r,t,n,a,o){return ee(n,a),52},F:(e,r,t,n)=>52,r:function(e,r,t,n,a){return ee(r,t),70},y:(e,r,t,n)=>{for(var a=0,o=0;o>2],l=s[r+4>>2];r+=8;for(var c=0;c>2]=a,0},a:f,V:fe,u:(e,r,t,a,i)=>((e,r,t,a)=>{var i=s[a+40>>2],u={tm_sec:o[a>>2],tm_min:o[a+4>>2],tm_hour:o[a+8>>2],tm_mday:o[a+12>>2],tm_mon:o[a+16>>2],tm_year:o[a+20>>2],tm_wday:o[a+24>>2],tm_yday:o[a+28>>2],tm_isdst:o[a+32>>2],tm_gmtoff:o[a+36>>2],tm_zone:i?A(i):""},l=A(t),c={"%c":"%a %b %d %H:%M:%S %Y","%D":"%m/%d/%y","%F":"%Y-%m-%d","%h":"%b","%r":"%I:%M:%S %p","%R":"%H:%M","%T":"%H:%M:%S","%x":"%m/%d/%y","%X":"%H:%M:%S","%Ec":"%c","%EC":"%C","%Ex":"%m/%d/%y","%EX":"%H:%M:%S","%Ey":"%y","%EY":"%Y","%Od":"%d","%Oe":"%e","%OH":"%H","%OI":"%I","%Om":"%m","%OM":"%M","%OS":"%S","%Ou":"%u","%OU":"%U","%OV":"%V","%Ow":"%w","%OW":"%W","%Oy":"%y"};for(var f in c)l=l.replace(new RegExp(f,"g"),c[f]);var h=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],d=["January","February","March","April","May","June","July","August","September","October","November","December"];function g(e,r,t){for(var n="number"==typeof e?e.toString():e||"";n.length0?1:0}var n;return 0===(n=t(e.getFullYear()-r.getFullYear()))&&0===(n=t(e.getMonth()-r.getMonth()))&&(n=t(e.getDate()-r.getDate())),n}function y(e){switch(e.getDay()){case 0:return new Date(e.getFullYear()-1,11,29);case 1:return e;case 2:return new Date(e.getFullYear(),0,3);case 3:return new Date(e.getFullYear(),0,2);case 4:return new Date(e.getFullYear(),0,1);case 5:return new Date(e.getFullYear()-1,11,31);case 6:return new Date(e.getFullYear()-1,11,30)}}function p(e){var r=((e,r)=>{for(var t=new Date(e.getTime());r>0;){var n=re(t.getFullYear()),a=t.getMonth(),o=(n?me:ve)[a];if(!(r>o-t.getDate()))return t.setDate(t.getDate()+r),t;r-=o-t.getDate()+1,t.setDate(1),a<11?t.setMonth(a+1):(t.setMonth(0),t.setFullYear(t.getFullYear()+1))}return t})(new Date(e.tm_year+1900,0,1),e.tm_yday),t=new Date(r.getFullYear(),0,4),n=new Date(r.getFullYear()+1,0,4),a=y(t),o=y(n);return v(a,r)<=0?v(o,r)<=0?r.getFullYear()+1:r.getFullYear():r.getFullYear()-1}var w={"%a":e=>h[e.tm_wday].substring(0,3),"%A":e=>h[e.tm_wday],"%b":e=>d[e.tm_mon].substring(0,3),"%B":e=>d[e.tm_mon],"%C":e=>m((e.tm_year+1900)/100|0,2),"%d":e=>m(e.tm_mday,2),"%e":e=>g(e.tm_mday,2," "),"%g":e=>p(e).toString().substring(2),"%G":e=>p(e),"%H":e=>m(e.tm_hour,2),"%I":e=>{var r=e.tm_hour;return 0==r?r=12:r>12&&(r-=12),m(r,2)},"%j":e=>m(e.tm_mday+((e,r)=>{for(var t=0,n=0;n<=r;t+=e[n++]);return t})(re(e.tm_year+1900)?me:ve,e.tm_mon-1),3),"%m":e=>m(e.tm_mon+1,2),"%M":e=>m(e.tm_min,2),"%n":()=>"\n","%p":e=>e.tm_hour>=0&&e.tm_hour<12?"AM":"PM","%S":e=>m(e.tm_sec,2),"%t":()=>"\t","%u":e=>e.tm_wday||7,"%U":e=>{var r=e.tm_yday+7-e.tm_wday;return m(Math.floor(r/7),2)},"%V":e=>{var r=Math.floor((e.tm_yday+7-(e.tm_wday+6)%7)/7);if((e.tm_wday+371-e.tm_yday-2)%7<=2&&r++,r){if(53==r){var t=(e.tm_wday+371-e.tm_yday)%7;4==t||3==t&&re(e.tm_year)||(r=1)}}else{r=52;var n=(e.tm_wday+7-e.tm_yday-1)%7;(4==n||5==n&&re(e.tm_year%400-1))&&r++}return m(r,2)},"%w":e=>e.tm_wday,"%W":e=>{var r=e.tm_yday+7-(e.tm_wday+6)%7;return m(Math.floor(r/7),2)},"%y":e=>(e.tm_year+1900).toString().substring(2),"%Y":e=>e.tm_year+1900,"%z":e=>{var r=e.tm_gmtoff,t=r>=0;return r=(r=Math.abs(r)/60)/60*100+r%60,(t?"+":"-")+String("0000"+r).slice(-4)},"%Z":e=>e.tm_zone,"%%":()=>"%"};for(var f in l=l.replace(/%%/g,"\0\0"),w)l.includes(f)&&(l=l.replace(new RegExp(f,"g"),w[f](u)));l=l.replace(/\0\0/g,"%");var b,_,T,C,M,E=(_=D(b=l)+1,T=new Array(_),F(b,T,0,T.length),T);return E.length>r?0:(C=E,M=e,n.set(C,M),E.length-1)})(e,r,t,a)},Ce={a:Ae};return WebAssembly.instantiate(t.wasm,Ce).then((e=>{var n=(e.instance||e).exports;ye=n.X,pe=n.Y,we=n.Z,be=n.$,_e=n.aa,n.setThrew,n.__cxa_increment_exception_refcount,Te=n.ba,n.ca,n.da,n.ea,n.fa,n.ga,n.ha,n.ia,n.ja,m=n._,function(e){e.W()}(n),r(t),pe()})),e.ready}; \ No newline at end of file diff --git a/oioioi/programs/static/code_formatter/clang-format.wasm b/oioioi/programs/static/code_formatter/clang-format.wasm new file mode 100644 index 000000000..540edb03b Binary files /dev/null and b/oioioi/programs/static/code_formatter/clang-format.wasm differ diff --git a/oioioi/programs/static/code_formatter/formatter.js b/oioioi/programs/static/code_formatter/formatter.js new file mode 100644 index 000000000..1cce89457 --- /dev/null +++ b/oioioi/programs/static/code_formatter/formatter.js @@ -0,0 +1,31 @@ +import init, { format, version } from "./clang-format.js"; + +// clang-format +async function cpp_code_formatter(source) { + await init(); + const formatted = format( + source, + "main.cc", + JSON.stringify({ + BasedOnStyle: "Chromium", + IndentWidth: 4, + ColumnLimit: 80, + }) + ); + return formatted; +} + +async function format_cpp_code() { + const source = document.getElementById("raw_source").textContent; + const formatted_source = await cpp_code_formatter(source); + const visible_source = document.getElementById("visible_source"); + const coloured_source = Prism.highlight(formatted_source, Prism.languages.cpp, "cpp"); + visible_source.innerHTML = coloured_source; + + const button = document.getElementById("format_btn"); + button.classList.remove("btn-outline-secondary"); + button.classList.add("btn-success"); + button.textContent = gettext("Formatted!"); +} + +globalThis.format_cpp_code = format_cpp_code; \ No newline at end of file diff --git a/oioioi/programs/static/code_formatter/readme.txt b/oioioi/programs/static/code_formatter/readme.txt new file mode 100644 index 000000000..bc84664f8 --- /dev/null +++ b/oioioi/programs/static/code_formatter/readme.txt @@ -0,0 +1,2 @@ +Clang-format WASM build (with source) can be found here: https://github.com/wasm-fmt/clang-format/releases/download/v0.2.8/clang-format.wasm +In order to update just replace the .wasm file. diff --git a/oioioi/programs/static/common/prism.css b/oioioi/programs/static/common/prism.css new file mode 100644 index 000000000..760c00a94 --- /dev/null +++ b/oioioi/programs/static/common/prism.css @@ -0,0 +1,4 @@ +/* PrismJS 1.29.0 +https://prismjs.com/download.html#themes=prism&languages=clike+c+cpp+java+pascal+python&plugins=line-numbers */ +code[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=language-],pre[class*=language-]{background:#f5f2f0}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}.token.cdata,.token.comment,.token.doctype,.token.prolog{color:#708090}.token.punctuation{color:#999}.token.namespace{opacity:.7}.token.boolean,.token.constant,.token.deleted,.token.number,.token.property,.token.symbol,.token.tag{color:#905}.token.attr-name,.token.builtin,.token.char,.token.inserted,.token.selector,.token.string{color:#690}.language-css .token.string,.style .token.string,.token.entity,.token.operator,.token.url{color:#9a6e3a;background:hsla(0,0%,100%,.5)}.token.atrule,.token.attr-value,.token.keyword{color:#07a}.token.class-name,.token.function{color:#dd4a68}.token.important,.token.regex,.token.variable{color:#e90}.token.bold,.token.important{font-weight:700}.token.italic{font-style:italic}.token.entity{cursor:help} +pre[class*=language-].line-numbers{position:relative;padding-left:3.8em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.8em;text-align:right} diff --git a/oioioi/programs/static/common/prism.js b/oioioi/programs/static/common/prism.js new file mode 100644 index 000000000..4e441f014 --- /dev/null +++ b/oioioi/programs/static/common/prism.js @@ -0,0 +1,10 @@ +/* PrismJS 1.29.0 +https://prismjs.com/download.html#themes=prism&languages=clike+c+cpp+java+pascal+python&plugins=line-numbers */ +var _self="undefined"!=typeof window?window:"undefined"!=typeof WorkerGlobalScope&&self instanceof WorkerGlobalScope?self:{},Prism=function(e){var n=/(?:^|\s)lang(?:uage)?-([\w-]+)(?=\s|$)/i,t=0,r={},a={manual:e.Prism&&e.Prism.manual,disableWorkerMessageHandler:e.Prism&&e.Prism.disableWorkerMessageHandler,util:{encode:function e(n){return n instanceof i?new i(n.type,e(n.content),n.alias):Array.isArray(n)?n.map(e):n.replace(/&/g,"&").replace(/=g.reach);A+=w.value.length,w=w.next){var E=w.value;if(n.length>e.length)return;if(!(E instanceof i)){var P,L=1;if(y){if(!(P=l(b,A,e,m))||P.index>=e.length)break;var S=P.index,O=P.index+P[0].length,j=A;for(j+=w.value.length;S>=j;)j+=(w=w.next).value.length;if(A=j-=w.value.length,w.value instanceof i)continue;for(var C=w;C!==n.tail&&(jg.reach&&(g.reach=W);var z=w.prev;if(_&&(z=u(n,z,_),A+=_.length),c(n,z,L),w=u(n,z,new i(f,p?a.tokenize(N,p):N,k,N)),M&&u(n,w,M),L>1){var I={cause:f+","+d,reach:W};o(e,n,t,w.prev,A,I),g&&I.reach>g.reach&&(g.reach=I.reach)}}}}}}function s(){var e={value:null,prev:null,next:null},n={value:null,prev:e,next:null};e.next=n,this.head=e,this.tail=n,this.length=0}function u(e,n,t){var r=n.next,a={value:t,prev:n,next:r};return n.next=a,r.prev=a,e.length++,a}function c(e,n,t){for(var r=n.next,a=0;a"+i.content+""},!e.document)return e.addEventListener?(a.disableWorkerMessageHandler||e.addEventListener("message",(function(n){var t=JSON.parse(n.data),r=t.language,i=t.code,l=t.immediateClose;e.postMessage(a.highlight(i,a.languages[r],r)),l&&e.close()}),!1),a):a;var g=a.util.currentScript();function f(){a.manual||a.highlightAll()}if(g&&(a.filename=g.src,g.hasAttribute("data-manual")&&(a.manual=!0)),!a.manual){var h=document.readyState;"loading"===h||"interactive"===h&&g&&g.defer?document.addEventListener("DOMContentLoaded",f):window.requestAnimationFrame?window.requestAnimationFrame(f):window.setTimeout(f,16)}return a}(_self);"undefined"!=typeof module&&module.exports&&(module.exports=Prism),"undefined"!=typeof global&&(global.Prism=Prism); +Prism.languages.clike={comment:[{pattern:/(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,lookbehind:!0,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},"class-name":{pattern:/(\b(?:class|extends|implements|instanceof|interface|new|trait)\s+|\bcatch\s+\()[\w.\\]+/i,lookbehind:!0,inside:{punctuation:/[.\\]/}},keyword:/\b(?:break|catch|continue|do|else|finally|for|function|if|in|instanceof|new|null|return|throw|try|while)\b/,boolean:/\b(?:false|true)\b/,function:/\b\w+(?=\()/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,operator:/[<>]=?|[!=]=?=?|--?|\+\+?|&&?|\|\|?|[?*/~^%]/,punctuation:/[{}[\];(),.:]/}; +Prism.languages.c=Prism.languages.extend("clike",{comment:{pattern:/\/\/(?:[^\r\n\\]|\\(?:\r\n?|\n|(?![\r\n])))*|\/\*[\s\S]*?(?:\*\/|$)/,greedy:!0},string:{pattern:/"(?:\\(?:\r\n|[\s\S])|[^"\\\r\n])*"/,greedy:!0},"class-name":{pattern:/(\b(?:enum|struct)\s+(?:__attribute__\s*\(\([\s\S]*?\)\)\s*)?)\w+|\b[a-z]\w*_t\b/,lookbehind:!0},keyword:/\b(?:_Alignas|_Alignof|_Atomic|_Bool|_Complex|_Generic|_Imaginary|_Noreturn|_Static_assert|_Thread_local|__attribute__|asm|auto|break|case|char|const|continue|default|do|double|else|enum|extern|float|for|goto|if|inline|int|long|register|return|short|signed|sizeof|static|struct|switch|typedef|typeof|union|unsigned|void|volatile|while)\b/,function:/\b[a-z_]\w*(?=\s*\()/i,number:/(?:\b0x(?:[\da-f]+(?:\.[\da-f]*)?|\.[\da-f]+)(?:p[+-]?\d+)?|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?)[ful]{0,4}/i,operator:/>>=?|<<=?|->|([-+&|:])\1|[?:~]|[-+*/%&|^!=<>]=?/}),Prism.languages.insertBefore("c","string",{char:{pattern:/'(?:\\(?:\r\n|[\s\S])|[^'\\\r\n]){0,32}'/,greedy:!0}}),Prism.languages.insertBefore("c","string",{macro:{pattern:/(^[\t ]*)#\s*[a-z](?:[^\r\n\\/]|\/(?!\*)|\/\*(?:[^*]|\*(?!\/))*\*\/|\\(?:\r\n|[\s\S]))*/im,lookbehind:!0,greedy:!0,alias:"property",inside:{string:[{pattern:/^(#\s*include\s*)<[^>]+>/,lookbehind:!0},Prism.languages.c.string],char:Prism.languages.c.char,comment:Prism.languages.c.comment,"macro-name":[{pattern:/(^#\s*define\s+)\w+\b(?!\()/i,lookbehind:!0},{pattern:/(^#\s*define\s+)\w+\b(?=\()/i,lookbehind:!0,alias:"function"}],directive:{pattern:/^(#\s*)[a-z]+/,lookbehind:!0,alias:"keyword"},"directive-hash":/^#/,punctuation:/##|\\(?=[\r\n])/,expression:{pattern:/\S[\s\S]*/,inside:Prism.languages.c}}}}),Prism.languages.insertBefore("c","function",{constant:/\b(?:EOF|NULL|SEEK_CUR|SEEK_END|SEEK_SET|__DATE__|__FILE__|__LINE__|__TIMESTAMP__|__TIME__|__func__|stderr|stdin|stdout)\b/}),delete Prism.languages.c.boolean; +!function(e){var t=/\b(?:alignas|alignof|asm|auto|bool|break|case|catch|char|char16_t|char32_t|char8_t|class|co_await|co_return|co_yield|compl|concept|const|const_cast|consteval|constexpr|constinit|continue|decltype|default|delete|do|double|dynamic_cast|else|enum|explicit|export|extern|final|float|for|friend|goto|if|import|inline|int|int16_t|int32_t|int64_t|int8_t|long|module|mutable|namespace|new|noexcept|nullptr|operator|override|private|protected|public|register|reinterpret_cast|requires|return|short|signed|sizeof|static|static_assert|static_cast|struct|switch|template|this|thread_local|throw|try|typedef|typeid|typename|uint16_t|uint32_t|uint64_t|uint8_t|union|unsigned|using|virtual|void|volatile|wchar_t|while)\b/,n="\\b(?!)\\w+(?:\\s*\\.\\s*\\w+)*\\b".replace(//g,(function(){return t.source}));e.languages.cpp=e.languages.extend("c",{"class-name":[{pattern:RegExp("(\\b(?:class|concept|enum|struct|typename)\\s+)(?!)\\w+".replace(//g,(function(){return t.source}))),lookbehind:!0},/\b[A-Z]\w*(?=\s*::\s*\w+\s*\()/,/\b[A-Z_]\w*(?=\s*::\s*~\w+\s*\()/i,/\b\w+(?=\s*<(?:[^<>]|<(?:[^<>]|<[^<>]*>)*>)*>\s*::\s*\w+\s*\()/],keyword:t,number:{pattern:/(?:\b0b[01']+|\b0x(?:[\da-f']+(?:\.[\da-f']*)?|\.[\da-f']+)(?:p[+-]?[\d']+)?|(?:\b[\d']+(?:\.[\d']*)?|\B\.[\d']+)(?:e[+-]?[\d']+)?)[ful]{0,4}/i,greedy:!0},operator:/>>=?|<<=?|->|--|\+\+|&&|\|\||[?:~]|<=>|[-+*/%&|^!=<>]=?|\b(?:and|and_eq|bitand|bitor|not|not_eq|or|or_eq|xor|xor_eq)\b/,boolean:/\b(?:false|true)\b/}),e.languages.insertBefore("cpp","string",{module:{pattern:RegExp('(\\b(?:import|module)\\s+)(?:"(?:\\\\(?:\r\n|[^])|[^"\\\\\r\n])*"|<[^<>\r\n]*>|'+"(?:\\s*:\\s*)?|:\\s*".replace(//g,(function(){return n}))+")"),lookbehind:!0,greedy:!0,inside:{string:/^[<"][\s\S]+/,operator:/:/,punctuation:/\./}},"raw-string":{pattern:/R"([^()\\ ]{0,16})\([\s\S]*?\)\1"/,alias:"string",greedy:!0}}),e.languages.insertBefore("cpp","keyword",{"generic-function":{pattern:/\b(?!operator\b)[a-z_]\w*\s*<(?:[^<>]|<[^<>]*>)*>(?=\s*\()/i,inside:{function:/^\w+/,generic:{pattern:/<[\s\S]+/,alias:"class-name",inside:e.languages.cpp}}}}),e.languages.insertBefore("cpp","operator",{"double-colon":{pattern:/::/,alias:"punctuation"}}),e.languages.insertBefore("cpp","class-name",{"base-clause":{pattern:/(\b(?:class|struct)\s+\w+\s*:\s*)[^;{}"'\s]+(?:\s+[^;{}"'\s]+)*(?=\s*[;{])/,lookbehind:!0,greedy:!0,inside:e.languages.extend("cpp",{})}}),e.languages.insertBefore("inside","double-colon",{"class-name":/\b[a-z_]\w*\b(?!\s*::)/i},e.languages.cpp["base-clause"])}(Prism); +!function(e){var n=/\b(?:abstract|assert|boolean|break|byte|case|catch|char|class|const|continue|default|do|double|else|enum|exports|extends|final|finally|float|for|goto|if|implements|import|instanceof|int|interface|long|module|native|new|non-sealed|null|open|opens|package|permits|private|protected|provides|public|record(?!\s*[(){}[\]<>=%~.:,;?+\-*/&|^])|requires|return|sealed|short|static|strictfp|super|switch|synchronized|this|throw|throws|to|transient|transitive|try|uses|var|void|volatile|while|with|yield)\b/,t="(?:[a-z]\\w*\\s*\\.\\s*)*(?:[A-Z]\\w*\\s*\\.\\s*)*",s={pattern:RegExp("(^|[^\\w.])"+t+"[A-Z](?:[\\d_A-Z]*[a-z]\\w*)?\\b"),lookbehind:!0,inside:{namespace:{pattern:/^[a-z]\w*(?:\s*\.\s*[a-z]\w*)*(?:\s*\.)?/,inside:{punctuation:/\./}},punctuation:/\./}};e.languages.java=e.languages.extend("clike",{string:{pattern:/(^|[^\\])"(?:\\.|[^"\\\r\n])*"/,lookbehind:!0,greedy:!0},"class-name":[s,{pattern:RegExp("(^|[^\\w.])"+t+"[A-Z]\\w*(?=\\s+\\w+\\s*[;,=()]|\\s*(?:\\[[\\s,]*\\]\\s*)?::\\s*new\\b)"),lookbehind:!0,inside:s.inside},{pattern:RegExp("(\\b(?:class|enum|extends|implements|instanceof|interface|new|record|throws)\\s+)"+t+"[A-Z]\\w*\\b"),lookbehind:!0,inside:s.inside}],keyword:n,function:[e.languages.clike.function,{pattern:/(::\s*)[a-z_]\w*/,lookbehind:!0}],number:/\b0b[01][01_]*L?\b|\b0x(?:\.[\da-f_p+-]+|[\da-f_]+(?:\.[\da-f_p+-]+)?)\b|(?:\b\d[\d_]*(?:\.[\d_]*)?|\B\.\d[\d_]*)(?:e[+-]?\d[\d_]*)?[dfl]?/i,operator:{pattern:/(^|[^.])(?:<<=?|>>>?=?|->|--|\+\+|&&|\|\||::|[?:~]|[-+*/%&|^!=<>]=?)/m,lookbehind:!0},constant:/\b[A-Z][A-Z_\d]+\b/}),e.languages.insertBefore("java","string",{"triple-quoted-string":{pattern:/"""[ \t]*[\r\n](?:(?:"|"")?(?:\\.|[^"\\]))*"""/,greedy:!0,alias:"string"},char:{pattern:/'(?:\\.|[^'\\\r\n]){1,6}'/,greedy:!0}}),e.languages.insertBefore("java","class-name",{annotation:{pattern:/(^|[^.])@\w+(?:\s*\.\s*\w+)*/,lookbehind:!0,alias:"punctuation"},generics:{pattern:/<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&)|<(?:[\w\s,.?]|&(?!&))*>)*>)*>)*>/,inside:{"class-name":s,keyword:n,punctuation:/[<>(),.:]/,operator:/[?&|]/}},import:[{pattern:RegExp("(\\bimport\\s+)"+t+"(?:[A-Z]\\w*|\\*)(?=\\s*;)"),lookbehind:!0,inside:{namespace:s.inside.namespace,punctuation:/\./,operator:/\*/,"class-name":/\w+/}},{pattern:RegExp("(\\bimport\\s+static\\s+)"+t+"(?:\\w+|\\*)(?=\\s*;)"),lookbehind:!0,alias:"static",inside:{namespace:s.inside.namespace,static:/\b\w+$/,punctuation:/\./,operator:/\*/,"class-name":/\w+/}}],namespace:{pattern:RegExp("(\\b(?:exports|import(?:\\s+static)?|module|open|opens|package|provides|requires|to|transitive|uses|with)\\s+)(?!)[a-z]\\w*(?:\\.[a-z]\\w*)*\\.?".replace(//g,(function(){return n.source}))),lookbehind:!0,inside:{punctuation:/\./}}})}(Prism); +Prism.languages.pascal={directive:{pattern:/\{\$[\s\S]*?\}/,greedy:!0,alias:["marco","property"]},comment:{pattern:/\(\*[\s\S]*?\*\)|\{[\s\S]*?\}|\/\/.*/,greedy:!0},string:{pattern:/(?:'(?:''|[^'\r\n])*'(?!')|#[&$%]?[a-f\d]+)+|\^[a-z]/i,greedy:!0},asm:{pattern:/(\basm\b)[\s\S]+?(?=\bend\s*[;[])/i,lookbehind:!0,greedy:!0,inside:null},keyword:[{pattern:/(^|[^&])\b(?:absolute|array|asm|begin|case|const|constructor|destructor|do|downto|else|end|file|for|function|goto|if|implementation|inherited|inline|interface|label|nil|object|of|operator|packed|procedure|program|record|reintroduce|repeat|self|set|string|then|to|type|unit|until|uses|var|while|with)\b/i,lookbehind:!0},{pattern:/(^|[^&])\b(?:dispose|exit|false|new|true)\b/i,lookbehind:!0},{pattern:/(^|[^&])\b(?:class|dispinterface|except|exports|finalization|finally|initialization|inline|library|on|out|packed|property|raise|resourcestring|threadvar|try)\b/i,lookbehind:!0},{pattern:/(^|[^&])\b(?:absolute|abstract|alias|assembler|bitpacked|break|cdecl|continue|cppdecl|cvar|default|deprecated|dynamic|enumerator|experimental|export|external|far|far16|forward|generic|helper|implements|index|interrupt|iochecks|local|message|name|near|nodefault|noreturn|nostackframe|oldfpccall|otherwise|overload|override|pascal|platform|private|protected|public|published|read|register|reintroduce|result|safecall|saveregisters|softfloat|specialize|static|stdcall|stored|strict|unaligned|unimplemented|varargs|virtual|write)\b/i,lookbehind:!0}],number:[/(?:[&%]\d+|\$[a-f\d]+)/i,/\b\d+(?:\.\d+)?(?:e[+-]?\d+)?/i],operator:[/\.\.|\*\*|:=|<[<=>]?|>[>=]?|[+\-*\/]=?|[@^=]/,{pattern:/(^|[^&])\b(?:and|as|div|exclude|in|include|is|mod|not|or|shl|shr|xor)\b/,lookbehind:!0}],punctuation:/\(\.|\.\)|[()\[\]:;,.]/},Prism.languages.pascal.asm.inside=Prism.languages.extend("pascal",{asm:void 0,keyword:void 0,operator:void 0}),Prism.languages.objectpascal=Prism.languages.pascal; +Prism.languages.python={comment:{pattern:/(^|[^\\])#.*/,lookbehind:!0,greedy:!0},"string-interpolation":{pattern:/(?:f|fr|rf)(?:("""|''')[\s\S]*?\1|("|')(?:\\.|(?!\2)[^\\\r\n])*\2)/i,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^{])(?:\{\{)*)\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}]|\{(?!\{)(?:[^{}])+\})+\})+\}/,lookbehind:!0,inside:{"format-spec":{pattern:/(:)[^:(){}]+(?=\}$)/,lookbehind:!0},"conversion-option":{pattern:/![sra](?=[:}]$)/,alias:"punctuation"},rest:null}},string:/[\s\S]+/}},"triple-quoted-string":{pattern:/(?:[rub]|br|rb)?("""|''')[\s\S]*?\1/i,greedy:!0,alias:"string"},string:{pattern:/(?:[rub]|br|rb)?("|')(?:\\.|(?!\1)[^\\\r\n])*\1/i,greedy:!0},function:{pattern:/((?:^|\s)def[ \t]+)[a-zA-Z_]\w*(?=\s*\()/g,lookbehind:!0},"class-name":{pattern:/(\bclass\s+)\w+/i,lookbehind:!0},decorator:{pattern:/(^[\t ]*)@\w+(?:\.\w+)*/m,lookbehind:!0,alias:["annotation","punctuation"],inside:{punctuation:/\./}},keyword:/\b(?:_(?=\s*:)|and|as|assert|async|await|break|case|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|match|nonlocal|not|or|pass|print|raise|return|try|while|with|yield)\b/,builtin:/\b(?:__import__|abs|all|any|apply|ascii|basestring|bin|bool|buffer|bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|complex|delattr|dict|dir|divmod|enumerate|eval|execfile|file|filter|float|format|frozenset|getattr|globals|hasattr|hash|help|hex|id|input|int|intern|isinstance|issubclass|iter|len|list|locals|long|map|max|memoryview|min|next|object|oct|open|ord|pow|property|range|raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|vars|xrange|zip)\b/,boolean:/\b(?:False|None|True)\b/,number:/\b0(?:b(?:_?[01])+|o(?:_?[0-7])+|x(?:_?[a-f0-9])+)\b|(?:\b\d+(?:_\d+)*(?:\.(?:\d+(?:_\d+)*)?)?|\B\.\d+(?:_\d+)*)(?:e[+-]?\d+(?:_\d+)*)?j?(?!\w)/i,operator:/[-+%=]=?|!=|:=|\*\*?=?|\/\/?=?|<[<=>]?|>[=>]?|[&|^~]/,punctuation:/[{}[\];(),.:]/},Prism.languages.python["string-interpolation"].inside.interpolation.inside.rest=Prism.languages.python,Prism.languages.py=Prism.languages.python; +!function(){if("undefined"!=typeof Prism&&"undefined"!=typeof document){var e="line-numbers",n=/\n(?!$)/g,t=Prism.plugins.lineNumbers={getLine:function(n,t){if("PRE"===n.tagName&&n.classList.contains(e)){var i=n.querySelector(".line-numbers-rows");if(i){var r=parseInt(n.getAttribute("data-start"),10)||1,s=r+(i.children.length-1);ts&&(t=s);var l=t-r;return i.children[l]}}},resize:function(e){r([e])},assumeViewportIndependence:!0},i=void 0;window.addEventListener("resize",(function(){t.assumeViewportIndependence&&i===window.innerWidth||(i=window.innerWidth,r(Array.prototype.slice.call(document.querySelectorAll("pre.line-numbers"))))})),Prism.hooks.add("complete",(function(t){if(t.code){var i=t.element,s=i.parentNode;if(s&&/pre/i.test(s.nodeName)&&!i.querySelector(".line-numbers-rows")&&Prism.util.isActive(i,e)){i.classList.remove(e),s.classList.add(e);var l,o=t.code.match(n),a=o?o.length+1:1,u=new Array(a+1).join("");(l=document.createElement("span")).setAttribute("aria-hidden","true"),l.className="line-numbers-rows",l.innerHTML=u,s.hasAttribute("data-start")&&(s.style.counterReset="linenumber "+(parseInt(s.getAttribute("data-start"),10)-1)),t.element.appendChild(l),r([s]),Prism.hooks.run("line-numbers",t)}}})),Prism.hooks.add("line-numbers",(function(e){e.plugins=e.plugins||{},e.plugins.lineNumbers=!0}))}function r(e){if(0!=(e=e.filter((function(e){var n,t=(n=e,n?window.getComputedStyle?getComputedStyle(n):n.currentStyle||null:null)["white-space"];return"pre-wrap"===t||"pre-line"===t}))).length){var t=e.map((function(e){var t=e.querySelector("code"),i=e.querySelector(".line-numbers-rows");if(t&&i){var r=e.querySelector(".line-numbers-sizer"),s=t.textContent.split(n);r||((r=document.createElement("span")).className="line-numbers-sizer",t.appendChild(r)),r.innerHTML="0",r.style.display="block";var l=r.getBoundingClientRect().height;return r.innerHTML="",{element:e,lines:s,lineHeights:[],oneLinerHeight:l,sizer:r}}})).filter(Boolean);t.forEach((function(e){var n=e.sizer,t=e.lines,i=e.lineHeights,r=e.oneLinerHeight;i[t.length-1]=void 0,t.forEach((function(e,t){if(e&&e.length>1){var s=n.appendChild(document.createElement("span"));s.style.display="block",s.textContent=e}else i[t]=r}))})),t.forEach((function(e){for(var n=e.sizer,t=e.lineHeights,i=0,r=0;r {{ css|safe }} + {% endblock %} {% block title %} @@ -13,17 +14,28 @@ {% endblock %} {% block main-content %} + + + {% if decode_error %} {% include "programs/file_decoding_error.html" %} {% endif %} - {% if is_source_safe %} - -
{{ source|safe }}
- {% else %} -
{{ raw_source }}
+ + {% if extension == 'cpp' or extension == 'cc' or extension == 'c' %} +       + + {% endif %} + + + + +
{{raw_source}}
+ {% endblock %} diff --git a/oioioi/programs/tests.py b/oioioi/programs/tests.py index 0cd8d6273..cffcb9a0a 100644 --- a/oioioi/programs/tests.py +++ b/oioioi/programs/tests.py @@ -151,7 +151,6 @@ def test_safe_exec_mode(self): contest = Contest.objects.get() self.assertEqual(contest.controller.get_safe_exec_mode(), 'sio2jail') - class TestProgramsViews(TestCase, TestStreamingMixin): fixtures = [ 'test_users', @@ -173,6 +172,9 @@ def test_submission_views(self): show_response = self.client.get( reverse('show_submission_source', kwargs=kwargs) ) + self.assertTrue( + 'format_btn' in show_response.content.decode('utf-8') + ) self.assertEqual(show_response.status_code, 200) # Download plain text response. download_response = self.client.get( @@ -267,6 +269,32 @@ def test_model_solutions_view(self): self.assertEqual(no_whitespaces_content.count('>10.00s<'), 5) +class TestProgramsViewsPython(TestCase, TestStreamingMixin): + fixtures = [ + 'test_users', + 'test_contest', + 'test_full_package', + 'test_problem_instance', + 'test_permissions', + 'test_submission_python', + ] + + def test_python_formatting_not_visible(self): + self.assertTrue(self.client.login(username='test_user')) + submission = ProgramSubmission.objects.get(pk=1) + kwargs = { + 'contest_id': submission.problem_instance.contest.id, + 'submission_id': submission.id, + } + # Download shown response. + show_response = self.client.get( + reverse('show_submission_source', kwargs=kwargs) + ) + self.assertFalse( + 'format_btn' in show_response.content.decode('utf-8') + ) + + class TestSourceWithoutContest(TestCase): fixtures = [ 'test_users', diff --git a/oioioi/programs/views.py b/oioioi/programs/views.py index 586ccc265..b221e07ab 100644 --- a/oioioi/programs/views.py +++ b/oioioi/programs/views.py @@ -1,11 +1,8 @@ import difflib -# Workaround for race condition in fnmatchcase which is used by pygments -import fnmatch import logging import os import shutil -import sys import tempfile import zipfile @@ -18,12 +15,6 @@ from django.urls import reverse from django.utils.translation import gettext_lazy as _ from django.views.decorators.http import require_POST -from pygments import highlight - -# pylint: disable=no-name-in-module -from pygments.formatters import HtmlFormatter -from pygments.lexers import guess_lexer_for_filename -from pygments.util import ClassNotFound from oioioi.base.permissions import enforce_condition from oioioi.base.utils import jsonify, strip_num_or_hash @@ -52,28 +43,22 @@ get_submittable_languages, ) -fnmatch._MAXCACHE = sys.maxsize - logger = logging.getLogger(__name__) @enforce_condition(~contest_exists | can_enter_contest) def show_submission_source_view(request, submission_id): + def get_prismjs_extension(extension): + if extension == "cc": + return "cpp" + return extension + source_file = get_submission_source_file_or_error(request, submission_id) raw_source, decode_error = decode_str(source_file.read()) filename = source_file.file.name + extension = filename.split('.')[-1] + prismjs_extension = get_prismjs_extension(extension) is_source_safe = False - try: - lexer = guess_lexer_for_filename(filename, raw_source) - formatter = HtmlFormatter( - linenos=True, line_number_chars=3, cssclass='syntax-highlight' - ) - formatted_source = highlight(raw_source, lexer, formatter) - formatted_source_css = HtmlFormatter().get_style_defs('.syntax-highlight') - is_source_safe = True - except ClassNotFound: - formatted_source = raw_source - formatted_source_css = '' download_url = reverse( 'download_submission_source', kwargs={'submission_id': submission_id} ) @@ -82,12 +67,12 @@ def show_submission_source_view(request, submission_id): 'programs/source.html', { 'raw_source': raw_source, - 'source': formatted_source, - 'css': formatted_source_css, 'is_source_safe': is_source_safe, 'download_url': download_url, 'decode_error': decode_error, 'submission_id': submission_id, + 'extension': extension, + 'prismjs_extension': prismjs_extension, }, ) diff --git a/setup.py b/setup.py index b1697aec0..1eb7ded21 100644 --- a/setup.py +++ b/setup.py @@ -35,7 +35,6 @@ "coreapi>=2.3,<2.4", "dj-pagination>=2.5,<2.6", "django-compressor>=4.3,<4.4", - "Pygments>=2.15,<2.16", "django-libsass>=0.9,<0.10", "django-debug-toolbar", "django-extensions>=3.2,<3.3",