
    z<iPg                       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jL                  d      Z' G d dejP                        Z) G d d e      Z* G d! d"e      Z+ G d# d$e      Z, G d% d&ej*                  jZ                        Z. G d' d(ej*                  j^                        Z0 G d) d*e      Z1 G d+ d,e      Z2 G d- d.ejf                        Z4 G d/ d0ejj                        Z6 G d1 d2ejn                        Z8 G d3 d4ejr                        Z: G d5 d6ejv                        Z< G d7 d8ejz                        Z> G d9 d:ej~                        Z@ G d; d<ej                        ZB G d= d>ej                        ZD G d? d@ej                        ZF G dA dBe      ZG G dC dDe      ZH G dE dFe      ZIdG ZJ G dH dIe      ZK G dJ dK      ZL G dL dMeL      ZM G dN dOe      ZN G dP dQeN      ZO G dR dS      ZP G dT dUeK      ZQeKZReQZSy)Vah  
.. 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 psycopg Connection Pooling
--------------------------------

The ``psycopg`` driver provides its own connection pool implementation that
may be used in place of SQLAlchemy's pooling functionality.
This pool implementation provides support for fixed and dynamic pool sizes
(including automatic downsizing for unused connections), connection health
pre-checks, and support for both synchronous and asynchronous code
environments.

Here is an example that uses the sync version of the pool, using
``psycopg_pool >= 3.3`` that introduces support for ``close_returns=True``::

    import psycopg_pool
    from sqlalchemy import create_engine
    from sqlalchemy.pool import NullPool

    # Create a psycopg_pool connection pool
    my_pool = psycopg_pool.ConnectionPool(
        conninfo="postgresql://scott:tiger@localhost/test",
        close_returns=True,  # Return "closed" active connections to the pool
        # ... other pool parameters as desired ...
    )

    # Create an engine that uses the connection pool to get a connection
    engine = create_engine(
        url="postgresql+psycopg://",  # Only need the dialect now
        poolclass=NullPool,  # Disable SQLAlchemy's default connection pool
        creator=my_pool.getconn,  # Use Psycopg 3 connection pool to obtain connections
    )

Similarly an the async example::

    import psycopg_pool
    from sqlalchemy.ext.asyncio import create_async_engine
    from sqlalchemy.pool import NullPool


    async def define_engine():
        # Create a psycopg_pool connection pool
        my_pool = psycopg_pool.AsyncConnectionPool(
            conninfo="postgresql://scott:tiger@localhost/test",
            open=False,  # See comment below
            close_returns=True,  # Return "closed" active connections to the pool
            # ... other pool parameters as desired ...
        )

        # Must explicitly open AsyncConnectionPool outside constructor
        # https://www.psycopg.org/psycopg3/docs/api/pool.html#psycopg_pool.AsyncConnectionPool
        await my_pool.open()

        # Create an engine that uses the connection pool to get a connection
        engine = create_async_engine(
            url="postgresql+psycopg://",  # Only need the dialect now
            poolclass=NullPool,  # Disable SQLAlchemy's default connection pool
            async_creator=my_pool.getconn,  # Use Psycopg 3 connection pool to obtain connections
        )

        return engine, my_pool

The resulting engine may then be used normally. Internally, Psycopg 3 handles
connection pooling::

    with engine.connect() as conn:
        print(conn.scalar(text("select 42")))

