cinap_lenrekadd hg and python4bb9e2215 years agoHistory
2147 lines · 58.3 KB · C
RawDownload
 * when it was supplied. */static intEnvironmentError_init(PyEnvironmentErrorObject *self, PyObject *args,    PyObject *kwds){    PyObject *myerrno = NULL, *strerror = NULL, *filename = NULL;    PyObject *subslice = NULL;     if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)        return -1;     if (PyTuple_GET_SIZE(args) <= 1 || PyTuple_GET_SIZE(args) > 3) {        return 0;    }     if (!PyArg_UnpackTuple(args, "EnvironmentError", 2, 3,                           &myerrno, &strerror, &filename)) {        return -1;    }    Py_CLEAR(self->myerrno);       /* replacing */    self->myerrno = myerrno;    Py_INCREF(self->myerrno);     Py_CLEAR(self->strerror);      /* replacing */    self->strerror = strerror;    Py_INCREF(self->strerror);     /* self->filename will remain Py_None otherwise */    if (filename != NULL) {        Py_CLEAR(self->filename);      /* replacing */        self->filename = filename;        Py_INCREF(self->filename);         subslice = PyTuple_GetSlice(args, 0, 2);        if (!subslice)            return -1;         Py_DECREF(self->args);  /* replacing args */        self->args = subslice;    }    return 0;} static intEnvironmentError_clear(PyEnvironmentErrorObject *self){    Py_CLEAR(self->myerrno);    Py_CLEAR(self->strerror);    Py_CLEAR(self->filename);    return BaseException_clear((PyBaseExceptionObject *)self);} static voidEnvironmentError_dealloc(PyEnvironmentErrorObject *self){    _PyObject_GC_UNTRACK(self);    EnvironmentError_clear(self);    self->ob_type->tp_free((PyObject *)self);} static intEnvironmentError_traverse(PyEnvironmentErrorObject *self, visitproc visit,        void *arg){    Py_VISIT(self->myerrno);    Py_VISIT(self->strerror);    Py_VISIT(self->filename);    return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);} static PyObject *EnvironmentError_str(PyEnvironmentErrorObject *self){    PyObject *rtnval = NULL;     if (self->filename) {        PyObject *fmt;        PyObject *repr;        PyObject *tuple;         fmt = PyString_FromString("[Errno %s] %s: %s");        if (!fmt)            return NULL;         repr = PyObject_Repr(self->filename);        if (!repr) {            Py_DECREF(fmt);            return NULL;        }        tuple = PyTuple_New(3);        if (!tuple) {            Py_DECREF(repr);            Py_DECREF(fmt);            return NULL;        }         if (self->myerrno) {            Py_INCREF(self->myerrno);            PyTuple_SET_ITEM(tuple, 0, self->myerrno);        }        else {            Py_INCREF(Py_None);            PyTuple_SET_ITEM(tuple, 0, Py_None);        }        if (self->strerror) {            Py_INCREF(self->strerror);            PyTuple_SET_ITEM(tuple, 1, self->strerror);        }        else {            Py_INCREF(Py_None);            PyTuple_SET_ITEM(tuple, 1, Py_None);        }         PyTuple_SET_ITEM(tuple, 2, repr);         rtnval = PyString_Format(fmt, tuple);         Py_DECREF(fmt);        Py_DECREF(tuple);    }    else if (self->myerrno && self->strerror) {        PyObject *fmt;        PyObject *tuple;         fmt = PyString_FromString("[Errno %s] %s");        if (!fmt)            return NULL;         tuple = PyTuple_New(2);        if (!tuple) {            Py_DECREF(fmt);            return NULL;        }         if (self->myerrno) {            Py_INCREF(self->myerrno);            PyTuple_SET_ITEM(tuple, 0, self->myerrno);        }        else {            Py_INCREF(Py_None);            PyTuple_SET_ITEM(tuple, 0, Py_None);        }        if (self->strerror) {            Py_INCREF(self->strerror);            PyTuple_SET_ITEM(tuple, 1, self->strerror);        }        else {            Py_INCREF(Py_None);            PyTuple_SET_ITEM(tuple, 1, Py_None);        }         rtnval = PyString_Format(fmt, tuple);         Py_DECREF(fmt);        Py_DECREF(tuple);    }    else        rtnval = BaseException_str((PyBaseExceptionObject *)self);     return rtnval;} static PyMemberDef EnvironmentError_members[] = {    {"message", T_OBJECT, offsetof(PyEnvironmentErrorObject, message), 0,        PyDoc_STR("exception message")},    {"errno", T_OBJECT, offsetof(PyEnvironmentErrorObject, myerrno), 0,        PyDoc_STR("exception errno")},    {"strerror", T_OBJECT, offsetof(PyEnvironmentErrorObject, strerror), 0,        PyDoc_STR("exception strerror")},    {"filename", T_OBJECT, offsetof(PyEnvironmentErrorObject, filename), 0,        PyDoc_STR("exception filename")},    {NULL}  /* Sentinel */};  static PyObject *EnvironmentError_reduce(PyEnvironmentErrorObject *self){    PyObject *args = self->args;    PyObject *res = NULL, *tmp;     /* self->args is only the first two real arguments if there was a     * file name given to EnvironmentError. */    if (PyTuple_GET_SIZE(args) == 2 && self->filename) {        args = PyTuple_New(3);        if (!args) return NULL;         tmp = PyTuple_GET_ITEM(self->args, 0);        Py_INCREF(tmp);        PyTuple_SET_ITEM(args, 0, tmp);         tmp = PyTuple_GET_ITEM(self->args, 1);        Py_INCREF(tmp);        PyTuple_SET_ITEM(args, 1, tmp);         Py_INCREF(self->filename);        PyTuple_SET_ITEM(args, 2, self->filename);    } else        Py_INCREF(args);     if (self->dict)        res = PyTuple_Pack(3, self->ob_type, args, self->dict);    else        res = PyTuple_Pack(2, self->ob_type, args);    Py_DECREF(args);    return res;}  static PyMethodDef EnvironmentError_methods[] = {    {"__reduce__", (PyCFunction)EnvironmentError_reduce, METH_NOARGS},    {NULL}}; ComplexExtendsException(PyExc_StandardError, EnvironmentError,                        EnvironmentError, EnvironmentError_dealloc,                        EnvironmentError_methods, EnvironmentError_members,                        EnvironmentError_str,                        "Base class for I/O related errors.");  /* *    IOError extends EnvironmentError */MiddlingExtendsException(PyExc_EnvironmentError, IOError,                         EnvironmentError, "I/O operation failed.");  /* *    OSError extends EnvironmentError */MiddlingExtendsException(PyExc_EnvironmentError, OSError,                         EnvironmentError, "OS system call failed.");  /* *    WindowsError extends OSError */#ifdef MS_WINDOWS#include "errmap.h" static intWindowsError_clear(PyWindowsErrorObject *self){    Py_CLEAR(self->myerrno);    Py_CLEAR(self->strerror);    Py_CLEAR(self->filename);    Py_CLEAR(self->winerror);    return BaseException_clear((PyBaseExceptionObject *)self);} static voidWindowsError_dealloc(PyWindowsErrorObject *self){    _PyObject_GC_UNTRACK(self);    WindowsError_clear(self);    self->ob_type->tp_free((PyObject *)self);} static intWindowsError_traverse(PyWindowsErrorObject *self, visitproc visit, void *arg){    Py_VISIT(self->myerrno);    Py_VISIT(self->strerror);    Py_VISIT(self->filename);    Py_VISIT(self->winerror);    return BaseException_traverse((PyBaseExceptionObject *)self, visit, arg);} static intWindowsError_init(PyWindowsErrorObject *self, PyObject *args, PyObject *kwds){    PyObject *o_errcode = NULL;    long errcode;    long posix_errno;     if (EnvironmentError_init((PyEnvironmentErrorObject *)self, args, kwds)            == -1)        return -1;     if (self->myerrno == NULL)        return 0;     /* Set errno to the POSIX errno, and winerror to the Win32       error code. */    errcode = PyInt_AsLong(self->myerrno);    if (errcode == -1 && PyErr_Occurred())        return -1;    posix_errno = winerror_to_errno(errcode);     Py_CLEAR(self->winerror);    self->winerror = self->myerrno;     o_errcode = PyInt_FromLong(posix_errno);    if (!o_errcode)        return -1;     self->myerrno = o_errcode;     return 0;}  static PyObject *WindowsError_str(PyWindowsErrorObject *self){    PyObject *rtnval = NULL;     if (self->filename) {        PyObject *fmt;        PyObject *repr;        PyObject *tuple;         fmt = PyString_FromString("[Error %s] %s: %s");        if (!fmt)            return NULL;         repr = PyObject_Repr(self->filename);        if (!repr) {            Py_DECREF(fmt);            return NULL;        }        tuple = PyTuple_New(3);        if (!tuple) {            Py_DECREF(repr);            Py_DECREF(fmt);            return NULL;        }         if (self->winerror) {            Py_INCREF(self->winerror);            PyTuple_SET_ITEM(tuple, 0, self->winerror);        }        else {            Py_INCREF(Py_None);            PyTuple_SET_ITEM(tuple, 0, Py_None);        }        if (self->strerror) {            Py_INCREF(self->strerror);            PyTuple_SET_ITEM(tuple, 1, self->strerror);        }        else {            Py_INCREF(Py_None);            PyTuple_SET_ITEM(tuple, 1, Py_None);        }         PyTuple_SET_ITEM(tuple, 2, repr);         rtnval = PyString_Format(fmt, tuple);         Py_DECREF(fmt);        Py_DECREF(tuple);    }    else if (self->winerror && self->strerror) {        PyObject *fmt;        PyObject *tuple;         fmt = PyString_FromString("[Error %s] %s");        if (!fmt)            return NULL;         tuple = PyTuple_New(2);        if (!tuple) {            Py_DECREF(fmt);            return NULL;        }         if (self->winerror) {            Py_INCREF(self->winerror);            PyTuple_SET_ITEM(tuple, 0, self->winerror);        }        else {            Py_INCREF(Py_None);            PyTuple_SET_ITEM(tuple, 0, Py_None);        }        if (self->strerror) {            Py_INCREF(self->strerror);            PyTuple_SET_ITEM(tuple, 1, self->strerror);        }        else {            Py_INCREF(Py_None);            PyTuple_SET_ITEM(tuple, 1, Py_None);        }         rtnval = PyString_Format(fmt, tuple);         Py_DECREF(fmt);        Py_DECREF(tuple);    }    else        rtnval = EnvironmentError_str((PyEnvironmentErrorObject *)self);     return rtnval;} static PyMemberDef WindowsError_members[] = {    {"message", T_OBJECT, offsetof(PyWindowsErrorObject, message), 0,        PyDoc_STR("exception message")},    {"errno", T_OBJECT, offsetof(PyWindowsErrorObject, myerrno), 0,        PyDoc_STR("POSIX exception code")},    {"strerror", T_OBJECT, offsetof(PyWindowsErrorObject, strerror), 0,        PyDoc_STR("exception strerror")},    {"filename", T_OBJECT, offsetof(PyWindowsErrorObject, filename), 0,        PyDoc_STR("exception filename")},    {"winerror", T_OBJECT, offsetof(PyWindowsErrorObject, winerror), 0,        PyDoc_STR("Win32 exception code")},    {NULL}  /* Sentinel */}; ComplexExtendsException(PyExc_OSError, WindowsError, WindowsError,                        WindowsError_dealloc, 0, WindowsError_members,                        WindowsError_str, "MS-Windows OS system call failed."); #endif /* MS_WINDOWS */  /* *    VMSError extends OSError (I think) */#ifdef __VMSMiddlingExtendsException(PyExc_OSError, VMSError, EnvironmentError,                         "OpenVMS OS system call failed.");#endif  /* *    EOFError extends StandardError */SimpleExtendsException(PyExc_StandardError, EOFError,                       "Read beyond end of file.");  /* *    RuntimeError extends StandardError */SimpleExtendsException(PyExc_StandardError, RuntimeError,                       "Unspecified run-time error.");  /* *    NotImplementedError extends RuntimeError */SimpleExtendsException(PyExc_RuntimeError, NotImplementedError,                       "Method or function hasn't been implemented yet."); /* *    NameError extends StandardError */SimpleExtendsException(PyExc_StandardError, NameError,                       "Name not found globally."); /* *    UnboundLocalError extends NameError */SimpleExtendsException(PyExc_NameError, UnboundLocalError,                       "Local name referenced but not bound to a value."); /* *    AttributeError extends StandardError */SimpleExtendsException(PyExc_StandardError, AttributeError,                       "Attribute not found.");  /* *    SyntaxError extends StandardError */ static intSyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds){    PyObject *info = NULL;    Py_ssize_t lenargs = PyTuple_GET_SIZE(args);     if (BaseException_init((PyBaseExceptionObject *)self, args, kwds) == -1)        return -1;     if (lenargs >= 1) {        Py_CLEAR(self->msg);        self->msg = PyTuple_GET_ITEM(args, 0);        Py_INCREF(self->msg);    }    if (lenargs == 2) {        info = PyTuple_GET_ITEM(args, 1);        info = PySequence_Tuple(info);        if (!info) return -1;         if (PyTuple_GET_SIZE(info) != 4) {            /* not a very good error message, but it's what Python 2.4 gives */            PyErr_SetString(PyExc_IndexError, "tuple index out of range");            Py_DECREF(info);            return -1;        }         Py_CLEAR(self->filename);        self->filename = PyTuple_GET_ITEM(info, 0);        Py_INCREF(self->filename);         Py_CLEAR(self->lineno);

Lines 501–1000 of 2147. Previous lines