This commit is contained in:
Gianfranco Costamagna 2018-06-28 22:01:20 +00:00 committed by GitHub
commit 61ce129775
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 44 additions and 46 deletions

View File

@ -96,7 +96,7 @@ struct connectionObject {
int status; /* status of the connection */
xidObject *tpc_xid; /* Transaction ID in two-phase commit */
long int async; /* 1 means the connection is async */
long int async_; /* 1 means the connection is async */
int protocol; /* protocol version */
int server_version; /* server version */
@ -160,7 +160,7 @@ HIDDEN void conn_notice_process(connectionObject *self);
HIDDEN void conn_notice_clean(connectionObject *self);
HIDDEN void conn_notifies_process(connectionObject *self);
RAISES_NEG HIDDEN int conn_setup(connectionObject *self, PGconn *pgconn);
HIDDEN int conn_connect(connectionObject *self, long int async);
HIDDEN int conn_connect(connectionObject *self, long int async_);
HIDDEN void conn_close(connectionObject *self);
HIDDEN void conn_close_locked(connectionObject *self);
RAISES_NEG HIDDEN int conn_commit(connectionObject *self);
@ -179,7 +179,7 @@ HIDDEN PyObject *conn_tpc_recover(connectionObject *self);
PyErr_SetString(InterfaceError, "connection already closed"); \
return NULL; }
#define EXC_IF_CONN_ASYNC(self, cmd) if ((self)->async == 1) { \
#define EXC_IF_CONN_ASYNC(self, cmd) if ((self)->async_ == 1) { \
PyErr_SetString(ProgrammingError, #cmd " cannot be used " \
"in asynchronous mode"); \
return NULL; }

View File

