Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions grader_support/gradelib.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import random
import re
import sys
import tokenize
from tokenize import tokenize, COMMENT, STRING
from io import BytesIO

import six
# the run library should overwrite this with a particular random seed for the test.
Expand Down Expand Up @@ -238,11 +239,7 @@ def _tokens(code):
A wrapper around tokenize.generate_tokens.
"""
# Protect against pathological inputs: http://bugs.python.org/issue16152
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment should also be removed, as the bug is fixed and the bug workaround is removed.

code = code.rstrip() + "\n"
if isinstance(code, str):
code = code.encode('utf8')
code = "# coding: utf8\n" + code
toks = tokenize.generate_tokens(six.BytesIO(code).readline)
toks = tokenize(BytesIO(code.encode('utf-8')).readline)
return toks

def _count_tokens(code, string):
Expand All @@ -253,7 +250,7 @@ def _count_tokens(code, string):

try:
for ttyp, ttok, __, __, __ in _tokens(code):
if ttyp in (tokenize.COMMENT, tokenize.STRING):
if ttyp in (COMMENT, STRING):
continue
if ttok == string:
count += 1
Expand Down Expand Up @@ -353,7 +350,7 @@ def count_non_comment_lines(at_least=None, at_most=None, exactly=None, error_msg
def check(code):
linenums = set()
for ttyp, ttok, (srow, __), __, __ in _tokens(code):
if ttyp in (tokenize.COMMENT, tokenize.STRING):
if ttyp in (COMMENT, STRING):
# Comments and strings don't count toward line count. If a string
# is the only thing on a line, then it's probably a docstring, so
# don't count it.
Expand Down Expand Up @@ -530,7 +527,7 @@ def invoke_student_function(fn_name, args, environment=None, output_writer=None)
"""
output_writer = output_writer or repr
def doit(submission_module):
for name, value in environment or {}.items():
for name, value in (environment or {}).items():
setattr(submission_module, name, value)
fn = getattr(submission_module, fn_name)
print(output_writer(fn(*args)))
Expand Down
3 changes: 2 additions & 1 deletion tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def test_codejail_config(self):
"VMEM": 1024
}
}
self.m.enable_codejail(config)
codejail_return = self.m.enable_codejail(config)
self.assertEqual(codejail_return, config["name"])
self.assertTrue(codejail.jail_code.is_configured("python"))
self.m.enable_codejail({
"name": "other-python",
Expand Down
4 changes: 2 additions & 2 deletions xqueue_watcher/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def enable_codejail(self, codejail_config):
user = codejail_config.get('user', getpass.getuser())
jail_code.configure(name, bin_path, user=user)
limits = codejail_config.get("limits", {})
for name, value in limits.items():
jail_code.set_limit(name, value)
for limit_name, value in limits.items():
jail_code.set_limit(limit_name, value)
self.log.info("configured codejail -> %s %s %s", name, bin_path, user)
return name

Expand Down