U
    ovg[                     @  s&  d Z ddlmZ ddlmZ ddlZddl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 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 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 ddlmZ ddlmZ ddl m!Z! ddl m"Z" e	r.ddlm#Z# ddl$m%Z% e&dZ'G dd dej(Z)G dd  d eZ*G d!d" d"eZ+G d#d$ d$eZ,G d%d& d&ejj-Z.G d'd( d(ejj/Z0G d)d* d*eZ1G d+d, d,eZ2G d-d. d.ej3Z4G d/d0 d0ej5Z6G d1d2 d2ej7Z8G d3d4 d4ej9Z:G d5d6 d6ej;Z<G d7d8 d8ej=Z>G d9d: d:ej?Z@G d;d< d<ejAZBG d=d> d>ejCZDG d?d@ d@ejEZFG dAdB dBeZGG dCdD dDeZHG dEdF dFeZIdGdH ZJG dIdJ dJeZKG dKdL dLZLG dMdN dNeLZMG dOdP dPeZNG dQdR dReNZOG dSdT dTZPG dUdV dVeKZQeKZReQZSdS )Wau  
.. dialect:: postgresql+psycopg
    :name: psycopg (a.k.a. psycopg 3)
    :dbapi: psycopg
    :connectstring: postgresql+psycopg://user:password@host:port/dbname[?key=value&key=value...]
    :url: https://pypi.org/project/psycopg/

``psycopg`` is the package and module name for version 3 of the ``psycopg``
database driver, formerly known as ``psycopg2``.  This driver is different
enough from its ``psycopg2`` predecessor that SQLAlchemy supports it
via a totally separate dialect; support for ``psycopg2`` is expected to remain
for as long as that package continues to function for modern Python versions,
and also remains the default dialect for the ``postgresql://`` dialect
series.

The SQLAlchemy ``psycopg`` dialect provides both a sync and an async
implementation under the same dialect name. The proper version is
selected depending on how the engine is created:

* calling :func:`_sa.create_engine` with ``postgresql+psycopg://...`` will
  automatically select the sync version, e.g.::

    from sqlalchemy import create_engine

    sync_engine = create_engine(
        "postgresql+psycopg://scott:tiger@localhost/test"
    )

* calling :func:`_asyncio.create_async_engine` with
  ``postgresql+psycopg://...`` will automatically select the async version,
  e.g.::

    from sqlalchemy.ext.asyncio import create_async_engine

    asyncio_engine = create_async_engine(
        "postgresql+psycopg://scott:tiger@localhost/test"
    )

The asyncio version of the dialect may also be specified explicitly using the
``psycopg_async`` suffix, as::

    from sqlalchemy.ext.asyncio import create_async_engine

    asyncio_engine = create_async_engine(
        "postgresql+psycopg_async://scott:tiger@localhost/test"
    )

.. seealso::

    :ref:`postgresql_psycopg2` - The SQLAlchemy ``psycopg``
    dialect shares most of its behavior with the ``psycopg2`` dialect.
    Further documentation is available there.

Using a different Cursor class
------------------------------

One of the differences between ``psycopg`` and the older ``psycopg2``
is how bound parameters are handled: ``psycopg2`` would bind them
client side, while ``psycopg`` by default will bind them server side.

It's possible to configure ``psycopg`` to do client side binding by
specifying the ``cursor_factory`` to be ``ClientCursor`` when creating
the engine::

    from psycopg import ClientCursor

    client_side_engine = create_engine(
        "postgresql+psycopg://...",
        connect_args={"cursor_factory": ClientCursor},
    )

Similarly when using an async engine the ``AsyncClientCursor`` can be
specified::

    from psycopg import AsyncClientCursor

    client_side_engine = create_async_engine(
        "postgresql+psycopg://...",
        connect_args={"cursor_factory": AsyncClientCursor},
    )

.. seealso::

    `Client-side-binding cursors <https://www.psycopg.org/psycopg3/docs/advanced/cursors.html#client-side-binding-cursors>`_

    )annotations)dequeN)cast)TYPE_CHECKING   )ranges)_PGDialect_common_psycopg)"_PGExecutionContext_common_psycopg)INTERVAL)
