
    iw                        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y)z*
Functions to manipulate conninfo strings
    )annotationsN   )_conninfo_attempts_conninfo_attempts_async_conninfo_utils)errors)pq)ConnDict	ConnParam   c                :   | s|sy|st        |        t        |       S |j                         D ci c]  \  }}|	|| }}}| rt        |       }|j	                  |       |}dj                  d |j                         D              } t        |        | S c c}}w )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
      c              3  T   K   | ]   \  }}| d t        t        |              " yw)=N)_param_escapestr).0kvs      p/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/venv/lib/python3.12/site-packages/psycopg/conninfo.py	<genexpr>z make_conninfo.<locals>.<genexpr>;   s)     T6Aq1#Q}SV456Ts   &()_parse_conninfor   itemsconninfo_to_dictupdatejoin)conninfokwargsr   r   tmps        r   make_conninfor!      s     F !8} "(Av11=adAFAx(

6xxTV\\^TTH HO Bs
   
BBc                    t        |       }|D ci c]B  }|j                  |j                  j                         |j                  j                         D }}|j	                         D ]  \  }}|	|||<    |S c c}w )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
    )r   valkeyworddecoder   )r   r   optsoptrvr   r   s          r   r   r   C   s     8$D:>36#''BUcggnn..B   1=BqE Is
   A;5A;c                    	 t         j                  j                  | 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   \   sP    4{{  !233 4  R)t34s   ,/ A&A!!A&z([\\'])z\sc                r    | syt         j                  t        j                  d|       x}       rd| z   dz   } | S )z9
    Apply the escaping rule required by PQconnectdb
    z''z\\\1')re_spacesearch	re_escapesub)ss    r   r   r   n   s8     IMM'155q6!GcMH    c                    t        j                  | d      }|t        }	 t        t	        |            }|dk  rt        }|S |dk  rd}|S # t
        $ r t        j                  d|      dw xY w)zG
    Return the timeout in seconds from the connection parameters.
    connect_timeoutNzbad value for connect_timeout: r      )r   	get_param_DEFAULT_CONNECT_TIMEOUTintfloat
ValueErrorr-   r/   )paramsvaluetimeouts      r   timeout_from_conninforD   {   s     .77@QRE}(XeEl# !| +
 N	 
1N  X  #B5)!LMSWWXs   A
 
#A-)r   )r   r   r   r   returnr   )r   r   r   r   rE   r
   )r   r   rE   zlist[pq.ConninfoOption])r7   r   rE   r   )rA   r
   rE   r>   )__doc__
__future__r   rer   r   r   r   r   r-   r	   abcr
   r   conninfo_attemptsconninfo_attempts_asyncr=   r!   r   r   compiler5   r3   r   rD    r8   r   <module>rN      s    # 	 K K   $ '88 2JJ 
  &R24 BJJz"	2::e
r8   