Commit ca16c755 by Ned Batchelder

Docstrings in the latest fashion.

parent bd3417ab
...@@ -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`.
......
...@@ -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.
......
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