PGCompiler)PGIdentifierPreparer)	REGCONFIG)JSON)JSONB)JSONPathType)CITEXT   )pool)util)AdaptedConnection)sqltypes)await_fallback)
await_only)Iterable)AsyncConnectionzsqlalchemy.dialects.postgresqlc                   @  s   e Zd ZdZdS )	_PGStringTN__name__
__module____qualname__render_bind_cast r!   r!   J/tmp/pip-unpacked-wheel-uqd9otp_/sqlalchemy/dialects/postgresql/psycopg.pyr      s   r   c                   @  s   e Zd ZdZdS )_PGREGCONFIGTNr   r!   r!   r!   r"   r#      s   r#   c                   @  s   e Zd Zdd Zdd ZdS )_PGJSONc                 C  s   |  d |jS N)_make_bind_processor_psycopg_Jsonselfdialectr!   r!   r"   bind_processor   s    z_PGJSON.bind_processorc                 C  s   d S r%   r!   r)   r*   coltyper!   r!   r"   result_processor   s    z_PGJSON.result_processorNr   r   r   r+   r.   r!   r!   r!   r"   r$      s   r$   c                   @  s   e Zd Zdd Zdd ZdS )_PGJSONBc                 C  s   |  d |jS r%   )r&   _psycopg_Jsonbr(   r!   r!   r"   r+      s    z_PGJSONB.bind_processorc                 C  s   d S r%   r!   r,   r!   r!   r"   r.      s    z_PGJSONB.result_processorNr/   r!   r!   r!   r"   r0      s   r0   c                   @  s   e Zd ZdZdZdS )_PGJSONIntIndexTypeZjson_int_indexTNr   r   r   Z__visit_name__r    r!   r!   r!   r"   r2      s   r2   c                   @  s   e Zd ZdZdZdS )_PGJSONStrIndexTypeZjson_str_indexTNr3   r!   r!   r!   r"   r4      s   r4   c                   @  s   e Zd ZdS )_PGJSONPathTypeNr   r   r   r!   r!   r!   r"   r5      s   r5   c                   @  s   e Zd ZdZdS )_PGIntervalTNr   r!   r!   r!   r"   r7      s   r7   c                   @  s   e Zd ZdZdS )_PGTimeStampTNr   r!   r!   r!   r"   r8      s   r8   c                   @  s   e Zd ZdZdS )_PGDateTNr   r!   r!   r!   r"   r9      s   r9   c                   @  s   e Zd ZdZdS )_PGTimeTNr   r!   r!   r!   r"   r:      s   r:   c                   @  s   e Zd ZdZdS )
_PGIntegerTNr   r!   r!   r!   r"   r;      s   r;   c                   @  s   e Zd ZdZdS )_PGSmallIntegerTNr   r!   r!   r!   r"   r<      s   r<   c                   @  s   e Zd ZdZdS )_PGNullTypeTNr   r!   r!   r!   r"   r=      s   r=   c                   @  s   e Zd ZdZdS )_PGBigIntegerTNr   r!   r!   r!   r"   r>      s   r>   c                   @  s   e Zd ZdZdS )
_PGBooleanTNr   r!   r!   r!   r"   r?      s   r?   c                   @  s   e Zd Zdd Zdd ZdS )_PsycopgRangec                   s   t t|j  fdd}|S )Nc                   s&   t | tjr" | j| j| j| j} | S r%   )
isinstancer   Rangelowerupperboundsemptyvaluepsycopg_Ranger!   r"   to_range   s       z._PsycopgRange.bind_processor.<locals>.to_range)r   PGDialect_psycopg_psycopg_Ranger)   r*   rK   r!   rI   r"   r+      s    z_PsycopgRange.bind_processorc                 C  s   dd }|S )Nc                 S  s2   | d k	r.t j| j| j| jr | jnd| j d} | S )N[)rE   rF   r   rB   Z_lowerZ_upperZ_boundsrG   r!   r!   r"   rK      s    z0_PsycopgRange.result_processor.<locals>.to_ranger!   r)   r*   r-   rK   r!   r!   r"   r.      s    
z_PsycopgRange.result_processorNr/   r!   r!   r!   r"   r@      s   r@   c                   @  s   e Zd Zdd Zdd ZdS )_PsycopgMultiRangec                   s4   t t|jt t|jtd   fdd}|S )Nc                   s0   t | t fr| S fddtd| D S )Nc                   s"   g | ]} |j |j|j|jqS r!   )rC   rD   rE   rF   ).0elementrI   r!   r"   
<listcomp>   s   zG_PsycopgMultiRange.bind_processor.<locals>.to_range.<locals>.<listcomp>zIterable[ranges.Range])rA   strr   rG   ZNoneTypeZpsycopg_MultirangerJ   r!   r"   rK      s    
z3_PsycopgMultiRange.bind_processor.<locals>.to_range)r   rL   rM   _psycopg_MultirangetyperN   r!   rX   r"   r+      s     z!_PsycopgMultiRange.bind_processorc                 C  s   dd }|S )Nc                 S  s$   | d krd S t dd | D S d S )Nc                 s  s4   | ],}t j|j|j|jr|jnd |j dV  qdS )rO   rP   NrQ   )rT   elemr!   r!   r"   	<genexpr>  s   zH_PsycopgMultiRange.result_processor.<locals>.to_range.<locals>.<genexpr>)r   Z
MultiRangerG   r!   r!   r"   rK     s
    
