o
    "4g                     @   s   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 d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)wraps   )SelfTypeVar   )abc)PGconn)connection_summary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__ Z/var/www/html/authentication-server/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 | 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   C   s   zPGconnDebug.__setattr__conninfoc                 C      | t tj|S N)r(   r
   connectr"   r.   r   r   r   r1   G      zPGconnDebug.connectc                 C   r/   r0   )r(   r
   connect_startr2   r   r   r   r4   K   r3   zPGconnDebug.connect_startc                 C   s   t tj|S r0   )r(   r
   ping)r   r.   r   r   r   r5   O   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|  | i |}t j}|d us@|d urFtd| |S )N=zPGconn.%s(%s)z, z	    <- %r)	appenditemsr)   r#   r6   joininspect	signaturereturn_annotation)r?   r@   reprsargkvrvrar>   r   r   
debugging_W   s   zdebugging.<locals>.debugging_)r   r   )r>   rO   r   rN   r   r(   T   s   r(   )r7   rE   loggingtypingr   r   	functoolsr   _compatr   r    r	   r
   miscr   r   	getLoggerr)   r   r(   r   r   r   r   <module>   s    
&