U
    ڲg                     @  s  U d Z ddlmZ ddlmZmZmZmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZ e
rd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 ddlmZ e dZ!de"d< dZ#de"d< dZ$de"d< dZ%de"d< edddZ&eg df Z'de"d< dZ(de"d< d Z)de"d!< d"Z*de"d#< ee+e)f Z,de"d$< ed%Z-ed&d'e-f Z.de"d(< ed)d'e-f Z/de"d*< G d+d, d,eZ0eegd-f Z1de"d.< ee#gef Z2de"d/< G d0d1 d1eZ3G d2d3 d3eZ4G d4d5 d5eZ5G d6d7 d7eZ6dS )8zN
Protocol objects representing different implementations of the same classes.
    )annotations)AnyCallable	GeneratorMapping)ProtocolSequenceTYPE_CHECKING   )pq)PyFormat)	TypeAliasTypeVar)sql)RowRowMaker)PGresult)WaitReady)LiteralString)AdaptersMap)BaseConnectionNtypeNoneTypezbytes | bytearray | memoryviewr   Bufferz.LiteralString | bytes | sql.SQL | sql.ComposedQueryz!Sequence[Any] | Mapping[str, Any]ParamsConnectionTypezBaseConnection[Any])boundPipelineCommandztype | tuple[DumperKey, ...]	DumperKeyzstr | int | None	ConnParamzdict[str, ConnParam]ConnDictConnMappingRVztuple[int, Wait]zReady | int	PQGenConnr   PQGenc                   @  s&   e Zd ZdZd
ddddddd	ZdS )WaitFunczU
    Wait on the connection which generated `PQgen` and return its final result.
    Nz	PQGen[RV]intzfloat | Noner$   )genfilenointervalreturnc                 C  s   d S N )selfr)   r*   r+   r.   r.   //tmp/pip-unpacked-wheel-b_ea6rx_/psycopg/abc.py__call__<   s    zWaitFunc.__call__)N)__name__
__module____qualname____doc__r1   r.   r.   r.   r0   r'   7   s    r'   Buffer | NoneDumpFuncLoadFuncc                   @  s4   e Zd ZdZeddddZedd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  s   dS )z1The adapters configuration that this object uses.Nr.   r/   r.   r.   r0   adaptersS   s    zAdaptContext.adaptersBaseConnection[Any] | Nonec                 C  s   dS )zThe connection used by this object, if available.

        :rtype: `~psycopg.Connection` or `~psycopg.AsyncConnection` or `!None`
        Nr.   r;   r.   r.   r0   
connectionX   s    zAdaptContext.connectionN)r2   r3   r4   r5   propertyr<   r>   r.   r.   r.   r0   r9   G   s
   r9   c                   @  sx   e Zd ZU dZded< ded< dddd	d
dZdddddZdddddZddddddZddd dddZ	dS )DumperzM
    Convert Python objects of type `!cls` to PostgreSQL representation.
    	pq.Formatformatr(   oidNr   AdaptContext | Noneclscontextc                 C  s   d S r-   r.   )r/   rF   rG   r.   r.   r0   __init__q       zDumper.__init__r   r6   objr,   c                 C  s   dS )zlConvert the object `!obj` to PostgreSQL representation.

        :param obj: the object to convert.
        Nr.   r/   rK   r.   r.   r0   dumps   s    zDumper.dumpr   c                 C  s   dS )ziConvert the object `!obj` to escaped representation.

        :param obj: the object to convert.
        Nr.   rL   r.   r.   r0   quotez   s    zDumper.quoter   r    rK   rB   r,   c                 C  s   dS )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/   rK   rB   r.   r.   r0   get_key   s    "zDumper.get_keyc                 C  s   dS )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.   rP   r.   r.   r0   upgrade   s    zDumper.upgrade)N)
