Commit 45a329ca by Ned Batchelder

Line length and indentation fixes.

parent 54d3f77e
......@@ -98,7 +98,9 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
"""
# Clean the globals for sending back as JSON over stdout.
"""
ok_types = (type(None), int, long, float, str, unicode, list, tuple, dict)
ok_types = (
type(None), int, long, float, str, unicode, list, tuple, dict
)
bad_keys = ("__builtins__",)
def jsonable(v):
if not isinstance(v, ok_types):
......@@ -108,7 +110,11 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
except Exception:
return False
return True
g_dict = {k:v for k,v in g_dict.iteritems() if jsonable(v) and k not in bad_keys}
g_dict = {
k:v
for k,v in g_dict.iteritems()
if jsonable(v) and k not in bad_keys
}
"""
# Write the globals back to the calling process.
"""
......@@ -124,9 +130,13 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
log.debug("Exec: %s", code)
log.debug("Stdin: %s", stdin)
res = jail_code.jail_code("python", code=jailed_code, stdin=stdin, files=files)
res = jail_code.jail_code(
"python", code=jailed_code, stdin=stdin, files=files
)
if res.status != 0:
raise SafeExecException("Couldn't execute jailed code: %s" % res.stderr)
raise SafeExecException(
"Couldn't execute jailed code: %s" % res.stderr
)
globals_dict.update(json.loads(res.stdout))
......@@ -195,7 +205,8 @@ def not_safe_exec(code, globals_dict, files=None, python_path=None):
# Wrap the exception in a SafeExecException, but we don't
# try here to include the traceback, since this is just a
# substitute implementation.
raise SafeExecException("{0.__class__.__name__}: {0!s}".format(e))
msg = "{0.__class__.__name__}: {0!s}".format(e)
raise SafeExecException(msg)
finally:
sys.path = original_path
......
......@@ -99,7 +99,10 @@ class TestFeatures(JailCodeHelpers, unittest.TestCase):
argv=["doit.py", "1", "2", "3"]
)
self.assertResultOk(res)
self.assertEqual(res.stdout, "This is doit.py!\nMy args are ['doit.py', '1', '2', '3']\n")
self.assertEqual(
res.stdout,
"This is doit.py!\nMy args are ['doit.py', '1', '2', '3']\n"
)
class TestLimits(JailCodeHelpers, unittest.TestCase):
......@@ -262,7 +265,8 @@ class TestMalware(JailCodeHelpers, unittest.TestCase):
# http://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
res = jailpy(code=dedent("""\
import new, sys
crash_me = new.function(new.code(0,0,0,0,"KABOOM",(),(),(),"","",0,""), {})
bad_code = new.code(0,0,0,0,"KABOOM",(),(),(),"","",0,"")
crash_me = new.function(bad_code, {})
print "Here we go..."
sys.stdout.flush()
crash_me()
......@@ -285,8 +289,7 @@ class TestMalware(JailCodeHelpers, unittest.TestCase):
res = jailpy(code=dedent("""
import os
places = [
"..", "/tmp", "/", "/home", "/etc",
"/var"
"..", "/tmp", "/", "/home", "/etc", "/var"
]
for place in places:
try:
......
......@@ -9,7 +9,7 @@ from codejail.safe_exec import safe_exec, not_safe_exec, SafeExecException
class SafeExecTests(unittest.TestCase):
"""The tests for `safe_exec`, will be mixed into specific test classes below."""
"""The tests for `safe_exec`, to be mixed into specific test classes."""
# SafeExecTests is a TestCase so pylint understands the methods it can
# call, but it's abstract, so stop nose from running the tests.
......
......@@ -9,7 +9,8 @@ import tempfile
class TempDirectory(object):
def __init__(self):
self.temp_dir = tempfile.mkdtemp(prefix="codejail-")
# Make directory readable by other users ('sandbox' user needs to be able to read it)
# Make directory readable by other users ('sandbox' user needs to be
# able to read it).
os.chmod(self.temp_dir, 0775)
def clean_up(self):
......
......@@ -35,7 +35,6 @@ load-plugins=
# it should appear only once).
disable=
# Never going to use these
# C0301: Line too long
# W0142: Used * or ** magic
# W0141: Used builtin function 'map'
......@@ -50,7 +49,7 @@ disable=
# R0912: Too many branches
# R0913: Too many arguments
# R0914: Too many local variables
C0301,C0302,W0141,W0142,R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914
C0302,W0141,W0142,R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914
[REPORTS]
......@@ -68,7 +67,7 @@ include-ids=yes
files-output=no
# Tells whether to display a full report or only the messages
reports=yes
reports=no
# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
......@@ -157,7 +156,7 @@ bad-names=foo,bar,baz,toto,tutu,tata
# Regular expression which should only match functions or classes name which do
# not require a docstring
no-docstring-rgx=(__.*__|test_.*)
no-docstring-rgx=(__.*__|test_.*|setUp|tearDown)
[MISCELLANEOUS]
......@@ -169,7 +168,7 @@ notes=FIXME,XXX,TODO
[FORMAT]
# Maximum number of characters on a single line.
max-line-length=120
max-line-length=79
# Maximum number of lines in a module
max-module-lines=1000
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment