mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-26 10:53:44 +03:00
Dropped funny handling of REPLICATION_* constants
This commit is contained in:
parent
c77615adc9
commit
7a3bce8fc3
|
@ -1008,9 +1008,6 @@ INIT_MODULE(_psycopg)(void)
|
||||||
if (0 != psyco_errors_init()) { goto exit; }
|
if (0 != psyco_errors_init()) { goto exit; }
|
||||||
psyco_errors_fill(dict);
|
psyco_errors_fill(dict);
|
||||||
|
|
||||||
replicationPhysicalConst = PyDict_GetItemString(dict, "REPLICATION_PHYSICAL");
|
|
||||||
replicationLogicalConst = PyDict_GetItemString(dict, "REPLICATION_LOGICAL");
|
|
||||||
|
|
||||||
Dprintf("initpsycopg: module initialization complete");
|
Dprintf("initpsycopg: module initialization complete");
|
||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
|
@ -45,9 +45,6 @@ typedef struct replicationConnectionObject {
|
||||||
#define REPLICATION_PHYSICAL 12345678
|
#define REPLICATION_PHYSICAL 12345678
|
||||||
#define REPLICATION_LOGICAL 87654321
|
#define REPLICATION_LOGICAL 87654321
|
||||||
|
|
||||||
extern HIDDEN PyObject *replicationPhysicalConst;
|
|
||||||
extern HIDDEN PyObject *replicationLogicalConst;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -41,21 +41,7 @@
|
||||||
static PyObject *
|
static PyObject *
|
||||||
psyco_repl_conn_get_type(replicationConnectionObject *self)
|
psyco_repl_conn_get_type(replicationConnectionObject *self)
|
||||||
{
|
{
|
||||||
connectionObject *conn = &self->conn;
|
return PyInt_FromLong(self->type);
|
||||||
PyObject *res = NULL;
|
|
||||||
|
|
||||||
EXC_IF_CONN_CLOSED(conn);
|
|
||||||
|
|
||||||
if (self->type == REPLICATION_PHYSICAL) {
|
|
||||||
res = replicationPhysicalConst;
|
|
||||||
} else if (self->type == REPLICATION_LOGICAL) {
|
|
||||||
res = replicationLogicalConst;
|
|
||||||
} else {
|
|
||||||
PyErr_Format(PyExc_TypeError, "unknown replication type constant: %ld", self->type);
|
|
||||||
}
|
|
||||||
|
|
||||||
Py_XINCREF(res);
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,15 +49,16 @@ static int
|
||||||
replicationConnection_init(replicationConnectionObject *self,
|
replicationConnection_init(replicationConnectionObject *self,
|
||||||
PyObject *args, PyObject *kwargs)
|
PyObject *args, PyObject *kwargs)
|
||||||
{
|
{
|
||||||
PyObject *dsn = NULL, *async = Py_False, *replication_type = NULL,
|
PyObject *dsn = NULL, *async = Py_False,
|
||||||
*item = NULL, *extras = NULL, *cursor = NULL,
|
*item = NULL, *extras = NULL, *cursor = NULL,
|
||||||
*newdsn = NULL, *newargs = NULL, *dsnopts = NULL;
|
*newdsn = NULL, *newargs = NULL, *dsnopts = NULL;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
long int replication_type;
|
||||||
|
|
||||||
/* 'replication_type' is not actually optional, but there's no
|
/* 'replication_type' is not actually optional, but there's no
|
||||||
good way to put it before 'async' in the list */
|
good way to put it before 'async' in the list */
|
||||||
static char *kwlist[] = {"dsn", "async", "replication_type", NULL};
|
static char *kwlist[] = {"dsn", "async", "replication_type", NULL};
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OO", kwlist,
|
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|Ol", kwlist,
|
||||||
&dsn, &async, &replication_type)) {
|
&dsn, &async, &replication_type)) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -87,9 +74,7 @@ replicationConnection_init(replicationConnectionObject *self,
|
||||||
if (!(extras = PyImport_ImportModule("psycopg2.extras"))) { goto exit; }
|
if (!(extras = PyImport_ImportModule("psycopg2.extras"))) { goto exit; }
|
||||||
if (!(cursor = PyObject_GetAttrString(extras, "ReplicationCursor"))) { goto exit; }
|
if (!(cursor = PyObject_GetAttrString(extras, "ReplicationCursor"))) { goto exit; }
|
||||||
|
|
||||||
/* checking the object reference helps to avoid recognizing
|
if (replication_type == REPLICATION_PHYSICAL) {
|
||||||
unrelated integer constants as valid input values */
|
|
||||||
if (replication_type == replicationPhysicalConst) {
|
|
||||||
self->type = REPLICATION_PHYSICAL;
|
self->type = REPLICATION_PHYSICAL;
|
||||||
|
|
||||||
#define SET_ITEM(k, v) \
|
#define SET_ITEM(k, v) \
|
||||||
|
@ -100,14 +85,15 @@ replicationConnection_init(replicationConnectionObject *self,
|
||||||
|
|
||||||
SET_ITEM(replication, true);
|
SET_ITEM(replication, true);
|
||||||
SET_ITEM(dbname, replication); /* required for .pgpass lookup */
|
SET_ITEM(dbname, replication); /* required for .pgpass lookup */
|
||||||
} else if (replication_type == replicationLogicalConst) {
|
} else if (replication_type == REPLICATION_LOGICAL) {
|
||||||
self->type = REPLICATION_LOGICAL;
|
self->type = REPLICATION_LOGICAL;
|
||||||
|
|
||||||
SET_ITEM(replication, database);
|
SET_ITEM(replication, database);
|
||||||
#undef SET_ITEM
|
#undef SET_ITEM
|
||||||
} else {
|
} else {
|
||||||
PyErr_SetString(PyExc_TypeError,
|
PyErr_SetString(PyExc_TypeError,
|
||||||
"replication_type must be either REPLICATION_PHYSICAL or REPLICATION_LOGICAL");
|
"replication_type must be either "
|
||||||
|
"REPLICATION_PHYSICAL or REPLICATION_LOGICAL");
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,6 +190,3 @@ PyTypeObject replicationConnectionType = {
|
||||||
0, /*tp_alloc*/
|
0, /*tp_alloc*/
|
||||||
0, /*tp_new*/
|
0, /*tp_new*/
|
||||||
};
|
};
|
||||||
|
|
||||||
PyObject *replicationPhysicalConst;
|
|
||||||
PyObject *replicationLogicalConst;
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user