{"action":"created","comment":{"url":"https://api.github.com/repos/edx/codejail/pulls/comments/69598591","id":69598591,"diff_hunk":"@@ -4,38 +4,20 @@\n import os.path\n import shutil\n import sys\n-import textwrap\n \n-try:\n-    import simplejson as json\n-except ImportError:\n-    import json\n-\n-from codejail import jail_code\n-from codejail.util import temp_directory, change_directory\n+from .exceptions import SafeExecException\n+from . import jail_code\n+from .util import temp_directory, change_directory, json_safe\n \n log = logging.getLogger(\"codejail\")\n \n \n # Flags to let developers temporarily change some behavior in this file.\n \n-# Set this to True to log all the code and globals being executed.\n-LOG_ALL_CODE = False\n # Set this to True to use the unsafe code, so that you can debug it.\n ALWAYS_BE_UNSAFE = False\n \n \n-class SafeExecException(Exception):\n-    \"\"\"\n-    Python code running in the sandbox has failed.\n-\n-    The message will be the stdout of the sandboxed process, which will usually\n-    contain the original exception message.\n-\n-    \"\"\"\n-    pass\n-\n-\n def safe_exec(code, globals_dict, files=None, python_path=None, slug=None,","path":"codejail/safe_exec.py","position":39,"original_position":39,"commit_id":"26fcca7c18264393223c6e86357abe53f2b35221","original_commit_id":"26fcca7c18264393223c6e86357abe53f2b35221","user":{"login":"nedbat","id":23789,"avatar_url":"https://avatars.githubusercontent.com/u/23789?v=3","gravatar_id":"","url":"https://api.github.com/users/nedbat","html_url":"https://github.com/nedbat","followers_url":"https://api.github.com/users/nedbat/followers","following_url":"https://api.github.com/users/nedbat/following{/other_user}","gists_url":"https://api.github.com/users/nedbat/gists{/gist_id}","starred_url":"https://api.github.com/users/nedbat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nedbat/subscriptions","organizations_url":"https://api.github.com/users/nedbat/orgs","repos_url":"https://api.github.com/users/nedbat/repos","events_url":"https://api.github.com/users/nedbat/events{/privacy}","received_events_url":"https://api.github.com/users/nedbat/received_events","type":"User","site_admin":false},"body":"The duplication of this docstring in jail_code.py is unfortunate.  You must have had a reason to move the bulk of this function into jail_code, but I'm not seeing it through my review telescope.  There's not much left in this file.","created_at":"2016-07-05T16:53:39Z","updated_at":"2016-07-05T16:53:39Z","html_url":"https://github.com/edx/codejail/pull/47#discussion_r69598591","pull_request_url":"https://api.github.com/repos/edx/codejail/pulls/47","_links":{"self":{"href":"https://api.github.com/repos/edx/codejail/pulls/comments/69598591"},"html":{"href":"https://github.com/edx/codejail/pull/47#discussion_r69598591"},"pull_request":{"href":"https://api.github.com/repos/edx/codejail/pulls/47"}}},"pull_request":{"url":"https://api.github.com/repos/edx/codejail/pulls/47","id":75505143,"html_url":"https://github.com/edx/codejail/pull/47","diff_url":"https://github.com/edx/codejail/pull/47.diff","patch_url":"https://github.com/edx/codejail/pull/47.patch","issue_url":"https://api.github.com/repos/edx/codejail/issues/47","number":47,"state":"open","locked":false,"title":"Restructure codejail to allow more flexible jailing","user":{"login":"jcdyer","id":77486,"avatar_url":"https://avatars.githubusercontent.com/u/77486?v=3","gravatar_id":"","url":"https://api.github.com/users/jcdyer","html_url":"https://github.com/jcdyer","followers_url":"https://api.github.com/users/jcdyer/followers","following_url":"https://api.github.com/users/jcdyer/following{/other_user}","gists_url":"https://api.github.com/users/jcdyer/gists{/gist_id}","starred_url":"https://api.github.com/users/jcdyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jcdyer/subscriptions","organizations_url":"https://api.github.com/users/jcdyer/orgs","repos_url":"https://api.github.com/users/jcdyer/repos","events_url":"https://api.github.com/users/jcdyer/events{/privacy}","received_events_url":"https://api.github.com/users/jcdyer/received_events","type":"User","site_admin":false},"body":"### [TNL-4843: Update CodeJail to handle Python 3](https://openedx.atlassian.net/browse/TNL-4843)\r\n\r\n* Introduce new `Jail` type that has its own `jail_code` and `safe_exec` methods.\r\n* Add ability to get Jail object by name.\r\n* Begin decoupling Jail name from language implementation.  (Still some legacy coupling to \"python\" name).\r\n* Introduce python3 safe_exec wrapper.\r\n\r\nNote:\r\n\r\n* `not_safe_exec` does not work with python3 because that runs code in the existing python process.  It's already a broken abstraction, because it runs the code in a different virtualenv than it would run in if it were sandboxed, so requirements may not match.\r\n\r\nTo manually explore:\r\n```bash\r\n$ virtualenv --python=/usr/bin/python2 /tmp/venv1\r\n$ virtualenv --python=/usr/bin/python2 /tmp/venv-sandbox2\r\n$ virtualenv --python=/usr/bin/python3 /tmp/venv-sandbox3\r\n$ . /tmp/venv1/bin/activate\r\n$ pip install -e git+https://github.com/edx/codejail@cdyer/multijail#egg=codejail\r\n$ python\r\n```\r\nThen:\r\n```python\r\n>>> import codejail\r\n>>> python2_jail = codejail.configure('python', '/tmp/venv-sandbox2/bin/python', lang=codejail.python2)\r\n>>> python3_jail = codejail.configure('python', '/tmp/venv-sandbox3/bin/python3', lang=codejail.python3)\r\n>>> result2 = python2_jail.jail_code('print \"hi reviewer\"')\r\n>>> print result2.stdout\r\nhi reviewer\r\n>>> result3 = python3_jail.jail_code('print \"hi reviewer\"')\r\n>>> print result3.stderr\r\n  File \"jailed_code\", line 1\r\n    print \"hi reviewer\"\r\n                      ^\r\nSyntaxError: Missing parentheses in call to 'print'\r\n>>> globals_dict = {'before': 8}\r\n>>> python3_jail.safe_exec('after = \"{}-)\".format(before)', globals_dict)\r\n>>> globals_dict\r\n{'before': 8, 'after': '8-)'}\r\n```\r\n\r\n### Sandbox\r\n- [ ] Build a sandbox for your branch and add a link here\r\n\r\n### Testing\r\n- [ ] Unit, integration, acceptance tests as appropriate\r\n\r\n### Reviewers\r\nIf you've been tagged for review, please check your corresponding box once you've given the :+1:.\r\n- [ ] Code review: @efischer19 \r\n- [ ] Code review: @nedbat \r\n- [ ] DevOps review: @edx/devops \r\n\r\nFYI: @muzaffaryousaf \r\n\r\n### Post-review\r\n- [ ] Squash commits\r\n\r\n","created_at":"2016-06-28T16:06:37Z","updated_at":"2016-07-05T16:53:39Z","closed_at":null,"merged_at":null,"merge_commit_sha":"619328a19bdf9baf5d107988aa2605732665b214","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/edx/codejail/pulls/47/commits","review_comments_url":"https://api.github.com/repos/edx/codejail/pulls/47/comments","review_comment_url":"https://api.github.com/repos/edx/codejail/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/codejail/issues/47/comments","statuses_url":"https://api.github.com/repos/edx/codejail/statuses/26fcca7c18264393223c6e86357abe53f2b35221","head":{"label":"edx:cdyer/multijail","ref":"cdyer/multijail","sha":"26fcca7c18264393223c6e86357abe53f2b35221","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":9703957,"name":"codejail","full_name":"edx/codejail","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/codejail","description":"Secure code execution","fork":false,"url":"https://api.github.com/repos/edx/codejail","forks_url":"https://api.github.com/repos/edx/codejail/forks","keys_url":"https://api.github.com/repos/edx/codejail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/codejail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/codejail/teams","hooks_url":"https://api.github.com/repos/edx/codejail/hooks","issue_events_url":"https://api.github.com/repos/edx/codejail/issues/events{/number}","events_url":"https://api.github.com/repos/edx/codejail/events","assignees_url":"https://api.github.com/repos/edx/codejail/assignees{/user}","branches_url":"https://api.github.com/repos/edx/codejail/branches{/branch}","tags_url":"https://api.github.com/repos/edx/codejail/tags","blobs_url":"https://api.github.com/repos/edx/codejail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/codejail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/codejail/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/codejail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/codejail/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/codejail/languages","stargazers_url":"https://api.github.com/repos/edx/codejail/stargazers","contributors_url":"https://api.github.com/repos/edx/codejail/contributors","subscribers_url":"https://api.github.com/repos/edx/codejail/subscribers","subscription_url":"https://api.github.com/repos/edx/codejail/subscription","commits_url":"https://api.github.com/repos/edx/codejail/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/codejail/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/codejail/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/codejail/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/codejail/contents/{+path}","compare_url":"https://api.github.com/repos/edx/codejail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/codejail/merges","archive_url":"https://api.github.com/repos/edx/codejail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/codejail/downloads","issues_url":"https://api.github.com/repos/edx/codejail/issues{/number}","pulls_url":"https://api.github.com/repos/edx/codejail/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/codejail/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/codejail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/codejail/labels{/name}","releases_url":"https://api.github.com/repos/edx/codejail/releases{/id}","deployments_url":"https://api.github.com/repos/edx/codejail/deployments","created_at":"2013-04-26T20:48:06Z","updated_at":"2016-07-02T08:59:20Z","pushed_at":"2016-06-30T14:40:09Z","git_url":"git://github.com/edx/codejail.git","ssh_url":"git@github.com:edx/codejail.git","clone_url":"https://github.com/edx/codejail.git","svn_url":"https://github.com/edx/codejail","homepage":null,"size":292,"stargazers_count":106,"watchers_count":106,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":11,"forks":28,"open_issues":11,"watchers":106,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"1903bc9f8818046c38b2e5af8c2f2030a0f6bd3a","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":9703957,"name":"codejail","full_name":"edx/codejail","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/codejail","description":"Secure code execution","fork":false,"url":"https://api.github.com/repos/edx/codejail","forks_url":"https://api.github.com/repos/edx/codejail/forks","keys_url":"https://api.github.com/repos/edx/codejail/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/codejail/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/codejail/teams","hooks_url":"https://api.github.com/repos/edx/codejail/hooks","issue_events_url":"https://api.github.com/repos/edx/codejail/issues/events{/number}","events_url":"https://api.github.com/repos/edx/codejail/events","assignees_url":"https://api.github.com/repos/edx/codejail/assignees{/user}","branches_url":"https://api.github.com/repos/edx/codejail/branches{/branch}","tags_url":"https://api.github.com/repos/edx/codejail/tags","blobs_url":"https://api.github.com/repos/edx/codejail/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/codejail/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/codejail/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/codejail/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/codejail/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/codejail/languages","stargazers_url":"https://api.github.com/repos/edx/codejail/stargazers","contributors_url":"https://api.github.com/repos/edx/codejail/contributors","subscribers_url":"https://api.github.com/repos/edx/codejail/subscribers","subscription_url":"https://api.github.com/repos/edx/codejail/subscription","commits_url":"https://api.github.com/repos/edx/codejail/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/codejail/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/codejail/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/codejail/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/codejail/contents/{+path}","compare_url":"https://api.github.com/repos/edx/codejail/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/codejail/merges","archive_url":"https://api.github.com/repos/edx/codejail/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/codejail/downloads","issues_url":"https://api.github.com/repos/edx/codejail/issues{/number}","pulls_url":"https://api.github.com/repos/edx/codejail/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/codejail/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/codejail/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/codejail/labels{/name}","releases_url":"https://api.github.com/repos/edx/codejail/releases{/id}","deployments_url":"https://api.github.com/repos/edx/codejail/deployments","created_at":"2013-04-26T20:48:06Z","updated_at":"2016-07-02T08:59:20Z","pushed_at":"2016-06-30T14:40:09Z","git_url":"git://github.com/edx/codejail.git","ssh_url":"git@github.com:edx/codejail.git","clone_url":"https://github.com/edx/codejail.git","svn_url":"https://github.com/edx/codejail","homepage":null,"size":292,"stargazers_count":106,"watchers_count":106,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":28,"mirror_url":null,"open_issues_count":11,"forks":28,"open_issues":11,"watchers":106,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/codejail/pulls/47"},"html":{"href":"https://github.com/edx/codejail/pull/47"},"issue":{"href":"https://api.github.com/repos/edx/codejail/issues/47"},"comments":{"href":"https://api.github.com/repos/edx/codejail/issues/47/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/codejail/pulls/47/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/codejail/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/codejail/pulls/47/commits"},"statuses":{"href":"https://api.github.com/repos/edx/codejail/statuses/26fcca7c18264393223c6e86357abe53f2b35221"}}}}
{"actor":{"display_login":"nedbat"}}