z5_PsycopgMultiRange.result_processor.<locals>.to_ranger!   rR   r!   r!   r"   r.     s    z#_PsycopgMultiRange.result_processorNr/   r!   r!   r!   r"   rS      s   rS   c                   @  s   e Zd ZdS )PGExecutionContext_psycopgNr6   r!   r!   r!   r"   r]     s   r]   c                   @  s   e Zd ZdS )PGCompiler_psycopgNr6   r!   r!   r!   r"   r^     s   r^   c                   @  s   e Zd ZdS )PGIdentifierPreparer_psycopgNr6   r!   r!   r!   r"   r_     s   r_   c                 C  s   t d| j| j d S )Nz%s: %s)loggerinfoZseverityZmessage_primary)Z
diagnosticr!   r!   r"   _log_notices!  s    rb   c                )      s  e Zd ZdZdZdZdZdZeZ	e
ZeZdZdZdZeejejeeeeeeeejeeeejje ejj!e"ejj#e$ej%e&e'e&ej(e)ej*e+ej,e-ej.e/ej0e1ej2e3e4j5e6e4j7e8iZ fddZ9 fdd	Z:d
d Z; fddZ<e=dd Z>e=dd Z?ej@dd ZAej@dd ZBej@dd ZCej@dd ZDej@dd ZEej@dd ZFdd ZG fd d!ZHd"d# ZId$d% ZJd&d' ZKd(d) ZLd*d+ ZMd5d-d.ZNd6d/d0ZOd7d1d2ZPej@d3d4 ZQ  ZRS )8rL   psycopgTZpyformat)r   r   Nc                   s   t  jf | | jrtd| jj}|rFtdd |dddD | _| jdk rXt	dd	d
l
m} || jj | _}| jdkrd	d l}|d|jjj |d|jjj | jrd	dlm} || j| | jrd	dlm} || j| d S )Nz(\d+)\.(\d+)(?:\.(\d+))?c                 s  s   | ]}|d k	rt |V  qd S r%   )int)rT   xr!   r!   r"   r\   T  s     z-PGDialect_psycopg.__init__.<locals>.<genexpr>r      r   )r   r   rf   z,psycopg version 3.0.2 or higher is required.r   )AdaptersMapFZinetZcidr)set_json_loads)set_json_dumps)super__init__dbapirematch__version__tuplegrouppsycopg_versionImportErrorZpsycopg.adaptrg   adapters_psycopg_adapters_mapZ_native_inet_typesZpsycopg.types.stringZregister_loadertypesstringZ
TextLoaderZ_json_deserializerZpsycopg.types.jsonrh   Z_json_serializerri   )r)   kwargsmrg   Zadapters_maprc   rh   ri   	__class__r!   r"   rk   N  s>    



  zPGDialect_psycopg.__init__c                   s<   t  |\}}| jr | j|d< | jd k	r4| j|d< ||fS )Ncontextclient_encoding)rj   create_connect_argsru   r}   )r)   urlZcargsZcparamsrz   r!   r"   r~   w  s    


