
    -h                        S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  SSKJ
r
  SSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJ r    SSK!Jr"   " S S\RH                  5      r% " S S\RL                  5      r' " S S \RP                  5      r) " S! S"\RT                  5      r+ " S# S$\5      r, " S% S&\5      r- " S' S(\R\                  5      r/ " S) S*\R`                  5      r1 " S+ S,\Rd                  5      r3 " S- S.\Rh                  5      r5 " S/ S0\Rd                  Rl                  5      r7 " S1 S2\Rd                  Rp                  5      r9 " S3 S4\Rd                  Rt                  5      r; " S5 S6\Rx                  5      r= " S7 S8\5      r> " S9 S:\R~                  5      r@ " S; S<\@5      rA " S= S>\5      rB " S? S@\5      rC " SA SB\5      rD " SC SD\5      rE " SE SF\5      rF " SG SH5      rG " SI SJ\G5      rH " SK SL\5      rI " SM SN\I5      rJ " SO SP5      rK0 \KR                  SQ_\KR                  SR_\KR                  SS_\KR                  ST_\KR                  SU_\KR                  SV_\KR                  SW_\KR                  SX_\KR                  SY_\KR                  SZ_\KR                  S[_\KR                  S\_\KR                  S]_\KR                  S^_\KRd                  S__\KRh                  S`_\KR                  Sa_\KR(                  Sb\KR                  Sc0ErZ " Sd Se\5      r[\[r\g! \# a    Sr" GNf = f)fa  
.. dialect:: postgresql+asyncpg
    :name: asyncpg
    :dbapi: asyncpg
    :connectstring: postgresql+asyncpg://user:password@host:port/dbname[?key=value&key=value...]
    :url: https://magicstack.github.io/asyncpg/

The asyncpg dialect is SQLAlchemy's first Python asyncio dialect.

Using a special asyncio mediation layer, the asyncpg dialect is usable
as the backend for the :ref:`SQLAlchemy asyncio <asyncio_toplevel>`
extension package.

This dialect should normally be used only with the
:func:`_asyncio.create_async_engine` engine creation function::

    from sqlalchemy.ext.asyncio import create_async_engine
    engine = create_async_engine("postgresql+asyncpg://user:pass@hostname/dbname")

The dialect can also be run as a "synchronous" dialect within the
:func:`_sa.create_engine` function, which will pass "await" calls into
an ad-hoc event loop.  This mode of operation is of **limited use**
and is for special testing scenarios only.  The mode can be enabled by
adding the SQLAlchemy-specific flag ``async_fallback`` to the URL
in conjunction with :func:`_sa.create_engine`::

    # for testing purposes only; do not use in production!
    engine = create_engine("postgresql+asyncpg://user:pass@hostname/dbname?async_fallback=true")


.. versionadded:: 1.4

.. note::

    By default asyncpg does not decode the ``json`` and ``jsonb`` types and
    returns them as strings. SQLAlchemy sets default type decoder for ``json``
    and ``jsonb`` types using the python builtin ``json.loads`` function.
    The json implementation used can be changed by setting the attribute
    ``json_deserializer`` when creating the engine with
    :func:`create_engine` or :func:`create_async_engine`.


.. _asyncpg_prepared_statement_cache:

Prepared Statement Cache
--------------------------

The asyncpg SQLAlchemy dialect makes use of ``asyncpg.connection.prepare()``
for all statements.   The prepared statement objects are cached after
construction which appears to grant a 10% or more performance improvement for
statement invocation.   The cache is on a per-DBAPI connection basis, which
means that the primary storage for prepared statements is within DBAPI
connections pooled within the connection pool.   The size of this cache
defaults to 100 statements per DBAPI connection and may be adjusted using the
``prepared_statement_cache_size`` DBAPI argument (note that while this argument
is implemented by SQLAlchemy, it is part of the DBAPI emulation portion of the
asyncpg dialect, therefore is handled as a DBAPI argument, not a dialect
argument)::


    engine = create_async_engine("postgresql+asyncpg://user:pass@hostname/dbname?prepared_statement_cache_size=500")

To disable the prepared statement cache, use a value of zero::

    engine = create_async_engine("postgresql+asyncpg://user:pass@hostname/dbname?prepared_statement_cache_size=0")

.. versionadded:: 1.4.0b2 Added ``prepared_statement_cache_size`` for asyncpg.


.. warning::  The ``asyncpg`` database driver necessarily uses caches for
   PostgreSQL type OIDs, which become stale when custom PostgreSQL datatypes
   such as ``ENUM`` objects are changed via DDL operations.   Additionally,
   prepared statements themselves which are optionally cached by SQLAlchemy's
   driver as described above may also become "stale" when DDL has been emitted
   to the PostgreSQL database which modifies the tables or other objects
   involved in a particular prepared statement.

   The SQLAlchemy asyncpg dialect will invalidate these caches within its local
   process when statements that represent DDL are emitted on a local
   connection, but this is only controllable within a single Python process /
   database engine.     If DDL changes are made from other database engines
   and/or processes, a running application may encounter asyncpg exceptions
   ``InvalidCachedStatementError`` and/or ``InternalServerError("cache lookup
   failed for type <oid>")`` if it refers to pooled database connections which
   operated upon the previous structures. The SQLAlchemy asyncpg dialect will
   recover from these error cases when the driver raises these exceptions by
   clearing its internal caches as well as those of the asyncpg driver in
   response to them, but cannot prevent them from being raised in the first
   place if the cached prepared statement or asyncpg type caches have gone
   stale, nor can it retry the statement as the PostgreSQL transaction is
   invalidated when these errors occur.

Disabling the PostgreSQL JIT to improve ENUM datatype handling
---------------------------------------------------------------

Asyncpg has an `issue <https://github.com/MagicStack/asyncpg/issues/727>`_ when
using PostgreSQL ENUM datatypes, where upon the creation of new database
connections, an expensive query may be emitted in order to retrieve metadata
regarding custom types which has been shown to negatively affect performance.
To mitigate this issue, the PostgreSQL "jit" setting may be disabled from the
client using this setting passed to :func:`_asyncio.create_async_engine`::

    engine = create_async_engine(
        "postgresql+asyncpg://user:password@localhost/tmp",
        connect_args={"server_settings": {"jit": "off"}},
    )

.. seealso::

    https://github.com/MagicStack/asyncpg/issues/727

    N   )json)_DECIMAL_TYPES)_FLOAT_TYPES)
