o
    DDi                     @   s   d Z ddlZddlZddlmZ ddl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 dZedZG dd dZdedefddZdS )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)wraps)Callable   )PGconnabc)connection_summary   )SelfTypeVarFunc.)boundzpsycopg.debugc                       s   e Zd ZU dZejed< dejf fddZdefddZ	d	ede
fd
dZd	ede
ddfddZededefddZededefddZededefddZ  ZS )PGconnDebugz,Wrapper for a PQconn logging all its access._pgconnpgconnc                    s   t  d| d S )Nr   )super__setattr__)selfr   	__class__ J/var/www/Datamplify/venv/lib/python3.10/site-packages/psycopg/pq/_debug.py__init__3   s   zPGconnDebug.__init__returnc                 C   s>   | 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infor   r   r   __repr__6   s   
zPGconnDebug.__repr__attrc                 C   s.   t t| j| }rt|S td|| |S )NzPGconn.%s -> %s)callablegetattrr   	debuggingloggerr#   r   r%   valuer   r   r   __getattr__;   s   zPGconnDebug.__getattr__r+   Nc                 C   s    t | j|| td|| d S )NzPGconn.%s <- %s)setattrr   r)   r#   r*   r   r   r   r   B   s   zPGconnDebug.__setattr__conninfoc                 C      | t tj|S N)r(   r   connectr"   r.   r   r   r   r1   F      zPGconnDebug.connectc                 C   r/   r0   )r(   r   connect_startr2   r   r   r   r4   J   r3   zPGconnDebug.connect_startc                 C   s   t tj|S r0   )r(   r   ping)r   r.   r   r   r   r5   N   s   zPGconnDebug.ping)__name__r   r    __doc__r   r   __annotations__r   strr$   r   r,   r   classmethodbytesr
   r1   r4   intr5   __classcell__r   r   r   r   r   .   s   
 
r   fr   c                    s&   t  dtdtdtf fdd}|S )zGWrap a function in order to log its arguments and return value on call.argskwargsr   c            	   
      s   g }| D ]}| | q| D ]\}}| | d| qtd jd| z	 | i |}W n tyG } ztd|  d }~ww t j	}|d usV|d ur\td| |S )N=zPGconn.%s(%s)z, z	    <- %r)
appenditemsr)   r#   r6   join	Exceptioninspect	signaturereturn_annotation)	r?   r@   reprsargkvrvexrar>   r   r   
debugging_V   s"   zdebugging.<locals>.debugging_)r   r   )r>   rQ   r   rP   r   r(   S   s   r(   )r7   rF   loggingtypingr   	functoolsr   collections.abcr    r   r   miscr   _compatr
   r   r   	getLoggerr)   r   r(   r   r   r   r   <module>   s    
%