1 import org.python.core.*;
3 public class atexit extends java.lang.Object {
4 static String[] jpy$mainProperties = new String[] {"python.modules.builtin", "exceptions:org.python.core.exceptions"};
5 static String[] jpy$proxyProperties = new String[] {"python.modules.builtin", "exceptions:org.python.core.exceptions", "python.options.showJavaExceptions", "true"};
6 static String[] jpy$packages = new String[] {"java.net", null, "java.lang", null, "org.python.core", null, "java.io", null, "java.util.zip", null};
8 public static class _PyInner extends PyFunctionTable implements PyRunnable {
9 private static PyObject s$0;
10 private static PyObject s$1;
11 private static PyObject s$2;
12 private static PyObject s$3;
13 private static PyObject s$4;
14 private static PyObject s$5;
15 private static PyObject s$6;
16 private static PyObject s$7;
17 private static PyObject i$8;
18 private static PyObject i$9;
19 private static PyObject s$10;
20 private static PyObject s$11;
21 private static PyObject s$12;
22 private static PyFunctionTable funcTable;
23 private static PyCode c$0__run_exitfuncs;
24 private static PyCode c$1_register;
25 private static PyCode c$2_x1;
26 private static PyCode c$3_x2;
27 private static PyCode c$4_x3;
28 private static PyCode c$5_main;
29 private static void initConstants() {
30 s$0 = Py.newString("\012atexit.py - allow programmer to define multiple exit functions to be executed\012upon normal program termination.\012\012One public function, register, is defined.\012");
31 s$1 = Py.newString("register");
32 s$2 = Py.newString("run any registered exit functions\012\012 _exithandlers is traversed in reverse order so functions are executed\012 last in, first out.\012 ");
33 s$3 = Py.newString("register a function to be executed upon normal program termination\012\012 func - function to be called at exit\012 targs - optional arguments to pass to func\012 kargs - optional keyword arguments to pass to func\012 ");
34 s$4 = Py.newString("__main__");
35 s$5 = Py.newString("running x1");
36 s$6 = Py.newString("running x2(%s)");
37 s$7 = Py.newString("running x3(%s, kwd=%s)");
38 i$8 = Py.newInteger(12);
39 i$9 = Py.newInteger(5);
40 s$10 = Py.newString("bar");
41 s$11 = Py.newString("no kwd args");
42 s$12 = Py.newString("/usr/share/jython/Lib-cpython/atexit.py");
43 funcTable = new _PyInner();
44 c$0__run_exitfuncs = Py.newCode(0, new String[] {"targs", "func", "kargs"}, "/usr/share/jython/Lib-cpython/atexit.py", "_run_exitfuncs", false, false, funcTable, 0, null, null, 0, 1);
45 c$1_register = Py.newCode(3, new String[] {"func", "targs", "kargs"}, "/usr/share/jython/Lib-cpython/atexit.py", "register", true, true, funcTable, 1, null, null, 0, 1);
46 c$2_x1 = Py.newCode(0, new String[] {}, "/usr/share/jython/Lib-cpython/atexit.py", "x1", false, false, funcTable, 2, null, null, 0, 1);
47 c$3_x2 = Py.newCode(1, new String[] {"n"}, "/usr/share/jython/Lib-cpython/atexit.py", "x2", false, false, funcTable, 3, null, null, 0, 1);
48 c$4_x3 = Py.newCode(2, new String[] {"n", "kwd"}, "/usr/share/jython/Lib-cpython/atexit.py", "x3", false, false, funcTable, 4, null, null, 0, 1);
49 c$5_main = Py.newCode(0, new String[] {}, "/usr/share/jython/Lib-cpython/atexit.py", "main", false, false, funcTable, 5, null, null, 0, 0);
53 public PyCode getMain() {
54 if (c$5_main == null) _PyInner.initConstants();
58 public PyObject call_function(int index, PyFrame frame) {
61 return _PyInner._run_exitfuncs$1(frame);
63 return _PyInner.register$2(frame);
65 return _PyInner.x1$3(frame);
67 return _PyInner.x2$4(frame);
69 return _PyInner.x3$5(frame);
71 return _PyInner.main$6(frame);
77 private static PyObject _run_exitfuncs$1(PyFrame frame) {
78 // Temporary Variables
79 PyObject[] t$0$PyObject__;
82 /* run any registered exit functions
84 _exithandlers is traversed in reverse order so functions are executed
87 while (frame.getglobal("_exithandlers").__nonzero__()) {
88 t$0$PyObject__ = org.python.core.Py.unpackSequence(frame.getglobal("_exithandlers").invoke("pop"), 3);
89 frame.setlocal(1, t$0$PyObject__[0]);
90 frame.setlocal(0, t$0$PyObject__[1]);
91 frame.setlocal(2, t$0$PyObject__[2]);
92 frame.getglobal("apply").__call__(frame.getlocal(1), frame.getlocal(0), frame.getlocal(2));
97 private static PyObject register$2(PyFrame frame) {
98 /* register a function to be executed upon normal program termination
100 func - function to be called at exit
101 targs - optional arguments to pass to func
102 kargs - optional keyword arguments to pass to func
104 frame.getglobal("_exithandlers").invoke("append", new PyTuple(new PyObject[] {frame.getlocal(0), frame.getlocal(1), frame.getlocal(2)}));
108 private static PyObject x1$3(PyFrame frame) {
113 private static PyObject x2$4(PyFrame frame) {
114 Py.println(s$6._mod(frame.getlocal(0).__repr__()));
118 private static PyObject x3$5(PyFrame frame) {
119 Py.println(s$7._mod(new PyTuple(new PyObject[] {frame.getlocal(0).__repr__(), frame.getlocal(1).__repr__()})));
123 private static PyObject main$6(PyFrame frame) {
124 frame.setglobal("__file__", s$12);
126 // Temporary Variables
128 PyException t$0$PyException;
132 atexit.py - allow programmer to define multiple exit functions to be executed
133 upon normal program termination.
135 One public function, register, is defined.
137 frame.setlocal("__all__", new PyList(new PyObject[] {s$1}));
138 frame.setlocal("_exithandlers", new PyList(new PyObject[] {}));
139 frame.setlocal("_run_exitfuncs", new PyFunction(frame.f_globals, new PyObject[] {}, c$0__run_exitfuncs));
140 frame.setlocal("register", new PyFunction(frame.f_globals, new PyObject[] {}, c$1_register));
141 frame.setlocal("sys", org.python.core.imp.importOne("sys", frame));
144 frame.setlocal("x", frame.getname("sys").__getattr__("exitfunc"));
146 catch (Throwable x$0) {
148 t$0$PyException = Py.setException(x$0, frame);
149 if (Py.matchException(t$0$PyException, frame.getname("AttributeError"))) {
150 frame.getname("sys").__setattr__("exitfunc", frame.getname("_run_exitfuncs"));
152 else throw t$0$PyException;
155 if (frame.getname("x")._ne(frame.getname("_run_exitfuncs")).__nonzero__()) {
156 frame.getname("register").__call__(frame.getname("x"));
159 frame.dellocal("sys");
160 if (frame.getname("__name__")._eq(s$4).__nonzero__()) {
161 frame.setlocal("x1", new PyFunction(frame.f_globals, new PyObject[] {}, c$2_x1));
162 frame.setlocal("x2", new PyFunction(frame.f_globals, new PyObject[] {}, c$3_x2));
163 frame.setlocal("x3", new PyFunction(frame.f_globals, new PyObject[] {frame.getname("None")}, c$4_x3));
164 frame.getname("register").__call__(frame.getname("x1"));
165 frame.getname("register").__call__(frame.getname("x2"), i$8);
166 frame.getname("register").__call__(frame.getname("x3"), i$9, s$10);
167 frame.getname("register").__call__(frame.getname("x3"), s$11);
173 public static void moduleDictInit(PyObject dict) {
174 dict.__setitem__("__name__", new PyString("atexit"));
175 Py.runCode(new _PyInner().getMain(), dict, dict);
178 public static void main(String[] args) throws java.lang.Exception {
179 String[] newargs = new String[args.length+1];
180 newargs[0] = "atexit";
181 System.arraycopy(args, 0, newargs, 1, args.length);
182 Py.runMain(atexit._PyInner.class, newargs, atexit.jpy$packages, atexit.jpy$mainProperties, "", new String[] {"string", "random", "util", "traceback", "sre_compile", "atexit", "sre", "sre_constants", "StringIO", "javaos", "socket", "yapm", "calendar", "repr", "copy_reg", "SocketServer", "server", "re", "linecache", "javapath", "UserDict", "copy", "threading", "stat", "PathVFS", "sre_parse"});