@ -802,11 +802,11 @@ _conn_async_connect(connectionObject *self)
}
int
conn_connect(connectionObject *self, long int async)
conn_connect(connectionObject *self, long int async_)
{
int rv;
if (async == 1) {
if (async_ == 1) {
Dprintf("con_connect: connecting in ASYNC mode");
rv = _conn_async_connect(self);
}
@ -934,7 +934,7 @@ _conn_poll_query(connectionObject *self)
case ASYNC_READ:
Dprintf("conn_poll: async_status = ASYNC_READ");
if (self->async) {
if (self->async_) {
res = _conn_poll_advance_read(self, pq_is_busy(self));
}
else {
@ -1061,7 +1061,7 @@ conn_poll(connectionObject *self)
case CONN_STATUS_CONNECTING:
res = _conn_poll_connecting(self);
if (res == PSYCO_POLL_OK && self->async) {
if (res == PSYCO_POLL_OK && self->async_) {
res = _conn_poll_setup_async(self);
}
break;
@ -1075,7 +1075,7 @@ conn_poll(connectionObject *self)
case CONN_STATUS_PREPARED:
res = _conn_poll_query(self);
if (res == PSYCO_POLL_OK && self->async && self->async_cursor) {
if (res == PSYCO_POLL_OK && self->async_ && self->async_cursor) {
/* An async query has just finished: parse the tuple in the
* target cursor. */
cursorObject *curs;

View File

@ -91,7 +91,7 @@ psyco_conn_cursor(connectionObject *self, PyObject *args, PyObject *kwargs)
goto exit;
}
if (name != Py_None && self->async == 1) {
if (name != Py_None && self->async_ == 1) {
PyErr_SetString(ProgrammingError,
"asynchronous connections "
"cannot produce named cursors");
@ -1069,7 +1069,7 @@ static PyObject *
psyco_conn_isexecuting(connectionObject *self)
{
/* synchronous connections will always return False */
if (self->async == 0) {
if (self->async_ == 0) {
Py_INCREF(Py_False);
return Py_False;
}
@ -1191,9 +1191,7 @@ static struct PyMemberDef connectionObject_members[] = {
{"notifies", T_OBJECT, offsetof(connectionObject, notifies), 0},
{"dsn", T_STRING, offsetof(connectionObject, dsn), READONLY,
"The current connection string."},
{"async", T_LONG, offsetof(connectionObject, async), READONLY,
"True if the connection is asynchronous."},
{"async_", T_LONG, offsetof(connectionObject, async), READONLY,
{"async_", T_LONG, offsetof(connectionObject, async_), READONLY,
"True if the connection is asynchronous."},
{"status", T_INT,
offsetof(connectionObject, status), READONLY,
@ -1299,19 +1297,19 @@ exit:
}
static int
connection_setup(connectionObject *self, const char *dsn, long int async)
connection_setup(connectionObject *self, const char *dsn, long int async_)
{
int res = -1;
Dprintf("connection_setup: init connection object at %p, "
"async %ld, refcnt = " FORMAT_CODE_PY_SSIZE_T,
self, async, Py_REFCNT(self)
self, async_, Py_REFCNT(self)
);
if (0 > psycopg_strdup(&self->dsn, dsn, -1)) { goto exit; }
if (!(self->notice_list = PyList_New(0))) { goto exit; }
if (!(self->notifies = PyList_New(0))) { goto exit; }
self->async = async;
self->async_ = async_;
self->status = CONN_STATUS_SETUP;
self->async_status = ASYNC_DONE;
if (!(self->string_types = PyDict_New())) { goto exit; }
@ -1323,7 +1321,7 @@ connection_setup(connectionObject *self, const char *dsn, long int async)
pthread_mutex_init(&(self->lock), NULL);
if (conn_connect(self, async) != 0) {
if (conn_connect(self, async_) != 0) {
Dprintf("connection_init: FAILED");
goto exit;
}
@ -1401,15 +1399,15 @@ static int
connection_init(PyObject *obj, PyObject *args, PyObject *kwds)
{
const char *dsn;
long int async = 0, async_ = 0;
static char *kwlist[] = {"dsn", "async", "async_", NULL};
long int async_ = 0, async__ = 0;
static char *kwlist[] = {"dsn", "async_", "async__", NULL};
if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|ll", kwlist,
&dsn, &async, &async_))
&dsn, &async_, &async__))
return -1;
if (async_) { async = async_; }
return connection_setup((connectionObject *)obj, dsn, async);
if (async__) { async_ = async__; }
return connection_setup((connectionObject *)obj, dsn, async_);
}
static PyObject *

View File

@ -124,7 +124,7 @@ while (0)
#define EXC_IF_CURS_ASYNC(self, cmd) \
do \
if ((self)->conn->async == 1) { \
if ((self)->conn->async_ == 1) { \
PyErr_SetString(ProgrammingError, \
#cmd " cannot be used in asynchronous mode"); \
return NULL; } \

View File

@ -345,7 +345,7 @@ _psyco_curs_merge_query_args(cursorObject *self,
RAISES_NEG static int
_psyco_curs_execute(cursorObject *self,
PyObject *operation, PyObject *vars,
long int async, int no_result)
long int async_, int no_result)
{
int res = -1;
int tmp;
@ -425,7 +425,7 @@ _psyco_curs_execute(cursorObject *self,
/* At this point, the SQL statement must be str, not unicode */
tmp = pq_execute(self, Bytes_AS_STRING(self->query), async, no_result, 0);
tmp = pq_execute(self, Bytes_AS_STRING(self->query), async_, no_result, 0);
Dprintf("psyco_curs_execute: res = %d, pgres = %p", tmp, self->pgres);
if (tmp < 0) { goto exit; }
@ -471,7 +471,7 @@ psyco_curs_execute(cursorObject *self, PyObject *args, PyObject *kwargs)
EXC_IF_ASYNC_IN_PROGRESS(self, execute);
EXC_IF_TPC_PREPARED(self->conn, execute);
if (0 > _psyco_curs_execute(self, operation, vars, self->conn->async, 0)) {
if (0 > _psyco_curs_execute(self, operation, vars, self->conn->async_, 0)) {
return NULL;
}
@ -1097,7 +1097,7 @@ psyco_curs_callproc(cursorObject *self, PyObject *args)
}
if (0 <= _psyco_curs_execute(
self, operation, pvals, self->conn->async, 0)) {
self, operation, pvals, self->conn->async_, 0)) {
/* The dict case is outside DBAPI scope anyway, so simply return None */
if (using_dict) {
res = Py_None;

View File

@ -68,7 +68,7 @@ psyco_repl_curs_start_replication_expert(replicationCursorObject *self,
Dprintf("psyco_repl_curs_start_replication_expert: '%s'; decode: %ld",
Bytes_AS_STRING(command), decode);
if (pq_execute(curs, Bytes_AS_STRING(command), conn->async,
if (pq_execute(curs, Bytes_AS_STRING(command), conn->async_,
1 /* no_result */, 1 /* no_begin */) >= 0) {
res = Py_None;
Py_INCREF(res);

View File

@ -41,7 +41,7 @@ class AsyncTests(ConnectingTestCase):
ConnectingTestCase.setUp(self)
self.sync_conn = self.conn
self.conn = self.connect(async=True)
self.conn = self.connect(client_handler=True)
self.wait(self.conn)
@ -57,8 +57,8 @@ class AsyncTests(ConnectingTestCase):
sync_cur = self.sync_conn.cursor()
del cur, sync_cur
self.assert_(self.conn.async)
self.assert_(not self.sync_conn.async)
self.assert_(self.conn.async_)
self.assert_(not self.sync_conn.async_)
# the async connection should be autocommit
self.assert_(self.conn.autocommit)
@ -70,17 +70,17 @@ class AsyncTests(ConnectingTestCase):
def test_async_subclass(self):
class MyConn(psycopg2.extensions.connection):
def __init__(self, dsn, async=0):
psycopg2.extensions.connection.__init__(self, dsn, async=async)
def __init__(self, dsn, client_handler=0):
psycopg2.extensions.connection.__init__(self, dsn, async_=client_handler)
conn = self.connect(connection_factory=MyConn, async=True)
conn = self.connect(connection_factory=MyConn, client_handler=True)
self.assert_(isinstance(conn, MyConn))
self.assert_(conn.async)
self.assert_(conn.async_)
conn.close()
def test_async_connection_error_message(self):
try:
cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', async=True)
cnn = psycopg2.connect('dbname=thisdatabasedoesntexist', client_handler=True)
self.wait(cnn)
except psycopg2.Error as e:
self.assertNotEqual(str(e), "asynchronous connection failed",
@ -103,7 +103,7 @@ class CancelTests(ConnectingTestCase):
@slow
@skip_before_postgres(8, 2)
def test_async_cancel(self):
async_conn = psycopg2.connect(dsn, async=True)
async_conn = psycopg2.connect(dsn, client_handler=True)
self.assertRaises(psycopg2.OperationalError, async_conn.cancel)
extras.wait_select(async_conn)
cur = async_conn.cursor()
@ -118,7 +118,7 @@ class CancelTests(ConnectingTestCase):
self.assertEqual(cur.fetchall(), [(1, )])
def test_async_connection_cancel(self):
async_conn = psycopg2.connect(dsn, async=True)
async_conn = psycopg2.connect(dsn, client_handler=True)
async_conn.close()
self.assertTrue(async_conn.closed)
@ -127,8 +127,8 @@ class ConnectTestCase(unittest.TestCase):
def setUp(self):
self.args = None
def connect_stub(dsn, connection_factory=None, async=False):
self.args = (dsn, connection_factory, async)
def connect_stub(dsn, connection_factory=None, client_handler=True):
self.args = (dsn, connection_factory, client_handler)
self._connect_orig = psycopg2._connect
psycopg2._connect = connect_stub
@ -139,12 +139,12 @@ class ConnectTestCase(unittest.TestCase):
def test_there_has_to_be_something(self):
self.assertRaises(TypeError, psycopg2.connect)
self.assertRaises(TypeError, psycopg2.connect,
connection_factory=lambda dsn, async=False: None)
connection_factory=lambda dsn, client_handler=False: None)
self.assertRaises(TypeError, psycopg2.connect,
async=True)
client_handler=True)
def test_factory(self):
def f(dsn, async=False):
def f(dsn, client_handler=False):
pass
psycopg2.connect(database='foo', host='baz', connection_factory=f)
@ -158,12 +158,12 @@ class ConnectTestCase(unittest.TestCase):
self.assertEqual(self.args[2], False)
def test_async(self):
psycopg2.connect(database='foo', host='baz', async=1)
psycopg2.connect(database='foo', host='baz', client_handler=1)
self.assertDsnEqual(self.args[0], 'dbname=foo host=baz')
self.assertEqual(self.args[1], None)
self.assert_(self.args[2])
psycopg2.connect("dbname=foo host=baz", async=True)
psycopg2.connect("dbname=foo host=baz", client_handler=True)
self.assertDsnEqual(self.args[0], 'dbname=foo host=baz')
self.assertEqual(self.args[1], None)
self.assert_(self.args[2])
@ -174,7 +174,7 @@ class AsyncReplicationTest(ReplicationTestCase):
@skip_repl_if_green
def test_async_replication(self):
conn = self.repl_connect(
connection_factory=LogicalReplicationConnection, async=1)
connection_factory=LogicalReplicationConnection, client_handler=1)
if conn is None:
return