o
    6	f                     @   s(  U d Z ddlmZmZmZmZ ddlmZmZ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 dd	lmZmZ eridd
lm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" e#dZ$e#e%d< ee&e'e(f Z)ee%d< eee&ddf Z*ee%d< eee ee+ef f Z,ee%d< e
dddZ-eg df Z.ee%d< ee#e	d f Z/ee%d< e
dZ0ee	e1df de0f Z2ee%d < 	 edde0f Z3ee%d!< 	 G d"d# d#eZ4eege)f Z5ee%d$< ee)gef Z6ee%d%< G d&d' d'eZ7G d(d) d)eZ8G d*d+ d+eZ9G d,d- d-eZ:dS ).zN
Protocol objects representing different implementations of the same classes.
    )AnyCallable	GeneratorMapping)ListOptionalSequenceTupleTypeVarUnion)TYPE_CHECKING)	TypeAlias   )pq)PyFormat)ProtocolLiteralString)sql)RowRowMaker)PGresult)WaitReady)BaseConnection)AdaptersMapNNoneTypeBufferzsql.SQLzsql.ComposedQueryParamsConnectionTypeBaseConnection[Any])boundPipelineCommand)	DumperKey.r#   RVr   r   	PQGenConnPQGenc                	   @   s6   e Zd ZdZ	d	dee dedee defddZ	dS )
WaitFunczU
    Wait on the connection which generated `PQgen` and return its final result.
    Ngenfilenotimeoutreturnc                 C      d S N )selfr(   r)   r*   r.   r.   D/home/ertert/spirit/venv/lib/python3.10/site-packages/psycopg/abc.py__call__7      zWaitFunc.__call__r-   )
__name__
__module____qualname____doc__r&   r$   intr   floatr1   r.   r.   r.   r0   r'   2   s    r'   DumpFuncLoadFuncc                   @   s4   e Zd ZdZed
ddZeded fddZd	S )AdaptContextaO  
    A context describing how types are adapted.

    Example of `~AdaptContext` are `~psycopg.Connection`, `~psycopg.Cursor`,
    `~psycopg.adapt.Transformer`, `~psycopg.adapt.AdaptersMap`.

    Note that this is a `~typing.Protocol`, so objects implementing
    `!AdaptContext` don't need to explicitly inherit from this class.

    r+   r   c                 C      dS )z1The adapters configuration that this object uses.Nr.   r/   r.   r.   r0   adaptersN   s   zAdaptContext.adaptersr    c                 C   r<   )zThe connection used by this object, if available.

        :rtype: `~psycopg.Connection` or `~psycopg.AsyncConnection` or `!None`
        Nr.   r=   r.   r.   r0   
connectionS      zAdaptContext.connectionNr+   r   )r3   r4   r5   r6   propertyr>   r   r?   r.   r.   r.   r0   r;   B   s    r;   c                   @   s   e Zd ZU dZejed< 	 eed< 	 ddede	e
 fddZd	ed
efddZd	ed
efddZd	eded
efddZd	eded
d fddZdS )DumperzM
    Convert Python objects of type `!cls` to PostgreSQL representation.
    formatoidNclscontextc                 C   r,   r-   r.   )r/   rF   rG   r.   r.   r0   __init__l       zDumper.__init__objr+   c                 C   r<   )zlConvert the object `!obj` to PostgreSQL representation.

        :param obj: the object to convert.
        Nr.   r/   rJ   r.   r.   r0   dumpn      zDumper.dumpc                 C   r<   )ziConvert the object `!obj` to escaped representation.

        :param obj: the object to convert.
        Nr.   rK   r.   r.   r0   quoteu   rM   zDumper.quotec                 C   r<   )a  Return an alternative key to upgrade the dumper to represent `!obj`.

        :param obj: The object to convert
        :param format: The format to convert to

        Normally the type of the object is all it takes to define how to dump
        the object to the database. For instance, a Python `~datetime.date` can
        be simply converted into a PostgreSQL :sql:`date`.

        In a few cases, just the type is not enough. For example:

        - A Python `~datetime.datetime` could be represented as a
          :sql:`timestamptz` or a :sql:`timestamp`, according to whether it
          specifies a `!tzinfo` or not.

        - A Python int could be stored as several Postgres types: int2, int4,
          int8, numeric. If a type too small is used, it may result in an
          overflow. If a type too large is used, PostgreSQL may not want to
          cast it to a smaller type.

        - Python lists should be dumped according to the type they contain to
          convert them to e.g. array of strings, array of ints (and which
          size of int?...)

        In these cases, a dumper can implement `!get_key()` and return a new
        class, or sequence of classes, that can be used to identify the same
        dumper again. If the mechanism is not needed, the method should return
        the same `!cls` object passed in the constructor.

        If a dumper implements `get_key()` it should also implement
        `upgrade()`.

        Nr.   r/   rJ   rD   r.   r.   r0   get_key|   s   "zDumper.get_keyc                 C   r<   )a  Return a new dumper to manage `!obj`.

        :param obj: The object to convert
        :param format: The format to convert to

        Once `Transformer.get_dumper()` has been notified by `get_key()` that
        this Dumper class cannot handle `!obj` itself, it will invoke
        `!upgrade()`, which should return a new `Dumper` instance, which will
        be reused for every objects for which `!get_key()` returns the same
        result.
        Nr.   rO   r.   r.   r0   upgrade   s   zDumper.upgrader-   )r3   r4   r5   r6   r   Format__annotations__r7   typer   r;   rH   r   r   rL   rN   r   r#   rP   rQ   r.   r.   r.   r0   rC   \   s   
 
