
    i                         d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZ dd	lmZmZ  ed
edef         Z ej"                  d      Z G d d      ZdedefdZy)a  
libpq debugging tools

These functionalities are exposed here for convenience, but are not part of
the public interface and are subject to change at any moment.

Suggested usage::

    import logging
    import psycopg
    from psycopg import pq
    from psycopg.pq._debug import PGconnDebug

    logging.basicConfig(level=logging.INFO, format="%(message)s")
    logger = logging.getLogger("psycopg.debug")
    logger.setLevel(logging.INFO)

    assert pq.__impl__ == "python"
    pq.PGconn = PGconnDebug

    with psycopg.connect("") as conn:
        conn.pgconn.trace(2)
        conn.pgconn.set_trace_flags(
            pq.Trace.SUPPRESS_TIMESTAMPS | pq.Trace.REGRESS_MODE)
        ...

    N)AnyCallable)wraps   )PGconnabc)connection_summary   )SelfTypeVarFunc.)boundzpsycopg.debugc                        e Zd ZU dZej
                  ed<   dej
                  f fdZdefdZ	dede
fdZded	e
dd
fdZededefd       Zededefd       Zededefd       Z xZS )PGconnDebugz,Wrapper for a PQconn logging all its access._pgconnpgconnc                 &    t         |   d|       y )Nr   )super__setattr__)selfr   	__class__s     q/var/www/html/hwPaymentPortal-be-dev/hw-payment-portal-api/venv/lib/python3.12/site-packages/psycopg/pq/_debug.py__init__zPGconnDebug.__init__2   s    Iv.    returnc                     | j                   j                   d| j                   j                   }t        | j                        }d| d| dt        |       ddS )N.< z at 0xx>)r   
__module____qualname__r	   r   id)r   clsinfos      r   __repr__zPGconnDebug.__repr__5   sW    **+1T^^-H-H,IJ!$,,/3%qfRXaL22r   attrc                     t        t        | j                  |      x}      rt        |      S t        j                  d||       |S )NzPGconn.%s -> %s)callablegetattrr   	debuggingloggerr&   r   r(   values      r   __getattr__zPGconnDebug.__getattr__:   s;    gdllD99U;U##KK)47Lr   r/   Nc                 `    t        | j                  ||       t        j                  d||       y )NzPGconn.%s <- %s)setattrr   r-   r&   r.   s      r   r   zPGconnDebug.__setattr__A   s#    dE*%tU3r   conninfoc                 L     |  t        t        j                        |            S N)r,   r   connectr%   r3   s     r   r6   zPGconnDebug.connectE   s    ,9V^^,X677r   c                 L     |  t        t        j                        |            S r5   )r,   r   connect_startr7   s     r   r9   zPGconnDebug.connect_startI   s     29V1128<==r   c                 @     t        t        j                        |      S r5   )r,   r   ping)r   r3   s     r   r;   zPGconnDebug.pingM   s    %y%h//r   )__name__r"   r#   __doc__r   r   __annotations__r   strr'   r   r0   r   classmethodbytesr   r6   r9   intr;   __classcell__)r   s   @r   r   r   -   s    6ZZ/szz /3# 3
  4 4C 4D 4 8u 8 8 8 >U >t > > 0U 0s 0 0r   r   fr   c                 T     t               dt        dt        dt        f fd       }|S )zGWrap a function in order to log its arguments and return value on call.argskwargsr   c                     g }| D ]  }|j                  |        |j                         D ]  \  }}|j                  | d|        t        j                  d	j                  dj                  |             	  	| i |}t        j                  	      j                  }||t        j                  d|       |S # t        $ r}t        j                  d|        d }~ww xY w)N=zPGconn.%s(%s)z, z	    <- %r)
appenditemsr-   r&   r<   joininspect	signaturereturn_annotation	Exception)
rF   rG   reprsargkvrvraexrD   s
            r   
debugging_zdebugging.<locals>.debugging_U   s     	%CLLC7$	%LLN 	'DAqLLA3au&	' 	OQZZ51AB	D#F#B ""1%77B~K,I  	KKR(	s   <B? ?	C$CC$)r   r   )rD   rX   s   ` r   r,   r,   R   s8     1X#    * r   )r=   rM   loggingtypingr   r   	functoolsr    r   r   miscr	   _compatr   r   r   	getLoggerr-   r   r,    r   r   <module>ra      sf   <       $ #vXc3h/0			?	+"0 "0J $ r   