.. seealso::

    `Connection pools <https://www.psycopg.org/psycopg3/docs/advanced/pool.html>`_ -
    the Psycopg 3 documentation for ``psycopg_pool.ConnectionPool``.

    `Example for older version of psycopg_pool
    <https://github.com/sqlalchemy/sqlalchemy/discussions/12522#discussioncomment-13024666>`_ -
    An example about using the ``psycopg_pool<3.3`` that did not have the
    ``close_returns``` parameter.

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                      e Zd ZdZy)	_PGStringTN__name__
__module____qualname__render_bind_cast     k/home/www/utuvibe.miabetepe.com/venv/lib/python3.12/site-packages/sqlalchemy/dialects/postgresql/psycopg.pyr   r          r$   r   c                      e Zd ZdZy)_PGREGCONFIGTNr   r#   r$   r%   r(   r(      r&   r$   r(   c                      e Zd Zd Zd Zy)_PGJSONc                :    | j                  d |j                        S N)_make_bind_processor_psycopg_Jsonselfdialects     r%   bind_processorz_PGJSON.bind_processor   s    ((w/D/DEEr$   c                     y r,   r#   r0   r1   coltypes      r%   result_processorz_PGJSON.result_processor       r$   Nr   r    r!   r2   r6   r#   r$   r%   r*   r*      s    Fr$   r*   c                      e Zd Zd Zd Zy)_PGJSONBc                :    | j                  d |j                        S r,   )r-   _psycopg_Jsonbr/   s     r%   r2   z_PGJSONB.bind_processor   s    ((w/E/EFFr$   c                     y r,   r#   r4   s      r%   r6   z_PGJSONB.result_processor   r7   r$   Nr8   r#   r$   r%   r:   r:      s    Gr$   r:   c                      e Zd ZdZdZy)_PGJSONIntIndexTypejson_int_indexTNr   r    r!   __visit_name__r"   r#   r$   r%   r?   r?          %Nr$   r?   c                      e Zd ZdZdZy)_PGJSONStrIndexTypejson_str_indexTNrA   r#   r$   r%   rE   rE      rC   r$   rE   c                      e Zd Zy)_PGJSONPathTypeNr   r    r!   r#   r$   r%   rH   rH          r$   rH   c                      e Zd ZdZy)_PGIntervalTNr   r#   r$   r%   rL   rL      r&   r$   rL   c                      e Zd ZdZy)_PGTimeStampTNr   r#   r$   r%   rN   rN      r&   r$   rN   c                      e Zd ZdZy)_PGDateTNr   r#   r$   r%   rP   rP      r&   r$   rP   c                      e Zd ZdZy)_PGTimeTNr   r#   r$   r%   rR   rR     r&   r$   rR   c                      e Zd ZdZy)
_PGIntegerTNr   r#   r$   r%   rT   rT     r&   r$   rT   c                      e Zd ZdZy)_PGSmallIntegerTNr   r#   r$   r%   rV   rV   	  r&   r$   rV   c                      e Zd ZdZy)_PGNullTypeTNr   r#   r$   r%   rX   rX     r&   r$   rX   c                      e Zd ZdZy)_PGBigIntegerTNr   r#   r$   r%   rZ   rZ     r&   r$   rZ   c                      e Zd ZdZy)
_PGBooleanTNr   r#   r$   r%   r\   r\     r&   r$   r\   c                      e Zd Zd Zd Zy)_PsycopgRangec                F    t        t        |      j                  fd}|S )Nc                    t        | t        j                        r3 | j                  | j                  | j
                  | j                        } | S r,   )
isinstancer   Rangelowerupperboundsempty)valuepsycopg_Ranges    r%   to_rangez._PsycopgRange.bind_processor.<locals>.to_range  s;    %.%KKellEKK Lr$   )r   PGDialect_psycopg_psycopg_Range)r0   r1   ri   rh   s      @r%   r2   z_PsycopgRange.bind_processor  s"    .8GG	 r$   c                    d }|S )Nc                    | Pt        j                  | j                  | j                  | j                  r| j                  nd| j                         } | S )N[)re   rf   r   rb   _lower_upper_boundsrg   s    r%   ri   z0_PsycopgRange.result_processor.<locals>.to_range'  sD     LLLL,1MM5==t#mm+	 Lr$   r#   r0   r1   r5   ri   s       r%   r6   z_PsycopgRange.result_processor&  s    	 r$   Nr8   r#   r$   r%   r^   r^     s    
r$   r^   c                      e Zd Zd Zd Zy)_PsycopgMultiRangec                    t        t        |      j                  t        t        |      j                  t	        d       fd}|S )Nc                    t        | t        f      r| S  t        d|       D cg c]5  } |j                  |j                  |j
                  |j                        7 c}      S c c}w )NzIterable[ranges.Range])ra   strr   rc   rd   re   rf   )rg   elementNoneTypepsycopg_Multirangerh   s     r%   ri   z3_PsycopgMultiRange.bind_processor.<locals>.to_range=  so    %#x1C!DE% $((@%#H   "	
 
s   :A()r   rj   rk   _psycopg_Multirangetype)r0   r1   ri   r|   r}   rh   s      @@@r%   r2   z!_PsycopgMultiRange.bind_processor5  sE    .8GG!w


 	 :	  r$   c                    d }|S )Nc                @    | y t        j                  d | D              S )Nc              3     K   | ]T  }t        j                  |j                  |j                  |j                  r|j                  nd |j                          V yw)rn   ro   Nrp   ).0elems     r%   	<genexpr>zH_PsycopgMultiRange.result_processor.<locals>.to_range.<locals>.<genexpr>T  sO      )  LL/3||t||"&,,.	 )s   AA)r   
MultiRangert   s    r%   ri   z5_PsycopgMultiRange.result_processor.<locals>.to_rangeP  s,    }(( ) !&)  r$   r#   ru   s       r%   r6   z#_PsycopgMultiRange.result_processorO  s    	 r$   Nr8   r#   r$   r%   rw   rw   4  s    4r$   rw   c                      e Zd Zy)PGExecutionContext_psycopgNrI   r#   r$   r%   r   r   a  rJ   r$   r   c                      e Zd Zy)PGCompiler_psycopgNrI   r#   r$   r%   r   r   e  rJ   r$   r   c                      e Zd Zy)PGIdentifierPreparer_psycopgNrI   r#   r$   r%   r   r   i  rJ   r$   r   c                Z    t         j                  d| j                  | j                         y )Nz%s: %s)loggerinfoseveritymessage_primary)
diagnostics    r%   _log_noticesr   m  s    
KK*--z/I/IJr$   c                      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j$                  ej(                  i ej,                  eeeeeeeej4                  eeeej4                  j>                  e ej4                  jB                  e"ej4                  jF                  e$ejJ                  e&e'e&ejP                  e)ejT                  e+ejX                  e-ej\                  e/ej`                  e1ejd                  e3e4jj                  e6e4jn                  e8i      Z fdZ9 fdZ:d Z; fd	Z<e=d
        Z>e=d        Z?ej                  d        ZAej                  d        ZBej                  d        ZCej                  d        ZDej                  d        ZEej                  d        ZFd ZG fdZHd ZId ZJd ZKd ZLd ZMddZN	 ddZO	 ddZPej                  d        ZQ xZRS )rj   psycopgTpyformat)r   r   Nc                   t        |   di | | j                  rUt        j                  d| j                  j
                        }|r(t        d |j                  ddd      D              | _        | j                  dk  rt        d      dd	l
m}  || j                  j                        x| _        }| j                  d
u rddd l}|j!                  d|j"                  j$                  j&                         |j!                  d|j"                  j$                  j&                         | j(                  rddlm}  || j(                  |       | j.                  rddlm}  || j.                  |       y y y )Nz(\d+)\.(\d+)(?:\.(\d+))?c              3  8   K   | ]  }|t        |        y wr,   )int)r   xs     r%   r   z-PGDialect_psycopg.__init__.<locals>.<genexpr>  s      - CF-s   r      r   )r   r   r   z,psycopg version 3.0.2 or higher is required.r   )AdaptersMapFinetcidr)set_json_loads)set_json_dumpsr#   )super__init__dbapirematch__version__tuplegrouppsycopg_versionImportErrorpsycopg.adaptr   adapters_psycopg_adapters_map_native_inet_typespsycopg.types.stringregister_loadertypesstring
TextLoader_json_deserializerpsycopg.types.jsonr   _json_serializerr   )	r0   kwargsmr   adapters_mapr   r   r   	__class__s	           r%   r   zPGDialect_psycopg.__init__  sE   "6"::4djj6L6LMA', -$%GGAq!$4- ($ ##i/!B  28C