$rC   c                   @   sH   e Zd ZU dZejed< 	 ddedee	 fddZ
ded	efd
dZdS )LoaderzK
    Convert PostgreSQL values with type OID `!oid` to Python objects.
    rD   NrE   rG   c                 C   r,   r-   r.   )r/   rE   rG   r.   r.   r0   rH      rI   zLoader.__init__datar+   c                 C   r<   )z|
        Convert the data returned by the database into a Python object.

        :param data: the data to convert.
        Nr.   )r/   rV   r.   r.   r0   load   r@   zLoader.loadr-   )r3   r4   r5   r6   r   rR   rS   r7   r   r;   rH   r   r   rW   r.   r.   r.   r0   rU      s   
 
rU   c                	   @   s  e Zd ZU eeedf  ed< eeej	  ed< d9dee
 fddZedee
 dd fd	d
Zeded fddZedefddZed:ddZeded fddZdddded dedeej	 ddfddZdee dej	ddfddZdee dej	ddfdd Zd!ee dee deee  fd"d#Zd$edefd%d&Zd$ededefd'd(Z d)ed*ed+d,ded- fd.d/Z!d0ed+d,ded- fd1d2Z"d3eee  deedf fd4d5Z#d6edej	de$fd7d8Z%dS );Transformer.typesformatsNrG   c                 C   r,   r-   r.   )r/   rG   r.   r.   r0   rH      rI   zTransformer.__init__r+   c                 C   r,   r-   r.   )rF   rG   r.   r.   r0   from_context      zTransformer.from_contextr    c                 C   r,   r-   r.   r=   r.   r.   r0   r?      r\   zTransformer.connectionc                 C   r,   r-   r.   r=   r.   r.   r0   encoding   r\   zTransformer.encodingr   c                 C   r,   r-   r.   r=   r.   r.   r0   r>      r\   zTransformer.adaptersr   c                 C   r,   r-   r.   r=   r.   r.   r0   pgresult   r\   zTransformer.pgresultT)set_loadersrD   resultr_   rD   c                C   r,   r-   r.   )r/   r`   r_   rD   r.   r.   r0   set_pgresult   r@   zTransformer.set_pgresultc                 C   r,   r-   r.   r/   rY   rD   r.   r.   r0   set_dumper_types   rI   zTransformer.set_dumper_typesc                 C   r,   r-   r.   rb   r.   r.   r0   set_loader_types   rI   zTransformer.set_loader_typesparamsc                 C   r,   r-   r.   )r/   re   rZ   r.   r.   r0   dump_sequence   r2   zTransformer.dump_sequencerJ   c                 C   r,   r-   r.   rK   r.   r.   r0   
as_literal   rI   zTransformer.as_literalc                 C   r,   r-   r.   rO   r.   r.   r0   
get_dumper   rI   zTransformer.get_dumperrow0row1make_rowzRowMaker[Row]r   c                 C   r,   r-   r.   )r/   ri   rj   rk   r.   r.   r0   	load_rows   r2   zTransformer.load_rowsrowc                 C   r,   r-   r.   )r/   rm   rk   r.   r.   r0   load_row   rI   zTransformer.load_rowrecordc                 C   r,   r-   r.   )r/   ro   r.   r.   r0   load_sequence   rI   zTransformer.load_sequencerE   c                 C   r,   r-   r.   )r/   rE   rD   r.   r.   r0   
get_loader   rI   zTransformer.get_loaderr-   rA   )&r3   r4   r5   r   r	   r7   rS   r   r   rR   r;   rH   classmethodr[   rB   r?   strr]   r>   r^   boolra   r   rc   rd   r   r   r   rf   bytesrg   rC   rh   rl   rn   rp   rU   rq   r.   r.   r.   r0   rX      s`   
 



"rX   );r6   typingr   r   r   r   r   r   r   r	   r
   r   r   typing_extensionsr    r   _enumsr   _compatr   r   r   rowsr   r   pq.abcr   waitingr   r   r?   r   _adapters_mapr   rT   r   rS   ru   	bytearray
memoryviewr   r   rs   r   r   r"   r#   r$   r7   r%   r&   r'   r9   r:   r;   rC   rU   rX   r.   r.   r.   r0   <module>   sD      S