z%PGDialect_psycopg.create_connect_argsc                 C  s   ddl m} ||jj|S Nr   )TypeInfo)psycopg.typesr   fetch
connectiondriver_connection)r)   r   namer   r!   r!   r"   _type_info_fetch  s    z"PGDialect_psycopg._type_info_fetchc                   sx   t  | | jsd| _| jrt| |d}|d k	| _| jrtddlm} | j	sPt
||| j	 |jsft
|||jj d S )NFZhstorer   )register_hstore)rj   
initializeZinsert_returningZinsert_executemany_returningZuse_native_hstorer   _has_native_hstoreZpsycopg.types.hstorer   ru   AssertionErrorr   r   )r)   r   ra   r   rz   r!   r"   r     s    


zPGDialect_psycopg.initializec                 C  s   dd l }|S )Nr   )rc   )clsrc   r!   r!   r"   import_dbapi  s    zPGDialect_psycopg.import_dbapic                 C  s   t S r%   )PGDialectAsync_psycopg)r   r   r!   r!   r"   get_async_dialect_cls  s    z'PGDialect_psycopg.get_async_dialect_clsc                 C  s&   | j jj| j jj| j jj| j jjdS )N)zREAD COMMITTEDzREAD UNCOMMITTEDzREPEATABLE READSERIALIZABLE)rl   ZIsolationLevelZREAD_COMMITTEDZREAD_UNCOMMITTEDZREPEATABLE_READr   r)   r!   r!   r"   _isolation_lookup  s
    z#PGDialect_psycopg._isolation_lookupc                 C  s   ddl m} |jS Nr   )json)r   r   ZJsonr)   r   r!   r!   r"   r'     s    zPGDialect_psycopg._psycopg_Jsonc                 C  s   ddl m} |jS r   )r   r   ZJsonbr   r!   r!   r"   r1     s    z PGDialect_psycopg._psycopg_Jsonbc                 C  s   ddl m} |S )Nr   )TransactionStatus)
psycopg.pqr   )r)   r   r!   r!   r"   _psycopg_TransactionStatus  s    z,PGDialect_psycopg._psycopg_TransactionStatusc                 C  s   ddl m} |S )Nr   )rB   )Zpsycopg.types.rangerB   )r)   rB   r!   r!   r"   rM     s    z PGDialect_psycopg._psycopg_Rangec                 C  s   ddl m} |S )Nr   )
Multirange)Zpsycopg.types.multiranger   )r)   r   r!   r!   r"   rY     s    z%PGDialect_psycopg._psycopg_Multirangec                 C  s   ||_ ||_d S r%   
autocommitisolation_levelr)   r   r   r   r!   r!   r"   _do_isolation_level  s    z%PGDialect_psycopg._do_isolation_levelc                   s,   |j j}t |}|| jjkr(|  |S r%   )ra   transaction_statusrj   get_isolation_levelr   IDLErollback)r)   dbapi_connectionZstatus_beforerH   rz   r!   r"   r     s
    z%PGDialect_psycopg.get_isolation_levelc                 C  s4   |dkr| j |dd d n| j |d| j| d d S )NZ
AUTOCOMMITTr   F)r   r   )r)   r   levelr!   r!   r"   set_isolation_level  s      z%PGDialect_psycopg.set_isolation_levelc                 C  s
   ||_ d S r%   Z	read_onlyr)   r   rH   r!   r!   r"   set_readonly  s    zPGDialect_psycopg.set_readonlyc                 C  s   |j S r%   r   r)   r   r!   r!   r"   get_readonly  s    zPGDialect_psycopg.get_readonlyc                   s>   dd }|g j d k	r.fdd} |  fdd}|S )Nc                 S  s   |  t d S r%   )Zadd_notice_handlerrb   connr!   r!   r"   notices  s    z-PGDialect_psycopg.on_connect.<locals>.noticesc                   s     |  j d S r%   )r   r   r   r   r!   r"   
on_connect  s    z0PGDialect_psycopg.on_connect.<locals>.on_connectc                   s    D ]}||  qd S r%   r!   )r   fn)fnsr!   r"   r     s    )r   append)r)   r   r   r!   )r   r)   r"   r     s    

