code formatting (ruff)
This commit is contained in:
parent
7eaf97632b
commit
8f741b521c
22 changed files with 92 additions and 153 deletions
|
|
@ -141,7 +141,7 @@ def get_logged_in_user(context):
|
|||
logging.update_log("_logininfo", [], u, login_info)
|
||||
context["cs_content_header"] = "Account Confirmation Succeeded"
|
||||
context["cs_content"] = (
|
||||
'Please <a href="%s">click here</a>' " to log in."
|
||||
'Please <a href="%s">click here</a> to log in.'
|
||||
) % url
|
||||
clear_session_vars(context, "login_message", "last_form")
|
||||
retval.update(login_info)
|
||||
|
|
@ -175,7 +175,7 @@ def get_logged_in_user(context):
|
|||
# can't send e-mail; show error message
|
||||
context["cs_content_header"] = "Password Reset: Error"
|
||||
context["cs_content"] = (
|
||||
"This feature is not available " "on this CAT-SOOP instance."
|
||||
"This feature is not available on this CAT-SOOP instance."
|
||||
)
|
||||
context["cs_handler"] = "passthrough"
|
||||
return {"cs_render_now": True}
|
||||
|
|
@ -207,7 +207,7 @@ def get_logged_in_user(context):
|
|||
context,
|
||||
email,
|
||||
"CAT-SOOP: Confirm Password Reset",
|
||||
*passwd_confirm_emails(context, uname, token)
|
||||
*passwd_confirm_emails(context, uname, token),
|
||||
)
|
||||
# show confirmation message
|
||||
context["cs_content_header"] = "Password Reset: Confirm"
|
||||
|
|
@ -222,7 +222,7 @@ def get_logged_in_user(context):
|
|||
# show the form.
|
||||
context["cs_content_header"] = "Forgot Password"
|
||||
context["cs_content"] = (
|
||||
"Please enter your information below to " "reset your password."
|
||||
"Please enter your information below to reset your password."
|
||||
)
|
||||
context["cs_content"] += generate_forgot_password_form(context)
|
||||
context["cs_handler"] = "passthrough"
|
||||
|
|
@ -234,7 +234,7 @@ def get_logged_in_user(context):
|
|||
# can't send e-mail; show error message
|
||||
context["cs_content_header"] = "Password Reset: Error"
|
||||
context["cs_content"] = (
|
||||
"This feature is not available " "on this CAT-SOOP instance."
|
||||
"This feature is not available on this CAT-SOOP instance."
|
||||
)
|
||||
context["cs_handler"] = "passthrough"
|
||||
return {"cs_render_now": True}
|
||||
|
|
@ -255,8 +255,7 @@ def get_logged_in_user(context):
|
|||
# the form again
|
||||
errs = "\n".join("<li>%s</li>" % i for i in errors)
|
||||
lmsg = (
|
||||
'<font color="red">Your password was not reset:\n'
|
||||
"<ul>%s</ul></font>"
|
||||
'<font color="red">Your password was not reset:\n<ul>%s</ul></font>'
|
||||
) % errs
|
||||
session["login_message"] = lmsg
|
||||
else:
|
||||
|
|
@ -333,7 +332,7 @@ def get_logged_in_user(context):
|
|||
info["cs_reload"] = True
|
||||
return info
|
||||
elif valid_uname:
|
||||
lmsg = '<font color="red">' "Incorrect username or password." "</font>"
|
||||
lmsg = '<font color="red">Incorrect username or password.</font>'
|
||||
session.update({"login_message": lmsg, "last_form": form})
|
||||
|
||||
# a user is asking to re-send the confirmation message
|
||||
|
|
@ -362,7 +361,7 @@ def get_logged_in_user(context):
|
|||
context,
|
||||
login_info["email"],
|
||||
"CAT-SOOP: Confirm E-mail Address",
|
||||
*reg_confirm_emails(context, uname, token)
|
||||
*reg_confirm_emails(context, uname, token),
|
||||
)
|
||||
context["cs_content_header"] = "Confirmation E-mail Sent"
|
||||
context["cs_content"] = (
|
||||
|
|
@ -460,7 +459,7 @@ def get_logged_in_user(context):
|
|||
context,
|
||||
email,
|
||||
"CAT-SOOP: Confirm E-mail Address",
|
||||
*reg_confirm_emails(context, uname, token)
|
||||
*reg_confirm_emails(context, uname, token),
|
||||
)
|
||||
confirmed = False
|
||||
else:
|
||||
|
|
@ -682,11 +681,7 @@ def generate_password_reset_form(context):
|
|||
'\n<td><span id="pwd_check"></span></td>'
|
||||
"\n</tr>"
|
||||
)
|
||||
out += (
|
||||
"\n<tr>"
|
||||
'\n<td style="text-align:right;"></td>'
|
||||
'\n<td style="text-align:right;">'
|
||||
)
|
||||
out += '\n<tr>\n<td style="text-align:right;"></td>\n<td style="text-align:right;">'
|
||||
out += _submit_button(
|
||||
["passwd", "passwd2"], "uname", [], "pwdform", "Change Password"
|
||||
)
|
||||
|
|
@ -735,11 +730,7 @@ def generate_password_change_form(context):
|
|||
'\n<td><span id="pwd_check"></span></td>'
|
||||
"\n</tr>"
|
||||
)
|
||||
out += (
|
||||
"\n<tr>"
|
||||
'\n<td style="text-align:right;"></td>'
|
||||
'\n<td style="text-align:right;">'
|
||||
)
|
||||
out += '\n<tr>\n<td style="text-align:right;"></td>\n<td style="text-align:right;">'
|
||||
out += _submit_button(
|
||||
["passwd", "passwd2", "oldpasswd"], "uname", [], "pwdform", "Change Password"
|
||||
)
|
||||
|
|
@ -789,12 +780,12 @@ def generate_login_form(context):
|
|||
out += _submit_button(
|
||||
["login_passwd"], "login_uname", ["login_uname"], "loginform", "Log In"
|
||||
)
|
||||
out += "<td>\n</tr>" "\n</table>"
|
||||
out += "<td>\n</tr>\n</table>"
|
||||
out += "<p>"
|
||||
if context["csm_mail"].can_send_email(context):
|
||||
base = _get_base_url(context)
|
||||
loc = base + "?loginaction=forgot_password"
|
||||
out += ("\nForgot your password? " 'Click <a href="%s">here</a>.<br/>') % loc
|
||||
out += ('\nForgot your password? Click <a href="%s">here</a>.<br/>') % loc
|
||||
if getattr(context["csm_base_context"], "cs_allow_registration", True):
|
||||
loc = _get_base_url(context)
|
||||
loc += "?loginaction=register"
|
||||
|
|
@ -881,11 +872,7 @@ def generate_registration_form(context):
|
|||
"\n</td>"
|
||||
"\n</tr>"
|
||||
) % last_name
|
||||
out += (
|
||||
"\n<tr>"
|
||||
'\n<td style="text-align:right;"></td>'
|
||||
'\n<td style="text-align:right;">'
|
||||
)
|
||||
out += '\n<tr>\n<td style="text-align:right;"></td>\n<td style="text-align:right;">'
|
||||
out += _submit_button(
|
||||
["passwd", "passwd2"],
|
||||
"uname",
|
||||
|
|
@ -893,7 +880,7 @@ def generate_registration_form(context):
|
|||
"regform",
|
||||
"Register",
|
||||
)
|
||||
out += "\n</td>" "\n</tr>"
|
||||
out += "\n</td>\n</tr>"
|
||||
out += REGISTRATION_FORM_CHECKER
|
||||
return out + "</table></form>"
|
||||
|
||||
|
|
@ -916,9 +903,7 @@ function _validate_password(p){
|
|||
}
|
||||
return null;
|
||||
}
|
||||
""" % (
|
||||
_pwd_too_short_msg
|
||||
)
|
||||
""" % (_pwd_too_short_msg)
|
||||
|
||||
|
||||
# EMAIL VALIDATION
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ if error is None:
|
|||
)
|
||||
desired_scope = desired_scope.split()
|
||||
scope_error = (
|
||||
"You must provide CAT-SOOP access " "to the following scopes: %r"
|
||||
"You must provide CAT-SOOP access to the following scopes: %r"
|
||||
) % desired_scope
|
||||
if "id_token" not in resp or any(
|
||||
i not in resp.get("scope", "").split() for i in desired_scope
|
||||
|
|
@ -170,8 +170,7 @@ if error is None:
|
|||
error = "Invalid ID Token issuer."
|
||||
elif body["nonce"] != stored_nonce:
|
||||
error = (
|
||||
"Suspected tampering!"
|
||||
"Nonce from server does not match local nonce."
|
||||
"Suspected tampering!Nonce from server does not match local nonce."
|
||||
)
|
||||
elif body["iat"] > now + 60:
|
||||
error = "ID Token is from the future. %r" % ((body["iat"], now),)
|
||||
|
|
|
|||
|
|
@ -235,7 +235,7 @@ def handle_activation_form(context):
|
|||
if "admin" in context[_n("perms")]:
|
||||
pwd = context[_n("activation_password")]
|
||||
out += (
|
||||
"\n<p><u>Staff:</u> password is " '<tt><font color="blue">%s</font></tt>'
|
||||
'\n<p><u>Staff:</u> password is <tt><font color="blue">%s</font></tt>'
|
||||
) % pwd
|
||||
out += "</form>"
|
||||
|
||||
|
|
@ -270,7 +270,7 @@ def handle_raw_html(context):
|
|||
reltime = context["csm_time"].long_timestamp(context[_n("rel")])
|
||||
reltime = reltime.replace(";", " at")
|
||||
return (
|
||||
"This page is not yet available. " "It will become available on %s."
|
||||
"This page is not yet available. It will become available on %s."
|
||||
) % reltime
|
||||
|
||||
page = ""
|
||||
|
|
@ -325,7 +325,7 @@ def handle_content_only(context):
|
|||
reltime = context["csm_time"].long_timestamp(context[_n("rel")])
|
||||
reltime = reltime.replace(";", " at")
|
||||
return (
|
||||
"This page is not yet available. " "It will become available on %s."
|
||||
"This page is not yet available. It will become available on %s."
|
||||
) % reltime
|
||||
|
||||
page = ""
|
||||
|
|
@ -380,7 +380,7 @@ def handle_view(context):
|
|||
reltime = context["csm_time"].long_timestamp(context[_n("rel")])
|
||||
reltime = reltime.replace(";", " at")
|
||||
return (
|
||||
"This page is not yet available. " "It will become available on %s."
|
||||
"This page is not yet available. It will become available on %s."
|
||||
) % reltime
|
||||
|
||||
page = ""
|
||||
|
|
@ -884,7 +884,7 @@ def handle_save(context):
|
|||
context, args.get("csq_prompt", "")
|
||||
)
|
||||
prompt = f'<div id="catsoop_preamble_{name}" style="display: inline;">{preamble}</div>\n<div id="catsoop_prompt_{name}" style="display: inline;">{prompt}</div>'
|
||||
rerender = f'{prompt}\n{question["render_html"](newstate["last_check"], **args)}'
|
||||
rerender = f"{prompt}\n{question['render_html'](newstate['last_check'], **args)}"
|
||||
out["rerender"] = str(rerender)
|
||||
|
||||
msg = f'<div id="{name}_check_message"><b><font color="red">This response has not yet been submitted.</font></b></div>'
|
||||
|
|
@ -992,7 +992,7 @@ def handle_revert(context):
|
|||
context, args.get("csq_prompt", "")
|
||||
)
|
||||
prompt = f'<div id="catsoop_preamble_{name}">{preamble}</div>\n<div id="catsoop_prompt_{name}" style="display: inline;">{prompt}</div>'
|
||||
rerender = f'{prompt}\n{question["render_html"](newstate["last_check"], **args)}'
|
||||
rerender = f"{prompt}\n{question['render_html'](newstate['last_check'], **args)}"
|
||||
out["rerender"] = str(rerender)
|
||||
|
||||
# cache responses
|
||||
|
|
@ -1126,7 +1126,7 @@ def handle_check(context):
|
|||
context, args.get("csq_prompt", "")
|
||||
)
|
||||
prompt = f'<div id="catsoop_preamble_{name}">{preamble}</div>\n<div id="catsoop_prompt_{name}" style="display: inline;">{prompt}</div>'
|
||||
rerender = f'{prompt}\n{question["render_html"](newstate["last_check"], **args)}'
|
||||
rerender = f"{prompt}\n{question['render_html'](newstate['last_check'], **args)}"
|
||||
out["rerender"] = str(rerender)
|
||||
|
||||
out["score_display"] = ""
|
||||
|
|
@ -1388,7 +1388,7 @@ def handle_submit(context):
|
|||
context, args.get("csq_prompt", "")
|
||||
)
|
||||
prompt = f'<div id="catsoop_preamble_{name}">{preamble}</div>\n<div id="catsoop_prompt_{name}" style="display: inline;">{prompt}</div>'
|
||||
rerender = f'{prompt}\n{question["render_html"](newstate["last_submit"], **args)}'
|
||||
rerender = f"{prompt}\n{question['render_html'](newstate['last_submit'], **args)}"
|
||||
out["rerender"] = str(rerender)
|
||||
|
||||
outdict[name] = out
|
||||
|
|
@ -1460,7 +1460,7 @@ def manage_groups(context):
|
|||
all_sections = {default_section: "Default Section"}
|
||||
if section is None:
|
||||
section = default_section
|
||||
hdr = "Group Assignments for %s, Section " '<span id="cs_groups_section">%s</span>'
|
||||
hdr = 'Group Assignments for %s, Section <span id="cs_groups_section">%s</span>'
|
||||
hdr %= (context["cs_original_path"], section)
|
||||
context["cs_content_header"] = hdr
|
||||
|
||||
|
|
@ -1533,15 +1533,11 @@ def clearanswer_msg(context, perms, name):
|
|||
_, qargs = namemap[name]
|
||||
error = None
|
||||
if "submit" not in perms and "submit_all" not in perms:
|
||||
error = (
|
||||
"You are not allowed undo your viewing of " "the answer to this question."
|
||||
)
|
||||
error = "You are not allowed undo your viewing of the answer to this question."
|
||||
elif name not in ansviewed:
|
||||
error = "You have not viewed the answer for this question."
|
||||
elif name not in namemap:
|
||||
error = (
|
||||
"No question with name %s. " "Please refresh before submitting."
|
||||
) % name
|
||||
error = ("No question with name %s. Please refresh before submitting.") % name
|
||||
elif "submit_all" not in perms:
|
||||
if timing == -1 and not i:
|
||||
error = "This question is not yet available."
|
||||
|
|
@ -1567,9 +1563,7 @@ def viewexp_msg(context, perms, name):
|
|||
elif name in expviewed:
|
||||
error = "You have already viewed the explanation for this question."
|
||||
elif name not in namemap:
|
||||
error = (
|
||||
"No question with name %s. " "Please refresh before submitting."
|
||||
) % name
|
||||
error = ("No question with name %s. Please refresh before submitting.") % name
|
||||
elif ("submit_all" not in perms) and timing == -1:
|
||||
error = "This question is not yet available."
|
||||
elif not _get(qargs, "csq_allow_viewexplanation", True, bool):
|
||||
|
|
@ -1596,9 +1590,7 @@ def viewanswer_msg(context, perms, name):
|
|||
elif name in ansviewed:
|
||||
error = "You have already viewed the answer for this question."
|
||||
elif name not in namemap:
|
||||
error = (
|
||||
"No question with name %s. " "Please refresh before submitting."
|
||||
) % name
|
||||
error = ("No question with name %s. Please refresh before submitting.") % name
|
||||
elif "submit_all" not in perms:
|
||||
if timing == -1 and not i:
|
||||
error = "This question is not yet available."
|
||||
|
|
@ -1619,9 +1611,7 @@ def save_msg(context, perms, name):
|
|||
elif "submit" not in perms and "submit_all" not in perms:
|
||||
error = "You are not allowed to check answers to this question."
|
||||
elif name not in namemap:
|
||||
error = (
|
||||
"No question with name %s. " "Please refresh before submitting."
|
||||
) % name
|
||||
error = ("No question with name %s. Please refresh before submitting.") % name
|
||||
elif "submit_all" not in perms:
|
||||
if timing == -1 and not i:
|
||||
error = "This question is not yet available."
|
||||
|
|
@ -1637,9 +1627,7 @@ def save_msg(context, perms, name):
|
|||
"You are not allowed to save to this question after viewing the answer."
|
||||
)
|
||||
elif timing == 1 and _get(context, "cs_auto_lock", False, bool):
|
||||
error = (
|
||||
"You are not allowed to save after the " "deadline for this question."
|
||||
)
|
||||
error = "You are not allowed to save after the deadline for this question."
|
||||
elif not _get(qargs, "csq_allow_save", True, bool):
|
||||
error = "Saving is not allowed for this question."
|
||||
return error
|
||||
|
|
@ -1667,9 +1655,7 @@ def check_msg(context, perms, name, is_revert=False):
|
|||
elif "submit" not in perms and "submit_all" not in perms:
|
||||
error = "You are not allowed to check answers to this question."
|
||||
elif name not in namemap:
|
||||
error = (
|
||||
"No question with name %s. " "Please refresh before submitting."
|
||||
) % name
|
||||
error = ("No question with name %s. Please refresh before submitting.") % name
|
||||
elif namemap[name][0].get("handle_check", None) is None:
|
||||
error = "This question type does not support checking."
|
||||
elif "submit_all" not in perms:
|
||||
|
|
@ -1683,9 +1669,7 @@ def check_msg(context, perms, name, is_revert=False):
|
|||
):
|
||||
error = "You are not allowed to check answers to this question after viewing the answer."
|
||||
elif timing == 1 and _get(context, "cs_auto_lock", False, bool):
|
||||
error = (
|
||||
"You are not allowed to check after the " "deadline for this problem."
|
||||
)
|
||||
error = "You are not allowed to check after the deadline for this problem."
|
||||
elif not _get(qargs, "csq_allow_check", True, bool):
|
||||
error = "Checking is not allowed for this question."
|
||||
return error
|
||||
|
|
@ -1719,9 +1703,7 @@ def submit_msg(context, perms, name):
|
|||
elif "submit" not in perms and "submit_all" not in perms:
|
||||
error = "You are not allowed to submit answers to this question."
|
||||
elif name not in namemap:
|
||||
error = (
|
||||
"No question with name %s. " "Please refresh before submitting."
|
||||
) % name
|
||||
error = ("No question with name %s. Please refresh before submitting.") % name
|
||||
elif "submit_all" not in perms:
|
||||
# don't allow if...
|
||||
if timing == -1 and not i:
|
||||
|
|
@ -1729,9 +1711,7 @@ def submit_msg(context, perms, name):
|
|||
error = "This question is not yet open for submissions."
|
||||
elif _get(context, "cs_auto_lock", False, bool) and timing == 1:
|
||||
# ...the problem auto locks and it is after the due date
|
||||
error = (
|
||||
"Submissions are not allowed after the " "deadline for this question"
|
||||
)
|
||||
error = "Submissions are not allowed after the deadline for this question"
|
||||
elif name in context[_n("locked")]:
|
||||
error = "You are not allowed to submit to this question."
|
||||
elif (
|
||||
|
|
@ -1762,8 +1742,7 @@ def submit_msg(context, perms, name):
|
|||
nleft, _ = nsubmits_left(context, name)
|
||||
if nleft <= 0:
|
||||
error = (
|
||||
"You have used all of your allowed "
|
||||
"submissions for this question."
|
||||
"You have used all of your allowed submissions for this question."
|
||||
)
|
||||
return error # None otherwise
|
||||
|
||||
|
|
@ -2309,9 +2288,9 @@ def default_javascript(context):
|
|||
for (name, (q, args)) in list(namemap.items())
|
||||
if _get(args, skipper, False, bool)
|
||||
]
|
||||
context[
|
||||
"cs_scripts"
|
||||
] += '<script type="text/javascript" src="_handler/default/cs_ajax.js"></script>'
|
||||
context["cs_scripts"] += (
|
||||
'<script type="text/javascript" src="_handler/default/cs_ajax.js"></script>'
|
||||
)
|
||||
out = """
|
||||
<script type="text/javascript">
|
||||
// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3
|
||||
|
|
@ -2367,9 +2346,7 @@ def default_timer(context):
|
|||
out += '\n<script type="text/javascript">'
|
||||
out += "\n// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3"
|
||||
out += (
|
||||
"\ncatsoop.timer_now = %d;"
|
||||
"\ncatsoop.timer_due = %d;"
|
||||
"\ncatsoop.time_url = %r;"
|
||||
"\ncatsoop.timer_now = %d;\ncatsoop.timer_due = %d;\ncatsoop.time_url = %r;"
|
||||
) % (
|
||||
context["csm_time"].unix(context[_n("now")]),
|
||||
context["csm_time"].unix(context[_n("due")]),
|
||||
|
|
@ -2387,9 +2364,7 @@ def default_timer(context):
|
|||
def exc_message(context):
|
||||
exc = traceback.format_exc()
|
||||
exc = context["csm_errors"].clear_info(context, exc)
|
||||
return (
|
||||
'<p><font color="red">' "<b>CAT-SOOP ERROR:</b>" "<pre>%s</pre></font>"
|
||||
) % exc
|
||||
return ('<p><font color="red"><b>CAT-SOOP ERROR:</b><pre>%s</pre></font>') % exc
|
||||
|
||||
|
||||
def _get_scores(context):
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ def handle(context):
|
|||
elif "view" in perms and current < rel:
|
||||
reltime = context["csm_time"].short_timestamp(rel)
|
||||
m = (
|
||||
"This handout is not yet available. " "It will become available at: %s"
|
||||
"This handout is not yet available. It will become available at: %s"
|
||||
) % reltime
|
||||
status = HTTPStatus.NOT_FOUND
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ def render_html(last_log, **info):
|
|||
rows,
|
||||
cols,
|
||||
)
|
||||
aria_label = info.get("csq_aria_label", f'catsoop_prompt_{info["csq_name"]}')
|
||||
aria_label = info.get("csq_aria_label", f"catsoop_prompt_{info['csq_name']}")
|
||||
out += ' aria-labelledby="%s"' % aria_label
|
||||
out += ' name="%s"' % info["csq_name"]
|
||||
out += ' id="%s"' % info["csq_name"]
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ def handle_submission(submissions, **info):
|
|||
except:
|
||||
return {
|
||||
"score": False,
|
||||
"msg": '<font color="red">Error: ' "could not parse input.</font>",
|
||||
"msg": '<font color="red">Error: could not parse input.</font>',
|
||||
}
|
||||
_m = None
|
||||
if sub is None:
|
||||
|
|
@ -557,7 +557,7 @@ def answer_display(**info):
|
|||
"<p>"
|
||||
) % (info["csq_soln"], info["csq_name"], a)
|
||||
else:
|
||||
out = ('<p><div id="%s_soln">' "<b>Multiple Possible Solutions:</b>") % info[
|
||||
out = ('<p><div id="%s_soln"><b>Multiple Possible Solutions:</b>') % info[
|
||||
"csq_name"
|
||||
]
|
||||
count = 1
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ def handle_submission(submissions, **info):
|
|||
|
||||
def render_html(last_log, **info):
|
||||
name = info["csq_name"]
|
||||
aria_label = info.get("csq_aria_label", f'catsoop_prompt_{info["csq_name"]}')
|
||||
aria_label = info.get("csq_aria_label", f"catsoop_prompt_{info['csq_name']}")
|
||||
out = (
|
||||
"""<input type="file" style="display: none" id=%s name="%s" aria-labelledby="%s"/>"""
|
||||
% (
|
||||
|
|
@ -100,9 +100,7 @@ def render_html(last_log, **info):
|
|||
if link is not None:
|
||||
out += "<br/>"
|
||||
out += (
|
||||
'<a href="%s" '
|
||||
'download="%s">Download Most '
|
||||
"Recent Submission</a><br/>"
|
||||
'<a href="%s" download="%s">Download Most Recent Submission</a><br/>'
|
||||
) % (
|
||||
link,
|
||||
html.escape(ll["name"]),
|
||||
|
|
@ -124,4 +122,4 @@ def answer_display(**info):
|
|||
data = csm_thirdparty.data_uri.DataURI.from_file(info["csq_soln"])
|
||||
ext = mimetypes.guess_extension(data.mimetype) or ".txt"
|
||||
name = name.rsplit(".", 1)[0] + ext
|
||||
return ('<a href="%s" ' 'download="%s">Download Solution</a>') % (data, name)
|
||||
return ('<a href="%s" download="%s">Download Solution</a>') % (data, name)
|
||||
|
|
|
|||
|
|
@ -116,9 +116,7 @@ def render_html(last_log, **info):
|
|||
return _renderers[r](last_log, **info)
|
||||
else:
|
||||
return (
|
||||
"<font color='red'>"
|
||||
"Invalid <tt>multiplechoice</tt> renderer: %s"
|
||||
"</font>"
|
||||
"<font color='red'>Invalid <tt>multiplechoice</tt> renderer: %s</font>"
|
||||
) % r
|
||||
|
||||
|
||||
|
|
@ -126,7 +124,7 @@ def render_html_dropdown(last_log, **info):
|
|||
if last_log is None:
|
||||
last_log = {}
|
||||
ll = last_log.get(info["csq_name"], {"data": "-1"})["data"]
|
||||
aria_label = info.get("csq_aria_label", f'catsoop_prompt_{info["csq_name"]}')
|
||||
aria_label = info.get("csq_aria_label", f"catsoop_prompt_{info['csq_name']}")
|
||||
out = '\n<select id="%s" name="%s" aria-labelledby="%s">' % (
|
||||
info["csq_name"],
|
||||
info["csq_name"],
|
||||
|
|
@ -144,7 +142,7 @@ def render_html_dropdown(last_log, **info):
|
|||
def render_html_checkbox(last_log, **info):
|
||||
if last_log is None:
|
||||
last_log = {}
|
||||
aria_label = info.get("csq_aria_label", f'catsoop_prompt_{info["csq_name"]}')
|
||||
aria_label = info.get("csq_aria_label", f"catsoop_prompt_{info['csq_name']}")
|
||||
out = "<fieldset aria-labelledby='%s'>" % aria_label
|
||||
name = info["csq_name"]
|
||||
last = last_log.get(info["csq_name"], None)
|
||||
|
|
@ -209,7 +207,7 @@ def render_html_checkbox(last_log, **info):
|
|||
def render_html_radio(last_log, **info):
|
||||
if last_log is None:
|
||||
last_log = {}
|
||||
aria_label = info.get("csq_aria_label", f'catsoop_prompt_{info["csq_name"]}')
|
||||
aria_label = info.get("csq_aria_label", f"catsoop_prompt_{info['csq_name']}")
|
||||
out = "<div role='radiogroup' aria-labelledby='%s'>" % aria_label
|
||||
name = info["csq_name"]
|
||||
last = last_log.get(info["csq_name"], {"data": None})["data"]
|
||||
|
|
|
|||
|
|
@ -213,9 +213,9 @@ def handle_check(submissions, **info):
|
|||
if not timeout:
|
||||
msg += "<p><b>"
|
||||
if complete:
|
||||
msg += '<font color="darkgreen">' "Your code ran to completion." "</font>"
|
||||
msg += '<font color="darkgreen">Your code ran to completion.</font>'
|
||||
else:
|
||||
msg += '<font color="red">' "Your code did not run to completion." "</font>"
|
||||
msg += '<font color="red">Your code did not run to completion.</font>'
|
||||
msg += "</b></p>"
|
||||
if out != "":
|
||||
msg += "\n<p><b>Your code produced the following output:</b>"
|
||||
|
|
@ -251,7 +251,7 @@ def handle_submission(submissions, **info):
|
|||
|
||||
inp = info["csq_input_check"](code)
|
||||
if inp is not None:
|
||||
msg = ('<div class="response">' '<font color="red">%s</font>' "</div>") % inp
|
||||
msg = ('<div class="response"><font color="red">%s</font></div>') % inp
|
||||
return {"score": 0, "msg": msg}
|
||||
|
||||
bak = info["csq_tests"]
|
||||
|
|
@ -270,9 +270,9 @@ def handle_submission(submissions, **info):
|
|||
'\n<br/><details%s><summary class="btn btn-catsoop">Show/Hide Detailed Results</summary>'
|
||||
% (" open" if info["csq_always_show_tests"] else "")
|
||||
)
|
||||
msg += (
|
||||
'<div class="response" id="%s_result_showhide">' "<h2>Test Results:</h2>"
|
||||
) % (info["csq_name"],)
|
||||
msg += ('<div class="response" id="%s_result_showhide"><h2>Test Results:</h2>') % (
|
||||
info["csq_name"],
|
||||
)
|
||||
test_results = []
|
||||
count = 1
|
||||
for test in info["csq_tests"]:
|
||||
|
|
@ -478,7 +478,7 @@ def handle_submission(submissions, **info):
|
|||
checkimg = ""
|
||||
msg = (
|
||||
(
|
||||
("\n<br/> Your score on your most recent " "submission was: %01.02f%%")
|
||||
("\n<br/> Your score on your most recent submission was: %01.02f%%")
|
||||
% (overall * 100)
|
||||
)
|
||||
+ checkimg
|
||||
|
|
@ -543,7 +543,7 @@ def render_html_upload(last_log, **info):
|
|||
init_code = None
|
||||
params = {
|
||||
"name": name,
|
||||
"aria_label": info.get("csq_aria_label", f'catsoop_prompt_{info["csq_name"]}'),
|
||||
"aria_label": info.get("csq_aria_label", f"catsoop_prompt_{info['csq_name']}"),
|
||||
"init": str(init_code),
|
||||
"safeinit": html.escape(init_code or ""),
|
||||
"b64init": b64encode(make_initial_display(info).encode()).decode(),
|
||||
|
|
@ -575,7 +575,7 @@ def render_html_upload(last_log, **info):
|
|||
if link is not None:
|
||||
out += "<br/>"
|
||||
out += (
|
||||
'<a href="%s" ' 'download="%s">Download Most ' "Recent Submission</a><br/>"
|
||||
'<a href="%s" download="%s">Download Most Recent Submission</a><br/>'
|
||||
) % (
|
||||
link,
|
||||
html.escape(init["name"]),
|
||||
|
|
@ -637,7 +637,7 @@ def render_html(last_log, **info):
|
|||
if renderer in RENDERERS:
|
||||
return RENDERERS[renderer](last_log or {}, **info)
|
||||
return (
|
||||
"<font color='red'>" "Invalid <tt>pythoncode</tt> interface: %s" "</font>"
|
||||
"<font color='red'>Invalid <tt>pythoncode</tt> interface: %s</font>"
|
||||
) % renderer
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -28,9 +28,7 @@ def markdownify(context, text):
|
|||
|
||||
def richtext_format(context, text, msg="Preview:"):
|
||||
out = "</br>%s<br/>" % msg
|
||||
out += (
|
||||
'<div style="background-color: #eeeeee;' 'padding:10px; border-radius:10px;">'
|
||||
)
|
||||
out += '<div style="background-color: #eeeeee;padding:10px; border-radius:10px;">'
|
||||
out += markdownify(context, text)
|
||||
out = out.replace("<script", "<script")
|
||||
out = out.replace("</script", "<script")
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ def render_html(last_log, **info):
|
|||
out = '<input type="text"'
|
||||
if info.get("csq_size", None) is not None:
|
||||
out += ' size="%s"' % info["csq_size"]
|
||||
aria_label = info.get("csq_aria_label", f'catsoop_prompt_{info["csq_name"]}')
|
||||
aria_label = info.get("csq_aria_label", f"catsoop_prompt_{info['csq_name']}")
|
||||
out += ' aria-labelledby="%s"' % aria_label
|
||||
out += ' value="%s"' % escape(last_log.get(info["csq_name"], {"data": ""})["data"])
|
||||
out += ' name="%s"' % info["csq_name"]
|
||||
|
|
|
|||
|
|
@ -86,11 +86,7 @@ Special: The page title, to be displayed in the browser's title bar
|
|||
"""
|
||||
|
||||
cs_base_logo_text = (
|
||||
"\\ "
|
||||
"\n/ /\\__/\\ "
|
||||
"\n\\__=( o_O )="
|
||||
"\n(__________) "
|
||||
"\n |_ |_ |_ |_ "
|
||||
"\\ \n/ /\\__/\\ \n\\__=( o_O )=\n(__________) \n |_ |_ |_ |_ "
|
||||
)
|
||||
"""
|
||||
Special: Text representing the CAT-SOOP Logo
|
||||
|
|
|
|||
|
|
@ -450,8 +450,7 @@ def display_page(context):
|
|||
if context["cs_dark_mode_invert_videos"]
|
||||
else "video.catsoop-darkmode-invert"
|
||||
)
|
||||
context["cs_dark_mode_javascript"] = (
|
||||
"""
|
||||
context["cs_dark_mode_javascript"] = """
|
||||
document.addEventListener("DOMContentLoaded", function(event) {
|
||||
if (DarkReader.isEnabled()) {
|
||||
var invertfilter = 'invert(100%%) hue-rotate(180deg)' +
|
||||
|
|
@ -463,11 +462,9 @@ def display_page(context):
|
|||
inverter.innerText = '%s, %s {filter: ' + invertfilter + ';}\\n\\n'
|
||||
document.head.appendChild(inverter);
|
||||
}
|
||||
});"""
|
||||
% (
|
||||
imgselector,
|
||||
videoselector,
|
||||
)
|
||||
});""" % (
|
||||
imgselector,
|
||||
videoselector,
|
||||
)
|
||||
|
||||
out = (
|
||||
|
|
@ -739,10 +736,7 @@ def main(environment, return_context=False, form_data=None):
|
|||
e,
|
||||
)
|
||||
if len(context["_cs_config_errors"]) > 0:
|
||||
m = (
|
||||
"The following errors occurred while "
|
||||
"loading global configuration:\n\n"
|
||||
)
|
||||
m = "The following errors occurred while loading global configuration:\n\n"
|
||||
m += "\n".join(context["_cs_config_errors"])
|
||||
out = errors.do_error_message(context, m)
|
||||
force_error = True
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ def do_error_message(context, msg=None):
|
|||
m,
|
||||
)
|
||||
new["cs_original_path"] = ""
|
||||
new["cs_content"] = ("<pre>ERROR:\n" "%s</pre>") % (m)
|
||||
new["cs_content"] = ("<pre>ERROR:\n%s</pre>") % (m)
|
||||
e = ': <font color="red">ERROR</font>'
|
||||
new["cs_header"] = new.get("cs_header", "") + e
|
||||
new["cs_content_header"] = "An Error Occurred:"
|
||||
|
|
@ -194,7 +194,7 @@ def do_404_message(context):
|
|||
if "cs_handler" in new:
|
||||
del new["cs_handler"]
|
||||
new["cs_content"] = (
|
||||
"<pre>CAT-SOOP could not find the specified file or resource:\n" "%r</pre>"
|
||||
"<pre>CAT-SOOP could not find the specified file or resource:\n%r</pre>"
|
||||
) % (html.escape(new["cs_original_path"]))
|
||||
new["cs_original_path"] = ""
|
||||
e = ': <font color="red">404</font>'
|
||||
|
|
@ -209,11 +209,7 @@ def do_404_message(context):
|
|||
|
||||
|
||||
error_404_logo = (
|
||||
"\\ ???????? "
|
||||
"\n/ /\\__/\\ "
|
||||
"\n\\__=( @_@ )="
|
||||
"\n(__________) "
|
||||
"\n |_ |_ |_ |_ "
|
||||
"\\ ???????? \n/ /\\__/\\ \n\\__=( @_@ )=\n(__________) \n |_ |_ |_ |_ "
|
||||
)
|
||||
"""This alternate logo replaces the CAT-SOOP logo on when a 404 (File Not
|
||||
Found) error is encountered."""
|
||||
|
|
|
|||
|
|
@ -87,9 +87,9 @@ def do_check(row):
|
|||
if lti_handler.have_data:
|
||||
if not "cs_session_data" in context:
|
||||
context["cs_session_data"] = {}
|
||||
context["cs_session_data"][
|
||||
"is_lti_user"
|
||||
] = True # so that course preload.py knows
|
||||
context["cs_session_data"]["is_lti_user"] = (
|
||||
True # so that course preload.py knows
|
||||
)
|
||||
|
||||
cfile = dispatch.content_file_location(context, row["path"])
|
||||
loader.load_content(
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ def _find_log(args):
|
|||
base = os.path.join(os.path.realpath(base_context.cs_data_root), "_logs/")
|
||||
if not (filename.startswith(base) and filename.endswith(".log")):
|
||||
print(
|
||||
("The given file is not a valid log file for this " "installation."),
|
||||
("The given file is not a valid log file for this installation."),
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ if os.path.isfile(_enc_salt_file):
|
|||
def _dots(x, start=""):
|
||||
l = len(x)
|
||||
for ix, i in enumerate(x):
|
||||
print(f"{start} {ix}/{l} ({ix/l*100:.02f}%)", flush=True)
|
||||
print(f"{start} {ix}/{l} ({ix / l * 100:.02f}%)", flush=True)
|
||||
yield i
|
||||
print()
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ if os.path.isfile(_enc_salt_file):
|
|||
def _dots(x, start=""):
|
||||
l = len(x)
|
||||
for ix, i in enumerate(x):
|
||||
print(f"{start} {ix}/{l} ({ix/l*100:.02f}%)", flush=True)
|
||||
print(f"{start} {ix}/{l} ({ix / l * 100:.02f}%)", flush=True)
|
||||
yield i
|
||||
print()
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ if os.path.isdir(uploads_dir):
|
|||
print(
|
||||
"Upload:",
|
||||
f"{u[:8]}... -> {upload_id_map[u][:8]}...",
|
||||
f"{ix}/{len(uploads)} ({ix/len(uploads)*100:.02f}%)",
|
||||
f"{ix}/{len(uploads)} ({ix / len(uploads) * 100:.02f}%)",
|
||||
)
|
||||
|
||||
|
||||
|
|
@ -189,4 +189,6 @@ if os.path.isdir(checker_dir):
|
|||
os.makedirs(newloc, exist_ok=True)
|
||||
with open(os.path.join(newloc, magic), "wb") as f:
|
||||
f.write(cslog.prep(result))
|
||||
print("Checker:", magic, f"{ix}/{len(results)} ({ix/len(results)*100:.02f}%)")
|
||||
print(
|
||||
"Checker:", magic, f"{ix}/{len(results)} ({ix / len(results) * 100:.02f}%)"
|
||||
)
|
||||
|
|
|
|||
2
catsoop/thirdparty/cgi.py
vendored
2
catsoop/thirdparty/cgi.py
vendored
|
|
@ -446,7 +446,7 @@ class FieldStorage:
|
|||
else:
|
||||
if not (isinstance(headers, (Mapping, Message))):
|
||||
raise TypeError(
|
||||
"headers must be mapping or an instance of " "email.message.Message"
|
||||
"headers must be mapping or an instance of email.message.Message"
|
||||
)
|
||||
self.headers = headers
|
||||
if fp is None:
|
||||
|
|
|
|||
8
catsoop/thirdparty/oauth2/__init__.py
vendored
8
catsoop/thirdparty/oauth2/__init__.py
vendored
|
|
@ -312,7 +312,7 @@ class Token(object):
|
|||
try:
|
||||
secret = params["oauth_token_secret"][0]
|
||||
except Exception:
|
||||
raise ValueError("'oauth_token_secret' not found in " "OAuth request.")
|
||||
raise ValueError("'oauth_token_secret' not found in OAuth request.")
|
||||
|
||||
token = Token(key, secret)
|
||||
try:
|
||||
|
|
@ -560,7 +560,7 @@ class Request(dict):
|
|||
parameters.update(header_params)
|
||||
except:
|
||||
raise Error(
|
||||
"Unable to parse OAuth parameters from " "Authorization header."
|
||||
"Unable to parse OAuth parameters from Authorization header."
|
||||
)
|
||||
|
||||
# GET or POST query string.
|
||||
|
|
@ -831,9 +831,7 @@ class Server(object):
|
|||
if not valid:
|
||||
key, base = signature_method.signing_base(request, consumer, token)
|
||||
|
||||
raise Error(
|
||||
"Invalid signature. Expected signature base " "string: %s" % base
|
||||
)
|
||||
raise Error("Invalid signature. Expected signature base string: %s" % base)
|
||||
|
||||
def _check_timestamp(self, timestamp):
|
||||
"""Verify that timestamp is recentish."""
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue