def main(): username = request.get_cookie("username", settings.cookie_secret) password = request.get_cookie("password", settings.cookie_secret) ok = api.check(username, password) if not ok: redirect("/login") meeting_list = api.meeting_list() owners = [] for meeting in meeting_list: if username.lower() in settings.admins or username.lower() in meeting.get("moderator_users"): owners.append(meeting) is_running = api.is_running(meeting.get("id")) if is_running: meeting["status"] = "running" else: meeting["status"] = "stopped" if username.lower() in settings.admins: is_admin = True users = api.suggest("") else: is_admin = users = None message = request.params.get("message") return jinja2_template( "main.html", message=message, is_admin=is_admin, owners=owners, meeting_list=meeting_list, username=username, users=users, )
def remove_user(): username = request.get_cookie("username", settings.cookie_secret) password = request.get_cookie("password", settings.cookie_secret) ok = api.check(username, password) if ok: username = request.params.get("username") print username api.remove_user(username) redirect("/start")
def join(): meeting_id = request.params.get("meeting_id") username = request.get_cookie("username", settings.cookie_secret) password = request.get_cookie("password", settings.cookie_secret) ok = api.check(username, password) if ok: url = api.join_meeting(username, password, meeting_id) if url: redirect(url) redirect("/start?message=permission+denied")
def add_user(): username = request.get_cookie("username", settings.cookie_secret) password = request.get_cookie("password", settings.cookie_secret) ok = api.check(username, password) if ok: username = request.params.get("username") password = request.params.get("password") api.add_user(username, password) redirect("/start?message=ok") redirect("/start?message=permission+denied")
def test_factorials_limited(self): print "\n\n\n" + " Test Factorials are correctly Limited ".center(75, "#") test_str = "factorial(1000)" target_str = "1" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" in response, 'Unexpected lack of "error" in response!') self.assertTrue(response["error"] == "Parsing Test Expression Failed.", "Error message not as expected '%s'." % response["error"]) print " PASS ".center(75, "#")
def login(): if request.method == "POST": username = request.params.get("username") password = request.params.get("password") ok = api.check(username, password) if ok: response.set_cookie("username", username, settings.cookie_secret) response.set_cookie("password", password, settings.cookie_secret) redirect("/start") redirect("/login") else: return jinja2_template("login.html")
def test_single_variables_unequal(self): print "\n\n\n" + " Test if Two Single Variables can be found Unequal ".center(75, "#") test_str = "x" target_str = "y" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def delete(): username = request.get_cookie("username", settings.cookie_secret) password = request.get_cookie("password", settings.cookie_secret) ok = api.check(username, password) if ok: meeting_id = request.params.get("meeting_id") if username in settings.admins: api.remove(meeting_id) else: info = api.get_meeting_info(meeting_id) if username in info.get("moderator_users"): api.remove(meeting_id) redirect("/start")
def test_large_bracket_expression(self): print "\n\n\n" + " Test Lots of Brackets and ^ in Expression ".center(75, "#") test_str = "720 + 1764 x + 1624 x^2 + 735 x^3 + 175 x^4 + 21 x^5 + x^6" target_str = "(x+1)(x+2)(x+3)(x+4)(x+5)(x+6)" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_sqrt_x_squared(self): print "\n\n\n" + " Test Square Root of x Squared ".center(75, "#") test_str = "sqrt(x**2)" target_str = "x" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "numeric", 'For these expressions, expected "equality_type" to be "numeric", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_extra_test_variables(self): print "\n\n\n" + " Test N+1 Variable Test Expression ".center(75, "#") test_str = "sin(exp(sqrt(2*x)))**2 + cos(exp(sqrt(x))**sqrt(2))**2" target_str = "1" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "numeric", 'For these expressions, expected "equality_type" to be "numeric", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_brackets_expand_symbolic(self): print "\n\n\n" + " Test Brackets can be Expanded for Symbolic Match ".center(75, "#") test_str = "(x + 1)(x + 1)" target_str = "x**2 + 2*x + 1" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_simplify_fractions_symbolic(self): print "\n\n\n" + " Test Fractions can be Simplified for Symbolic not Exact Match ".center(75, "#") test_str = "(2*x*y*x)/(2*x*y*y)" target_str = "x/y" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_logarithms(self): print "\n\n\n" + " Test if Logarithms Work ".center(75, "#") test_str = "x*log(x)/log(10) + ln(3) + ln(2)" target_str = "log(x,10)*x + ln(6)" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_strict_inequalities(self): print "\n\n\n" + " Test if Strict Inequalities Can be Distinguished ".center(75, "#") test_str = "x**2 + x + 1 > 0" target_str = "x + 1 + x**2 >= 0" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_differential_equations(self): print "\n\n\n" + " Test Differential Equations ".center(75, "#") test_str = "Derivative(Derivative(y, x), x) == y*cos(x) + sin(x)*Derivative(y, x)" target_str = "Derivative(y, x, x) == Derivative(sin(x) * y, x)" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_derivatives(self): print "\n\n\n" + " Test if Derivatives Work ".center(75, "#") test_str = "2 * y * Derivative(y, x)" target_str = "Derivative(y**2, x)" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_plus_or_minus(self): print "\n\n\n" + " Test if The ± Symbol Works ".center(75, "#") test_str = "a ± b" target_str = "a ± b" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_equations(self): print "\n\n\n" + " Test if Equations Can be Parsed and Checked ".center(75, "#") test_str = "x**2 + x + 1 == 0" target_str = "x + 1 + x**2 == 0" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_addition_order_exact_match(self): print "\n\n\n" + " Test if Addition Order matters for Exact Match ".center(75, "#") test_str = "1 + x" target_str = "x + 1" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_main_trig_functions_symbolic(self): print "\n\n\n" + " Test if sin, cos and tan and inverses Work Symbolically ".center(75, "#") test_str = "arcsin(x) + arccos(x) + arctan(x) + sin(x)**2 + cos(x)**2 + tan(x)" target_str = "1 + tan(x) + arcsin(x) + arccos(x) + arctan(x)" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "symbolic", 'For these expressions, expected "equality_type" to be "symbolic", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_simple_brackets_ignored_exact(self): print "\n\n\n" + " Test that Simple Brackets are Ignored for Exact Match ".center(75, "#") test_str = "((x))" target_str = "x" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_variable_ordering_ignored_exact(self): print "\n\n\n" + " Test that Variable Ordering is Ignored for Exact Match ".center(75, "#") test_str = "x * y * z" target_str = "z * x * y" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_implicit_multiplication(self): print "\n\n\n" + " Test that Implicit Multiplication Works ".center(75, "#") test_str = "xyz" target_str = "x * y * z" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_single_variables_equal(self): print "\n\n\n" + " Test if Single Variables can be Equal ".center(75, "#") test_str = "x" target_str = "x" symbols = None response = api.check(test_str, target_str, symbols) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "true", 'Expected "equal" to be "true", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "exact", 'For these expressions, expected "equality_type" to be "exact", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def test_disallowed_extra_variables(self): print "\n\n\n" + " Enforce Only Allowed Symbols ".center(75, "#") test_str = "sin(exp(sqrt(2*x)))**2 + cos(exp(sqrt(x))**sqrt(2))**2" target_str = "1" symbols = None response = api.check(test_str, target_str, symbols, check_symbols=True) self.assertTrue("error" not in response, 'Unexpected "error" in response!') self.assertTrue("equal" in response, 'Key "equal" not in response!') self.assertTrue(response["equal"] == "false", 'Expected "equal" to be "false", got "%s"!' % response["equal"]) self.assertTrue("equality_type" in response, 'Key "equality_type" not in response!') self.assertTrue(response["equality_type"] in EQUALITY_TYPES, 'Unexpected "equality_type": "%s"!' % response["equality_type"]) self.assertTrue(response["equality_type"] == "symbolic", 'For enforced symbols, expected "equality_type" to be "symbolic", got "%s"!' % response["equality_type"]) print " PASS ".center(75, "#")
def change_password(): if request.method == "GET": return jinja2_template("change_password.html") else: username = request.params.get("username") old_password = request.params.get("old_passwd") new_passwd = request.params.get("new_passwd") retype = request.params.get("retype") ok = api.check(username, old_password) if ok and new_passwd == retype: api.change_password(username, new_passwd) response.set_cookie("password", new_passwd, settings.cookie_secret) redirect("/start") redirect("/change_password")
def create(): username = request.get_cookie("username", settings.cookie_secret) password = request.get_cookie("password", settings.cookie_secret) ok = api.check(username, password) if ok: name = request.params.get("name") if not api.is_valid(name): return "Choose other name" attendee_users = request.params.get("to_users").split(",") attendee_users.remove("") # remove last comma "," moderator_users = [username.lower()] meeting_id = api.create_meeting(name, attendee_users, moderator_users) if meeting_id: url = api.join_meeting(username, password, meeting_id) redirect(url) redirect("/start")
def edit(): username = request.get_cookie("username", settings.cookie_secret) password = request.get_cookie("password", settings.cookie_secret) ok = api.check(username, password) if ok: username = username.lower() if request.method == "GET": meeting_id = request.params.get("meeting_id") info = api.get_meeting_info(meeting_id) if username not in info.get("moderator_users") and username not in settings.admins: redirect("/start") users = api.suggest("") # username = username.lower() # if username in users: # users.remove(username) attendee_users = info.get("attendee_users") if "" in info.get("attendee_users"): attendee_users.remove("") attendee_users = [x.strip() for x in attendee_users] # remove start/end space if username not in attendee_users: attendee_users.append(username) info["attendee_users"] = attendee_users users = [x for x in users if x not in attendee_users] return jinja2_template("edit.html", users=users, info=info) else: meeting_id = request.params.get("meeting_id") name = request.params.get("name") attendee_users = request.params.get("attendee_users").split(",") attendee_users = [x.strip() for x in attendee_users if x != ""] api.update(username, meeting_id, name, attendee_users) redirect("/start")
"""Module for interacting with the problems.""" from random import randint import pymongo from voluptuous import ALLOW_EXTRA, Range, Required, Schema import api from api import PicoException, check, validate problem_schema = Schema( { Required("name"): check(("The problem's display name must be a string.", [str])), Required("sanitized_name"): check(("The problems's sanitized name must be a string.", [str])), Required("score"): check(("Score must be a positive integer.", [int, Range(min=0)])), Required("author"): check(("Author must be a string.", [str])), Required("category"): check(("Category must be a string.", [str])), Required("instances"): check(("The instances must be a list.", [list])), Required("hints"): check(("Hints must be a list.", [list])), "walkthrough": check(("The problem walkthrough must be a string.", [str])), "description": check(("The problem description must be a string.", [str])), "version":
from voluptuous import Length, Required, Schema import api from api import cache, check, log_action, PicoException from api.cache import memoize PROBLEMSOLVED_FILTER = ['category', 'name', 'score', 'solve_time'] new_team_schema = Schema( { Required("team_name"): check( ("The team name must be between 3 and 40 characters.", [str, Length(min=3, max=40)]), ("This team name conflicts with an existing user name.", [lambda name: api.user.get_user(name=name) is None]), ("A team with that name already exists.", [lambda name: api.team.get_team(name=name) is None]), ), Required("team_password"): check(("Passwords must be between 3 and 20 characters.", [str, Length(min=3, max=20)])) }, extra=True) def get_team(tid=None, name=None): """ Retrieve a team based on a property (tid, name, etc.). Args:
"""Helper functions required for v0 endpoints.""" from datetime import datetime from functools import wraps from bson import json_util from flask import request, session from voluptuous import Length, Required, Schema import api from api import check user_login_schema = Schema({ Required('username'): check(("Usernames must be between 3 and 50 characters.", [str, Length(min=3, max=50)]), ), Required('password'): check(("Passwords must be between 3 and 50 characters.", [str, Length(min=3, max=50)])) }) def WebSuccess(message=None, data=None): """Legacy successful response wrapper.""" return json_util.dumps({'status': 1, 'message': message, 'data': data}) def WebError(message=None, data=None): """Legacy failure response wrapper.""" return json_util.dumps({'status': 0, 'message': message, 'data': data})
"""Module for interacting with bundles.""" from voluptuous import Required, Schema import api from api import check, validate bundle_schema = Schema({ Required("name"): check(("The bundle name must be a string.", [str])), Required("author"): check(("The bundle author must be a string.", [str])), Required("categories"): check(("The bundle categories must be a list.", [list])), Required("problems"): check(("The bundle problems must be a list.", [list])), Required("description"): check(("The bundle description must be a string.", [str])), "organization": check(("The bundle organization must be a string.", [str])), "dependencies": check(("The bundle dependencies must be a dict.", [dict])), "dependencies_enabled": check(("The dependencies enabled state must be a bool.", [lambda x: type(x) == bool])), "pkg_dependencies": check(("The package dependencies must be a list.", [lambda x: type(x) == list])) })
"""Module for interacting with bundles.""" from voluptuous import Required, Schema import api from api import check, validate bundle_schema = Schema({ Required("author"): check(("The bundle author must be a string.", [str])), Required("name"): check(("The bundle name must be a string.", [str])), Required("description"): check(("The bundle description must be a string.", [str])), "dependencies": check(("The bundle dependencies must be a dict.", [dict])), "dependencies_enabled": check(("The dependencies enabled state must be a bool.", [lambda x: type(x) == bool])), }) def get_bundle(bid): """ Return the bundle dict corresponding to the given bid. Args: bid: bundle ID Returns: The associated bundle dict, or None if not found
"""Module for interacting with the problems.""" from random import randint import pymongo from flask import current_app from voluptuous import ALLOW_EXTRA, Range, Required, Schema import api from api import check, PicoException, validate from api.cache import memoize problem_schema = Schema( { Required("name"): check( ("The problem's display name must be a string.", [str]) ), Required("sanitized_name"): check( ("The problems's sanitized name must be a string.", [str]) ), Required("score"): check( ("Score must be a positive integer.", [int, Range(min=0)]) ), Required("author"): check(("Author must be a string.", [str])), Required("category"): check(("Category must be a string.", [str])), Required("instances"): check(("The instances must be a list.", [list])), Required("organization"): check(("Organization must be string.", [str])), Required("event"): check(("Event must be string.", [str])), Required("unique_name"): check( ("The problems's unique name must be a string.", [str]) ),
"""Module for handling groups of teams.""" from voluptuous import Required, Schema import api from api import cache, check, log_action, PicoException, validate group_settings_schema = Schema({ Required("email_filter"): check(( "Email filter must be a list of emails.", [lambda emails: type(emails) == list], )), Required("hidden"): check(( "Hidden property of a group is a boolean.", [lambda hidden: type(hidden) == bool], )), }) def get_group(gid=None, name=None, owner_tid=None): """ Retrieve a group based on its name or gid. Args: name: the name of the group gid: the gid of the group owner_tid: the tid of the group owner Returns: The group dict, or None if not found.
"""Module for handling flag submissions.""" from datetime import datetime import api from api import cache, check, log_action, PicoException, validate from api.cache import memoize from voluptuous import Length, Required, Schema submission_schema = Schema( { Required("tid"): check( ("This does not look like a valid tid.", [str, Length(max=100)]) ), Required("pid"): check( ("This does not look like a valid pid.", [str, Length(max=100)]) ), Required("key"): check( ("This does not look like a valid key.", [str, Length(max=100)]) ), } ) DEBUG_KEY = None def grade_problem(pid, key, tid=None): """ Grade the problem with its associated flag. Args:
"""Module for handling flag submissions.""" from datetime import datetime from voluptuous import Length, Required, Schema import api from api import cache, check, log_action, PicoException, validate submission_schema = Schema({ Required("tid"): check(("This does not look like a valid tid.", [str, Length(max=100)])), Required("pid"): check(("This does not look like a valid pid.", [str, Length(max=100)])), Required("key"): check(("This does not look like a valid key.", [str, Length(max=100)])) }) DEBUG_KEY = None def grade_problem(pid, key, tid=None): """ Grade the problem with its associated flag. Args: tid: tid if provided pid: problem's pid key: user's submission Returns:
"""Module for handling problem feedback.""" from datetime import datetime from voluptuous import Length, Required, Schema import api from api import check, log_action, PicoException, validate feedback_schema = Schema({ Required("liked"): check(("liked must be a boolean", [lambda x: type(x) == bool])), "comment": check(("The comment must be no more than 500 characters", [str, Length(max=500)])), "timeSpent": check(("Time spend must be a number", [int])), "source": check(("The source must be no more than 500 characters", [str, Length(max=10)])) }) def get_problem_feedback(pid=None, tid=None, uid=None, count_only=False): """ Retrieve feedback for a given problem, team, or user. Args: pid: the problem id tid: the team id uid: the user id