org.python.core.PyType Java Examples
The following examples show how to use
org.python.core.PyType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PythonRowDoFnSecurityTest.java From components with Apache License 2.0 | 6 votes |
@Test(expected = UserCodeException.class) public void test_limitCode() throws Throwable { String command = "from java.security import AccessControlException, Permissions, AllPermission, SecureClassLoader, CodeSource\n" + "from java.net import URL\n" + "import java.security\n" + "\n" + "class MagicClassLoader(SecureClassLoader):\n" + " def _init_(self):\n" + " SecureClassLoader._init_(self)\n" + " self.datamap = {}\n" + " self.codeSource = CodeSource(URL('file:/pwn'), None)\n" + "\n" + " def addClass(self, name, data):\n" + " self.datamap[name] = data\n" + "\n" + " def findClass(self, name):\n" + " data = self.datamap[name]\n" + " return self.super_defineClass(name, data, 0, len(data), self.codeSource)\n" + " \n" + " def getPermissions(self, codesource):\n" + " permissions = Permissions()\n" + " permissions.add(AllPermission())\n" + " return permissions \n" + "\n" + "output = input\n"; try { execute(command); } catch (PyException pyEx) { assertEquals("ImportError", ((PyType) pyEx.type).getName()); assertEquals("No module named os", ((PyBaseExceptionDerived) pyEx.value).getMessage().toString()); return; } assertTrue(false); }
Example #2
Source File: PythonRowDoFnSecurityTest.java From components with Apache License 2.0 | 5 votes |
@Test public void test_oss() throws Throwable { String command = "import oss"; try { execute(command); } catch (PyException pyEx) { assertEquals("ImportError", ((PyType) pyEx.type).getName()); assertEquals("No module named oss", ((PyBaseExceptionDerived) pyEx.value).getMessage().toString()); return; } assertTrue(false); }
Example #3
Source File: PythonExecutor.java From score with Apache License 2.0 | 5 votes |
private boolean keyIsExcluded(String key, PyObject value) { return (key.startsWith("__") && key.endsWith("__")) || value instanceof PyFile || value instanceof PyModule || value instanceof PyFunction || value instanceof PySystemState || value instanceof PyClass || value instanceof PyType || value instanceof PyReflectedFunction; }