Package org.python.core

Examples of org.python.core.PyException


    public static void sleep(double secs) {
        try {
            java.lang.Thread.sleep((long) (secs * 1000));
        } catch (java.lang.InterruptedException e) {
            throw new PyException(Py.KeyboardInterrupt, "interrupted sleep");
        }
    }
View Full Code Here


        } catch (PyException e) {
            PyObject immutable = this.asImmutable(e, o);
            b = this._set.remove(immutable);
        }
        if (!b) {
            throw new PyException(Py.LookupError, o.toString());
        }
    }
View Full Code Here

        }
        return __builtin__.tuple(res);
    }

    private static PyException StructError(String explanation) {
        return new PyException(error, explanation);
    }
View Full Code Here

            if (e instanceof ExitScriptException) {
                return null;
            }
            //actually, this is more likely to happen when raising an exception in jython
            if (e instanceof PyException) {
                PyException pE = (PyException) e;
                if (pE.type instanceof PyJavaClass) {
                    PyJavaClass t = (PyJavaClass) pE.type;
                    if (t.__name__ != null && t.__name__.equals("org.python.pydev.jython.ExitScriptException")) {
                        return null;
                    }
View Full Code Here

        return PyTuple.fromIterable(res);
    }


    static PyException StructError(String explanation) {
        return new PyException(error, explanation);
    }
View Full Code Here

    public String raw_input(PyObject prompt) {
        try {
            String line = Readline.readline(prompt == null ? "" : prompt.toString());
            return (line == null ? "" : line);
        } catch(EOFException eofe) {
            throw new PyException(Py.EOFError);
        } catch(IOException ioe) {
            throw new PyException(Py.IOError);
        }
    }
View Full Code Here

                if (reduce != null) {
                    tup = reduce.__call__(Py.newInteger(protocol));
                } else {
                    reduce = object.__findattr__("__reduce__");
                    if (reduce == null)
                        throw new PyException(UnpickleableError, object);
                    tup = reduce.__call__();
                }
            } else {
                tup = reduce.__call__(object);
            }

            if (tup instanceof PyString) {
                save_global(object, tup);
                return;
            }

            if (!(tup instanceof PyTuple)) {
                throw new PyException(PicklingError,
                            "Value returned by " + reduce.__repr__() +
                            " must be a tuple");
            }

            int l = tup.__len__();
            if (l < 2 || l > 5) {
                throw new PyException(PicklingError,
                            "tuple returned by " + reduce.__repr__() +
                            " must contain two to five elements");
            }

            PyObject callable = tup.__finditem__(0);
            PyObject arg_tup = tup.__finditem__(1);
            PyObject state = (l > 2) ? tup.__finditem__(2) : Py.None;
            PyObject listitems = (l > 3) ? tup.__finditem__(3) : Py.None;
            PyObject dictitems = (l > 4) ? tup.__finditem__(4) : Py.None;

            if (!(arg_tup instanceof PyTuple) && arg_tup != Py.None) {
                throw new PyException(PicklingError,
                            "Second element of tupe returned by " +
                            reduce.__repr__() + " must be a tuple");
            }
            save_reduce(callable, arg_tup, state, listitems, dictitems, object);
        }
View Full Code Here

                return false;
            }

            if (protocol == 0) {
                if (!Py.isInstance(pid, PyString.TYPE)) {
                    throw new PyException(PicklingError, "persistent id must be string");
                }
                file.write(PERSID);
                file.write(pid.toString());
                file.write("\n");
            } else {
View Full Code Here

            PyObject callableName = callable.__findattr__("__name__");
            if(protocol >= 2 && callableName != null
                    && "__newobj__".equals(callableName.toString())) {
                PyObject cls = arg_tup.__finditem__(0);
                if(cls.__findattr__("__new__") == null)
                    throw new PyException(PicklingError,
                                          "args[0] from __newobj__ args has no __new__");
                // TODO: check class
                save(cls);
                save(arg_tup.__getslice__(Py.One, Py.None));
                file.write(NEWOBJ);
View Full Code Here

                case LONG1:           load_bin_long(1); break;
                case LONG4:           load_bin_long(4); break;
                case STOP:
                    return load_stop();
                default:
                    throw new PyException(UnpicklingError,
                                          String.format("invalid load key, '%s'.", key));
                }
            }
        }
View Full Code Here

TOP

Related Classes of org.python.core.PyException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.