99import urllib .request
1010
1111# language IDs on judge0, see Documentation
12- languages = {"C++" : 10 , " Java" : 27 , "Python" : 34 , "C" : 4 , "Bash" : 1 }
12+ languages = {'Assembly' : 45 , 'Bash' : 46 , 'Basic' : 47 , 'C' : 50 , 'C++' : 54 , 'C#' : 51 , 'Common Lisp' : 55 , 'D' : 56 , 'Elixir' : 57 , 'Erlang' : 58 , 'Executable' : 44 , 'Fortran' : 59 , 'Go' : 60 , 'Haskell' : 61 , ' Java' : 62 , 'JavaScript' : 63 , 'Lua' : 64 , 'OCaml' : 65 , 'Octave' : 66 , 'Pascal' : 67 , 'PHP' : 68 , 'Plain Text' : 43 , 'Prolog' : 69 , 'Python2' : 70 , 'Python3' : 71 , 'Ruby' : 72 , 'Rust' : 73 , 'TypeScript' : 74 }
1313
1414api_params = {
15- "number_of_runs" : "1" ,
1615 "cpu_time_limit" : "2" ,
1716 "cpu_extra_time" : "0.5" ,
1817 "wall_time_limit" : "5" ,
@@ -51,6 +50,7 @@ def __init__(
5150 self .__memory = None
5251 self .__time = None
5352 self .__stdout = None
53+ self .languages = list (languages .keys ())
5454
5555 if self .path :
5656 if not os .path .exists (source ):
@@ -69,19 +69,28 @@ def __init__(
6969 self .inp = inp
7070
7171 def __readCode (self ):
72- with open (self .source , "r" ) as myfile :
73- data = myfile .read ()
74- return data
72+ try :
73+ with open (self .source , "r" ) as program_file :
74+ data = program_file .read ()
75+ return data
76+ except FileNotFoundError as e :
77+ raise e
7578
7679 def __readExpectedOutput (self ):
77- with open (self .output , "r" ) as out :
78- data = out .read ()
79- return data
80+ try :
81+ with open (self .output , "r" ) as exp_out :
82+ data = exp_out .read ()
83+ return data
84+ except FileNotFoundError as e :
85+ raise e
8086
8187 def __readStandardInput (self ):
82- with open (self .inp , "r" ) as out :
83- data = out .read ()
84- return data
88+ try :
89+ with open (self .inp , "r" ) as standard_input :
90+ data = standard_input .read ()
91+ return data
92+ except FileNotFoundError as e :
93+ raise e
8594
8695 def __readStatus (self , token : str ):
8796 """
@@ -121,47 +130,39 @@ def __submit(self):
121130 return token
122131
123132 def getSubmissionDate (self ):
124- """
125- return submission date/time of program
126- """
133+ """Submission date/time of program"""
127134 return self .__response ["created_at" ]
128135
129136 def getExitCode (self ):
130- """
131- return exitcode of program (0 or 1)
132- """
137+ """Exitcode of program (0 or 1)"""
133138 return self .__response ["exit_code" ]
134139
135140 def getOutput (self ):
136- """
137- return standard output of program
138- """
141+ """Standard output of the program"""
139142 return self .__stdout
140143
141144 def getMemory (self ):
142- """
143- return memory used by the program
144- """
145+ """Memory used by the program"""
145146 return self .__memory
146147
147148 def getError (self ):
148- """
149- return any error message occured during execution of program
150- """
149+ """Error occured during execution of program"""
151150 if self .__response ["stderr" ] != "" :
152151 return self .__response ["stderr" ]
153152 return None
154153
155154 def getTime (self ):
156- """
157- return execution time of program
158- """
155+ """Execution time of program"""
159156 return self .__time
160157
161- def run (self ):
162- """
163- submit the source code on judge0's server & return status
164- """
158+ def setFlags (self , options : str ):
159+ """Options for the compiler (i.e. compiler flags)"""
160+ api_params ["compiler_options" ] = options
161+
162+ def run (self , number_of_runs : int = 1 ):
163+ """Submit the source code on judge0's server & return status"""
164+ api_params ["number_of_runs" ] = number_of_runs
165+
165166 if os .path .exists (self .source ):
166167 if self .path :
167168 if self .inp is not None :
@@ -173,9 +174,7 @@ def run(self):
173174 self .__token = token
174175
175176 def getStatus (self ):
176- """
177- Return submission status
178- """
177+ """Submission status"""
179178 status = self .__readStatus (self .__token )
180179
181180 return status
0 commit comments