##9 D& &&%/+,,GMM00;; ,,GMM00;; &&=t66E$$=t44lC %C r$   c                    t         |   |      \  }}| j                  r| j                  |d<   | j                  | j                  |d<   ||fS )Ncontextclient_encoding)r   create_connect_argsr   r   )r0   urlcargscparamsr   s       r%   r   z%PGDialect_psycopg.create_connect_args  sV    4S9w%%!%!;!;GI+)-)=)=G%&g~r$   c                Z    ddl m} |j                  |j                  j                  |      S Nr   )TypeInfo)psycopg.typesr   fetch
connectiondriver_connection)r0   r   namer   s       r%   _type_info_fetchz"PGDialect_psycopg._type_info_fetch  s"    *~~j33EEtLLr$   c                X   t         |   |       | j                  sd| _        | j                  r{| j                  |d      }|d u| _        | j                  rSddlm} | j                  sJ  ||| j                         |j                  sJ  |||j                  j                         y y y )NFhstorer   )register_hstore)r   
initializeinsert_returninginsert_executemany_returninguse_native_hstorer   _has_native_hstorepsycopg.types.hstorer   r   r   r   )r0   r   r   r   r   s       r%   r   zPGDialect_psycopg.initialize  s    :& $$05D-
 !!((X>D&*$&6D#&&@ 1111d&@&@A ",,,,j&;&;&M&MN ' "r$   c                    dd l }|S )Nr   )r   )clsr   s     r%   import_dbapizPGDialect_psycopg.import_dbapi  s
    r$   c                    t         S r,   )PGDialectAsync_psycopg)r   r   s     r%   get_async_dialect_clsz'PGDialect_psycopg.get_async_dialect_cls  s    %%r$   c                    | j                   j                  j                  | j                   j                  j                  | j                   j                  j                  | j                   j                  j
                  dS )N)zREAD COMMITTEDzREAD UNCOMMITTEDzREPEATABLE READSERIALIZABLE)r   IsolationLevelREAD_COMMITTEDREAD_UNCOMMITTEDREPEATABLE_READr   r0   s    r%   _isolation_lookupz#PGDialect_psycopg._isolation_lookup  sZ     #jj77FF $

 9 9 J J#zz88HH JJ55BB	
 	