zPGDialect_psycopg.on_connectc                 C  s*   t || jjr&|d k	r&|js"|jr&dS dS )NTF)rA   rl   Errorclosedbroken)r)   er   cursorr!   r!   r"   is_disconnect  s    zPGDialect_psycopg.is_disconnectFc              
   C  s`   |j j}|s|jj| jjkr$|  |j}z|s<| |d |	| W 5 |sZ| || X d S )NT)
r   r   ra   r   r   r   r   r   _do_autocommitexecute)r)   r   commandrecoverZ
dbapi_connZbefore_autocommitr!   r!   r"   _do_prepared_twophase  s    z'PGDialect_psycopg._do_prepared_twophasec                 C  s.   |r| j |d| d|d n| |j d S )NzROLLBACK PREPARED ''r   )r   Zdo_rollbackr   r)   r   xidZis_preparedr   r!   r!   r"   do_rollback_twophase  s     
 z&PGDialect_psycopg.do_rollback_twophasec                 C  s.   |r| j |d| d|d n| |j d S )NzCOMMIT PREPARED 'r   r   )r   Z	do_commitr   r   r!   r!   r"   do_commit_twophase(  s     
 z$PGDialect_psycopg.do_commit_twophasec                 C  s   dS )N;r!   r   r!   r!   r"   _dialect_specific_select_one2  s    z.PGDialect_psycopg._dialect_specific_select_one)F)TF)TF)Sr   r   r   Zdriversupports_statement_cacheZsupports_server_side_cursorsZdefault_paramstyleZsupports_sane_multi_rowcountr]   Zexecution_ctx_clsr^   Zstatement_compilerr_   preparerrr   r   ru   r   Zupdate_copyr   Zcolspecsr   Stringr   r   r#   r   r$   r   r   r0   r   r5   JSONIntIndexTyper2   JSONStrIndexTyper4   ZIntervalr7   r
   Dater9   DateTimer8   Timer:   Integerr;   SmallIntegerr<   
BigIntegerr>   r   ZAbstractSingleRanger@   ZAbstractMultiRangerS   rk   r~   r   r   classmethodr   r   Zmemoized_propertyr   r'   r1   r   rM   rY   r   r   r   r   r   r   r   r   r   r   r   __classcell__r!   r!   rz   r"   rL   %  s                      )










   
   

rL   c                   @  s   e Zd ZdZdZddddZdd Zed	d
 Zej	dd
 Zdd Z
dddZdd Zdd Zdd ZdddZdd ZdS )AsyncAdapt_psycopg_cursor)_cursorawait__rowsNNonereturnc                 C  s   || _ || _t | _d S r%   )r   r   r   r   )r)   r   r   r!   r!   r"   rk   <  s    z"AsyncAdapt_psycopg_cursor.__init__c                 C  s   t | j|S r%   )getattrr   r)   r   r!   r!   r"   __getattr__A  s    z%AsyncAdapt_psycopg_cursor.__getattr__c                 C  s   | j jS r%   r   	arraysizer   r!   r!   r"   r   D  s    z#AsyncAdapt_psycopg_cursor.arraysizec                 C  s   || j _d S r%   r   r)   rH   r!   r!   r"   r   H  s    c                 C  s   | j   | j  d S r%   )r   clearr   _closer   r!   r!   r"   closeL  s    
zAsyncAdapt_psycopg_cursor.closec                 K  sP   |  | jj||f|}| jj}|rL|j| jjkrL|  | j }t|| _	|S r%   )
r   r   r   Zpgresultstatus_psycopg_ExecStatusZ	TUPLES_OKfetchallr   r   )r)   queryparamskwresultresZrowsr!   r!   r"   r   Q  s    
z!AsyncAdapt_psycopg_cursor.executec                 C  s   |  | j||S r%   )r   r   executemany)r)   r   Z
params_seqr!   r!   r"   r   ]  s    z%AsyncAdapt_psycopg_cursor.executemanyc                 c  s   | j r| j  V  q d S r%   r   popleftr   r!   r!   r"   __iter__`  s    z"AsyncAdapt_psycopg_cursor.__iter__c                 C  s   | j r| j  S d S d S r%   r   r   r!   r!   r"   fetchoned  s    
z"AsyncAdapt_psycopg_cursor.fetchonec                   s6   |d kr| j j}| j  fddtt|t D S )Nc                   s   g | ]}   qS r!   )r   )rT   _rrr!   r"   rV   o  s     z7AsyncAdapt_psycopg_cursor.fetchmany.<locals>.<listcomp>)r   r   r   rangeminlenr)   sizer!   r   r"   	fetchmanyj  s    z#AsyncAdapt_psycopg_cursor.fetchmanyc                 C  s   t | j}| j  |S r%   )listr   r   )r)   retvalr!   r!   r"   r   q  s    

