From: Finn B. <bc...@us...> - 2001-02-22 13:03:08
|
Update of /cvsroot/jython/jython/org/python/modules In directory usw-pr-cvs1:/tmp/cvs-serv23858 Modified Files: cPickle.java Log Message: Use handcoded version of the exceptions. The cPickle_exceptions file is no longer required. Index: cPickle.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/modules/cPickle.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -r1.15 -r1.16 *** cPickle.java 2001/02/02 11:29:42 1.15 --- cPickle.java 2001/02/22 13:04:10 1.16 *************** *** 343,347 **** public static String[] __depends__ = new String[] { "copy_reg", - "cPickle_exceptions", }; --- 343,346 ---- *************** *** 351,437 **** public static PyObject UnpicklingError; - static { - PyObject excModule = importModule("cPickle_exceptions"); - - PickleError = excModule.__getattr__("PickleError"); - PicklingError = excModule.__getattr__("PicklingError"); - UnpickleableError = excModule.__getattr__("UnpickleableError"); - UnpicklingError = excModule.__getattr__("UnpicklingError"); - } - - - /** - * Super class for all pickling errors - */ - /* - public static class PickleError extends exceptions.Exception { - - public PickleError() { } - - public PickleError(PyObject[] args, String[] kws) { - super(args, kws); - } - - public PyString __str__() { - if (args.__len__() > 0 && args.__getitem__(0).__len__() > 0) - return args.__getitem__(0).__str__(); - else - return new PyString("(what)"); - } - } - */ - - /** - * This exception is raised when an unpicklable object is - * passed to Pickler.dump(). - */ - - /* - public static class PicklingError extends PickleError { - public PicklingError() { } - - public PicklingError(PyObject[] args, String[] kws) { - super(args, kws); - } - } - - */ - - - - /* - public static class UnpickleableError extends PicklingError { - public UnpickleableError() { } - - public UnpickleableError(PyObject[] args, String[] kws) { - super(args, kws); - } - public PyString __str__() { - PyObject a = args.__len__() > 0 ? - args.__getitem__(0) : - new PyString("(what)"); - return new PyString("Cannot pickle %s objects").__mod__(a). - __str__(); - } - } - */ - - - /** - * This exception if the input file does not contain a valid pickled - * object or it is unsafe to unpickle the object. - */ - - /* - public static class UnpicklingError extends PickleError { - public UnpicklingError() { } - - public UnpicklingError(PyObject[] args, String[] kws) { - super(args, kws); - } - } - */ - - public static final PyString BadPickleGet = new PyString("cPickle.BadPickleGet"); --- 350,353 ---- *************** *** 533,538 **** --- 449,523 ---- safe_constructors = (PyDictionary) copyreg.__getattr__("safe_constructors"); + + PickleError = buildClass("PickleError", Py.Exception, + "_PickleError", ""); + PicklingError = buildClass("PicklingError", PickleError, + "_empty__init__", ""); + UnpickleableError = buildClass("UnpickleableError", PicklingError, + "_UnpickleableError", ""); + UnpicklingError = buildClass("UnpicklingError", PickleError, + "_empty__init__", ""); + } + + // An empty __init__ method + public static PyObject _empty__init__(PyObject[] arg, String[] kws) { + PyObject dict = new PyStringMap(); + dict.__setitem__("__module__", new PyString("cPickle")); + return dict; + } + + public static PyObject _PickleError(PyObject[] arg, String[] kws) { + PyObject dict = _empty__init__(arg, kws); + dict.__setitem__("__init__", getJavaFunc("_PickleError__init__")); + dict.__setitem__("__str__", getJavaFunc("_PickleError__str__")); + return dict; + } + + public static void _PickleError__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 _PickleError__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.__len__() > 0 && args.__getitem__(0).__len__() > 0) + return args.__getitem__(0).__str__(); + else + return new PyString("(what)"); } + public static PyObject _UnpickleableError(PyObject[] arg, String[] kws) { + PyObject dict = _empty__init__(arg, kws); + dict.__setitem__("__init__", getJavaFunc("_UnpickleableError__init__")); + dict.__setitem__("__str__", getJavaFunc("_UnpickleableError__str__")); + return dict; + } + + public static void _UnpickleableError__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 _UnpickleableError__str__(PyObject[] arg, String[] kws) { + ArgParser ap = new ArgParser("__str__", arg, kws, "self"); + PyObject self = ap.getPyObject(0); + + PyObject args = self.__getattr__("args"); + PyObject a = args.__len__() > 0 ? args.__getitem__(0) : + new PyString("(what)"); + return new PyString("Cannot pickle %s objects").__mod__(a).__str__(); + } + + public cPickle() { } *************** *** 2065,2068 **** --- 2050,2071 ---- }); return __builtin__.__import__(name, null, null, silly_list); + } + + private static PyObject getJavaFunc(String name) { + return Py.newJavaFunc(cPickle.class, name); + } + + private static PyObject buildClass(String classname, + PyObject superclass, + String classCodeName, + String doc) { + PyObject[] sclass = Py.EmptyObjects; + if (superclass != null) + sclass = new PyObject[] { superclass }; + PyObject cls = Py.makeClass( + classname, sclass, + Py.newJavaCode(cPickle.class, classCodeName), + new PyString(doc)); + return cls; } } |