Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def excepthook(type, value, tb):
"""Report an exception."""
if (issubclass(type, Error) or issubclass(type, lib50.Error)) and str(value):
for line in str(value).split("\n"):
cprint(str(line), "yellow")
elif not isinstance(value, KeyboardInterrupt):
cprint(_("Sorry, something's wrong! Let sysadmins@cs50.harvard.edu know!"), "yellow")
if excepthook.verbose:
traceback.print_exception(type, value, tb)
cprint(_("Submission cancelled."), "red")
def __call__(self, parser, namespace, values, option_string=None):
try:
lib50.logout()
except lib50.Error:
raise Error(_("failed to logout"))
else:
cprint(_("logged out successfully"), "green")
parser.exit()
def check_version():
"""Check that submit50 is the latest version according to submit50.io."""
# Retrieve version info
res = requests.get(f"{SUBMIT_URL}/versions/submit50")
if res.status_code != 200:
raise Error(_("You have an unknown version of submit50. "
"Email sysadmins@cs50.harvard.edu!"))
# Check that latest version == version installed
required_version = pkg_resources.parse_version(res.text.strip())
local_version = pkg_resources.parse_version(__version__)
if required_version > local_version:
raise Error(_("You have an outdated version of submit50. "
"Please upgrade."))
def check_announcements():
"""Check for any announcements from submit.cs50.io, raise Error if so."""
res = requests.get(f"{SUBMIT_URL}/status/submit50")
if res.status_code == 200 and res.text.strip():
raise Error(res.text.strip())
def prompt(included, excluded):
if included:
cprint(_("Files that will be submitted:"), "green")
for file in included:
cprint("./{}".format(file), "green")
else:
raise Error(_("No files in this directory are expected for submission."))
# Files that won't be submitted
if excluded:
cprint(_("Files that won't be submitted:"), "yellow")
for other in excluded:
cprint("./{}".format(other), "yellow")
# Prompt for honesty
readline.clear_history()
try:
answer = input(_("Keeping in mind the course's policy on academic honesty, "
"are you sure you want to submit these files (yes/no)? "))
except EOFError:
answer = None
print()
if not answer or not re.match(f"^\s*(?:{_('y|yes')})\s*$", answer, re.I):