public static PyObject globals() { return Py.getFrame().f_globals; }
public static PyFrame _getframe(int depth) { PyFrame f = Py.getFrame(); while (depth > 0 && f != null) { f = f.f_back; --depth; } if (f == null) { throw Py.ValueError("call stack is not deep enough"); } return f; }
public PyException(PyObject type, PyObject value, PyTraceback traceback) { this.type = type; this.value = value; if (traceback != null) { this.traceback = traceback; isReRaise = true; } else { PyFrame frame = Py.getFrame(); if (frame != null && frame.tracefunc != null) { frame.tracefunc = frame.tracefunc.traceException(frame, this); } } }
public static CompilerFlags getCompilerFlags(int flags, boolean dont_inherit) { final PyFrame frame; if (dont_inherit) { frame = null; } else { frame = Py.getFrame(); } return CompilerFlags.getCompilerFlags(flags, frame); }
public static CompilerFlags getCompilerFlags(CompilerFlags flags, boolean dont_inherit) { final PyFrame frame; if (dont_inherit) { frame = null; } else { frame = Py.getFrame(); } return CompilerFlags.getCompilerFlags(flags, frame); }
public static PyObject locals() { return Py.getFrame().getLocals(); }
@Override protected Map<String, Object> getParamsFromVariables() throws IOException { PyFrame frame = Py.getFrame(); @SuppressWarnings("unchecked") List<PyTuple> locals = ((PyStringMap) frame.getLocals()).items(); Map<String, Object> vars = new HashMap<String, Object>(); for (PyTuple item : locals) { String key = (String) item.get(0); Object obj = item.get(1); if (obj != null) { String value = item.get(1).toString(); vars.put(key, value); } } return vars; }
/** * Ensure dict contains a __module__, retrieving it from the current frame if it * doesn't exist. * * @param dict a PyObject mapping */ public static void ensureModule(PyObject dict) { if (dict.__finditem__("__module__") != null) { return; } PyFrame frame = Py.getFrame(); if (frame == null) { return; } PyObject name = frame.f_globals.__finditem__("__name__"); if (name != null) { dict.__setitem__("__module__", name); } }
public static PyObject __import__(String name, PyObject globals, PyObject locals, PyObject fromlist, int level) { PyFrame frame = Py.getFrame(); PyObject builtins; if (frame != null && frame.f_builtins != null) { builtins = frame.f_builtins; } else { builtins = Py.getSystemState().builtins; } PyObject __import__ = builtins.__finditem__("__import__"); if (__import__ == null) { return null; } PyObject[] args; if (level < 0) { // for backward compatibility provide only 4 arguments args = new PyObject[] {Py.newString(name), globals, locals, fromlist}; } else { args = new PyObject[] {Py.newString(name), globals, locals, fromlist, Py.newInteger(level)}; } PyObject module = __import__.__call__(args); return module; }
PyObject globals = getFrame().f_globals; if (globals != null) { metaclass = globals.__finditem__("__metaclass__");