Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
codejail
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
codejail
Commits
ca16c755
Commit
ca16c755
authored
May 02, 2013
by
Ned Batchelder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Docstrings in the latest fashion.
parent
bd3417ab
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
8 deletions
+17
-8
codejail/jail_code.py
+9
-4
codejail/safe_exec.py
+8
-4
No files found.
codejail/jail_code.py
View file @
ca16c755
...
@@ -27,7 +27,8 @@ COMMANDS = {}
...
@@ -27,7 +27,8 @@ COMMANDS = {}
def
configure
(
command
,
bin_path
,
user
=
None
):
def
configure
(
command
,
bin_path
,
user
=
None
):
"""Configure a command for `jail_code` to use.
"""
Configure a command for `jail_code` to use.
`command` is the abstract command you're configuring, such as "python" or
`command` is the abstract command you're configuring, such as "python" or
"node". `bin_path` is the path to the binary. `user`, if provided, is
"node". `bin_path` is the path to the binary. `user`, if provided, is
...
@@ -47,7 +48,8 @@ def configure(command, bin_path, user=None):
...
@@ -47,7 +48,8 @@ def configure(command, bin_path, user=None):
def
is_configured
(
command
):
def
is_configured
(
command
):
"""Has `jail_code` been configured for `command`?
"""
Has `jail_code` been configured for `command`?
Returns true if the abstract command `command` has been configured for use
Returns true if the abstract command `command` has been configured for use
in the `jail_code` function.
in the `jail_code` function.
...
@@ -63,13 +65,16 @@ if hasattr(sys, 'real_prefix'):
...
@@ -63,13 +65,16 @@ if hasattr(sys, 'real_prefix'):
class
JailResult
(
object
):
class
JailResult
(
object
):
"""A passive object for us to return from jail_code."""
"""
A passive object for us to return from jail_code.
"""
def
__init__
(
self
):
def
__init__
(
self
):
self
.
stdout
=
self
.
stderr
=
self
.
status
=
None
self
.
stdout
=
self
.
stderr
=
self
.
status
=
None
def
jail_code
(
command
,
code
=
None
,
files
=
None
,
argv
=
None
,
stdin
=
None
):
def
jail_code
(
command
,
code
=
None
,
files
=
None
,
argv
=
None
,
stdin
=
None
):
"""Run code in a jailed subprocess.
"""
Run code in a jailed subprocess.
`command` is an abstract command ("python", "node", ...) that must have
`command` is an abstract command ("python", "node", ...) that must have
been configured using `configure`.
been configured using `configure`.
...
...
codejail/safe_exec.py
View file @
ca16c755
...
@@ -14,7 +14,8 @@ log = logging.getLogger(__name__)
...
@@ -14,7 +14,8 @@ log = logging.getLogger(__name__)
class
SafeExecException
(
Exception
):
class
SafeExecException
(
Exception
):
"""Python code running in the sandbox has failed.
"""
Python code running in the sandbox has failed.
The message will be the stdout of the sandboxed process, which will usually
The message will be the stdout of the sandboxed process, which will usually
contain the original exception message.
contain the original exception message.
...
@@ -24,7 +25,8 @@ class SafeExecException(Exception):
...
@@ -24,7 +25,8 @@ class SafeExecException(Exception):
def
safe_exec
(
code
,
globals_dict
,
files
=
None
,
python_path
=
None
):
def
safe_exec
(
code
,
globals_dict
,
files
=
None
,
python_path
=
None
):
"""Execute code as "exec" does, but safely.
"""
Execute code as "exec" does, but safely.
`code` is a string of Python code. `globals_dict` is used as the globals
`code` is a string of Python code. `globals_dict` is used as the globals
during execution. Modifications the code makes to `globals_dict` are
during execution. Modifications the code makes to `globals_dict` are
...
@@ -105,7 +107,8 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
...
@@ -105,7 +107,8 @@ def safe_exec(code, globals_dict, files=None, python_path=None):
def
json_safe
(
d
):
def
json_safe
(
d
):
"""Return only the JSON-safe part of d.
"""
Return only the JSON-safe part of d.
Used to emulate reading data through a serialization straw.
Used to emulate reading data through a serialization straw.
...
@@ -128,7 +131,8 @@ def json_safe(d):
...
@@ -128,7 +131,8 @@ def json_safe(d):
def
not_safe_exec
(
code
,
globals_dict
,
files
=
None
,
python_path
=
None
):
def
not_safe_exec
(
code
,
globals_dict
,
files
=
None
,
python_path
=
None
):
"""Another implementation of `safe_exec`, but not safe.
"""
Another implementation of `safe_exec`, but not safe.
This can be swapped in for debugging problems in sandboxed Python code.
This can be swapped in for debugging problems in sandboxed Python code.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment