mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-07-01 10:13:05 +03:00
Add connection.get_host_addr()
This commit is contained in:
parent
a971c11d50
commit
555e9f4489
|
@ -910,6 +910,20 @@ The ``connection`` class
|
||||||
.. versionadded:: 2.7
|
.. versionadded:: 2.7
|
||||||
|
|
||||||
|
|
||||||
|
.. index::
|
||||||
|
pair: Connection; Parameters
|
||||||
|
|
||||||
|
.. method:: get_host_addr()
|
||||||
|
|
||||||
|
Get the server IP address of the active connection.
|
||||||
|
|
||||||
|
.. seealso:: libpq docs for `PQhostaddr()`__ for details.
|
||||||
|
|
||||||
|
.. __: https://www.postgresql.org/docs/current/libpq-status.html#LIBPQ-PQHOSTADDR
|
||||||
|
|
||||||
|
.. versionadded:: 2.9.10
|
||||||
|
|
||||||
|
|
||||||
.. testcode::
|
.. testcode::
|
||||||
:hide:
|
:hide:
|
||||||
|
|
||||||
|
|
|
@ -947,6 +947,16 @@ exit:
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define psyco_conn_get_host_addr_doc \
|
||||||
|
"get_host_addr() -- Get the server IP address of the active connection."
|
||||||
|
|
||||||
|
static PyObject *
|
||||||
|
psyco_conn_get_host_addr(connectionObject *self, PyObject *dummy)
|
||||||
|
{
|
||||||
|
EXC_IF_CONN_CLOSED(self);
|
||||||
|
|
||||||
|
return Text_FromUTF8(PQhostaddr(self->pgconn));
|
||||||
|
}
|
||||||
|
|
||||||
/* lobject method - allocate a new lobject */
|
/* lobject method - allocate a new lobject */
|
||||||
|
|
||||||
|
@ -1220,6 +1230,8 @@ static struct PyMethodDef connectionObject_methods[] = {
|
||||||
METH_VARARGS, psyco_conn_get_parameter_status_doc},
|
METH_VARARGS, psyco_conn_get_parameter_status_doc},
|
||||||
{"get_dsn_parameters", (PyCFunction)psyco_conn_get_dsn_parameters,
|
{"get_dsn_parameters", (PyCFunction)psyco_conn_get_dsn_parameters,
|
||||||
METH_NOARGS, psyco_conn_get_dsn_parameters_doc},
|
METH_NOARGS, psyco_conn_get_dsn_parameters_doc},
|
||||||
|
{"get_host_addr", (PyCFunction)psyco_conn_get_host_addr,
|
||||||
|
METH_NOARGS, psyco_conn_get_host_addr_doc},
|
||||||
{"get_backend_pid", (PyCFunction)psyco_conn_get_backend_pid,
|
{"get_backend_pid", (PyCFunction)psyco_conn_get_backend_pid,
|
||||||
METH_NOARGS, psyco_conn_get_backend_pid_doc},
|
METH_NOARGS, psyco_conn_get_backend_pid_doc},
|
||||||
{"lobject", (PyCFunction)psyco_conn_lobject,
|
{"lobject", (PyCFunction)psyco_conn_lobject,
|
||||||
|
|
|
@ -1826,6 +1826,9 @@ class TestConnectionInfo(ConnectingTestCase):
|
||||||
self.assertEqual(d['dbname'], dbname) # the only param we can check reliably
|
self.assertEqual(d['dbname'], dbname) # the only param we can check reliably
|
||||||
self.assert_('password' not in d, d)
|
self.assert_('password' not in d, d)
|
||||||
|
|
||||||
|
def test_host_addr(self):
|
||||||
|
self.assertEqual(self.conn.get_host_addr(), "")
|
||||||
|
|
||||||
def test_status(self):
|
def test_status(self):
|
||||||
self.assertEqual(self.conn.info.status, 0)
|
self.assertEqual(self.conn.info.status, 0)
|
||||||
self.assertEqual(self.bconn.info.status, 1)
|
self.assertEqual(self.bconn.info.status, 1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user