示例#1
0
  /** <i>Internal use only. Do not call this method explicit.</i> */
  public static void classDictInit(PyObject dict) {
    dict.invoke("clear");
    dict.__setitem__("__name__", new PyString("exceptions"));
    dict.__setitem__("__doc__", new PyString(__doc__));

    ThreadState ts = Py.getThreadState();
    if (ts.getSystemState() == null) { // TODO: is this check still useful??
      ts.setSystemState(Py.defaultSystemState);
    }
    // Push frame
    PyFrame frame = new PyFrame(null, new PyStringMap());
    frame.f_back = ts.frame;
    if (frame.f_builtins == null) {
      if (frame.f_back != null) {
        frame.f_builtins = frame.f_back.f_builtins;
      } else {
        frame.f_builtins = PySystemState.getDefaultBuiltins();
      }
    }
    ts.frame = frame;

    dict.__setitem__("BaseException", PyBaseException.TYPE);

    buildClass(dict, "KeyboardInterrupt", "BaseException", "Program interrupted by user.");

    buildClass(
        dict, "SystemExit", "BaseException", SystemExit(), "Request to exit from the interpreter.");

    buildClass(
        dict, "Exception", "BaseException", "Common base class for all non-exit exceptions.");

    buildClass(
        dict,
        "StandardError",
        "Exception",
        "Base class for all standard Python exceptions that do not represent\n"
            + "interpreter exiting.");

    buildClass(dict, "SyntaxError", "StandardError", SyntaxError(), "Invalid syntax.");

    buildClass(dict, "IndentationError", "SyntaxError", "Improper indentation.");

    buildClass(dict, "TabError", "IndentationError", "Improper mixture of spaces and tabs.");

    buildClass(
        dict,
        "EnvironmentError",
        "StandardError",
        EnvironmentError(),
        "Base class for I/O related errors.");

    buildClass(dict, "IOError", "EnvironmentError", "I/O operation failed.");

    buildClass(dict, "OSError", "EnvironmentError", "OS system call failed.");

    buildClass(dict, "RuntimeError", "StandardError", "Unspecified run-time error.");

    buildClass(
        dict,
        "NotImplementedError",
        "RuntimeError",
        "Method or function hasn't been implemented yet.");

    buildClass(
        dict,
        "SystemError",
        "StandardError",
        "Internal error in the Python interpreter.\n\n"
            + "Please report this to the Python maintainer, "
            + "along with the traceback,\n"
            + "the Python version, and the hardware/OS "
            + "platform and version.");

    buildClass(
        dict, "ReferenceError", "StandardError", "Weak ref proxy used after referent went away.");

    buildClass(dict, "EOFError", "StandardError", "Read beyond end of file.");

    buildClass(
        dict,
        "ImportError",
        "StandardError",
        "Import can't find module, or can't find name in module.");

    buildClass(dict, "TypeError", "StandardError", "Inappropriate argument type.");

    buildClass(
        dict, "ValueError", "StandardError", "Inappropriate argument value (of correct type).");

    buildClass(dict, "UnicodeError", "ValueError", "Unicode related error.");

    buildClass(
        dict,
        "UnicodeEncodeError",
        "UnicodeError",
        UnicodeEncodeError(),
        "Unicode encoding error.");

    buildClass(
        dict,
        "UnicodeDecodeError",
        "UnicodeError",
        UnicodeDecodeError(),
        "Unicode decoding error.");

    buildClass(
        dict,
        "UnicodeTranslateError",
        "UnicodeError",
        UnicodeTranslateError(),
        "Unicode translation error.");

    buildClass(dict, "AssertionError", "StandardError", "Assertion failed.");

    buildClass(dict, "ArithmeticError", "StandardError", "Base class for arithmetic errors.");

    buildClass(dict, "OverflowError", "ArithmeticError", "Result too large to be represented.");

    buildClass(dict, "FloatingPointError", "ArithmeticError", "Floating point operation failed.");

    buildClass(
        dict,
        "ZeroDivisionError",
        "ArithmeticError",
        "Second argument to a division or modulo operation " + "was zero.");

    buildClass(dict, "LookupError", "StandardError", "Base class for lookup errors.");

    buildClass(dict, "IndexError", "LookupError", "Sequence index out of range.");

    buildClass(dict, "KeyError", "LookupError", KeyError(), "Mapping key not found.");

    buildClass(dict, "AttributeError", "StandardError", "Attribute not found.");

    buildClass(dict, "NameError", "StandardError", "Name not found globally.");

    buildClass(
        dict, "UnboundLocalError", "NameError", "Local name referenced but not bound to a value.");

    buildClass(dict, "MemoryError", "StandardError", "Out of memory.");

    buildClass(dict, "BufferError", "StandardError", "Buffer error.");

    buildClass(dict, "StopIteration", "Exception", "Signal the end from iterator.next().");

    buildClass(dict, "GeneratorExit", "BaseException", "Request that a generator exit.");

    buildClass(dict, "Warning", "Exception", "Base class for warning categories.");

    buildClass(dict, "UserWarning", "Warning", "Base class for warnings generated by user code.");

    buildClass(
        dict,
        "DeprecationWarning",
        "Warning",
        "Base class for warnings about deprecated features.");

    buildClass(
        dict,
        "PendingDeprecationWarning",
        "Warning",
        "Base class for warnings about features which will be deprecated\n" + "in the future.");

    buildClass(dict, "SyntaxWarning", "Warning", "Base class for warnings about dubious syntax.");

    buildClass(
        dict,
        "RuntimeWarning",
        "Warning",
        "Base class for warnings about dubious runtime behavior.");

    buildClass(
        dict,
        "FutureWarning",
        "Warning",
        "Base class for warnings about constructs that will change semantically\n"
            + "in the future.");

    buildClass(
        dict,
        "ImportWarning",
        "Warning",
        "Base class for warnings about probable mistakes in module imports");

    buildClass(
        dict,
        "UnicodeWarning",
        "Warning",
        "Base class for warnings about Unicode related problems, mostly\n"
            + "related to conversion problems.");

    buildClass(
        dict,
        "BytesWarning",
        "Warning",
        "Base class for warnings about bytes and buffer related problems, mostly\n"
            + "related to conversion from str or comparing to str.");

    // Initialize ZipImportError here, where it's safe to; it's
    // needed immediately
    zipimport.initClassExceptions(dict);

    ts.frame = ts.frame.f_back;
  }