z"AsyncAdapt_psycopg_cursor.fetchall)N)N)r   r   r   	__slots__r   rk   r   propertyr   setterr   r   r   r   r   r   r   r!   r!   r!   r"   r   7  s   



r   c                   @  s@   e Zd ZdddZdd Zdd Zdd	d
Zdd Zdd ZdS )AsyncAdapt_psycopg_ss_cursorNc                 K  s   |  | jj||f| | S r%   )r   r   r   )r)   r   r   r   r!   r!   r"   r   x  s    z$AsyncAdapt_psycopg_ss_cursor.executec                 C  s   |  | j  d S r%   )r   r   r   r   r!   r!   r"   r   |  s    z"AsyncAdapt_psycopg_ss_cursor.closec                 C  s   |  | j S r%   )r   r   r   r   r!   r!   r"   r     s    z%AsyncAdapt_psycopg_ss_cursor.fetchoner   c                 C  s   |  | j|S r%   )r   r   r   r   r!   r!   r"   r     s    z&AsyncAdapt_psycopg_ss_cursor.fetchmanyc                 C  s   |  | j S r%   )r   r   r   r   r!   r!   r"   r     s    z%AsyncAdapt_psycopg_ss_cursor.fetchallc                 c  s>   | j  }z| | V  W q
 tk
r6   Y q:Y q
X q
d S r%   )r   	__aiter__r   	__anext__StopAsyncIteration)r)   iteratorr!   r!   r"   r     s
    
z%AsyncAdapt_psycopg_ss_cursor.__iter__)N)r   )	r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   r   w  s   

r   c                   @  s   e Zd ZU ded< dZeeZddddZdd	 Z	d ddZ
dd Zdd Zdd Zdd Zedd Zejdd Zdd Zdd Zdd Zdd Zd
S )!AsyncAdapt_psycopg_connectionr   _connectionr!   r   r   c                 C  s
   || _ d S r%   r  r   r!   r!   r"   rk     s    z&AsyncAdapt_psycopg_connection.__init__c                 C  s   t | j|S r%   )r   r  r   r!   r!   r"   r     s    z)AsyncAdapt_psycopg_connection.__getattr__Nc                 K  s$   |  | jj||f|}t|| j S r%   )r   r  r   r   )r)   r   r   r   r   r!   r!   r"   r     s    z%AsyncAdapt_psycopg_connection.executec                 O  s4   | j j||}t|dr$t|| jS t|| jS d S )Nr   )r  r   hasattrr   r   r   )r)   argsr   r   r!   r!   r"   r     s    
z$AsyncAdapt_psycopg_connection.cursorc                 C  s   |  | j  d S r%   )r   r  commitr   r!   r!   r"   r    s    z$AsyncAdapt_psycopg_connection.commitc                 C  s   |  | j  d S r%   )r   r  r   r   r!   r!   r"   r     s    z&AsyncAdapt_psycopg_connection.rollbackc                 C  s   |  | j  d S r%   )r   r  r   r   r!   r!   r"   r     s    z#AsyncAdapt_psycopg_connection.closec                 C  s   | j jS r%   )r  r   r   r!   r!   r"   r     s    z(AsyncAdapt_psycopg_connection.autocommitc                 C  s   |  | d S r%   set_autocommitr   r!   r!   r"   r     s    c                 C  s   |  | j| d S r%   )r   r  r	  r   r!   r!   r"   r	    s    z,AsyncAdapt_psycopg_connection.set_autocommitc                 C  s   |  | j| d S r%   )r   r  r   r   r!   r!   r"   r     s    z1AsyncAdapt_psycopg_connection.set_isolation_levelc                 C  s   |  | j| d S r%   )r   r  set_read_onlyr   r!   r!   r"   r
    s    z+AsyncAdapt_psycopg_connection.set_read_onlyc                 C  s   |  | j| d S r%   )r   r  set_deferrabler   r!   r!   r"   r    s    z,AsyncAdapt_psycopg_connection.set_deferrable)N)r   r   r   __annotations__r   staticmethodr   r   rk   r   r   r   r  r   r   r   r   r   r	  r   r
  r  r!   r!   r!   r"   r    s$   



