Skip to content
This repository has been archived by the owner on Jan 21, 2021. It is now read-only.

modernized the repo's codebase #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

2 changes: 1 addition & 1 deletion evil_tests/hello/answer.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print "hello world"
print("hello world")
8 changes: 4 additions & 4 deletions evil_tests/hello/wrong_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
i += x

# correct output, but takes too long
print "hello world"
print("hello world")

# Debugging
import sys
sys.stdout = sys.__stdout__

print "#" * 80
print "Still running! Should have been killed."
print "#" * 80
print("#" * 80)
print("Still running! Should have been killed.")
print("#" * 80)
6 changes: 3 additions & 3 deletions evil_tests/hello/wrong_fork.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
if os.fork() == 0:
# in child
break
print "forked!"
print("forked!")
except:
import sys
print "Got exception: " + str(sys.exc_info())
print("Got exception: " + str(sys.exc_info()))

import time
time.sleep(60) # Can I see a bunch of these in top?
print "hello world"
print("hello world")

2 changes: 1 addition & 1 deletion evil_tests/hello/wrong_network.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import requests
r = requests.get('http://www.edx.org')
print "hello world"
print("hello world")

4 changes: 2 additions & 2 deletions evil_tests/hello/wrong_output.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# We start so well...
print "hello world"
print("hello world")

# but then get a bit too excited...
for i in range(10000):
print "hello world!"
print("hello world!")
2 changes: 1 addition & 1 deletion evil_tests/hello/wrong_sleep.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import time
time.sleep(10)
print "hello world"
print("hello world")
2 changes: 1 addition & 1 deletion evil_tests/hello/wrong_stdout.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
import sys
sys.stdout = sys.__stdout__

print "O hai"
print("O hai")
4 changes: 2 additions & 2 deletions evil_tests/isVowel/answer.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
def isVowel(char):
'''
"""
char: a single letter of any case

returns: True if char is a vowel and False otherwise.
'''
"""
if char == 'a' or char == 'e' or char == 'i' or char == 'o' or char == 'u':
return True
elif char == 'A' or char == 'E' or char == 'I' or char == 'O' or char == 'U':
Expand Down
34 changes: 17 additions & 17 deletions pyxserver_wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import sys
from time import localtime, strftime, time

import settings # Not django, but do something similar
from . import settings # Not django, but do something similar

from sandbox import sandbox
from .sandbox import sandbox

# make sure we can find the grader files
sys.path.append(settings.GRADER_ROOT)
Expand All @@ -28,7 +28,7 @@
log = logging.getLogger("xserver." + __name__)


results_template = u"""
results_template = """
<div class="test">
<header>Test results</header>
<section>
Expand All @@ -44,7 +44,7 @@
"""