r$   c                &    ddl m} |j                  S Nr   )json)r   r   Jsonr0   r   s     r%   r.   zPGDialect_psycopg._psycopg_Json  s    &yyr$   c                &    ddl m} |j                  S r   )r   r   Jsonbr   s     r%   r<   z PGDialect_psycopg._psycopg_Jsonb  s    &zzr$   c                    ddl m} |S )Nr   )TransactionStatus)
psycopg.pqr   )r0   r   s     r%   _psycopg_TransactionStatusz,PGDialect_psycopg._psycopg_TransactionStatus  s    0  r$   c                    ddl m} |S )Nr   )rb   )psycopg.types.rangerb   )r0   rb   s     r%   rk   z PGDialect_psycopg._psycopg_Range  s
    -r$   c                    ddl m} |S )Nr   )
Multirange)psycopg.types.multiranger   )r0   r   s     r%   r~   z%PGDialect_psycopg._psycopg_Multirange  s    7r$   c                     ||_         ||_        y r,   
autocommitisolation_levelr0   r   r   r   s       r%   _do_isolation_levelz%PGDialect_psycopg._do_isolation_level  s     *
%4
"r$   c                    |j                   j                  }t        |   |      }|| j                  j
                  k(  r|j                          |S r,   )r   transaction_statusr   get_isolation_levelr   IDLErollback)r0   dbapi_connectionstatus_beforerg   r   s       r%   r   z%PGDialect_psycopg.get_isolation_level!  sK    (--@@+,<= D;;@@@%%'r$   c                z    |dk(  r| j                  |dd        y | j                  |d| j                  |          y )N
AUTOCOMMITTr   F)r   r   )r0   r   levels      r%   set_isolation_levelz%PGDialect_psycopg.set_isolation_level+  sM    L $$ T4 %  $$   $ 6 6u = % r$   c                    ||_         y r,   	read_onlyr0   r   rg   s      r%   set_readonlyzPGDialect_psycopg.set_readonly7  s
    $