_INT_TYPESENUMINTERVAL)OID)
PGCompiler)	PGDialect)PGExecutionContext)PGIdentifierPreparer)REGCLASSUUID   )exc)pool)
processors)util)AdaptedConnection)sqltypes)asyncio)await_fallback)
await_onlyc                       \ rS rSrS rSrg)AsyncpgTime   c                 T    U R                   (       a  UR                  $ UR                  $ N)timezone	TIME_W_TZTIMEselfdbapis     {C:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/dialects/postgresql/asyncpg.pyget_dbapi_typeAsyncpgTime.get_dbapi_type   s    ==??"::     N__name__
__module____qualname____firstlineno__r*   __static_attributes__r-   r,   r)   r   r      s    r,   r   c                       \ rS rSrS rSrg)AsyncpgDate   c                     UR                   $ r"   )DATEr&   s     r)   r*   AsyncpgDate.get_dbapi_type       zzr,   r-   Nr.   r-   r,   r)   r5   r5          r,   r5   c                       \ rS rSrS rSrg)AsyncpgDateTime   c                 T    U R                   (       a  UR                  $ UR                  $ r"   )r#   TIMESTAMP_W_TZ	TIMESTAMPr&   s     r)   r*   AsyncpgDateTime.get_dbapi_type   s    =='''??"r,   r-   Nr.   r-   r,   r)   r=   r=      s    #r,   r=   c                       \ rS rSrS rSrg)AsyncpgBoolean   c                     UR                   $ r"   )BOOLEANr&   s     r)   r*   AsyncpgBoolean.get_dbapi_type       }}r,   r-   Nr.   r-   r,   r)   rD   rD          r,   rD   c                   *    \ rS rSrS r\S 5       rSrg)AsyncPgInterval   c                     UR                   $ r"   r
   r&   s     r)   r*   AsyncPgInterval.get_dbapi_type   s    ~~r,   c                 (    [        UR                  S9$ )N)	precision)rL   second_precision)clsintervalkws      r)   adapt_emulated_to_native(AsyncPgInterval.adapt_emulated_to_native   s     )B)BCCr,   r-   N)r/   r0   r1   r2   r*   classmethodrV   r3   r-   r,   r)   rL   rL      s     D Dr,   rL   c                       \ rS rSrS rSrg)AsyncPgEnum   c                     UR                   $ r"   r   r&   s     r)   r*   AsyncPgEnum.get_dbapi_type   r:   r,   r-   Nr.   r-   r,   r)   rZ   rZ      r;   r,   rZ   c                       \ rS rSrS rSrg)AsyncpgInteger   c                     UR                   $ r"   INTEGERr&   s     r)   r*   AsyncpgInteger.get_dbapi_type   rI   r,   r-   Nr.   r-   r,   r)   r_   r_      rJ   r,   r_   c                       \ rS rSrS rSrg)AsyncpgBigInteger   c                     UR                   $ r"   )
