o
    6	f                     @   s   U d Z ddlmZmZ ddlmZmZmZ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r9dd	lmZ ejZejZed
ZG dd dejeZG dd dejeZed ed< ercejZn	ddl	mZ ejZG dd deZG dd deZdS )z)
Entry point into the adaptation system.
    )ABCabstractmethod)AnyOptionalTypeTYPE_CHECKING   )pqabc)_adapters_map)PyFormat)_psycopg)BaseConnection\c                   @   s   e Zd ZU dZdZeed< 	 ejj	Z
ejed< 	 ddedeej fdd	Zd
efddZeded
efddZded
efddZdeded
ejfddZdeded
d fddZdS )DumperzP
    Convert Python object of the type `!cls` to PostgreSQL representation.
    r   oidformatNclscontextc                 C       || _ |r|j| _d S d | _d S N)r   
connectionselfr   r    r   F/home/ertert/spirit/venv/lib/python3.10/site-packages/psycopg/adapt.py__init__#   
   zDumper.__init__returnc              	   C   s2   dt | j dt | j d| j dt| dd	S )N<.z (oid=z) at 0xx>)type
__module____qualname__r   id)r   r   r   r   __repr__)   s   zDumper.__repr__objc                 C   s   d S r   r   )r   r(   r   r   r   dump/   s   zDumper.dumpc                 C   sx   |  |}| jrt| jj}||S t }||}t|vr'd| d S d| d }|ddkr:|dd}|S )z
        By default return the `dump()` value quoted and sanitised, so
        that the result can be used to build a SQL string. This works well
        for most types and you won't likely have to implement this method in a
        subclass.
           's    E'   \s   \\)	r)   r   r	   Escapingpgconnescape_literalescape_stringORD_BSreplace)r   r(   valueescoutrvr   r   r   quote2   s   


zDumper.quotec                 C   s   | j S )a  
        Implementation of the `~psycopg.abc.Dumper.get_key()` member of the
        `~psycopg.abc.Dumper` protocol. Look at its definition for details.

        This implementation returns the `!cls` passed in the constructor.
        Subclasses needing to specialise the PostgreSQL type according to the
        *value* of the object dumped (not only according to to its type)
        should override this class.

        )r   r   r(   r   r   r   r   get_key]   s   zDumper.get_keyc                 C   s   | S )a/  
        Implementation of the `~psycopg.abc.Dumper.upgrade()` member of the
        `~psycopg.abc.Dumper` protocol. Look at its definition for details.

        This implementation just returns `!self`. If a subclass implements
        `get_key()` it should probably override `!upgrade()` too.
        r   r7   r   r   r   upgradej   s   zDumper.upgrader   )__name__r$   r%   __doc__r   int__annotations__r	   FormatTEXTr   r#   r   r
   AdaptContextr   strr'   r   r   Bufferr)   r6   r   	DumperKeyr8   r9   r   r   r   r   r      s   
 +r   c                   @   sV   e Zd ZU dZejjZejed< 	 dde	de
ej fddZeded	efd
dZdS )LoaderzK
    Convert PostgreSQL values with type OID `!oid` to Python objects.
    r   Nr   r   c                 C   r   r   )r   r   r   r   r   r   r   r   r   }   r   zLoader.__init__datar   c                 C   s   dS )z.Convert a PostgreSQL value to a Python object.Nr   )r   rF   r   r   r   load   s   zLoader.loadr   )r:   r$   r%   r;   r	   r>   r?   r   r=   r<   r   r
   r@   r   r   rB   r   rG   r   r   r   r   rD   u   s   
 rD   zabc.TransformerTransformer)
_transformc                       2   e Zd ZdZddedeej f fddZ  Z	S )RecursiveDumperz:Dumper with a transformer to help dumping recursive types.Nr   r   c                       t  || t|| _d S r   superr   rH   from_context_txr   	__class__r   r   r         zRecursiveDumper.__init__r   )
r:   r$   r%   r;   r#   r   r
   r@   r   __classcell__r   r   rQ   r   rK          &rK   c                       rJ   )RecursiveLoaderz:Loader with a transformer to help loading recursive types.Nr   r   c                    rL   r   rM   rE   rQ   r   r   r      rS   zRecursiveLoader.__init__r   )
r:   r$   r%   r;   r<   r   r
   r@   r   rT   r   r   rQ   r   rV      rU   rV   N)r;   r
   r   r   typingr   r   r   r    r	   r   _enumsr   _cmoduler   r   r   AdaptersMaprB   ordr0   r   rD   r=   rH   rI   rK   rV   r   r   r   r   <module>   s*    ]