o
    6	f                     @   s   d Z ddlZddlZddlmZmZmZmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ er6dd
l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CallableTypeVarTYPE_CHECKING)wraps   )Self   )PGconn)connection_summary)abcFunc.)boundzpsycopg.debugc                       s   e Zd ZU dZded< d 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.
abc.PGconn_pgconnpgconnc                    s   t  d| d S )Nr   )super__setattr__)selfr   	__class__ J/home/ertert/spirit/venv/lib/python3.10/site-packages/psycopg/pq/_debug.py__init__5   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__8   s   
zPGconnDebug.__repr__attrc                 C   s.   t | j|}t|rt|S td|| |S )NzPGconn.%s -> %s)getattrr   callable	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   E   s   zPGconnDebug.__setattr__conninfoc                 C      | t tj|S N)r*   r
   connectr$   r0   r   r   r   r3   I      zPGconnDebug.connectc                 C   r1   r2   )r*   r
   connect_startr4   r   r   r   r6   M   r5   zPGconnDebug.connect_startc                 C   s   t tj|S r2   )r*   r
   ping)r   r0   r   r   r   r7   Q   s   zPGconnDebug.ping)r   r   )__name__r!   r"   __doc____annotations__r   strr&   r   r.   r   classmethodbytesr   r3   r6   intr7   __classcell__r   r   r   r   r   0   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|  | i |}t j}|d us@|d urFtd| |S )N=zPGconn.%s(%s)z, z	    <- %r)	appenditemsr+   r%   r8   joininspect	signaturereturn_annotation)rA   rB   reprsargkvrvrar@   r   r   
debugging_Y   s   zdebugging.<locals>.debugging_)r   r   )r@   rQ   r   rP   r   r*   V   s   r*   )r9   rG   loggingtypingr   r   r   r   	functoolsr   _compatr    r
   miscr   r   r   	getLoggerr+   r   r*   r   r   r   r   <module>   s    
&