mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-11 03:26:37 +03:00
Merge pull request #818 from jdufresne/bool-simplify
Simplify PyBool usage with Python convenience macros/functions
This commit is contained in:
commit
b233778acd
|
@ -616,10 +616,7 @@ psyco_conn_set_session(connectionObject *self, PyObject *args, PyObject *kwargs)
|
|||
static PyObject *
|
||||
psyco_conn_autocommit_get(connectionObject *self)
|
||||
{
|
||||
PyObject *ret;
|
||||
ret = self->autocommit ? Py_True : Py_False;
|
||||
Py_INCREF(ret);
|
||||
return ret;
|
||||
return PyBool_FromLong(self->autocommit);
|
||||
}
|
||||
|
||||
BORROWED static PyObject *
|
||||
|
@ -1100,25 +1097,21 @@ psyco_conn_isexecuting(connectionObject *self)
|
|||
{
|
||||
/* synchronous connections will always return False */
|
||||
if (self->async == 0) {
|
||||
Py_INCREF(Py_False);
|
||||
return Py_False;
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
/* check if the connection is still being built */
|
||||
if (self->status != CONN_STATUS_READY) {
|
||||
Py_INCREF(Py_True);
|
||||
return Py_True;
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
/* check if there is a query being executed */
|
||||
if (self->async_cursor != NULL) {
|
||||
Py_INCREF(Py_True);
|
||||
return Py_True;
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
|
||||
/* otherwise it's not executing */
|
||||
Py_INCREF(Py_False);
|
||||
return Py_False;
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -352,11 +352,7 @@ static const char needs_password_doc[] =
|
|||
static PyObject *
|
||||
needs_password_get(connInfoObject *self)
|
||||
{
|
||||
PyObject *rv;
|
||||
|
||||
rv = PQconnectionNeedsPassword(self->conn->pgconn) ? Py_True : Py_False;
|
||||
Py_INCREF(rv);
|
||||
return rv;
|
||||
return PyBool_FromLong(PQconnectionNeedsPassword(self->conn->pgconn));
|
||||
}
|
||||
|
||||
|
||||
|
@ -372,11 +368,7 @@ static const char used_password_doc[] =
|
|||
static PyObject *
|
||||
used_password_get(connInfoObject *self)
|
||||
{
|
||||
PyObject *rv;
|
||||
|
||||
rv = PQconnectionUsedPassword(self->conn->pgconn) ? Py_True : Py_False;
|
||||
Py_INCREF(rv);
|
||||
return rv;
|
||||
return PyBool_FromLong(PQconnectionUsedPassword(self->conn->pgconn));
|
||||
}
|
||||
|
||||
|
||||
|
@ -398,8 +390,7 @@ ssl_in_use_get(connInfoObject *self)
|
|||
PyObject *rv = NULL;
|
||||
|
||||
#if PG_VERSION_NUM >= 90500
|
||||
rv = PQsslInUse(self->conn->pgconn) ? Py_True : Py_False;
|
||||
Py_INCREF(rv);
|
||||
rv = PyBool_FromLong(PQsslInUse(self->conn->pgconn));
|
||||
#else
|
||||
PyErr_SetString(NotSupportedError,
|
||||
"'ssl_in_use' not available in libpq < 9.5");
|
||||
|
|
|
@ -1667,12 +1667,7 @@ exit:
|
|||
static PyObject *
|
||||
psyco_curs_get_closed(cursorObject *self, void *closure)
|
||||
{
|
||||
PyObject *closed;
|
||||
|
||||
closed = (self->closed || (self->conn && self->conn->closed)) ?
|
||||
Py_True : Py_False;
|
||||
Py_INCREF(closed);
|
||||
return closed;
|
||||
return PyBool_FromLong(self->closed || (self->conn && self->conn->closed));
|
||||
}
|
||||
|
||||
/* extension: withhold - get or set "WITH HOLD" for named cursors */
|
||||
|
@ -1683,10 +1678,7 @@ psyco_curs_get_closed(cursorObject *self, void *closure)
|
|||
static PyObject *
|
||||
psyco_curs_withhold_get(cursorObject *self)
|
||||
{
|
||||
PyObject *ret;
|
||||
ret = self->withhold ? Py_True : Py_False;
|
||||
Py_INCREF(ret);
|
||||
return ret;
|
||||
return PyBool_FromLong(self->withhold);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -257,11 +257,7 @@ psyco_lobj_export(lobjectObject *self, PyObject *args)
|
|||
static PyObject *
|
||||
psyco_lobj_get_closed(lobjectObject *self, void *closure)
|
||||
{
|
||||
PyObject *closed;
|
||||
|
||||
closed = lobject_is_closed(self) ? Py_True : Py_False;
|
||||
Py_INCREF(closed);
|
||||
return closed;
|
||||
return PyBool_FromLong(lobject_is_closed(self));
|
||||
}
|
||||
|
||||
#define psyco_lobj_truncate_doc \
|
||||
|
|
|
@ -395,18 +395,11 @@ typecast_cmp(PyObject *obj1, PyObject* obj2)
|
|||
static PyObject*
|
||||
typecast_richcompare(PyObject *obj1, PyObject* obj2, int opid)
|
||||
{
|
||||
PyObject *result = NULL;
|
||||
int res = typecast_cmp(obj1, obj2);
|
||||
|
||||
if (PyErr_Occurred()) return NULL;
|
||||
|
||||
if ((opid == Py_EQ && res == 0) || (opid != Py_EQ && res != 0))
|
||||
result = Py_True;
|
||||
else
|
||||
result = Py_False;
|
||||
|
||||
Py_INCREF(result);
|
||||
return result;
|
||||
return PyBool_FromLong((opid == Py_EQ && res == 0) || (opid != Py_EQ && res != 0));
|
||||
}
|
||||
|
||||
static struct PyMemberDef typecastObject_members[] = {
|
||||
|
|
Loading…
Reference in New Issue
Block a user