BIGINTEGERr&   s     r)   r*    AsyncpgBigInteger.get_dbapi_type   s    r,   r-   Nr.   r-   r,   r)   rf   rf      s     r,   rf   c                        \ rS rSrS rS rSrg)AsyncpgJSON   c                     UR                   $ r"   )JSONr&   s     r)   r*   AsyncpgJSON.get_dbapi_type   r:   r,   c                     g r"   r-   r'   dialectcoltypes      r)   result_processorAsyncpgJSON.result_processor       r,   r-   Nr/   r0   r1   r2   r*   ru   r3   r-   r,   r)   rl   rl      s    r,   rl   c                        \ rS rSrS rS rSrg)AsyncpgJSONB   c                     UR                   $ r"   )JSONBr&   s     r)   r*   AsyncpgJSONB.get_dbapi_type       {{r,   c                     g r"   r-   rr   s      r)   ru   AsyncpgJSONB.result_processor   rw   r,   r-   Nrx   r-   r,   r)   rz   rz      s    r,   rz   c                       \ rS rSrS rSrg)AsyncpgJSONIndexType   c                     [        S5      e)Nzshould not be hereNotImplementedErrorr&   s     r)   r*   #AsyncpgJSONIndexType.get_dbapi_type   s    !"677r,   r-   Nr.   r-   r,   r)   r   r      s    8r,   r   c                       \ rS rSrS rSrg)AsyncpgJSONIntIndexType   c                     UR                   $ r"   rb   r&   s     r)   r*   &AsyncpgJSONIntIndexType.get_dbapi_type   rI   r,   r-   Nr.   r-   r,   r)   r   r      rJ   r,   r   c                       \ rS rSrS rSrg)AsyncpgJSONStrIndexType   c                     UR                   $ r"   STRINGr&   s     r)   r*   &AsyncpgJSONStrIndexType.get_dbapi_type       ||r,   r-   Nr.   r-   r,   r)   r   r          r,   r   c                       \ rS rSrS rSrg)AsyncpgJSONPathType   c                     S nU$ )Nc                     [        U [        R                  R                  5      (       d   eU  Vs/ s H  n[        R                  " U5      PM     nnU$ s  snf r"   )
isinstancer   collections_abcSequence	text_type)valueelemtokenss      r)   process3AsyncpgJSONPathType.bind_processor.<locals>.process   sH    eT%9%9%B%BCCCC7<=utdnnT*uF=M >s    Ar-   r'   rs   r   s      r)   bind_processor"AsyncpgJSONPathType.bind_processor   s    	
 r,   r-   N)r/   r0   r1   r2   r   r3   r-   r,   r)   r   r      s    r,   r   c                   &    \ rS rSrS rS rS rSrg)AsyncpgUUID   c                     UR                   $ r"   r   r&   s     r)   r*   AsyncpgUUID.get_dbapi_type   r:   r,   c                 T    U R                   (       d  UR                  (       a  S nU$ g g )Nc                 "    U b  [        U 5      n U $ r"   )_python_UUIDr   s    r)   r   +AsyncpgUUID.bind_processor.<locals>.process   s    $(/Er,   as_uuiduse_native_uuidr   s      r)   r   AsyncpgUUID.bind_processor   $    || 7 7
 N !8|r,   c                 T    U R                   (       d  UR                  (       a  S nU$ g g )Nc                 "    U b  [        U 5      n U $ r"   )strr   s    r)   r   -AsyncpgUUID.result_processor.<locals>.process	  s    $JEr,   r   )r'   rs   rt   r   s       r)   ru   AsyncpgUUID.result_processor  r   r,   r-   Nr/   r0   r1   r2   r*   r   ru   r3   r-   r,   r)   r   r      s    r,   r   c                   &    \ rS rSrS rS rS rSrg)AsyncpgNumerici  c                     UR                   $ r"   )NUMBERr&   s     r)   r*   AsyncpgNumeric.get_dbapi_type  r   r,   c                     g r"   r-   )r'   rs   s     r)   r   AsyncpgNumeric.bind_processor  rw   r,   c                    U R                   (       ag  U[        ;   a/  [        R                  " [        R
                  U R                  5      $ U[        ;   d
  U[        ;   a  g [        R                  " SU-  5      eU[        ;   a  g U[        ;   d
  U[        ;   a  [        R                  $ [        R                  " SU-  5      e)NzUnknown PG numeric type: %d)	asdecimalr   r   to_decimal_processor_factorydecimalDecimal_effective_decimal_return_scaler   r   r   InvalidRequestErrorto_floatrr   s      r)   ru   AsyncpgNumeric.result_processor  s    >>,&!>>OOT%I%I  N*g.C--1G;  ,&N*g.C!***--1G; r,   r-   Nr   r-   r,   r)   r   r     s    r,   r   c                       \ rS rSrS rSrg)AsyncpgFloati1  c                     UR                   $ r"   )FLOATr&   s     r)   r*   AsyncpgFloat.get_dbapi_type2  r   r,   r-   Nr.   r-   r,   r)   r   r   1  s    r,   r   c                       \ rS rSrS rSrg)AsyncpgREGCLASSi6  c                     UR                   $ r"   r   r&   s     r)   r*   AsyncpgREGCLASS.get_dbapi_type7  r   r,   r-   Nr.   r-   r,   r)   r   r   6  r   r,   r   c                       \ rS rSrS rSrg)
AsyncpgOIDi;  c                     UR                   $ r"   rb   r&   s     r)   r*   AsyncpgOID.get_dbapi_type<  rI   r,   r-   Nr.   r-   r,   r)   r   r   ;  rJ   r,   r   c                   &    \ rS rSrS rS rS rSrg)PGExecutionContext_asyncpgi@  c                     [        UU R                  R                  R                  U R                  R                  R                  45      (       a  U R                  R                  5         g g r"   )r   rs   r(   InvalidCachedStatementErrorInternalServerError_invalidate_schema_cache)r'   es     r)   handle_dbapi_exception1PGExecutionContext_asyncpg.handle_dbapi_exceptionA  sT    "">>""66
 
 LL113
r,   c                     U R                   (       a  U R                  R                  5         U R                  R                  U R                  l        U R
                  (       d  g [        R                  1U l        g r"   )	isddlrs   r   _invalidate_schema_cache_asofcursorcompiledAsyncAdapt_asyncpg_dbapir	   exclude_set_input_sizesr'   s    r)   pre_exec#PGExecutionContext_asyncpg.pre_execK  sT    ::LL113 LL66 	1 }}
 )A(E(E'F$r,   c                 4    U R                   R                  SS9$ )NT)server_side)_dbapi_connectionr   r   s    r)   create_server_side_cursor4PGExecutionContext_asyncpg.create_server_side_cursor[  s    %%,,,>>r,   )r   N)r/   r0   r1   r2   r   r   r   r3   r-   r,   r)   r   r   @  s    4G ?r,   r   c                       \ rS rSrSrg)PGCompiler_asyncpgi_  r-   Nr/   r0   r1   r2   r3   r-   r,   r)   r   r   _      r,   r   c                       \ rS rSrSrg)PGIdentifierPreparer_asyncpgic  r-   Nr   r-   r,   r)   r   r   c  r   r,   r   c                   r    \ rS rSrSrSrS rS rS rS r	S r
S	 rSS jrS rS rS rS rSS jrS rSrg
)AsyncAdapt_asyncpg_cursorig  )	_adapt_connection_connection_rowsdescription	arraysizerowcount_inputsizes_cursorr   Fc                     Xl         UR                  U l        / U l        S U l        S U l        SU l        SU l        S U l        SU l        g )Nr   r   )	r   r   r   r  r   r   r   r   r   )r'   adapt_connections     r)   __init__"AsyncAdapt_asyncpg_cursor.__init__v  sJ    !1+77
-.*r,   c                 "    / U R                   S S & g r"   r   r   s    r)   closeAsyncAdapt_asyncpg_cursor.close  s    

1r,   c                 :    U R                   R                  U5        g r"   )r   _handle_exceptionr'   errors     r)   r  +AsyncAdapt_asyncpg_cursor._handle_exception  s    007r,   c                     U R                   (       d  [        S [        US5       5       5      $ [        S [        S U R                    5       S5       5       5      $ )Nc              3   0   #    U  H  u  pS U-  v   M     g7f)$%dNr-   ).0idx_s      r)   	<genexpr>DAsyncAdapt_asyncpg_cursor._parameter_placeholders.<locals>.<genexpr>  s     H3G3Gs   r   c              3   J   #    U  H  u  pU(       a  S X4-  OSU-  v   M     g7f)z$%d::%sr  Nr-   )r  r  typs      r)   r  r    s/      !HC +.	SJ&53;>!s   !#c              3   L   #    U  H  n[         R                  U5      v   M     g 7fr"   )	_pg_typesget)r  r  s     r)   r  r    s     D3CCY]]3''3Cs   "$)r   tuple	enumerate)r'   paramss     r)   _parameter_placeholders1AsyncAdapt_asyncpg_cursor._parameter_placeholders  sR    H9VQ3GHHH  )D43C3CDa!  r,   c                   #    U R                   nUR                   IS h  vN   UR                  (       d  UR                  5       I S h  vN   Ub  XR	                  U5      -  nOSn UR                  XR                  5      I S h  vN u  pEU(       a>  U Vs/ s H*  nUR                  UR                  R                  S S S S S 4PM,     snU l
        OS U l
        U R                  (       a$  UR                  " U6 I S h  vN U l        SU l        OrUR                  " U6 I S h  vN U l        UR#                  5       n[$        R&                  " SU5      nU(       a   [)        UR+                  S5      5      U l        OSU l         S S S 5      IS h  vN   g  GNq GNK GNs  snf  N N! [,         a  n	U R/                  U	5         S n	A	NCS n	A	ff = f N?! , IS h  vN  (       d  f       g = f7f)Nr-   r  z)(?:SELECT|UPDATE|DELETE|INSERT \d+) (\d+)r   )r   _execute_mutex_started_start_transactionr   _preparer   nametypeoidr   r   r   r  r   fetchr   get_statusmsgrematchintgroup	Exceptionr  )
r'   	operation
parametersr  prepared_stmt
attributesattrstatusregr  s
             r)   _prepare_and_execute.AsyncAdapt_asyncpg_cursor._prepare_and_execute  s    11#222#,,&99;;;%%(D(D) 	  