r  c                   @  s   e Zd ZdZeeZdS )%AsyncAdaptFallback_psycopg_connectionr!   N)r   r   r   r   r  r   r   r!   r!   r!   r"   r    s   r  c                   @  s"   e Zd ZddddZdd ZdS )PsycopgAdaptDBAPIr   r   c                 C  s2   || _ | j j D ]\}}|dkr|| j|< qd S )Nconnect)rc   __dict__items)r)   rc   kvr!   r!   r"   rk     s    zPsycopgAdaptDBAPI.__init__c                 O  sP   | dd}| d| jjj}t|r:tt|||S tt	|||S d S )Nasync_fallbackFZasync_creator_fn)
poprc   r   r  r   asboolr  r   r  r   )r)   argr   r  Z
creator_fnr!   r!   r"   r    s     
zPsycopgAdaptDBAPI.connectN)r   r   r   rk   r  r!   r!   r!   r"   r    s   r  c                   @  s\   e Zd ZdZdZedd Zedd Zdd Zdd	 Z	d
d Z
dd Zdd Zdd ZdS )r   Tc                 C  s"   dd l }ddlm} |t_t|S )Nr   )
ExecStatus)rc   r   r  r   r   r  )r   rc   r  r!   r!   r"   r     s    z#PGDialectAsync_psycopg.import_dbapic                 C  s(   |j dd}t|rtjS tjS d S )Nr  F)r   getr   r  r   ZFallbackAsyncAdaptedQueuePoolZAsyncAdaptedQueuePool)r   r   r  r!   r!   r"   get_pool_class  s    
z%PGDialectAsync_psycopg.get_pool_classc                 C  s&   ddl m} |j}|||j|S r   )r   r   r   r   r   r   )r)   r   r   r   Zadaptedr!   r!   r"   r     s    z'PGDialectAsync_psycopg._type_info_fetchc                 C  s   | | || d S r%   )r	  r   r   r!   r!   r"   r     s    
z*PGDialectAsync_psycopg._do_isolation_levelc                 C  s   | | d S r%   r  r   r!   r!   r"   r     s    z%PGDialectAsync_psycopg._do_autocommitc                 C  s   | | d S r%   )r
  r   r!   r!   r"   r     s    z#PGDialectAsync_psycopg.set_readonlyc                 C  s   | | d S r%   )r  r   r!   r!   r"   r    s    z%PGDialectAsync_psycopg.set_deferrablec                 C  s   |j S r%   r  r   r!   r!   r"   get_driver_connection
  s    z,PGDialectAsync_psycopg.get_driver_connectionN)r   r   r   Zis_asyncr   r   r   r  r   r   r   r   r  r  r!   r!   r!   r"   r     s   

r   )T__doc__
__future__r   collectionsr   loggingrm   typingr   r    r   Z_psycopg_commonr   r	   baser
   r   r   r   r   r   r   r   rv   r   r   r   Zenginer   Zsqlr   Zutil.concurrencyr   r   r   rc   r   	getLoggerr`   r   r   r#   r$   r0   r   r2   r   r4   r5   r7   r   r8   r   r9   r   r:   r   r;   r   r<   ZNullTyper=   r   r>   Booleanr?   ZAbstractSingleRangeImplr@   ZAbstractMultiRangeImplrS   r]   r^   r_   rb   rL   r   r   r  r  r  r   r*   Zdialect_asyncr!   r!   r!   r"   <module>	   sx   V
-  @4-