.. _dnspython: https://dnspython.readthedocs.io/
-.. autofunction:: resolve_srv
+.. function:: resolve_srv
+
+ Apply SRV DNS lookup as defined in :RFC:`2782`.
+
+ :param params: The input parameters, for instance as returned by
+ `~psycopg.conninfo.conninfo_to_dict()`.
+ :return: An updated list of connection parameters.
+
+ For every host defined in the ``params["host"]`` list (comma-separated),
+ perform SRV lookup if the host is in the form ``_Service._Proto.Target``.
+ If lookup is successful, return a params dict with hosts and ports replaced
+ with the looked-up entries.
+
+ Raise `~psycopg.OperationalError` if no lookup is successful and no host
+ (looked up or unchanged) could be returned.
+
+ In addition to the rules defined by RFC 2782 about the host name pattern,
+ perform SRV lookup also if the the port is the string ``SRV`` (case
+ insensitive).
.. warning::
This is an experimental functionality.
cnn = SrvCognizantConnection.connect("host=_postgres._tcp.db.psycopg.org")
-.. autofunction:: resolve_srv_async
+.. function:: resolve_srv_async
+
+ Async equivalent of `resolve_srv()`.
.. automethod:: psycopg.Connection._get_connection_params
This is an experimental method.
-.. autofunction:: resolve_hostaddr_async
+.. function:: resolve_hostaddr_async
+
+ Perform async DNS lookup of the hosts and return a new params dict.
+
+ .. deprecated:: 3.1
+ The use of this function is not necessary anymore, because
+ `psycopg.AsyncConnection.connect()` performs non-blocking name
+ resolution automatically.
+
+ :param params: The input parameters, for instance as returned by
+ `~psycopg.conninfo.conninfo_to_dict()`.
+
+ If a ``host`` param is present but not ``hostname``, resolve the host
+ addresses dynamically.
+
+ The function may change the input ``host``, ``hostname``, ``port`` to allow
+ connecting without further DNS lookups, eventually removing hosts that are
+ not resolved, keeping the lists of hosts and ports consistent.
+
+ Raise `~psycopg.OperationalError` if connection is not possible (e.g. no
+ host resolve, inconsistent lists length).
+
+ See `the PostgreSQL docs`__ for explanation of how these params are used,
+ and how they support multiple entries.
+
+ .. __: https://www.postgresql.org/docs/current/libpq-connect.html
+ #LIBPQ-PARAMKEYWORDS
+
+ .. warning::
+ Before psycopg 3.1, this function doesn't handle the ``/etc/hosts`` file.
.. note::
Starting from psycopg 3.1, a similar operation is performed
The use of this function is not necessary anymore, because
`psycopg.AsyncConnection.connect()` performs non-blocking name
resolution automatically.
-
- :param params: The input parameters, for instance as returned by
- `~psycopg.conninfo.conninfo_to_dict()`.
-
- If a ``host`` param is present but not ``hostname``, resolve the host
- addresses dynamically.
-
- The function may change the input ``host``, ``hostname``, ``port`` to allow
- connecting without further DNS lookups, eventually removing hosts that are
- not resolved, keeping the lists of hosts and ports consistent.
-
- Raise `~psycopg.OperationalError` if connection is not possible (e.g. no
- host resolve, inconsistent lists length).
-
- See `the PostgreSQL docs`__ for explanation of how these params are used,
- and how they support multiple entries.
-
- .. __: https://www.postgresql.org/docs/current/libpq-connect.html
- #LIBPQ-PARAMKEYWORDS
-
- .. warning::
- Before psycopg 3.1, this function doesn't handle the ``/etc/hosts`` file.
"""
warnings.warn(
"from psycopg 3.1, resolve_hostaddr_async() is not needed anymore",
def resolve_srv(params: Dict[str, Any]) -> Dict[str, Any]:
- """Apply SRV DNS lookup as defined in :RFC:`2782`.
-
- :param params: The input parameters, for instance as returned by
- `~psycopg.conninfo.conninfo_to_dict()`.
- :return: An updated list of connection parameters.
-
- For every host defined in the ``params["host"]`` list (comma-separated),
- perform SRV lookup if the host is in the form ``_Service._Proto.Target``.
- If lookup is successful, return a params dict with hosts and ports replaced
- with the looked-up entries.
-
- Raise `~psycopg.OperationalError` if no lookup is successful and no host
- (looked up or unchanged) could be returned.
-
- In addition to the rules defined by RFC 2782 about the host name pattern,
- perform SRV lookup also if the the port is the string ``SRV`` (case
- insensitive).
- """
+ """Apply SRV DNS lookup as defined in :RFC:`2782`."""
return Rfc2782Resolver().resolve(params)