📄 exceptions.java
字号:
"Base class for warnings about dubious runtime behavior."); buildClass(dict, "OverflowWarning", "Warning", "empty__init__", "Base class for warnings about numeric overflow."); ts.frame = ts.frame.f_back; } // An empty __init__ method public static PyObject empty__init__(PyObject[] arg, String[] kws) { PyObject dict = new PyStringMap(); dict.__setitem__("__module__", new PyString("exceptions")); return dict; } public static PyObject Exception(PyObject[] arg, String[] kws) { PyObject dict = empty__init__(arg, kws); dict.__setitem__("__init__", getJavaFunc("Exception__init__")); dict.__setitem__("__str__", getJavaFunc("Exception__str__")); dict.__setitem__("__getitem__", getJavaFunc("Exception__getitem__")); return dict; } public static void Exception__init__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__init__", arg, kws, "self", "args"); PyObject self = ap.getPyObject(0); PyObject args = ap.getList(1); self.__setattr__("args", args); } public static PyString Exception__str__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__str__", arg, kws, "self"); PyObject self = ap.getPyObject(0); PyObject args = self.__getattr__("args"); if (!args.__nonzero__()) return new PyString(""); else if (args.__len__() == 1) return args.__getitem__(0).__str__(); else return args.__str__(); } public static PyObject Exception__getitem__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__getitem__", arg, kws, "self", "i"); PyObject self = ap.getPyObject(0); PyObject i = ap.getPyObject(1); return self.__getattr__("args").__getitem__(i); } public static PyObject SyntaxError(PyObject[] arg, String[] kws) { PyObject __dict__ = empty__init__(arg, kws); __dict__.__setitem__("filename", Py.None); __dict__.__setitem__("lineno", Py.None); __dict__.__setitem__("offset", Py.None); __dict__.__setitem__("text", Py.None); __dict__.__setitem__("msg", new PyString("")); __dict__.__setitem__("__init__", getJavaFunc("SyntaxError__init__")); __dict__.__setitem__("__str__", getJavaFunc("SyntaxError__str__")); return __dict__; } public static void SyntaxError__init__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__init__", arg, kws, "self", "args"); PyObject self = ap.getPyObject(0); PyObject args = ap.getList(1); self.__setattr__("args", args); if (args.__len__() >= 1) self.__setattr__("msg", args.__getitem__(0)); if (args.__len__() == 2) { PyObject info = args.__getitem__(1); try { PyObject[] tmp = Py.unpackSequence(info, 4); self.__setattr__("filename", tmp[0]); self.__setattr__("lineno", tmp[1]); self.__setattr__("offset", tmp[2]); self.__setattr__("text", tmp[3]); } catch (PyException exc) { ; } } } public static PyString SyntaxError__str__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__init__", arg, kws, "self", "args"); PyObject self = ap.getPyObject(0); PyString str = self.__getattr__("msg").__str__(); PyObject filename = basename(self.__findattr__("filename")); PyObject lineno = self.__findattr__("lineno"); if (filename instanceof PyString && lineno instanceof PyInteger) return new PyString(str + " (" + filename + ", line " + lineno + ")"); else if (filename instanceof PyString) return new PyString(str + " (" + filename + ")"); else if (lineno instanceof PyInteger) return new PyString(str + " (line " + lineno + ")"); return str; } private static PyObject basename(PyObject filename) { if (filename instanceof PyString) { int i = ((PyString) filename).rfind(java.io.File.separator); if (i >= 0) return filename.__getslice__( new PyInteger(i+1), new PyInteger(Integer.MAX_VALUE)); } return filename; } public static PyObject EnvironmentError(PyObject[] arg, String[] kws) { PyObject dict = empty__init__(arg, kws); dict.__setitem__("__init__", getJavaFunc("EnvironmentError__init__")); dict.__setitem__("__str__", getJavaFunc("EnvironmentError__str__")); return dict; } public static void EnvironmentError__init__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__init__", arg, kws, "self", "args"); PyObject self = ap.getPyObject(0); PyObject args = ap.getList(1); self.__setattr__("args", args); self.__setattr__("errno", Py.None); self.__setattr__("strerror", Py.None); self.__setattr__("filename", Py.None); if (args.__len__() == 3) { // open() errors give third argument which is the filename. BUT, // so common in-place unpacking doesn't break, e.g.: // // except IOError, (errno, strerror): // // we hack args so that it only contains two items. This also // means we need our own __str__() which prints out the filename // when it was supplied. PyObject[] tmp = Py.unpackSequence(args, 3); self.__setattr__("errno", tmp[0]); self.__setattr__("strerror", tmp[1]); self.__setattr__("filename", tmp[2]); self.__setattr__("args", args.__getslice__(Py.Zero, Py.newInteger(2), Py.One)); } if (args.__len__() == 2) { // common case: PyErr_SetFromErrno() PyObject[] tmp = Py.unpackSequence(args, 2); self.__setattr__("errno", tmp[0]); self.__setattr__("strerror", tmp[1]); } } public static PyString EnvironmentError__str__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__init__", arg, kws, "self"); PyObject self = ap.getPyObject(0); if (self.__getattr__("filename") != Py.None) { return Py.newString("[Errno %s] %s: %s").__mod__( new PyTuple(new PyObject[] { self.__getattr__("errno"), self.__getattr__("strerror"), self.__getattr__("filename")})).__str__(); } else if (self.__getattr__("errno").__nonzero__() && self.__getattr__("strerror").__nonzero__()) { return Py.newString("[Errno %s] %s").__mod__( new PyTuple(new PyObject[] { self.__getattr__("errno"), self.__getattr__("strerror")})).__str__(); } else { return Exception__str__(arg, kws); } } public static PyObject SystemExit(PyObject[] arg, String[] kws) { PyObject dict = empty__init__(arg, kws); dict.__setitem__("__init__", getJavaFunc("SystemExit__init__")); return dict; } public static void SystemExit__init__(PyObject[] arg, String[] kws) { ArgParser ap = new ArgParser("__init__", arg, kws, "self", "args"); PyObject self = ap.getPyObject(0); PyObject args = ap.getList(1); self.__setattr__("args", args); if (args.__len__() == 0) self.__setattr__("code", Py.None); else if (args.__len__() == 1) self.__setattr__("code", args.__getitem__(0)); else self.__setattr__("code", args); } private static PyObject getJavaFunc(String name) { return Py.newJavaFunc(exceptions.class, name); } private static PyObject buildClass(PyObject dict, String classname, String superclass, String classCodeName, String doc) { PyObject[] sclass = Py.EmptyObjects; if (superclass != null) sclass = new PyObject[] { dict.__getitem__(new PyString(superclass)) }; PyObject cls = Py.makeClass( classname, sclass, Py.newJavaCode(exceptions.class, classCodeName), new PyString(doc)); dict.__setitem__(classname, cls); return cls; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -