1#!/usr/bin/env python3 2 3import json 4import os 5import urllib.request 6import urllib.parse 7 8 9from scriptCommon import catchPath 10 11def upload(options): 12# request_blah = urllib.request.Request('https:// 13 14 request = urllib.request.Request('https://melpon.org/wandbox/api/compile.json', method='POST') 15 json_bytes = json.dumps(options).encode('utf-8') 16 request.add_header('Content-Type', 'application/json; charset=utf-8') 17 request.add_header('Content-Length', len(json_bytes)) 18 response = urllib.request.urlopen(request, json_bytes) 19 return json.loads(response.read().decode('utf-8')) 20 21main_file = ''' 22#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one cpp file 23#include "catch.hpp" 24 25unsigned int Factorial( unsigned int number ) { 26 return number <= 1 ? number : Factorial(number-1)*number; 27} 28 29TEST_CASE( "Factorials are computed", "[factorial]" ) { 30 REQUIRE( Factorial(1) == 1 ); 31 REQUIRE( Factorial(2) == 2 ); 32 REQUIRE( Factorial(3) == 6 ); 33 REQUIRE( Factorial(10) == 3628800 ); 34} 35''' 36 37def uploadFiles(): 38 response = upload({ 39 'compiler': 'gcc-head', 40 'code': main_file, 41 'codes': [{ 42 'file': 'catch.hpp', 43 'code': open(os.path.join(catchPath, 'single_include', 'catch2', 'catch.hpp')).read() 44 }], 45 'options': 'c++11,cpp-no-pedantic,boost-nothing', 46 'compiler-option-raw': '-DCATCH_CONFIG_FAST_COMPILE', 47 'save': True 48 }) 49 50 if 'url' in response and 'compiler_error' not in response: 51 return True, response['url'] 52 else: 53 return False, response 54