
    R
h|                        d Z ddlmZ ddlZddlmZmZmZ ddlmZ	 ddlm
Z
 ddlmZmZ ej        Zej        Zd	ZdddZdddZddZ ej        d          Z ej        d          Zd dZd!dZdS )"z*
Functions to manipulate conninfo strings
    )annotationsN   )_conninfo_attempts_conninfo_attempts_async_conninfo_utils)errors)pq)ConnDict	ConnParam    conninfostrkwargsr   returnc                ^   | s|sdS |st          |            t          |           S d |                                D             }| r&t          |           }|                    |           |}d                    d |                                D                       } t          |            | S )a  
    Merge a string and keyword params into a single conninfo string.

    :param conninfo: A `connection string`__ as accepted by PostgreSQL.
    :param kwargs: Parameters overriding the ones specified in `!conninfo`.
    :return: A connection string valid for PostgreSQL, with the `!kwargs`
        parameters merged.

    Raise `~psycopg.ProgrammingError` if the input doesn't make a valid
    conninfo string.

    .. __: https://www.postgresql.org/docs/current/libpq-connect.html
           #LIBPQ-CONNSTRING
    r   c                    i | ]
\  }}|||S N .0kvs      [/var/www/html/01_SiteInternet/03_Maps/venv/lib/python3.11/site-packages/psycopg/conninfo.py
<dictcomp>z!make_conninfo.<locals>.<dictcomp>4   s    AAAv11=a===     c              3  ^   K   | ](\  }}| d t          t          |                     V  )dS )=N)_param_escaper   r   s      r   	<genexpr>z make_conninfo.<locals>.<genexpr>;   sB      TT6Aq166}SVV4466TTTTTTr   )_parse_conninfor   itemsconninfo_to_dictupdatejoin)r   r   tmps      r   make_conninfor(      s      F r  !!!8}} BAAAAF x((

6xxTTV\\^^TTTTTH HOr   r
   c                ~    t          |           }d |D             }|                                D ]\  }}||||<   |S )a  
    Convert the `!conninfo` string into a dictionary of parameters.

    :param conninfo: A `connection string`__ as accepted by PostgreSQL.
    :param kwargs: Parameters overriding the ones specified in `!conninfo`.
    :return: Dictionary with the parameters parsed from `!conninfo` and
        `!kwargs`.

    Raise `~psycopg.ProgrammingError` if `!conninfo` is not a a valid connection
    string.

    .. __: https://www.postgresql.org/docs/current/libpq-connect.html
           #LIBPQ-CONNSTRING
    c                ~    i | ]:}|j         	|j                                        |j                                         ;S r   )valkeyworddecode)r   opts     r   r   z$conninfo_to_dict.<locals>.<dictcomp>S   sB       36#'BUcgnn..BUBUBUr   )r"   r#   )r   r   optsrvr   r   s         r   r$   r$   C   s`     8$$D :>  B   1=BqEIr   list[pq.ConninfoOption]c                    	 t           j                            |                                           S # t          j        $ r'}t	          j        t          |                    dd}~ww xY w)z
    Verify that `!conninfo` is a valid connection string.

    Raise ProgrammingError if the string is not valid.

    Return the result of pq.Conninfo.parse() on success.
    N)r	   ConninfoparseencodeeOperationalErrorProgrammingErrorr   )r   exs     r   r"   r"   \   sb    4{  !2!2333 4 4 4 R))t34s   03 A)"A$$A)z([\\'])z\ssc                    | sdS t                               d|           } t                              |           rd| z   dz   } | S )z9
    Apply the escaping rule required by PQconnectdb
    z''z\\\1')	re_escapesubre_spacesearch)r:   s    r   r    r    n   sJ      tgq!!Aq !GcMHr   paramsintc                    t          j        | d          }|t          }	 t          t	          |                    }n&# t
          $ r t          j        d|          dw xY w|dk    rt          }n|dk     rd}|S )zG
    Return the timeout in seconds from the connection parameters.
    connect_timeoutNzbad value for connect_timeout: r      )r   	get_param_DEFAULT_CONNECT_TIMEOUTrB   float
ValueErrorr6   r8   )rA   valuetimeouts      r   timeout_from_conninforL   |   s     .7@QRRE}(XeEll## X X X !L5!L!LMMSWWX !|| +	1Ns	   = #A )r   )r   r   r   r   r   r   )r   r   r   r   r   r
   )r   r   r   r1   )r:   r   r   r   )rA   r
   r   rB   )__doc__
__future__r   rer   r   r   r   r   r6   r	   abcr
   r   conninfo_attemptsconninfo_attempts_asyncrG   r(   r$   r"   compiler=   r?   r    rL   r   r   r   <module>rT      s?    # " " " " " 				 K K K K K K K K K K             $ $ $ $ $ $ $ $ '8 2J 
  & & & & &R    24 4 4 4 BJz""	2:e        r   