r$   c                    |j                   S r,   r  r0   r   s     r%   get_readonlyzPGDialect_psycopg.get_readonly:  s    ###r$   c                d     d }|g j                    fd}j                  |       fd}|S )Nc                .    | j                  t               y r,   )add_notice_handlerr   )conns    r%   noticesz-PGDialect_psycopg.on_connect.<locals>.notices>  s    ##L1r$   c                >    j                  | j                         y r,   )r  r   )r  r0   s    r%   
on_connectz0PGDialect_psycopg.on_connect.<locals>.on_connectE  s    ((t/C/CDr$   c                $    D ]
  } ||         y r,   r#   )r  fnfnss     r%   r  z0PGDialect_psycopg.on_connect.<locals>.on_connectK  s     4r$   )r   append)r0   r  r  r  s   `  @r%   r  zPGDialect_psycopg.on_connect=  s>    	2 i+E JJz"	 r$   c                z    t        || j                  j                        r||j                  s|j                  ryy)NTF)ra   r   Errorclosedbroken)r0   er   cursors       r%   is_disconnectzPGDialect_psycopg.is_disconnectQ  s2    a))*z/E  J$5$5r$   c                p   |j                   j                  }|s-|j                  j                  | j                  j
                  k7  r|j                          |j                  }	 |s| j                  |d       |j                  |       |s| j                  ||       y y # |s| j                  ||       w w xY w)NT)
r   r   r   r   r   r   r   r   _do_autocommitexecute)r0   r   commandrecover
dbapi_connbefore_autocommits         r%   _do_prepared_twophasez'PGDialect_psycopg._do_prepared_twophaseW  s    **;;
 11..334 !&11	C$##J5w'$##J0AB %$##J0AB %s   #%B B5c                p    |r| j                  |d| d|       y | j                  |j                         y )NzROLLBACK PREPARED ''r!  )r$  do_rollbackr   r0   r   xidis_preparedr!  s        r%   do_rollback_twophasez&PGDialect_psycopg.do_rollback_twophasej  sA     &&1#a8' '  Z223r$   c                p    |r| j                  |d| d|       y | j                  |j                         y )NzCOMMIT PREPARED 'r&  r'  )r$  	do_commitr   r)  s        r%   do_commit_twophasez$PGDialect_psycopg.do_commit_twophaset  s?     &&/uA6 '  NN:001r$   c                     y)N;r#   r   s    r%   _dialect_specific_select_onez.PGDialect_psycopg._dialect_specific_select_one~  s    r$   )F)TF)Sr   r    r!   driversupports_statement_cachesupports_server_side_cursorsdefault_paramstylesupports_sane_multi_rowcountr   execution_ctx_clsr   statement_compilerr   preparerr   r   r   r   update_copyr	   colspecsr   Stringr   r   r(   r   r*   r   r   r:   r   rH   JSONIntIndexTyper?   JSONStrIndexTyperE   IntervalrL   r   DaterP   DateTimerN   TimerR   IntegerrT   SmallIntegerrV   
BigIntegerrZ   r   AbstractSingleRanger^   AbstractMultiRangerw   r   r   r   r   classmethodr   r   memoized_propertyr   r.   r<   r   rk   r~   r   r   r  r  r
  r  r  r$  r,  r/  r2  __classcell__)r   s   @r%   rj   rj   q  s   F##' ##' 2++HO t!**	
