Ejemplo n.º 1
0
Archivo: main.py Proyecto: stden/TSWeb
def sumbit(channel):
    try:
        problems, compilers, extensions = get_compilers(channel)
    except testsys.CommunicationException as e:
        return render_template("error.html", text=e.message)

    if request.method == 'GET':
        config = {}
        config['problems'] = problems
        config['compilers'] = compilers
        return render_template("submit.html", **config)
    elif request.method == 'POST':
        if request.files['file']:
            data = request.files['file'].read().encode('cp866')
            filepath = secure_filename(request.files['file'].filename)
            filename = ''.join(filepath.split('.')[:-1])
        if request.form['solution']:
            data = request.form['solution'].encode('cp866')
            filepath = request.form['prob'] + '.' + request.form['lang']
            filename = request.form['prob']

        if not data:
            return util.error("No solution presented")


#        if not filepath.split('.')[-1] in extensions:
#            return error("Invalid file type")
        if not request.form['prob'] in problems:
            return util.error("Unknown problem '{0}'".format(
                request.form['prob']))
        if not compilers[int(request.form.get('lang', '0')) -
                         1][0] in extensions:
            return util.error("Unknown compiler '{0}'".format(
                request.form['lang']))

        state, answer = util.communicate(
            channel, {
                'Team': session['team'],
                'Password': session['password'],
                'ContestId': session['contestid'],
                'Problem': request.form['prob'],
                'Contents': data,
                'Source': filename,
                'Compiler': compilers[int(request.form['lang']) - 1][1],
                'Extension': compilers[int(request.form['lang']) - 1][0]
            })

        if state == 'error':
            return answer

        return render_template("submit_status.html")
Ejemplo n.º 2
0
Archivo: main.py Proyecto: stden/TSWeb
def sumbit(channel):
    try:
        problems, compilers, extensions = get_compilers(channel)
    except testsys.CommunicationException as e:
        return render_template("error.html", text=e.message)

    if request.method == "GET":
        config = {}
        config["problems"] = problems
        config["compilers"] = compilers
        return render_template("submit.html", **config)
    elif request.method == "POST":
        if request.files["file"]:
            data = request.files["file"].read().encode("cp866")
            filepath = secure_filename(request.files["file"].filename)
            filename = "".join(filepath.split(".")[:-1])
        if request.form["solution"]:
            data = request.form["solution"].encode("cp866")
            filepath = request.form["prob"] + "." + request.form["lang"]
            filename = request.form["prob"]

        if not data:
            return util.error("No solution presented")
        #        if not filepath.split('.')[-1] in extensions:
        #            return error("Invalid file type")
        if not request.form["prob"] in problems:
            return util.error("Unknown problem '{0}'".format(request.form["prob"]))
        if not compilers[int(request.form.get("lang", "0")) - 1][0] in extensions:
            return util.error("Unknown compiler '{0}'".format(request.form["lang"]))

        state, answer = util.communicate(
            channel,
            {
                "Team": session["team"],
                "Password": session["password"],
                "ContestId": session["contestid"],
                "Problem": request.form["prob"],
                "Contents": data,
                "Source": filename,
                "Compiler": compilers[int(request.form["lang"]) - 1][1],
                "Extension": compilers[int(request.form["lang"]) - 1][0],
            },
        )

        if state == "error":
            return answer

        return render_template("submit_status.html")
Ejemplo n.º 3
0
        def wrapper(*args, **kwargs):
            channel = testsys.get_channel(chan)
            try:
                channel.open(1)
            except testsys.ConnectionFailedException as e:
                return util.error(e.message)

            try:
                return f(channel, *args, **kwargs)
            finally:
                channel.close()