results_correct_template = u"""
results_correct_template = """
<div class="result-output result-correct">
<h4>{short-description}</h4>
<pre>{long-description}</pre>
Expand All @@ -58,7 +58,7 @@
"""


results_incorrect_template = u"""
results_incorrect_template = """
<div class="result-output result-incorrect">
<h4>{short-description}</h4>
<pre>{long-description}</pre>
Expand All @@ -78,15 +78,15 @@ def format_errors(errors):
error_list = [esc(e) for e in errors or []]
if error_list:
try:
items = u'\n'.join([u'<li><pre>{0}</pre></li>\n'.format(e) for e in error_list])
error_string = u'<ul>\n{0}</ul>\n'.format(items)
error_string = u'<div class="result-errors">{0}</div>'.format(error_string)
items = '\n'.join([f'<li><pre>{e}</pre></li>\n' for e in error_list])
error_string = f'<ul>\n{items}</ul>\n'
error_string = f'<div class="result-errors">{error_string}</div>'
except UnicodeDecodeError:
# See http://wiki.python.org/moin/UnicodeDecodeError; this error happens in the above unicode encoding
# because it's assuming str `e` is in ascii encoding; when it is in Unicode already it gets sad.
items = '\n'.join(['<li><pre>{0}</pre></li>\n'.format(e) for e in error_list])
error_string = '<ul>\n{0}</ul>\n'.format(items)
error_string = '<div class="result-errors">{0}</div>'.format(error_string)
items = '\n'.join([f'<li><pre>{e}</pre></li>\n' for e in error_list])
error_string = f'<ul>\n{items}</ul>\n'
error_string = f'<div class="result-errors">{error_string}</div>'
return error_string


Expand All @@ -95,9 +95,9 @@ def to_dict(result):
# TODO: replace with mako template
esc = cgi.escape
if result[1]:
long_desc = u'<p>{0}</p>'.format(esc(result[1]))
long_desc = '<p>{}</p>'.format(esc(result[1]))
else:
long_desc = u''
long_desc = ''
return {'short-description': esc(result[0]),
'long-description': long_desc,
'correct': result[2], # Boolean; don't escape.
Expand Down Expand Up @@ -151,10 +151,10 @@ def do_POST(data):
# However, for debugging, still want to see what the problem is
statsd.increment('xserver.grader_payload_error')

log.debug("error parsing: '{0}' -- {1}".format(payload, err))
log.debug(f"error parsing: '{payload}' -- {err}")
raise

log.debug("Processing submission, grader payload: {0}".format(payload))
log.debug(f"Processing submission, grader payload: {payload}")
relative_grader_path = grader_config['grader']
grader_path = os.path.join(settings.GRADER_ROOT, relative_grader_path)
start = time()
Expand Down Expand Up @@ -187,13 +187,13 @@ def post_wrapper(data):
try:
return do_POST(data)
except:
log.exception("Error processing request: {0}".format(data))
log.exception(f"Error processing request: {data}")
return None

handlers = {'GET': do_GET,
'POST': post_wrapper,
}
if method in handlers.keys():
if method in list(handlers.keys()):
reply = handlers[method](data)

if reply is not None:
Expand Down
14 changes: 7 additions & 7 deletions requirements/base.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Django >= 1.4, < 1.5
Django<2.3
pika
django_nose==1.4.1
django_nose
nosexcover
rednose
requests==2.22.0
boto==2.6.0
path.py==10.0
dogstatsd-python==0.2.1
requests
boto
path.py
dogstatsd-python
south
anyjson==0.3.3
anyjson
numpy==1.6.2
lxml==2.3.6
newrelic==2.46.0.37
Expand Down
45 changes: 24 additions & 21 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,32 @@
#
# make upgrade
#
anyjson==0.3.3
boto==2.6.0
certifi==2019.11.28 # via requests
chardet==3.0.4 # via requests
colorama==0.4.3 # via rednose
coverage==5.0.2 # via nosexcover
django==1.4.22
django_nose==1.4.1
dogstatsd-python==0.2.1
gunicorn==0.17.4
idna==2.8 # via requests
lxml==2.3.6
newrelic==2.46.0.37
anyjson==0.3.3 # via -r requirements/base.in
boto==2.49.0 # via -r requirements/base.in
certifi==2020.12.5 # via requests
chardet==4.0.0 # via requests
colorama==0.4.4 # via rednose
coverage==5.3.1 # via nosexcover
django-nose==1.4.7 # via -r requirements/base.in
django==2.2.17 # via -r requirements/base.in
dogstatsd-python==0.5.6 # via -r requirements/base.in
gunicorn==0.17.4 # via -r requirements/base.in
idna==2.10 # via requests
lxml==2.3.6 # via -r requirements/base.in
newrelic==2.46.0.37 # via -r requirements/base.in
nose==1.3.7 # via django-nose, nosexcover
nosexcover==1.0.11
numpy==1.6.2
path.py==10.0
pika==1.1.0
rednose==1.3.0
requests==2.22.0
south==1.0.2
nosexcover==1.0.11 # via -r requirements/base.in
numpy==1.6.2 # via -r requirements/base.in
path.py==12.5.0 # via -r requirements/base.in
path==15.0.1 # via path.py
pika==1.1.0 # via -r requirements/base.in
pytz==2020.5 # via django
rednose==1.3.0 # via -r requirements/base.in
requests==2.25.1 # via -r requirements/base.in
south==1.0.2 # via -r requirements/base.in
sqlparse==0.4.1 # via django
termstyle==0.1.11 # via rednose
urllib3==1.25.7 # via requests
urllib3==1.26.2 # via requests

# The following packages are considered to be unsafe in a requirements file:
# setuptools
1 change: 0 additions & 1 deletion sandbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@

2 changes: 1 addition & 1 deletion sandbox/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def record_suspicious_submission(msg, code_str):
logging to avoids need for more config changes (S3 credentials, python
requirements).
"""
log.warning('Suspicious code: {0}, {1}'.format(msg, code_str))
log.warning(f'Suspicious code: {msg}, {code_str}')