%.2B2K2KAA3 -)  %/( %/D !II IIMM      %/(D$ (,D$##)6)=)=z)J#JDL$&DM'4':':J'G!GDJ*88:F((DfC (+CIIaL(9(*] 322 <-
(  $K "H  .&&u--.a 3222s   G&FG&%GF	G'F"FF"1F3F";F<F"GF"F  AF"6G7F">G?G&
G
G&GF"F" F""
G,G=GGG
G&G#GG#G&c                 6  #    U R                   nUR                   IS h  vN   UR                  U R                  5      I S h  vN   UR                  (       d  UR                  5       I S h  vN   XR                  US   5      -  n U R                  R                  X5      I S h  vN sS S S 5      IS h  vN   $  N Nz NS N N! [         a  nU R                  U5         S nAOS nAff = fS S S 5      IS h  vN    g ! , IS h  vN  (       d  f       g = f7fNr   )r   r#  _check_type_cache_invalidationr   r$  r%  r   r   executemanyr0  r  )r'   r1  seq_of_parametersr  r  s        r)   _executemany&AsyncAdapt_asyncpg_cursor._executemany  s     11#222"AA22   $,,&99;;;!$@$@!!$% I.!--99  322
 < 3   .&&u--.! 322222s   DB;DC?B=(C?+B?,C?C%C&C)D5C6D=C??C?CD
C*C% C?%C**C?-D8C;9D?DDDDNc                 X    U R                   R                  U R                  X5      5        g r"   )r   await_r8  )r'   r1  r2  s      r)   execute!AsyncAdapt_asyncpg_cursor.execute  s$    %%%%i<	
r,   c                 V    U R                   R                  U R                  X5      5      $ r"   )r   rB  r?  r'   r1  r>  s      r)   r=  %AsyncAdapt_asyncpg_cursor.executemany  s)    %%,,i;
 	
r,   c                     Xl         g r"   )r   )r'   
inputsizess     r)   setinputsizes'AsyncAdapt_asyncpg_cursor.setinputsizes  s    %r,   c              #      #    U R                   (       a1  U R                   R                  S5      v   U R                   (       a  M0  g g 7fr;  r   popr   s    r)   __iter__"AsyncAdapt_asyncpg_cursor.__iter__  s*     jj**..## jjjs   A AAc                 \    U R                   (       a  U R                   R                  S5      $ g r;  rM  r   s    r)   fetchone"AsyncAdapt_asyncpg_cursor.fetchone  s    ::::>>!$$r,   c                 z    Uc  U R                   nU R                  SU nU R                  US  U R                  S S & U$ r;  )r   r   )r'   sizeretvals      r)   	fetchmany#AsyncAdapt_asyncpg_cursor.fetchmany  s=    <>>DAd#

45)

1r,   c                 B    U R                   S S  n/ U R                   S S & U$ r"   r  )r'   rV  s     r)   fetchall"AsyncAdapt_asyncpg_cursor.fetchall  s!    A

1r,   )	r   r   r  r   r   r   r   r   r   r"   )r/   r0   r1   r2   	__slots__r   r  r	  r  r   r8  r?  rC  r=  rJ  rO  rR  rW  rZ  r3   r-   r,   r)   r   r   g  sR    
I K	/8	4.l.,



&$r,   r   c                   j   ^  \ rS rSrSrSrU 4S jrS rS rS r	S r
S	 rSS
 jrS rS rS rSrU =r$ )AsyncAdapt_asyncpg_ss_cursori  T)
_rowbufferc                 :   > [         [        U ]  U5        S U l        g r"   )superr^  r  r_  )r'   r  	__class__s     r)   r  %AsyncAdapt_asyncpg_ss_cursor.__init__  s    *D:;KLr,   c                      S U l         S U l        g r"   r  r_  r   s    r)   r	  "AsyncAdapt_asyncpg_ss_cursor.close  s    r,   c                     U R                   R                  U R                  R                  S5      5      n[        R
                  " U5      U l        g )N2   )r   rB  r  r*  collectionsdequer_  )r'   new_rowss     r)   _buffer_rows)AsyncAdapt_asyncpg_ss_cursor._buffer_rows  s9    ))001C1CB1GH%++H5r,   c                     U $ r"   r-   r   s    r)   	__aiter__&AsyncAdapt_asyncpg_ss_cursor.__aiter__  s    r,   c                  #    U R                   (       d  U R                  5          U R                   (       a0  U R                   R                  5       7v   U R                   (       a  M0  U R                  5         U R                   (       d  g Me  7fr"   r_  rl  popleftr   s    r)   	__anext__&AsyncAdapt_asyncpg_ss_cursor.__anext__  s]     //oo--// /// ?? s   A"B
&$B
c                     U R                   (       d"  U R                  5         U R                   (       d  g U R                   R                  5       $ r"   rr  r   s    r)   rR  %AsyncAdapt_asyncpg_ss_cursor.fetchone#  s2    ??&&((r,   c                    Uc  U R                  5       $ U R                  (       d  U R                  5         [        U R                  5      n[	        U5      nX:  aE  UR                  U R                  R                  U R                  R                  X-
  5      5      5        USU n[        R                  " X!S  5      U l        U$ r;  )rZ  r_  rl  listlenextendr   rB  r  r*  ri  rj  )r'   rU  buflbresults        r)   rW  &AsyncAdapt_asyncpg_ss_cursor.fetchmany*  s    <==?"4??#X9JJ&&--dll.@.@.KL Qt%++CJ7r,   c                     [        U R                  5      [        U R                  R                  U R	                  5       5      5      -   nU R                  R                  5         U$ r"   )ry  r_  r   rB  _allclear)r'   rets     r)   rZ  %AsyncAdapt_asyncpg_ss_cursor.fetchall<  sM    4??#d""))$))+6'
 
 	
r,   c                    #    / n U R                   R                  S5      I S h  vN nU(       a  UR                  U5        M>   U$  N!7f)Ni  )r  r*  r{  )r'   rowsbatchs      r)   r  !AsyncAdapt_asyncpg_ss_cursor._allC  sE      ,,,,T22EE" 3s   "AA"Ac                     [        S5      e)Nz2server side cursor doesn't support executemany yetr   rF  s      r)   r=  (AsyncAdapt_asyncpg_ss_cursor.executemanyQ  s    !@
 	
r,   re  r"   )r/   r0   r1   r2   r   r\  r  r	  rl  ro  rt  rR  rW  rZ  r  r=  r3   __classcell__rb  s   @r)   r^  r^    sD    KI6
)$
 
