From: Daniele Varrazzo Date: Tue, 26 Aug 2025 02:16:25 +0000 (+0200) Subject: feat: expose used_gssapi attribute to the public API X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0950694522e73852c07ab7e4d747e8a9ab0cb045;p=thirdparty%2Fpsycopg.git feat: expose used_gssapi attribute to the public API Already implemented in 3.1.10, but kept as internal implementation. Fix #1138 --- diff --git a/docs/api/objects.rst b/docs/api/objects.rst index 5f6e2902e..fb9714e3b 100644 --- a/docs/api/objects.rst +++ b/docs/api/objects.rst @@ -150,6 +150,10 @@ Libpq capabilities information .. automethod:: has_hostaddr .. automethod:: has_pipeline .. automethod:: has_set_trace_flags + .. automethod:: has_used_gssapi + + .. versionadded:: 3.3 + .. automethod:: has_cancel_safe .. note:: diff --git a/docs/api/pq.rst b/docs/api/pq.rst index cb500eff7..6b74a33fe 100644 --- a/docs/api/pq.rst +++ b/docs/api/pq.rst @@ -91,6 +91,9 @@ Objects wrapping libpq structures and functions .. automethod:: get_cancel .. autoattribute:: needs_password .. autoattribute:: used_password + .. autoattribute:: used_gssapi + + .. versionadded:: 3.3 .. automethod:: encrypt_password diff --git a/docs/news.rst b/docs/news.rst index 4b7584e84..973f62307 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -13,13 +13,23 @@ Future releases Psycopg 3.3.0 (unreleased) ^^^^^^^^^^^^^^^^^^^^^^^^^^ +.. rubric:: New top-level features + - Cursors are now iterators, not only iterables. This means you can call ``next(cur)`` to fetch the next row (:ticket:`#1064`). -- Drop support for Python 3.8 (:ticket:`#976`) and 3.9 (:ticket:`#1056`). - Add `Cursor.results()` to iterate over the result sets of the queries executed though `~Cursor.executemany()` or `~Cursor.execute()` (:ticket:`#1080`). +.. rubric:: New libpq wrapper features + +- Add `pq.PGconn.used_gssapi` attribute and `Capabilities.has_used_gssapi()` + function (:ticket:`#1138`). + +.. rubric:: Other changes + +- Drop support for Python 3.8 (:ticket:`#976`) and 3.9 (:ticket:`#1056`). + Psycopg 3.2.10 (unreleased) ^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/psycopg/psycopg/_capabilities.py b/psycopg/psycopg/_capabilities.py index b5427cb4a..49aef12f8 100644 --- a/psycopg/psycopg/_capabilities.py +++ b/psycopg/psycopg/_capabilities.py @@ -46,6 +46,13 @@ class Capabilities: """ return self._has_feature("PGconn.set_trace_flags()", 140000, check=check) + def has_used_gssapi(self, check: bool = False) -> bool: + """Check if the `pq.PGconn.used_gssapi` attribute is implemented. + + The feature requires libpq 16.0 or greater. + """ + return self._has_feature("PGconn.used_gssapi", 160000, check=check) + def has_cancel_safe(self, check: bool = False) -> bool: """Check if the `Connection.cancel_safe()` method is implemented. diff --git a/psycopg/psycopg/pq/pq_ctypes.py b/psycopg/psycopg/pq/pq_ctypes.py index 059f0ae45..686df557e 100644 --- a/psycopg/psycopg/pq/pq_ctypes.py +++ b/psycopg/psycopg/pq/pq_ctypes.py @@ -270,6 +270,10 @@ class PGconn: @property def used_gssapi(self) -> bool: + """True if the connection authentication method used GSSAPI. + + See :pq:`PQconnectionUsedGSSAPI` for details. + """ return bool(impl.PQconnectionUsedGSSAPI(self._pgconn_ptr)) @property diff --git a/tests/test_capabilities.py b/tests/test_capabilities.py index 674a083c2..f58471a15 100644 --- a/tests/test_capabilities.py +++ b/tests/test_capabilities.py @@ -15,6 +15,7 @@ caps = [ ("has_hostaddr", "Connection.info.hostaddr", 12), ("has_pipeline", "Connection.pipeline()", 14), ("has_set_trace_flags", "PGconn.set_trace_flags()", 14), + ("has_used_gssapi", "PGconn.used_gssapi", 16), ("has_cancel_safe", "Connection.cancel_safe()", 17), ("has_stream_chunked", "Cursor.stream() with 'size' parameter greater than 1", 17), ("has_send_close_prepared", "PGconn.send_close_prepared()", 17),