OOY	
|	
 '	
 F		

 MM7	
 8	
 MM&&	
 MM**,?	
 MM**,?	
 {	
 k	
 MM7	
 |	
 MM7	
 j	
  !!?!	
" #	
$ &&%%'9'	
H2'DRM
O4  
 & & 

 
 
 
 
 
 
! !
 
 
 
 
5
%$(C( :?4 :?2 
 r$   rj   c                      e Zd ZdZdZddZd Zed        Zej                  d        ZddZ
d Zdd	Zd
 Zd Zd ZddZd Zy)AsyncAdapt_psycopg_cursor)_cursorawait__rowsNc                >    || _         || _        t               | _        y r,   )rN  rO  r   rP  )r0   r  rO  s      r%   r   z"AsyncAdapt_psycopg_cursor.__init__  s    W
r$   c                .    t        | j                  |      S r,   )getattrrN  r0   r   s     r%   __getattr__z%AsyncAdapt_psycopg_cursor.__getattr__  s    t||T**r$   c                .    | j                   j                  S r,   rN  	arraysizer   s    r%   rX  z#AsyncAdapt_psycopg_cursor.arraysize  s    ||%%%r$   c                &    || j                   _        y r,   rW  r0   rg   s     r%   rX  z#AsyncAdapt_psycopg_cursor.arraysize  s    !&r$   c                   K   y wr,   r#   r   s    r%   _async_soft_closez+AsyncAdapt_psycopg_cursor._async_soft_close  s	     s   c                l    | j                   j                          | j                  j                          y r,   )rP  clearrN  _closer   s    r%   closezAsyncAdapt_psycopg_cursor.close  s"    

r$   c                H   | j                   | j                  j                  ||fi |      }| j                  j                  }|r\|j                  | j
                  j                  k(  r9| j                  | j                  j                               }t        |      | _	        |S r,   )
rO  rN  r  pgresultstatus_psycopg_ExecStatus	TUPLES_OKfetchallr   rP  )r0   queryparamskwresultresrowss          r%   r  z!AsyncAdapt_psycopg_cursor.execute  s    1T\\11%F2FGll## 3::!9!9!C!CC;;t||4467DtDJr$   c                X    | j                  | j                  j                  ||            S r,   )rO  rN  executemany)r0   rg  
params_seqs      r%   rn  z%AsyncAdapt_psycopg_cursor.executemany  s"    {{4<<33E:FGGr$   c              #  x   K   | j                   r*| j                   j                          | j                   r)y y wr,   rP  popleftr   s    r%   __iter__z"AsyncAdapt_psycopg_cursor.__iter__  s)     jj**$$&& jjs   5::c                P    | j                   r| j                   j                         S y r,   rq  r   s    r%   fetchonez"AsyncAdapt_psycopg_cursor.fetchone  s    ::::%%''r$   c                    || j                   j                  }| j                  }t        t	        |t        |                  D cg c]  }|j                          c}S c c}w r,   )rN  rX  rP  rangeminlenrr  )r0   sizerr_s       r%   	fetchmanyz#AsyncAdapt_psycopg_cursor.fetchmany  sI    <<<))DZZ&+Cc"g,>&?@

@@@s   Ac                d    t        | j                        }| j                  j                          |S r,   )listrP  r^  )r0   retvals     r%   rf  z"AsyncAdapt_psycopg_cursor.fetchall  s%    djj!

r$   returnNoner,   )r   r    r!   	__slots__rd  r   rU  propertyrX  setterr\  r`  r  rn  rs  ru  r}  rf  r#   r$   r%   rM  rM    so    .I
+ & & ' '

H'Ar$   rM  c                  4    e Zd ZddZd Zd Zd	dZd Zd Zy)
AsyncAdapt_psycopg_ss_cursorNc                `    | j                   | j                  j                  ||fi |       | S r,   )rO  rN  r  )r0   rg  rh  ri  s       r%   r  z$AsyncAdapt_psycopg_ss_cursor.execute  s,    (DLL((="=>r$   c                V    | j                  | j                  j                                y r,   )rO  rN  r`  r   s    r%   r`  z"AsyncAdapt_psycopg_ss_cursor.close  s    DLL&&()r$   c                T    | j                  | j                  j                               S r,   )rO  rN  ru  r   s    r%   ru  z%AsyncAdapt_psycopg_ss_cursor.fetchone      {{4<<00233r$   c                V    | j                  | j                  j                  |            S r,   )rO  rN  r}  )r0   rz  s     r%   r}  z&AsyncAdapt_psycopg_ss_cursor.fetchmany  s     {{4<<11$788r$   c                T    | j                  | j                  j                               S r,   )rO  rN  rf  r   s    r%   rf  z%AsyncAdapt_psycopg_ss_cursor.fetchall  r  r$   c              #     K   | j                   j                         }	 	 | j                  |j                                ## t        $ r Y y w xY wwr,   )rN  	__aiter__rO  	__anext__StopAsyncIteration)r0   iterators     r%   rs  z%AsyncAdapt_psycopg_ss_cursor.__iter__  sP     <<))+kk("4"4"677  & s(   A!A  A	A
AAAr,   )r   )	r   r    r!   r  r`  ru  r}  rf  rs  r#   r$   r%   r  r    s     *494r$   r  c                      e Zd ZU ded<   dZ ee      ZddZd Z	ddZ
d Zd	 Zd
 Zd Zed        Zej"                  d        Zd Zd Zd Zd Zy)AsyncAdapt_psycopg_connectionr   _connectionr#   c                    || _         y r,   r  r	  s     r%   r   z&AsyncAdapt_psycopg_connection.__init__  s
    %r$   c                .    t        | j                  |      S r,   )rS  r  rT  s     r%   rU  z)AsyncAdapt_psycopg_connection.__getattr__  s    t''..r$   Nc                    | j                   | j                  j                  ||fi |      }t        || j                         S r,   )rO  r  r  rM  )r0   rg  rh  ri  r  s        r%   r  z%AsyncAdapt_psycopg_connection.execute  s<    5T--55eVJrJK(==r$   c                     | j                   j                  |i |}t        |d      rt        || j                        S t        || j                        S )Nr   )r  r  hasattrr  rO  rM  )r0   argsri  r  s       r%   r  z$AsyncAdapt_psycopg_connection.cursor  sK    (!!(($5"566"/DD,VT[[AAr$   c                V    | j                  | j                  j                                y r,   )rO  r  commitr   s    r%   r  z$AsyncAdapt_psycopg_connection.commit  s    D$$++-.r$   c                V    | j                  | j                  j                                y r,   )rO  r  r   r   s    r%   r   z&AsyncAdapt_psycopg_connection.rollback  s    D$$--/0r$   c                V    | j                  | j                  j                                y r,   )rO  r  r`  r   s    r%   r`  z#AsyncAdapt_psycopg_connection.close  s    D$$**,-r$   c                .    | j                   j                  S r,   )r  r   r   s    r%   r   z(AsyncAdapt_psycopg_connection.autocommit  s    ***r$   c                &    | j                  |       y r,   set_autocommitrZ  s     r%   r   z(AsyncAdapt_psycopg_connection.autocommit  s    E"r$   c                X    | j                  | j                  j                  |             y r,   )rO  r  r  rZ  s     r%   r  z,AsyncAdapt_psycopg_connection.set_autocommit      D$$33E:;r$   c                X    | j                  | j                  j                  |             y r,   )rO  r  r  rZ  s     r%   r  z1AsyncAdapt_psycopg_connection.set_isolation_level
  s    D$$88?@r$   c                X    | j                  | j                  j                  |             y r,   )rO  r  set_read_onlyrZ  s     r%   r  z+AsyncAdapt_psycopg_connection.set_read_only  s    D$$2259:r$   c                X    | j                  | j                  j                  |             y r,   )rO  r  set_deferrablerZ  s     r%   r  z,AsyncAdapt_psycopg_connection.set_deferrable  r  r$   r  r,   )r   r    r!   __annotations__r  staticmethodr   rO  r   rU  r  r  r  r   r`  r  r   r  r  r  r  r  r#   r$   r%   r  r    s~      I*%F&/>B/1. + + # #<A;<r$   r  c                       e Zd ZdZ ee      Zy)%AsyncAdaptFallback_psycopg_connectionr#   N)r   r    r!   r  r  r   rO  r#   r$   r%   r  r    s    I.)Fr$   r  c                      e Zd ZddZd Zy)PsycopgAdaptDBAPIc                    || _         | j                   j                  j                         D ]  \  }}|dk7  s|| j                  |<    y )Nconnect)r   __dict__items)r0   r   kvs       r%   r   zPsycopgAdaptDBAPI.__init__  sD    LL))//1 	%DAqI~#$a 	%r$   c           	        |j                  dd      }|j                  d| j                  j                  j                        }t	        j
                  |      rt        t         ||i |            S t        t         ||i |            S )Nasync_fallbackFasync_creator_fn)
popr   r   r  r   asboolr  r   r  r   )r0   argri  r  
creator_fns        r%   r  zPsycopgAdaptDBAPI.connect!  s     0%8VV < < D D

 ;;~&8z35"56  1:s1b12 r$   Nr  )r   r    r!   r   r  r#   r$   r%   r  r    s    %r$   r  c                  X    e Zd ZdZdZed        Zed        Zd Zd Z	d Z
d Zd Zd	 Zy
)r   Tc                B    dd l }ddlm} |t        _        t        |      S )Nr   )
ExecStatus)r   r   r  rM  rd  r  )r   r   r  s      r%   r   z#PGDialectAsync_psycopg.import_dbapi4  s    )8B!5 ))r$   c                    |j                   j                  dd      }t        j                  |      rt        j
                  S t        j                  S )Nr  F)rg  getr   r  r   FallbackAsyncAdaptedQueuePoolAsyncAdaptedQueuePool)r   r   r  s      r%   get_pool_classz%PGDialectAsync_psycopg.get_pool_class=  s;    '7?;;~&555---r$   c                |    ddl m} |j                  }|j                  |j	                  |j
                  |            S r   )r   r   r   rO  r   r   )r0   r   r   r   adapteds        r%   r   z'PGDialectAsync_psycopg._type_info_fetchF  s0    *''~~hnnW-F-FMNNr$   c                H    |j                  |       |j                  |       y r,   )r  r  r   s       r%   r   z*PGDialectAsync_psycopg._do_isolation_levelL  s    !!*-&&7r$   c                &    |j                  |       y r,   r  r  s      r%   r  z%PGDialectAsync_psycopg._do_autocommitP      !!%(r$   c                &    |j                  |       y r,   )r  r  s      r%   r  z#PGDialectAsync_psycopg.set_readonlyS  s      'r$   c                &    |j                  |       y r,   )r  r  s      r%   r  z%PGDialectAsync_psycopg.set_deferrableV  r  r$   c                    |j                   S r,   r  r	  s     r%   get_driver_connectionz,PGDialectAsync_psycopg.get_driver_connectionY  s    %%%r$   N)r   r    r!   is_asyncr4  rI  r   r  r   r   r  r  r  r  r#   r$   r%   r   r   0  sR    H#* * . .O8)()&r$   r   )T__doc__
__future__r   collectionsr   loggingr   typingr   r    r   _psycopg_commonr	   r
   baser   r   r   r   r   r   r   r   r   r   r   r   enginer   sqlr   util.concurrencyr   r   r   r   r   	getLoggerr   r=  r   r(   r*   r:   r>  r?   r?  rE   rH   rL   rB  rN   rA  rP   rC  rR   rD  rT   rE  rV   NullTyperX   rF  rZ   Booleanr\   AbstractSingleRangeImplr^   AbstractMultiRangeImplrw   r   r   r   r   rj   rM  r  r  r  r  r   r1   dialect_asyncr#   r$   r%   <module>r     s-  aD #   	     6 ?   &        '  . *'			;	< 9 d u (--88 (--88 	l 	( 8$$ hmm hmm !! h++ (## H'' !! F22 6*66 *Z	!C 		 		#7 	KO1 Od@ @F#< 41<$5 1<h*,I *
 .*&. *&Z &r$   