r,   r^  c                       \ rS rSrSr\" \5      rSS jrS r	S r
S r\S 5       r\R                  S 5       rS	 rS
 rSS jrS rS rS rS rS rS rSrg)AsyncAdapt_asyncpg_connectioniW  )r(   r   isolation_level_isolation_settingreadonly
deferrable_transactionr$  _prepared_statement_cacher   r#  c                 ,   Xl         X l        S=U l        U l        SU l        SU l        S U l        SU l        [        R                  " 5       U l	        [        R                  " 5       U l        U(       a  [        R                  " U5      U l        g S U l        g )Nread_committedF)r(   r   r  r  r  r  r  r$  timer   r   Lockr#  r   LRUCacher  )r'   r(   
connectionprepared_statement_cache_sizes       r)   r  &AsyncAdapt_asyncpg_connection.__init__h  sw    
%9IIt6 -1YY[*%lln(-1]]-.D* .2D*r,   c                    #    XR                   :  a)  U R                  R                  5       I S h  vN   Xl         g g  N7fr"   )r   r   reload_schema_state)r'   invalidate_timestamps     r)   r<  <AsyncAdapt_asyncpg_connection._check_type_cache_invalidationz  s8     "D"DD""668881E. E8s   -><>c                   #    U R                  U5      I S h  vN   U R                  nUc6  U R                  R                  U5      I S h  vN nUR	                  5       nXE4$ X;   a  X1   u  pEnXb:  a  XE4$ U R                  R                  U5      I S h  vN nUR	                  5       nXE[
        R
                  " 5       4X1'   XE4$  N N| N47fr"   )r<  r  r   prepareget_attributesr  )r'   r1  r  cacher3  r4  cached_timestamps          r)   r&  &AsyncAdapt_asyncpg_connection._prepare  s     112FGGG..="&"2"2":":9"EEM&557J ,,
 :?:J7M'7
  6$00"..66yAA"113
)tyy{C((1 	H F  Bs4   C
C1C
	C
A	C
C1C
C
C
c                 z   U R                   R                  5       (       a  S U l        SU l        [	        U[
        R                  5      (       dn  U R                  R                  n[        U5      R                   H=  nX2;   d  M
  X#   " [        U5      < SU< 35      n[        USS 5      =Ul        Ul        XAe   UeUe)NFz: sqlstate)r   	is_closedr  r$  r   r   Errorr(   _asyncpg_error_translater(  __mro__getattrpgcoder  )r'   r  exception_mappingsuper_translated_errors        r)   r  /AsyncAdapt_asyncpg_connection._handle_exception  s    %%'' $D!DM%!9!?!?@@ $

 C Cu+--.'8'@$(K7($
  z489$+(1*5 . Kr,   c                      U R                   S:H  $ N
autocommit)r  r   s    r)   r  (AsyncAdapt_asyncpg_connection.autocommit  s    ##|33r,   c                 D    U(       a  SU l         g U R                  U l         g r  )r  r  r'   r   s     r)   r  r    s    #/D #'#:#:D r,   c                 b    U R                   (       a  U R                  5         U=U l        U l        g r"   )r$  rollbackr  r  )r'   levels     r)   set_isolation_level1AsyncAdapt_asyncpg_connection.set_isolation_level  s"    ==MMO9>>t6r,   c                 R  #    U R                   S:X  a  g  U R                  R                  U R                   U R                  U R                  S9U l        U R
                  R                  5       I S h  vN   SU l        g  N! [         a  nU R                  U5         S nAg S nAff = f7f)Nr  )	isolationr  r  T)
r  r   transactionr  r  r  startr$  r0  r  r  s     r)   r%  0AsyncAdapt_asyncpg_connection._start_transaction  s     </
	! $ 0 0 < <..?? != !D
 ##))+++ !DM	 , 	*""5))	*sA   B'AA? 0A=1A? 5B'=A? ?
B$	BB'B$$B'c                 <    U(       a  [        U 5      $ [        U 5      $ r"   )r^  r   )r'   r   s     r)   r   $AsyncAdapt_asyncpg_connection.cursor  s    /55,T22r,   c                    #     U R                   R                  5       I S h  vN   S U l         SU l        g  N! S U l         SU l        f = f7fNF)r  r  r$  r   s    r)   _rollback_and_discard3AsyncAdapt_asyncpg_connection._rollback_and_discard  sJ     	"##,,... !%D!DM / !%D!DM%   A
7 57 A
7 AA
c                    #     U R                   R                  5       I S h  vN   S U l         SU l        g  N! S U l         SU l        f = f7fr  )r  commitr$  r   s    r)   _commit_and_discard1AsyncAdapt_asyncpg_connection._commit_and_discard  sJ     	"##**,,, !%D!DM - !%D!DMr  c                     U R                   (       a/   U R                  U R                  5       5        S U l        SU l         g g ! [         a  nU R                  U5         S nAg S nAff = fr  )r$  rB  r  r  r0  r  r  s     r)   r  &AsyncAdapt_asyncpg_connection.rollback  s\    ==.D6689$(! %	 
  . &&u--.   -A 
A'A""A'c                     U R                   (       a/   U R                  U R                  5       5        S U l        SU l         g g ! [         a  nU R                  U5         S nAg S nAff = fr  )r$  rB  r  r  r0  r  r  s     r)   r  $AsyncAdapt_asyncpg_connection.commit  s\    ==.D4467$(! %	 
  . &&u--.r  c                 v    U R                  5         U R                  U R                  R                  5       5        g r"   )r  rB  r   r	  r   s    r)   r	  #AsyncAdapt_asyncpg_connection.close  s&    D$$**,-r,   c                 8    U R                   R                  5         g r"   )r   	terminater   s    r)   r  'AsyncAdapt_asyncpg_connection.terminate  s    ""$r,   )r   r#  r   r  r  r$  r  r(   r  r  r  N)d   )F)r/   r0   r1   r2   r\  staticmethodr   rB  r  r<  r&  r  propertyr  setterr  r%  r   r  r  r  r  r	  r  r3   r-   r,   r)   r  r  W  s    I *%F2$F
)6, 4 4 ; ;?
! 3""	.	..
%r,   r  c                   (    \ rS rSrSr\" \5      rSrg)%AsyncAdaptFallback_asyncpg_connectioni  r-   N)	r/   r0   r1   r2   r\  r  r   rB  r3   r-   r,   r)   r  r    s    I.)Fr,   r  c                      \ rS rSrS rS r " S S\5      r " S S\5      r " S S	\5      r	 " S
 S\5      r
 " S S\
5      r " S S\
5      r " S S\
5      r " S S\
5      r " S S\
5      r " S S\
5      r " S S\5      r " S S\5      r\R(                  S 5       rS r\R.                  " S5      r\R.                  " S5      r\R.                  " S 5      r\R.                  " S!5      r\R.                  " S"5      r\R.                  " S#5      r\R.                  " S$5      r\R.                  " S%5      r\R.                  " S&5      r \R.                  " S'5      r!\R.                  " S(5      r"\R.                  " S)5      r#\R.                  " S*5      r$\R.                  " S+5      r%\R.                  " S,5      r&\R.                  " S-5      r'\R.                  " S.5      r(\R.                  " S/5      r)\R.                  " S05      r*\r+\*r,S1r-g2)3r   i  c                     Xl         SU l        g )Nformatasyncpg
paramstyler'   r  s     r)   r  !AsyncAdapt_asyncpg_dbapi.__init__  s    "r,   c           
      8   UR                  SS5      nUR                  SS5      n[        R                  " U5      (       a.  [        U [	        U R
                  R                  " U0 UD65      US9$ [        U [        U R
                  R                  " U0 UD65      US9$ )Nasync_fallbackFr  r  )r  )	rN  r   asboolr  r   r  connectr  r   )r'   argrU   r  r  s        r)   r   AsyncAdapt_asyncpg_dbapi.connect  s     0%8(*+S)
% ;;~&&8t||33S?B?@.K  14<<//;;<.K r,   c                       \ rS rSrSrg)AsyncAdapt_asyncpg_dbapi.Errori$  r-   Nr   r-   r,   r)   r  r  $      r,   r  c                       \ rS rSrSrg) AsyncAdapt_asyncpg_dbapi.Warningi'  r-   Nr   r-   r,   r)   Warningr  '  r  r,   r  c                       \ rS rSrSrg)'AsyncAdapt_asyncpg_dbapi.InterfaceErrori*  r-   Nr   r-   r,   r)   InterfaceErrorr  *  r  r,   r  c                       \ rS rSrSrg)&AsyncAdapt_asyncpg_dbapi.DatabaseErrori-  r-   Nr   r-   r,   r)   DatabaseErrorr  -  r  r,   r  c                       \ rS rSrSrg)&AsyncAdapt_asyncpg_dbapi.InternalErrori0  r-   Nr   r-   r,   r)   InternalErrorr  0  r  r,   r  c                       \ rS rSrSrg))AsyncAdapt_asyncpg_dbapi.OperationalErrori3  r-   Nr   r-   r,   r)   OperationalErrorr  3  r  r,   r  c                       \ rS rSrSrg))AsyncAdapt_asyncpg_dbapi.ProgrammingErrori6  r-   Nr   r-   r,   r)   ProgrammingErrorr  6  r  r,   r   c                       \ rS rSrSrg)'AsyncAdapt_asyncpg_dbapi.IntegrityErrori9  r-   Nr   r-   r,   r)   IntegrityErrorr  9  r  r,   r  c                       \ rS rSrSrg)"AsyncAdapt_asyncpg_dbapi.DataErrori<  r-   Nr   r-   r,   r)   	DataErrorr  <  r  r,   r  c                       \ rS rSrSrg)*AsyncAdapt_asyncpg_dbapi.NotSupportedErrori?  r-   Nr   r-   r,   r)   NotSupportedErrorr  ?  r  r,   r	  c                       \ rS rSrSrg),AsyncAdapt_asyncpg_dbapi.InternalServerErroriB  r-   Nr   r-   r,   r)   r   r  B  r  r,   r   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )4AsyncAdapt_asyncpg_dbapi.InvalidCachedStatementErroriE  c                 H   > [         [        R                  U ]   US-   5        g )Nzc (SQLAlchemy asyncpg dialect will now invalidate all prepared caches in response to this exception))ra  r   r   r  )r'   messagerb  s     r)   r  =AsyncAdapt_asyncpg_dbapi.InvalidCachedStatementError.__init__F  s-    (DDd E Er,   r-   )r/   r0   r1   r2   r  r3   r  r  s   @r)   r   r  E  s    	 	r,   r   c                    SS K nUR                  R                  U R                  UR                  R                  U R
                  UR                  R                  U R                  UR                  R                  U R                  UR                  R                  U R                  UR                  R                  U R                  0$ r;  )r  
exceptions!IntegrityConstraintViolationErrorr  PostgresErrorr  SyntaxOrAccessErrorr   r  r   r   r  s     r)   r  1AsyncAdapt_asyncpg_dbapi._asyncpg_error_translateN  s     @@$BUBU,,djj22D4I4I--t/B/B::D<\<\22D4L4L
 	
r,   c                     U$ r"   r-   r  s     r)   BinaryAsyncAdapt_asyncpg_dbapi.Binary[  s    r,   r   rA   r@   r%   r$   r8   r   r   r   rG   rc   ri   BYTESDECIMALro   r}   r	   r   BYTEAr  N).r/   r0   r1   r2   r  r  r0  r  r  r  r  r  r  r   r  r  r	  r   r   r   memoized_propertyr  r  symbolr   rA   r@   r%   r$   r8   r   r   r   rG   rc   ri   r  r  ro   r}   r	   r   r  DATETIMEBINARYr3   r-   r,   r)   r   r     s   #$	 )    = =  M M m &7  


 

 [["FK(I[[!12N;;vDK(I;;vD{{:&H[["FKK Ekk)$Gkk)$G\*JKK Ekk)$G;;vDKK E;;vD;;vDKK EHFr,   r   varchar	timestampztimestamp with time zonedater  ztime with time zonerT   numericfloatboolintegerbigintbytesr   r   jsonbenumuuidbyteac            
       ^  ^  \ rS rSrSrSrSrSrSrSr	Sr
Sr\r\r\rSrSr\R*                  " \R.                  0 \R2                  \_\R6                  \_\R:                  \_\R>                  \ _\!\ _\"\#_\RH                  \%_\RL                  \'_\RP                  \)_\RT                  \+_\RX                  \-_\R\                  \/_\0Rb                  \2_\R\                  Rf                  \4_\R\                  Rj                  \6_\R\                  Rn                  \8_\R\                  Rr                  \:_\Rv                  \<\=\>\?\@0E5      rSrASrBS rC\R                  S 5       rE\FS	 5       rG\R                  S
 5       rHS rIS rJS rKS rLS rMSS jrNS rO\FS 5       rPS rQS rRS rSS rTU 4S jrUS rVSrWU =rX$ )PGDialect_asyncpgi  r  Tr  Fr   c                 8    [         R                   " 5       U l        g r"   )r  r   r   s    r)   r   *PGDialect_asyncpg._invalidate_schema_cache  s    -1YY[*r,   c                    U R                   (       ai  [        U R                   S5      (       aN  [        [        R                  " SU R                   R
                  5       Vs/ s H  n[        U5      PM     sn5      $ gs  snf )N__version__z(\d+)(?:[-\.]?|$))c   r4  r4  )r(   hasattrr  r,  findallr3  r.  )r'   xs     r)   _dbapi_version PGDialect_asyncpg._dbapi_version  sm    ::'$**m<<  ZZ,djj.D.D F   s   A<c                 *    [        [        S5      5      $ )Nr  )r   
__import__)rS   s    r)   r(   PGDialect_asyncpg.dbapi  s    '
9(=>>r,   c                     SSSSS.$ )Nr  r  repeatable_readserializable)
AUTOCOMMITzREAD COMMITTEDzREPEATABLE READSERIALIZABLEr-   r   s    r)   _isolation_lookup#PGDialect_asyncpg._isolation_lookup  s     '.0*	
 	
r,   c                 D    U R                   UR                  SS5         nUR                  U5        g ! [         ab  n[        R                  " [
        R                  " SU< SU R                  < SSR                  U R                   5      < 35      US9   S nANyS nAff = f)Nr   zInvalid value 'z2' for isolation_level. Valid isolation levels for z are z, )replace_context)
rB  replaceKeyErrorr   raise_r   ArgumentErrorr'  joinr  )r'   r  r  errs       r)   r  %PGDialect_asyncpg.set_isolation_level  s    
	**5==c+BCE 	&&u-  	KK!! dii43I3I)JL
 !$	s   3 
BABBc                     X!l         g r"   r  r'   r  r   s      r)   set_readonlyPGDialect_asyncpg.set_readonly  s    #r,   c                     UR                   $ r"   rO  r'   r  s     r)   get_readonlyPGDialect_asyncpg.get_readonly  s    """r,   c                     X!l         g r"   r  rP  s      r)   set_deferrable PGDialect_asyncpg.set_deferrable  s     %r,   c                     UR                   $ r"   rX  rT  s     r)   get_deferrable PGDialect_asyncpg.get_deferrable  s    $$$r,   c                 $    UR                  5         g r"   )r  )r'   dbapi_connections     r)   do_terminatePGDialect_asyncpg.do_terminate  s    ""$r,   c                     UR                  SS9nUR                  UR                  5        [        R                  " US[
        5        [        R                  " US[
        5        / U4$ )Nuser)usernamer  port)translate_connect_argsupdatequeryr   coerce_kw_typer.  )r'   urloptss      r)   create_connect_args%PGDialect_asyncpg.create_connect_args  sT    ))6):CIID"A3GD&#.Dzr,   c                     UR                   R                  SS5      n[        R                  " U5      (       a  [        R
                  $ [        R                  $ )Nr  F)rh  r  r   r  r   FallbackAsyncAdaptedQueuePoolAsyncAdaptedQueuePool)rS   rj  r  s      r)   get_pool_class PGDialect_asyncpg.get_pool_class  s@     '7?;;~&&555---r,   c                     U(       a  UR                   R                  5       $ [        XR                  R                  5      =(       a    S[        U5      ;   $ )Nzconnection is closed)r   r  r   r(   r  r   )r'   r   r  r   s       r)   is_disconnectPGDialect_asyncpg.is_disconnect  sE    ))3355::,, 3(CF23r,   c                     U R                   (       a'  UR                  " U VVVs/ s H  u  pEoePM	     snnn6   g UR                  " S0 U VVVs0 s H  u  pEnU(       d  M  XE_M     snnnD6  g s  snnnf s  snnnf )Nr-   )
positionalrJ  )r'   r   list_of_tuplescontextkeydbtypesqltypes          r)   do_set_input_sizes$PGDialect_asyncpg.do_set_input_sizes  sw    ??  5CD^1S'&^D     1?0>,W  CK0> Es   A-A4A4c                    ^#    UR                   nU R                  =(       d    [        R                  mU4S jnUR	                  S[
        R                  USSS9I Sh  vN   g N7f)zset up JSON codec for asyncpg.