r2   r3   r4   r5   __annotations__rH   rM   rN   rQ   rR   r.   r.   r.   r0   r@   a   s   
$r@   c                   @  s<   e Zd ZU dZded< dddddd	Zd
ddddZdS )LoaderzK
    Convert PostgreSQL values with type OID `!oid` to Python objects.
    rA   rB   Nr(   rD   )rC   rG   c                 C  s   d S r-   r.   )r/   rC   rG   r.   r.   r0   rH      rI   zLoader.__init__r   r   )datar,   c                 C  s   dS )z|
        Convert the data returned by the database into a Python object.

        :param data: the data to convert.
        Nr.   )r/   rU   r.   r.   r0   load   s    zLoader.load)N)r2   r3   r4   r5   rS   rH   rV   r.   r.   r.   r0   rT      s   
rT   c                   @  sF  e Zd ZU ded< ded< dKdddd	Zedd d
ddZeddddZeddddZ	eddddZ
eddddZddddddddd d!Zd"d#dd$d%d&Zd"d#dd$d'd(Zd)d*d+d,d-d.Zd/d0d1d2d3Zd/d4d5d6d7d8Zd9d9d:d;d<d=d>Zd9d:d?d@dAdBZd+dCdDdEdFZd9d#dGdHdIdJZdS )LTransformerztuple[int, ...] | Nonetypeszlist[pq.Format] | NoneformatsNrD   )rG   c                 C  s   d S r-   r.   )r/   rG   r.   r.   r0   rH      rI   zTransformer.__init__)rG   r,   c                 C  s   d S r-   r.   rE   r.   r.   r0   from_context   s    zTransformer.from_contextr=   r:   c                 C  s   d S r-   r.   r;   r.   r.   r0   r>      s    zTransformer.connectionstrc                 C  s   d S r-   r.   r;   r.   r.   r0   encoding   s    zTransformer.encodingr   c                 C  s   d S r-   r.   r;   r.   r.   r0   r<      s    zTransformer.adapterszPGresult | Nonec                 C  s   d S r-   r.   r;   r.   r.   r0   pgresult   s    zTransformer.pgresultT)set_loadersrB   boolzpq.Format | NoneNone)resultr^   rB   r,   c                C  s   d S r-   r.   )r/   ra   r^   rB   r.   r.   r0   set_pgresult   s    zTransformer.set_pgresultzSequence[int]rA   )rX   rB   r,   c                 C  s   d S r-   r.   r/   rX   rB   r.   r.   r0   set_dumper_types   rI   zTransformer.set_dumper_typesc                 C  s   d S r-   r.   rc   r.   r.   r0   set_loader_types   rI   zTransformer.set_loader_typeszSequence[Any]zSequence[PyFormat]zSequence[Buffer | None])paramsrY   r,   c                 C  s   d S r-   r.   )r/   rf   rY   r.   r.   r0   dump_sequence   s    zTransformer.dump_sequencer   bytesrJ   c                 C  s   d S r-   r.   rL   r.   r.   r0   
as_literal   rI   zTransformer.as_literalr   r@   rO   c                 C  s   d S r-   r.   rP   r.   r.   r0   
get_dumper   rI   zTransformer.get_dumperr(   zRowMaker[Row]z	list[Row])row0row1make_rowr,   c                 C  s   d S r-   r.   )r/   rk   rl   rm   r.   r.   r0   	load_rows   rI   zTransformer.load_rowsz
Row | None)rowrm   r,   c                 C  s   d S r-   r.   )r/   ro   rm   r.   r.   r0   load_row   rI   zTransformer.load_rowztuple[Any, ...])recordr,   c                 C  s   d S r-   r.   )r/   rq   r.   r.   r0   load_sequence   rI   zTransformer.load_sequencerT   )rC   rB   r,   c                 C  s   d S r-   r.   )r/   rC   rB   r.   r.   r0   
get_loader   rI   zTransformer.get_loader)N)r2   r3   r4   rS   rH   classmethodrZ   r?   r>   r\   r<   r]   rb   rd   re   rg   ri   rj   rn   rp   rr   rs   r.   r.   r.   r0   rW      s2   
rW   )7r5   
__future__r   typingr   r   r   r   r   r   r	    r   Z_enumsr   _compatr   r   r   Zrowsr   r   Zpq.abcr   Zwaitingr   r   r   Z_adapters_mapr   Z_connection_baser   r   r   rS   r   r   r   r   r   r    r!   r"   r[   r#   r$   r%   r&   r'   r7   r8   r9   r@   rT   rW   r.   r.   r.   r0   <module>   sD   S