Package org.python.core

Examples of org.python.core.PyException


    log.error(t.getMessage(), t);

    Runnable r = new Runnable() {
      public void run() {
        if (t instanceof PyException) {
          PyException pyT = (PyException) t;

          JOptionPane.showMessageDialog(HermesBrowser.this, message + ": " + pyT.traceback.dumpStack(), "Error", JOptionPane.ERROR_MESSAGE);
        } else {

          JOptionPane.showMessageDialog(HermesBrowser.this, message + ": " + t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
View Full Code Here


      public void run() {
        String detail = null;

        if (t instanceof PyException) {
          StringBuffer s = new StringBuffer();
          PyException pyT = (PyException) t;
          pyT.traceback.dumpStack(s);

          detail = s.toString();
        } else {
          StringWriter s = new StringWriter();
View Full Code Here

    private void handleScriptException(ScriptException e, TestResult result) {
        Throwable cause = e.getCause();

        // handle ThreadDeath exception
        if (cause instanceof PyException) {
            PyException pe = (PyException) cause;
            if (pe.value instanceof PyJavaInstance) {
                Object javaError = pe.value.__tojava__(Throwable.class);
                if (javaError != null && javaError != Py.NoConversion) {
                    if (javaError instanceof ThreadDeath) {
                        dumpScriptPythonStackDetails(result, cause);
                        throw (ThreadDeath) javaError;
                    }
                }
            }
        }

        result.setFailedLineNumber(e.getLineNumber());
        result.setStatus(TestResult.Status.NOT_AVAILABLE);
        String message = null;
        boolean dumpStack = true;

        if (cause instanceof PySyntaxError) {
            // set a clear syntax error message
            PySyntaxError syntaxError = (PySyntaxError) cause;
            try {
                PyString fileName, text;
                PyInteger lineNumber, columnNumber;
                if (syntaxError.value instanceof PyTuple) {
                    PyObject[] infos = ((PyTuple) ((PyTuple) syntaxError.value).getArray()[1]).getArray();
                    fileName = (PyString) infos[0];
                    lineNumber = (PyInteger) infos[1];
                    columnNumber = (PyInteger) infos[2];
                    text = (PyString) infos[3];
                } else {
                    fileName = (PyString) syntaxError.value.__getattr__(new PyString("filename"));
                    lineNumber = (PyInteger) syntaxError.value.__getattr__(new PyString("lineno"));
                    columnNumber = (PyInteger) syntaxError.value.__getattr__(new PyString("offset"));
                    text = (PyString) syntaxError.value.__getattr__(new PyString("text"));
                    message = "Python syntax error in file " + fileName + " at line " + lineNumber + ", column " + columnNumber + ":\n" + text;

                }
                message = "Python syntax error in file " + fileName + " at line " + lineNumber + ", column " + columnNumber + ":\n" + text;
                result.addStackTraceElement(new StackTraceElement("", "", fileName.toString(), Integer.parseInt(lineNumber.toString())));
                dumpStack = false;
            } catch (PyException pye) {
                message = "Python syntax error (Couldn't decode localization of error)";
            }
        } else if (cause instanceof PyException) {
            PyException pe = (PyException) cause;
            if (pe.value instanceof PyJavaInstance) {
                // check  if exception is UndeclaredThrowableException
                // in this case status is "failed" and message is taken from cause exception
                Object javaError = pe.value.__tojava__(Throwable.class);
                if (javaError != null && javaError != Py.NoConversion) {
View Full Code Here

                // Check the character for legality
                // The 64 in stead of the expected 63 is because
                // there are a few uuencodes out there that use
                // '@' as zero instead of space.
                if (this_ch < ' ' || this_ch > (' ' + 64)) {
                    throw new PyException(Error, "Illegal char");
                }
                this_ch = (char) ((this_ch - ' ') & 077);
            }
            // Shift it in on the low end, and see if there's
            // a byte ready for output.
            leftchar = (leftchar << 6) | (this_ch);
            leftbits += 6;
            if (leftbits >= 8) {
                leftbits -= 8;
                bin_data.append((char) ((leftchar >> leftbits) & 0xff));
                leftchar &= ((1 << leftbits) - 1);
                bin_len--;
            }
        }
        // Finally, check that if there's anything left on the line
        // that it's whitespace only.
        while (ascii_len-- > 0) {
            this_ch = ascii_data.charAt(++i);
            // Extra '@' may be written as padding in some cases
            if (this_ch != ' ' && this_ch != '@' && this_ch != '\n' && this_ch != '\r') {
                throw new PyException(Error, "Trailing garbage");
            }
        }
        return bin_data.toString();
    }
View Full Code Here

        int leftchar = 0;

        int bin_len = bin_data.length();
        if (bin_len > 45) {
            // The 45 is a limit that appears in all uuencode's
            throw new PyException(Error, "At most 45 bytes at once");
        }

        StringBuffer ascii_data = new StringBuffer();

        // Store the length */
 
View Full Code Here

                leftchar &= ((1 << leftbits) - 1);
            }
        }
        // Check that no bits are left
        if (leftbits != 0) {
            throw new PyException(Error, "Incorrect padding");
        }
        return bin_data.toString();
    }
View Full Code Here

        StringBuffer ascii_data = new StringBuffer();

        int bin_len = bin_data.length();
        if (bin_len > BASE64_MAXBIN) {
            throw new PyException(Error, "Too much data for base64 line");
        }

        for (int i = 0; bin_len > 0; bin_len--, i++) {
            // Shift the data into our buffer
            leftchar = (leftchar << 8) | bin_data.charAt(i);
View Full Code Here

            // Get the byte and look it up
            this_ch = (char) table_a2b_hqx[ascii_data.charAt(i)];
            if (this_ch == SKIP)
                continue;
            if (this_ch == FAIL) {
                throw new PyException(Error, "Illegal char");
            }
            if (this_ch == DONE) {
                // The terminating colon
                done = true;
                break;
            }

            // Shift it into the buffer and see if any bytes are ready
            leftchar = (leftchar << 6) | (this_ch);
            leftbits += 6;
            if (leftbits >= 8) {
                leftbits -= 8;
                bin_data.append((char) ((leftchar >> leftbits) & 0xff));
                leftchar &= ((1 << leftbits) - 1);
            }
        }

        if (leftbits != 0 && !done) {
            throw new PyException(Incomplete, "String has incomplete number of bytes");
        }

        return new PyTuple(new PyObject[] { Py.java2py(bin_data.toString()), Py.newInteger(done ? 1 : 0) });
    }
View Full Code Here

        StringBuffer out_data = new StringBuffer();

        // Handle first byte separately (since we have to get angry
        // in case of an orphaned RLE code).
        if (--in_len < 0)
            throw new PyException(Incomplete);
        in_byte = in_data.charAt(i++);

        if (in_byte == RUNCHAR) {
            if (--in_len < 0)
                throw new PyException(Incomplete);
            in_repeat = in_data.charAt(i++);

            if (in_repeat != 0) {
                // Note Error, not Incomplete (which is at the end
                // of the string only). This is a programmer error.
                throw new PyException(Error, "Orphaned RLE code at start");
            }
            out_data.append(RUNCHAR);
        } else {
            out_data.append(in_byte);
        }

        while (in_len > 0) {
            if (--in_len < 0)
                throw new PyException(Incomplete);
            in_byte = in_data.charAt(i++);

            if (in_byte == RUNCHAR) {
                if (--in_len < 0)
                    throw new PyException(Incomplete);
                in_repeat = in_data.charAt(i++);

                if (in_repeat == 0) {
                    // Just an escaped RUNCHAR value
                    out_data.append(RUNCHAR);
View Full Code Here

        }
        return time() - __initialclock__;
    }

    private static void throwValueError(String msg) {
        throw new PyException(Py.ValueError, new PyString(msg));
    }
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.