Exemplo n.º 1
0
 def compiler_list(self, prob_id):
     known_compilers = {1: 'fpc', 2: 'gcc', 3: 'g++', 22: 'php', 23: 'python', 24: 'perl', 25: 'mcs', 26: 'ruby', 27: 'python3'}
     data = self._cache_get("/mod/statements/view.php?chapterid=%d"%prob_id).decode('utf-8', 'replace')
     ans = []
     for i in data.split('<select name="lang_id" id="lang_id" ', 1)[1].split('>', 1)[1].split('</select>', 1)[0].replace('<option value="', "<option value='").split("<option value='")[1:]:
         a = int(i.split("'", 1)[0].split('"', 1)[0])
         c = html.unescape(i.split('</option>', 1)[0].split('>', 1)[1])
         b = known_compilers.get(a, str(a))
         ans.append(bjtypes.compiler_t(a, b, c.strip()))
     return ans
Exemplo n.º 2
0
 def compiler_list(self, prob_id):
     code, headers, data = self._cache_get(self.urls['submission'].format(prob_id=prob_id))
     if b'<input type="submit" name="action_35" value="Change!" />' in data:
         raise BruteError("Password change is required.")
     data = data.decode('utf-8')
     if '<input type="hidden" name="lang_id" value="' in data:
         data = data.split('<input type="hidden" name="lang_id" value="', 1)[1]
         num_id = int(data.split('"', 1)[0])
         lit_id = html.unescape(data.split('</td><td class="b0">', 1)[1].split('</td>', 1)[0])
         short, long = lit_id.strip().split(' - ')
         return [bjtypes.compiler_t(num_id, short, long)]
     try: data = data.split('<select name="lang_id">', 1)[1].split('</select>', 1)[0]
     except IndexError: raise BruteError("Failed to fetch language list")
     data = data.split('<option ')[1:]
     ans = [] 
     for i in data:
         a, b = (' '+i).split(' value="', 1)[1].split('"', 1)
         b = b.split('>', 1)[1].split('</option>', 1)[0]
         if not a.isnumeric(): continue
         b, c = html.unescape(b).split(' - ')
         ans.append(bjtypes.compiler_t(int(a), b.strip(), c.strip()))
     return ans
Exemplo n.º 3
0
 def _get_submit(self):
     data = self.opener.open(self.base_url + '/submit?locale=en')
     if data.geturl() not in (self.base_url + '/submit',
                              self.base_url + '/submit?locale=en'):
         return [], [], None
     data = data.read().decode('utf-8', 'replace')
     csrf = self._get_csrf(data)
     data1 = data.split('name="submittedProblemIndex">',
                        1)[1].split('</select>',
                                    1)[0].split('<option value="')
     tasks = [i.split('"', 1)[0] for i in data1[2:]]
     data2 = data.split('name="programTypeId">',
                        1)[1].split('</select>',
                                    1)[0].split('<option value="')
     langs = [(int(i.split('"', 1)[0]),
               html.unescape(
                   i.split('>', 1)[1].split('</option>', 1)[0].strip()))
              for i in data2[1:]]
     short_codes = {
         43: 'gcc',
         42: 'g++11',
         50: 'g++14',
         54: 'g++',
         2: 'msvc2010',
         59: 'msvc2017',
         9: 'mcs',
         7: 'python',
         31: 'python3',
         40: 'pypy',
         41: 'pypy3'
     }
     langs_ans = []
     for i, j in langs:
         langs_ans.append(
             bjtypes.compiler_t(i, short_codes.get(i, str(i)), j))
     return (tasks, langs_ans, csrf)
Exemplo n.º 4
0
 def compiler_list(self, prob_id):
     code, headers, data = self._cache_get(self.url+'?SID=%s&EJSID=%s&action=contest-status-json&json=1'%self.cookies, False)
     data = mbjson(data)
     if code != 200 or not data or not data['ok']:
         raise BruteError("Failed to fetch compiler list.")
     return [bjtypes.compiler_t(i['id'], i['short_name'], i['long_name']) for i in data['result']['compilers']]
Exemplo n.º 5
0
 def compiler_list(self, task):
     return [
         bjtypes.compiler_t(i['id'], i['id__str'].lower(), i['name'])
         for i in self._get_dashboard("Failed to fetch compiler list.")
         ['languages']
     ]
Exemplo n.º 6
0
 def compiler_list(self, task):
     code, headers, data = self._cache_get('/toolchains')
     if code == 200:
         return [bjtypes.compiler_t(i, x['id'], x['description']) for i, x in enumerate(data)]
     else:
         raise BruteError("Failed to fetch compiler list.")