File size: 1,447 Bytes
acd4009
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from dataclasses import dataclass, field
from unittest import ExtendedUnittest

from resource_limit import ResourceLimits

def fix_uts(uts):
	uts_fx = []
	for ut in uts:
		uts_fx.append({
			"input": ut["input"],
			"output": ut["output"],
		})
	return uts_fx

@dataclass
class JobData:
    language: str
    source_code: str
    unittests: list[ExtendedUnittest]
    compile_cmd: str | None = None
    compile_flags: str | None = None
    execute_cmd: str | None = None
    execute_flags: str | None = None
    limits: ResourceLimits | None = None
    block_network: bool = True
    stop_on_first_fail: bool = True
    use_sanitizer: bool = False

    @classmethod
    def json_parser(cls, form):
        return cls(
            language=form.get("language"),
            source_code=form.get("source_code"),
            unittests=[ExtendedUnittest(**t) for t in fix_uts(form.get("unittests"))],
            compile_cmd=form.get("compile_cmd"),
            compile_flags=form.get("compile_flags"),
            execute_cmd=form.get("execute_cmd"),
            execute_flags=form.get("execute_flags"),
            limits=ResourceLimits(**form.get("limits")) if form.get("limits") is not None else None,
            block_network=form.get("block_network", True),
            stop_on_first_fail=form.get("stop_on_first_fail", True),
            use_sanitizer=form.get("use_sanitizer", False),
        )


@dataclass
class LanguageError:
    msg: str