This occurs for all new connections and
can be overridden by third party dialects.

.. versionadded:: 1.4.27

c                 0   > T" U R                  5       5      $ r"   decode	bin_valuedeserializers    r)   _json_decoderAPGDialect_asyncpg.setup_asyncpg_json_codec.<locals>._json_decoder.  s    	 0 0 233r,   r   
pg_catalogbinaryencoderdecoderschemar  N)r   _json_deserializer_py_jsonloadsset_type_codecr   encode)r'   connasyncpg_connectionr  r  s       @r)   setup_asyncpg_json_codec*PGDialect_asyncpg.setup_asyncpg_json_codec!  s_      "--..@(..	4 !//JJ! 0 
 	
 	
s   AA%A#A%c                    ^#    UR                   nU R                  =(       d    [        R                  mS nU R                  =(       d    [        R                  mU4S jnUR	                  SUUSSS9I Sh  vN   g N7f)zset up JSONB codec for asyncpg.

This occurs for all new connections and
can be overridden by third party dialects.

.. versionadded:: 1.4.27

c                 (    SU R                  5       -   $ )N   )r  )	str_values    r)   _jsonb_encoderCPGDialect_asyncpg.setup_asyncpg_jsonb_codec.<locals>._jsonb_encoderF  s     Y--///r,   c                 6   > T" U SS  R                  5       5      $ )Nr   r  r  s    r)   _jsonb_decoderCPGDialect_asyncpg.setup_asyncpg_jsonb_codec.<locals>._jsonb_decoderM  s      	!" 4 4 677r,   r*  r  r  r  N)r   r  r  r  r  )r'   r  r  r  r  r  s        @r)   setup_asyncpg_jsonb_codec+PGDialect_asyncpg.setup_asyncpg_jsonb_codec9  sv      "--..@(..	0
 ..@(..	8
 !//"" 0 
 	
 	
s   A2A=5A;6A=c                 >   >^ ^ [         [        T ]  5       mU U4S jnU$ )zon_connect for asyncpg

A major component of this for asyncpg is to set up type decoders at the
asyncpg level.

See https://github.com/MagicStack/asyncpg/issues/623 for
notes on JSON/JSONB implementation.

c                    > U R                  TR                  U 5      5        U R                  TR                  U 5      5        Tb	  T" U 5        g g r"   )rB  r  r  )r  r'   super_connects    r)   r  -PGDialect_asyncpg.on_connect.<locals>.connectg  sD    KK55d;<KK66t<=(d# )r,   )ra  r/  
on_connect)r'   r  r  rb  s   ` @r)   r  PGDialect_asyncpg.on_connectZ  s!     /AC	$ r,   c                     UR                   $ r"   )r   rT  s     r)   get_driver_connection'PGDialect_asyncpg.get_driver_connectiono  s    %%%r,   )r   )returnN)Yr/   r0   r1   r2   driversupports_statement_cachesupports_unicode_statementssupports_server_side_cursorssupports_unicode_bindshas_terminatedefault_paramstylesupports_sane_multi_rowcountr   execution_ctx_clsr   statement_compilerr   prepareruse_setinputsizesr   r   update_copyr   colspecsr   Timer   Dater5   DateTimer=   IntervalrL   r   r   r   BooleanrD   Integerr_   
BigIntegerrf   Numericr   Floatr   ro   rl   r   r}   rz   JSONPathTyper   JSONIndexTyper   JSONIntIndexTyper   JSONStrIndexTyper   EnumrZ   r   r   r   r   is_asyncr   r   r  r8  rX   r(   rB  r  rQ  rU  rY  r\  r`  rl  rq  rt  r}  r  r  r  r  r3   r  r  s   @r)   r/  r/    sg   F#"&#' !M!#( 2++HO	
MM;	
MM;	
 	
 		

 o	
 +	
 n	
 n	
 !2	
 n	
 NNL	
 MM;	
 JJ	
 MM&&(;	
 MM'')=	
  MM**,C!	
" MM**,C#	
$ MM;o)	
H2 H$%!9 
    ? ? 

 
.$#&%% . .3
0
B*& &r,   r/  )]__doc__ri  r   r   r  r,  r   baser   r   r   r	   r   r   r   r   r   r   r   r   r   r   r   r   enginer   sqlr   util.concurrencyr   r   r   r,  r   ImportErrorr  r   r  r5   r  r=   r  rD   rL   rZ   r  r_   r  rf   ro   rl   r}   rz   r  r   r  r   r  r   r  r   r   r  r   r   r   r   r   r   r   r   r^  r  r  r   r   rA   r@   r8   r%   r$   r   r   rG   rc   ri   r  r  r  r  r/  rs   r-   r,   r)   <module>r     s  ob    	            $ &       '  ' . *)
(-- (-- 
#h'' #X%% 
Dh D$ 
X%% 
 ++  
$)) 4:: 88==66 8
hmm<< 
hmm<< 
$++ $ 2X%% @> 
h 
 
?!3 ?>	 		#7 	Y YxQ
#< Q
hm%$5 m%`*,I *f fR##Y&& ++-G !!6	
 !!6 &&(= %%z ##Y ""G $$f $$i '' ""G $$i !!6  ""G!" !!6#$ !!6""G'	.c&	 c&L w  Ls   M0 0M<;M<