def sandbox_cmd_list():
"""
Expand Down
2 changes: 1 addition & 1 deletion sandbox/tests/dirs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def main():
while True:
i += 1
if i % 100 == 0:
print "Made {0} dirs!".format(i)
print(f"Made {i} dirs!")
os.mkdir('deepdir')
os.chdir('deepdir')

Expand Down
4 changes: 2 additions & 2 deletions settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import json
import os
from logsettings import get_logger_config
from .logsettings import get_logger_config
from path import Path
import sys

Expand All @@ -29,7 +29,7 @@
# AWS

if os.path.isfile(ENV_ROOT / "env.json"):
print "Opening env.json file"
print("Opening env.json file")
with open(ENV_ROOT / "env.json") as env_file:
ENV_TOKENS = json.load(env_file)

Expand Down
2 changes: 1 addition & 1 deletion tests/hello.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print "Hello, world!"
print("Hello, world!")
2 changes: 1 addition & 1 deletion tests/hello/answer.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print "hello world"
print("hello world")
2 changes: 1 addition & 1 deletion tests/hello/wrong.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
print "hello"
print("hello")
2 changes: 1 addition & 1 deletion tests/hello/wrong2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import time
time.sleep(0.1)
print "hello"
print("hello")
16 changes: 8 additions & 8 deletions tests/test-runserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def upload(paths):
Given a list of paths, upload them to the sandbox, and return an id that
identifies the created directory.
"""
files = dict( (os.path.basename(f)+unique, open(f)) for f in paths)
files = { os.path.basename(f)+unique: open(f) for f in paths}
return upload_files(files)

def upload_files(files):
endpoint = upload_server + 'upload'
r = requests.post(endpoint, files=files)

if r.status_code != requests.codes.ok:
log.error("Request error: {0}".format(r.text))
log.error(f"Request error: {r.text}")
return None

if r.json is None:
Expand Down Expand Up @@ -70,9 +70,9 @@ def main(args):
global runserver
global upload_server
if len(args) < 4:
print "Usage: test-runserver.py http://x-server-to-upload-to:port/ http://x-server-to-run-on:port/ FILES cmd"
print "The first file in FILES will be randomized by appending a random string,"
print "and the name of that file in 'cmd' will be modified the same way."
print("Usage: test-runserver.py http://x-server-to-upload-to:port/ http://x-server-to-run-on:port/ FILES cmd")
print("The first file in FILES will be randomized by appending a random string,")
print("and the name of that file in 'cmd' will be modified the same way.")
sys.exit(1)

upload_server = args[0]
Expand All @@ -87,14 +87,14 @@ def main(args):

start = time.time()
id = upload(files)
print "Upload took %.03f sec" % (time.time() - start)
print("Upload took %.03f sec" % (time.time() - start))

start = time.time()
cmd = cmd.replace(files[0], files[0]+unique)
r = run(id, cmd)
print "run took %.03f sec" % (time.time() - start)
print("run took %.03f sec" % (time.time() - start))
if r is None:
print 'error'
print('error')

if __name__=="__main__":
main(sys.argv[1:])
Expand Down
Loading