mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-22 17:06:33 +03:00
psycopg2.Error object and type renamed more consistently
This commit is contained in:
parent
114c62fac8
commit
b503db9ce6
|
@ -33,7 +33,7 @@ extern HIDDEN PyTypeObject diagnosticsType;
|
|||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
||||
PsycoErrorObject *err; /* exception to retrieve the diagnostics from */
|
||||
errorObject *err; /* exception to retrieve the diagnostics from */
|
||||
|
||||
} diagnosticsObject;
|
||||
|
||||
|
|
|
@ -122,14 +122,14 @@ diagnostics_init(diagnosticsObject *self, PyObject *args, PyObject *kwds)
|
|||
if (!PyArg_ParseTuple(args, "O", &err))
|
||||
return -1;
|
||||
|
||||
if (!PyObject_TypeCheck(err, &ErrorType)) {
|
||||
if (!PyObject_TypeCheck(err, &errorType)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"The argument must be a psycopg2.Error");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_INCREF(err);
|
||||
self->err = (PsycoErrorObject *)err;
|
||||
self->err = (errorObject *)err;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#ifndef PSYCOPG_ERROR_H
|
||||
#define PSYCOPG_ERROR_H 1
|
||||
|
||||
extern HIDDEN PyTypeObject ErrorType;
|
||||
extern HIDDEN PyTypeObject errorType;
|
||||
|
||||
typedef struct {
|
||||
PyBaseExceptionObject exc;
|
||||
|
@ -36,8 +36,8 @@ typedef struct {
|
|||
cursorObject *cursor;
|
||||
char *codec;
|
||||
PGresult *pgres;
|
||||
} PsycoErrorObject;
|
||||
} errorObject;
|
||||
|
||||
HIDDEN PyObject *error_text_from_chars(PsycoErrorObject *self, const char *str);
|
||||
HIDDEN PyObject *error_text_from_chars(errorObject *self, const char *str);
|
||||
|
||||
#endif /* PSYCOPG_ERROR_H */
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
|
||||
|
||||
PyObject *
|
||||
error_text_from_chars(PsycoErrorObject *self, const char *str)
|
||||
error_text_from_chars(errorObject *self, const char *str)
|
||||
{
|
||||
if (str == NULL) {
|
||||
Py_INCREF(Py_None);
|
||||
|
@ -61,11 +61,11 @@ static const char diag_doc[] =
|
|||
"A Diagnostics object to get further information about the error";
|
||||
|
||||
static PyMemberDef error_members[] = {
|
||||
{ "pgerror", T_OBJECT, offsetof(PsycoErrorObject, pgerror),
|
||||
{ "pgerror", T_OBJECT, offsetof(errorObject, pgerror),
|
||||
READONLY, (char *)pgerror_doc },
|
||||
{ "pgcode", T_OBJECT, offsetof(PsycoErrorObject, pgcode),
|
||||
{ "pgcode", T_OBJECT, offsetof(errorObject, pgcode),
|
||||
READONLY, (char *)pgcode_doc },
|
||||
{ "cursor", T_OBJECT, offsetof(PsycoErrorObject, cursor),
|
||||
{ "cursor", T_OBJECT, offsetof(errorObject, cursor),
|
||||
READONLY, (char *)cursor_doc },
|
||||
{ NULL }
|
||||
};
|
||||
|
@ -78,7 +78,7 @@ error_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
|
|||
}
|
||||
|
||||
static int
|
||||
error_init(PsycoErrorObject *self, PyObject *args, PyObject *kwargs)
|
||||
error_init(errorObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
if (((PyTypeObject *)PyExc_StandardError)->tp_init(
|
||||
(PyObject *)self, args, kwargs) < 0) {
|
||||
|
@ -88,7 +88,7 @@ error_init(PsycoErrorObject *self, PyObject *args, PyObject *kwargs)
|
|||
}
|
||||
|
||||
static int
|
||||
error_traverse(PsycoErrorObject *self, visitproc visit, void *arg)
|
||||
error_traverse(errorObject *self, visitproc visit, void *arg)
|
||||
{
|
||||
Py_VISIT(self->cursor);
|
||||
return ((PyTypeObject *)PyExc_StandardError)->tp_traverse(
|
||||
|
@ -96,7 +96,7 @@ error_traverse(PsycoErrorObject *self, visitproc visit, void *arg)
|
|||
}
|
||||
|
||||
static int
|
||||
error_clear(PsycoErrorObject *self)
|
||||
error_clear(errorObject *self)
|
||||
{
|
||||
Py_CLEAR(self->pgerror);
|
||||
Py_CLEAR(self->pgcode);
|
||||
|
@ -107,7 +107,7 @@ error_clear(PsycoErrorObject *self)
|
|||
}
|
||||
|
||||
static void
|
||||
error_dealloc(PsycoErrorObject *self)
|
||||
error_dealloc(errorObject *self)
|
||||
{
|
||||
error_clear(self);
|
||||
return Py_TYPE(self)->tp_free((PyObject *)self);
|
||||
|
@ -115,7 +115,7 @@ error_dealloc(PsycoErrorObject *self)
|
|||
|
||||
|
||||
static PyObject *
|
||||
error_get_diag(PsycoErrorObject *self, void *closure)
|
||||
error_get_diag(errorObject *self, void *closure)
|
||||
{
|
||||
return PyObject_CallFunctionObjArgs(
|
||||
(PyObject *)&diagnosticsType, (PyObject *)self, NULL);
|
||||
|
@ -136,7 +136,7 @@ static struct PyGetSetDef error_getsets[] = {
|
|||
* would require implementing __getstate__, and as of 2012 it's a little
|
||||
* bit too late to care. */
|
||||
static PyObject *
|
||||
psyco_error_reduce(PsycoErrorObject *self)
|
||||
psyco_error_reduce(errorObject *self)
|
||||
{
|
||||
PyObject *meth = NULL;
|
||||
PyObject *tuple = NULL;
|
||||
|
@ -187,7 +187,7 @@ error:
|
|||
}
|
||||
|
||||
PyObject *
|
||||
psyco_error_setstate(PsycoErrorObject *self, PyObject *state)
|
||||
psyco_error_setstate(errorObject *self, PyObject *state)
|
||||
{
|
||||
PyObject *rv = NULL;
|
||||
|
||||
|
@ -242,10 +242,10 @@ static PyMethodDef error_methods[] = {
|
|||
};
|
||||
|
||||
|
||||
PyTypeObject ErrorType = {
|
||||
PyTypeObject errorType = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"psycopg2.Error",
|
||||
sizeof(PsycoErrorObject),
|
||||
sizeof(errorObject),
|
||||
0,
|
||||
(destructor)error_dealloc, /* tp_dealloc */
|
||||
0, /*tp_print*/
|
||||
|
|
|
@ -218,8 +218,8 @@ pq_raise(connectionObject *conn, cursorObject *curs, PGresult **pgres)
|
|||
|
||||
pyerr = psyco_set_error(exc, curs, err2);
|
||||
|
||||
if (pyerr && PyObject_TypeCheck(pyerr, &ErrorType)) {
|
||||
PsycoErrorObject *perr = (PsycoErrorObject *)pyerr;
|
||||
if (pyerr && PyObject_TypeCheck(pyerr, &errorType)) {
|
||||
errorObject *perr = (errorObject *)pyerr;
|
||||
|
||||
PyMem_Free(perr->codec);
|
||||
psycopg_strdup(&perr->codec, conn->codec, 0);
|
||||
|
|
|
@ -448,7 +448,7 @@ psyco_errors_init(void)
|
|||
int rv = -1;
|
||||
|
||||
/* 'Error' has been defined elsewhere: only init the other classes */
|
||||
Error = (PyObject *)&ErrorType;
|
||||
Error = (PyObject *)&errorType;
|
||||
|
||||
for (i = 1; exctable[i].name; i++) {
|
||||
if (!(dict = PyDict_New())) { goto exit; }
|
||||
|
@ -534,8 +534,8 @@ psyco_set_error(PyObject *exc, cursorObject *curs, const char *msg)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (err && PyObject_TypeCheck(err, &ErrorType)) {
|
||||
PsycoErrorObject *perr = (PsycoErrorObject *)err;
|
||||
if (err && PyObject_TypeCheck(err, &errorType)) {
|
||||
errorObject *perr = (errorObject *)err;
|
||||
if (curs) {
|
||||
Py_CLEAR(perr->cursor);
|
||||
Py_INCREF(curs);
|
||||
|
@ -782,7 +782,7 @@ INIT_MODULE(_psycopg)(void)
|
|||
Py_TYPE(&chunkType) = &PyType_Type;
|
||||
Py_TYPE(&NotifyType) = &PyType_Type;
|
||||
Py_TYPE(&XidType) = &PyType_Type;
|
||||
Py_TYPE(&ErrorType) = &PyType_Type;
|
||||
Py_TYPE(&errorType) = &PyType_Type;
|
||||
Py_TYPE(&diagnosticsType) = &PyType_Type;
|
||||
|
||||
if (PyType_Ready(&connectionType) == -1) goto exit;
|
||||
|
@ -800,8 +800,8 @@ INIT_MODULE(_psycopg)(void)
|
|||
if (PyType_Ready(&chunkType) == -1) goto exit;
|
||||
if (PyType_Ready(&NotifyType) == -1) goto exit;
|
||||
if (PyType_Ready(&XidType) == -1) goto exit;
|
||||
ErrorType.tp_base = (PyTypeObject *)PyExc_StandardError;
|
||||
if (PyType_Ready(&ErrorType) == -1) goto exit;
|
||||
errorType.tp_base = (PyTypeObject *)PyExc_StandardError;
|
||||
if (PyType_Ready(&errorType) == -1) goto exit;
|
||||
if (PyType_Ready(&diagnosticsType) == -1) goto exit;
|
||||
|
||||
#ifdef PSYCOPG_EXTENSIONS
|
||||
|
@ -937,7 +937,7 @@ INIT_MODULE(_psycopg)(void)
|
|||
pydatetimeType.tp_alloc = PyType_GenericAlloc;
|
||||
NotifyType.tp_alloc = PyType_GenericAlloc;
|
||||
XidType.tp_alloc = PyType_GenericAlloc;
|
||||
ErrorType.tp_alloc = PyType_GenericAlloc;
|
||||
errorType.tp_alloc = PyType_GenericAlloc;
|
||||
diagnosticsType.tp_alloc = PyType_GenericAlloc;
|
||||
|
||||
#ifdef PSYCOPG_EXTENSIONS
|
||||
|
|
Loading…
Reference in New Issue
Block a user