
    -h^              	       l   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  \	R"                  " SS05      r\	R"                  " SS05      r\	R(                  " \SSSS// SQ/ SQS9 " S S\5      5       r " S S5      r " S S\\5      rS rS r\\l        g)     N   )engine)result)ReversibleProxy)StartableContext)_ensure_sync_result   )util)object_session)Session)state)greenlet_spawnprebuffer_rowsTstream_resultsz:class:`_orm.Session`z:class:`_asyncio.AsyncSession`r   identity_key)__contains____iter__addadd_allexpire
expire_allexpungeexpunge_allis_modifiedin_transactionin_nested_transaction)dirtydeletednewidentity_map	is_active	autoflushno_autoflushinfo)classmethodsmethods
attributesc                      \ rS rSr% SrSrSrS!S jr\r	 \\
S'     S"S jrS rS\R                  S4S	 jrS\R                  S4S
 jrS\R                  S4S jr    S#S jrS\R                  S4S jrS\R                  S4S jrS rS$S jrS%S jrS rS rS!S jrS rS rS rS rS rS r S r!\"S 5       r#S r$S r%S r&S r'g)&AsyncSession   aI  Asyncio version of :class:`_orm.Session`.

The :class:`_asyncio.AsyncSession` is a proxy for a traditional
:class:`_orm.Session` instance.

.. versionadded:: 1.4

To use an :class:`_asyncio.AsyncSession` with custom :class:`_orm.Session`
implementations, see the
:paramref:`_asyncio.AsyncSession.sync_session_class` parameter.


TNc                 d   SUS'   U(       a  Xl         [        R                  " U5      nU(       a?  X l        UR	                  5        VVs0 s H  u  pVU[        R                  " U5      _M     nnnU(       a  X0l        U R                  U R
                  " SXS.UD65      =U l        U l        gs  snnf )a}  Construct a new :class:`_asyncio.AsyncSession`.

All parameters other than ``sync_session_class`` are passed to the
``sync_session_class`` callable directly to instantiate a new
:class:`_orm.Session`. Refer to :meth:`_orm.Session.__init__` for
parameter documentation.

:param sync_session_class:
  A :class:`_orm.Session` subclass or other callable which will be used
  to construct the :class:`_orm.Session` which will be proxied. This
  parameter may be used to provide custom :class:`_orm.Session`
  subclasses. Defaults to the
  :attr:`_asyncio.AsyncSession.sync_session_class` class-level
  attribute.

  .. versionadded:: 1.4.24

Tfuture)bindbindsN )	r-   r   _get_sync_engine_or_connectionr.   itemssync_session_class_assign_proxiedsync_session_proxied)selfr-   r.   r2   kwkeybs          sC:\Users\ROHAN GUPTA\OneDrive\Desktop\mathbuddy-assessment\venv\Lib\site-packages\sqlalchemy/ext/asyncio/session.py__init__AsyncSession.__init__H   s    & 8I88>DJ $kkm+FC V::1==+  
 &8#,0,@,@##AAbA-
 	
DMs   	#B,r4   c                 ^   #    [        U R                  R                  UUUS9I Sh  vN $  N7f)a}  Expire and refresh the attributes on the given instance.

A query will be issued to the database and all attributes will be
refreshed with their current database value.

This is the async version of the :meth:`_orm.Session.refresh` method.
See that method for a complete description of all options.

.. seealso::

    :meth:`_orm.Session.refresh` - main documentation for refresh

)attribute_nameswith_for_updateN)r   r4   refresh)r6   instancer>   r?   s       r:   r@   AsyncSession.refresh   s6     " $%%++	
 
 	
 
   $-+-c                 P   #    [        XR                  /UQ70 UD6I Sh  vN $  N7f)a  Invoke the given sync callable passing sync self as the first
argument.

This method maintains the asyncio event loop all the way through
to the database connection by running the given callable in a
specially instrumented greenlet.

E.g.::

    with AsyncSession(async_engine) as session:
        await session.run_sync(some_business_method)

.. note::

    The provided callable is invoked inline within the asyncio event
    loop, and will block on traditional IO calls.  IO within this
    callable should only call into SQLAlchemy's asyncio database
    APIs which will be properly adapted to the greenlet context.

.. seealso::

    :ref:`session_run_sync`
N)r   r4   )r6   fnargr7   s       r:   run_syncAsyncSession.run_sync   s(     2 $B(9(9FCF2FFFFs   &$&c                   #    U(       a*  [         R                  " U5      R                  [        5      nO[        n[	        U R
                  R                  U4UUUS.UD6I Sh  vN n[        X`R                  5      I Sh  vN $  N! N7f)zExecute a statement and return a buffered
:class:`_engine.Result` object.

.. seealso::

    :meth:`_orm.Session.execute` - main documentation for execute

paramsexecution_optionsbind_argumentsN)r
   immutabledictunion_EXECUTE_OPTIONSr   r4   executer   r6   	statementrK   rL   rM   r7   r   s          r:   rQ   AsyncSession.execute   s     "  $ 2 23D E K K ! !1%%%
 /)
 
 
 )>>>
 ?s$   A B"B#B?B BBc                 l   #    U R                   " U4UUUS.UD6I Sh  vN nUR                  5       $  N7f)zExecute a statement and return a scalar result.

.. seealso::

    :meth:`_orm.Session.scalar` - main documentation for scalar

rJ   N)rQ   scalarrR   s          r:   rV   AsyncSession.scalar   sH       ||
/)	

 
 
 }}
   424c                 l   #    U R                   " U4UUUS.UD6I Sh  vN nUR                  5       $  N7f)a  Execute a statement and return scalar results.

:return: a :class:`_result.ScalarResult` object

.. versionadded:: 1.4.24 Added :meth:`_asyncio.AsyncSession.scalars`

.. versionadded:: 1.4.26 Added
   :meth:`_asyncio.async_scoped_session.scalars`

.. seealso::

    :meth:`_orm.Session.scalars` - main documentation for scalars

    :meth:`_asyncio.AsyncSession.stream_scalars` - streaming version

rJ   N)rQ   scalarsrR   s          r:   rZ   AsyncSession.scalars   sI     2 ||
/)	

 
 
 ~~
rX   c           
      d   #    [        U R                  R                  UUUUUUS9I Sh  vN $  N7f)zReturn an instance based on the given primary key identifier,
or ``None`` if not found.

.. seealso::

    :meth:`_orm.Session.get` - main documentation for get


)optionspopulate_existingr?   identity_tokenN)r   r4   get)r6   entityidentr]   r^   r?   r_   s          r:   r`   AsyncSession.get  s?     $ $!!/+)
 
 	
 
s   '0.0c                   #    U(       a*  [         R                  " U5      R                  [        5      nO[        n[	        U R
                  R                  U4UUUS.UD6I Sh  vN n[        R                  " U5      $  N7f)zRExecute a statement and return a streaming
:class:`_asyncio.AsyncResult` object.

rJ   N)	r
   rN   rO   _STREAM_OPTIONSr   r4   rQ   _resultAsyncResultrR   s          r:   streamAsyncSession.stream7  s       $ 2 23D E K K! !0%%%
 /)
 
 
 ""6**
s   A A?"A=#A?c                 l   #    U R                   " U4UUUS.UD6I Sh  vN nUR                  5       $  N7f)a"  Execute a statement and return a stream of scalar results.

:return: an :class:`_asyncio.AsyncScalarResult` object

.. versionadded:: 1.4.24

.. seealso::

    :meth:`_orm.Session.scalars` - main documentation for scalars

    :meth:`_asyncio.AsyncSession.scalars` - non streaming version

rJ   N)rh   rZ   rR   s          r:   stream_scalarsAsyncSession.stream_scalarsU  sI     , {{
/)	

 
 
 ~~
rX   c                 ^   #    [        U R                  R                  U5      I Sh  vN $  N7f)a$  Mark an instance as deleted.

The database delete operation occurs upon ``flush()``.

As this operation may need to cascade along unloaded relationships,
it is awaitable to allow for those queries to take place.

.. seealso::

    :meth:`_orm.Session.delete` - main documentation for delete

N)r   r4   delete)r6   rA   s     r:   rn   AsyncSession.deletet  s&      $D$5$5$<$<hGGGGrC   c                 \   #    [        U R                  R                  XUS9I Sh  vN $  N7f)zCopy the state of a given instance into a corresponding instance
within this :class:`_asyncio.AsyncSession`.

.. seealso::

    :meth:`_orm.Session.merge` - main documentation for merge

)loadr]   N)r   r4   merge)r6   rA   rq   r]   s       r:   rr   AsyncSession.merge  s1      $##X'
 
 	
 
   #,*,c                 \   #    [        U R                  R                  US9I Sh  vN   g N7f)z|Flush all the object changes to the database.

.. seealso::

    :meth:`_orm.Session.flush` - main documentation for flush

)objectsN)r   r4   flush)r6   rv   s     r:   rw   AsyncSession.flush  s#      T..44gFFFs   ",*,c                 h    U R                   R                  5       nUb  [        R                  U5      $ g)zReturn the current root transaction in progress, if any.

:return: an :class:`_asyncio.AsyncSessionTransaction` object, or
 ``None``.

.. versionadded:: 1.4.18

N)r4   get_transactionAsyncSessionTransaction_retrieve_proxy_for_targetr6   transs     r:   rz   AsyncSession.get_transaction  s2     !!113*EEeLL    c                 h    U R                   R                  5       nUb  [        R                  U5      $ g)zReturn the current nested transaction in progress, if any.

:return: an :class:`_asyncio.AsyncSessionTransaction` object, or
 ``None``.

.. versionadded:: 1.4.18

N)r4   get_nested_transactionr{   r|   r}   s     r:   r   #AsyncSession.get_nested_transaction  s2     !!88:*EEeLLr   c                 @    U R                   R                  " SXUS.UD6$ )a  Return a "bind" to which the synchronous proxied :class:`_orm.Session`
is bound.

Unlike the :meth:`_orm.Session.get_bind` method, this method is
currently **not** used by this :class:`.AsyncSession` in any way
in order to resolve engines for requests.

.. note::

    This method proxies directly to the :meth:`_orm.Session.get_bind`
    method, however is currently **not** useful as an override target,
    in contrast to that of the :meth:`_orm.Session.get_bind` method.
    The example below illustrates how to implement custom
    :meth:`_orm.Session.get_bind` schemes that work with
    :class:`.AsyncSession` and :class:`.AsyncEngine`.

The pattern introduced at :ref:`session_custom_partitioning`
illustrates how to apply a custom bind-lookup scheme to a
:class:`_orm.Session` given a set of :class:`_engine.Engine` objects.
To apply a corresponding :meth:`_orm.Session.get_bind` implementation
for use with a :class:`.AsyncSession` and :class:`.AsyncEngine`
objects, continue to subclass :class:`_orm.Session` and apply it to
:class:`.AsyncSession` using
:paramref:`.AsyncSession.sync_session_class`. The inner method must
continue to return :class:`_engine.Engine` instances, which can be
acquired from a :class:`_asyncio.AsyncEngine` using the
:attr:`_asyncio.AsyncEngine.sync_engine` attribute::

    # using example from "Custom Vertical Partitioning"


    import random

    from sqlalchemy.ext.asyncio import AsyncSession
    from sqlalchemy.ext.asyncio import create_async_engine
    from sqlalchemy.orm import Session, sessionmaker

    # construct async engines w/ async drivers
    engines = {
        'leader':create_async_engine("sqlite+aiosqlite:///leader.db"),
        'other':create_async_engine("sqlite+aiosqlite:///other.db"),
        'follower1':create_async_engine("sqlite+aiosqlite:///follower1.db"),
        'follower2':create_async_engine("sqlite+aiosqlite:///follower2.db"),
    }

    class RoutingSession(Session):
        def get_bind(self, mapper=None, clause=None, **kw):
            # within get_bind(), return sync engines
            if mapper and issubclass(mapper.class_, MyOtherClass):
                return engines['other'].sync_engine
            elif self._flushing or isinstance(clause, (Update, Delete)):
                return engines['leader'].sync_engine
            else:
                return engines[
                    random.choice(['follower1','follower2'])
                ].sync_engine

    # apply to AsyncSession using sync_session_class
    AsyncSessionMaker = sessionmaker(
        class_=AsyncSession,
        sync_session_class=RoutingSession
    )

The :meth:`_orm.Session.get_bind` method is called in a non-asyncio,
implicitly non-blocking context in the same manner as ORM event hooks
and functions that are invoked via :meth:`.AsyncSession.run_sync`, so
routines that wish to run SQL commands inside of
:meth:`_orm.Session.get_bind` can continue to do so using
blocking-style code, which will be translated to implicitly async calls
at the point of invoking IO on the database drivers.

)mapperclauser-   r/   )r4   get_bind)r6   r   r   r-   r7   s        r:   r   AsyncSession.get_bind  s0    T   )) 
t
79
 	
r   c                    #    [        U R                  R                  40 UD6I Sh  vN n[        R                  R                  U5      $  N#7f)a  Return a :class:`_asyncio.AsyncConnection` object corresponding to
this :class:`.Session` object's transactional state.

This method may also be used to establish execution options for the
database connection used by the current transaction.

.. versionadded:: 1.4.24  Added \**kw arguments which are passed
   through to the underlying :meth:`_orm.Session.connection` method.

.. seealso::

    :meth:`_orm.Session.connection` - main documentation for
    "connection"

N)r   r4   
connectionr   AsyncConnectionr|   )r6   r7   sync_connections      r:   r   AsyncSession.connection  sP     " !/((!
,.!
 
 %%@@
 	

s   $AA
$Ac                     [        U 5      $ )a~  Return an :class:`_asyncio.AsyncSessionTransaction` object.

The underlying :class:`_orm.Session` will perform the
"begin" action when the :class:`_asyncio.AsyncSessionTransaction`
object is entered::

    async with async_session.begin():
        # .. ORM transaction is begun

Note that database IO will not normally occur when the session-level
transaction is begun, as database transactions begin on an
on-demand basis.  However, the begin block is async to accommodate
for a :meth:`_orm.SessionEvents.after_transaction_create`
event hook that may perform IO.

For a general description of ORM begin, see
:meth:`_orm.Session.begin`.

r{   r6   r7   s     r:   beginAsyncSession.begin  s    * 't,,r   c                     [        U SS9$ )a  Return an :class:`_asyncio.AsyncSessionTransaction` object
which will begin a "nested" transaction, e.g. SAVEPOINT.

Behavior is the same as that of :meth:`_asyncio.AsyncSession.begin`.

For a general description of ORM begin nested, see
:meth:`_orm.Session.begin_nested`.

T)nestedr   r   s     r:   begin_nestedAsyncSession.begin_nested6  s     'tD99r   c                 \   #    [        U R                  R                  5      I Sh  vN $  N7f)z-Rollback the current transaction in progress.N)r   r4   rollbackr6   s    r:   r   AsyncSession.rollbackC  s"     #D$5$5$>$>????rt   c                 \   #    [        U R                  R                  5      I Sh  vN $  N7f)z+Commit the current transaction in progress.N)r   r4   commitr   s    r:   r   AsyncSession.commitG  s"     #D$5$5$<$<====rt   c                 ^   #    [        U R                  R                  5      I Sh  vN   g N7f)a  Close out the transactional resources and ORM objects used by this
:class:`_asyncio.AsyncSession`.

This expunges all ORM objects associated with this
:class:`_asyncio.AsyncSession`, ends any transaction in progress and
:term:`releases` any :class:`_asyncio.AsyncConnection` objects which
this :class:`_asyncio.AsyncSession` itself has checked out from
associated :class:`_asyncio.AsyncEngine` objects. The operation then
leaves the :class:`_asyncio.AsyncSession` in a state which it may be
used again.

.. tip::

    The :meth:`_asyncio.AsyncSession.close` method **does not prevent
    the Session from being used again**. The
    :class:`_asyncio.AsyncSession` itself does not actually have a
    distinct "closed" state; it merely means the
    :class:`_asyncio.AsyncSession` will release all database
    connections and ORM objects.


.. seealso::

    :ref:`session_closing` - detail on the semantics of
    :meth:`_asyncio.AsyncSession.close`

N)r   r4   closer   s    r:   r   AsyncSession.closeK  s!     8 T..44555s   #-+-c                 \   #    [        U R                  R                  5      I Sh  vN $  N7f)zuClose this Session, using connection invalidation.

For a complete description, see :meth:`_orm.Session.invalidate`.
N)r   r4   
invalidater   s    r:   r   AsyncSession.invalidatei  s$     
 $D$5$5$@$@AAAArt   c                 \   #    [        U R                  R                  5      I Sh  vN $  N7f)z2Close all :class:`_asyncio.AsyncSession` sessions.N)r   r4   	close_allr   s    r:   r   AsyncSession.close_allp  s$      $D$5$5$?$?@@@@rt   c                    #    U $ 7fNr/   r   s    r:   
__aenter__AsyncSession.__aenter__u  s
     s   c                    #    [         R                  " 5       R                  U R                  5       5      n[         R                  " U5      I S h  vN   g  N7fr   )asyncioget_event_loopcreate_taskr   shield)r6   type_value	tracebacktasks        r:   	__aexit__AsyncSession.__aexit__x  s6     %%'33DJJLAnnT"""s   AAAAc                     [        U 5      $ r   )_AsyncSessionContextManagerr   s    r:   _maker_context_manager#AsyncSession._maker_context_manager|  s    *400r   )r5   r-   r.   r4   r2   )NNN)NN)NFNN)TNr   )(__name__
__module____qualname____firstlineno____doc___is_asynciodispatchr;   r   r2   __annotations__r@   rG   r
   
EMPTY_DICTrQ   rV   rZ   r`   rh   rk   rn   rr   rw   rz   r   r   r   r   r   r   r   r   r   classmethodr   r   r   r   __static_attributes__r/   r   r:   r)   r)      s*   < KH$
L !  	 ?C
0G< // ?J //8 //  L 
> //+B // >H
G L
\
0-.:@>6<B A A#1r   r)   c                   &    \ rS rSrS rS rS rSrg)r   i  c                     Xl         g r   )async_session)r6   r   s     r:   r;   $_AsyncSessionContextManager.__init__  s    *r   c                    #    U R                   R                  5       U l        U R                  R                  5       I S h  vN   U R                   $  N7fr   )r   r   r~   r   r   s    r:   r   &_AsyncSessionContextManager.__aenter__  sB     ''--/
jj##%%%!!! 	&s   =AA Ac                    ^ ^^^#    U UUU4S jn[         R                  " 5       R                  U" 5       5      n[         R                  " U5      I S h  vN   g  N7f)Nc                     >#    T R                   R                  TTT5      I S h  vN   T R                  R                  TTT5      I S h  vN   g  N* N7fr   )r~   r   r   )r6   r   r   r   s   r:   go1_AsyncSessionContextManager.__aexit__.<locals>.go  sI     **&&ueY???$$..ueYGGG @Gs!   !AA$A	A
AA)r   r   r   r   )r6   r   r   r   r   r   s   ````  r:   r   %_AsyncSessionContextManager.__aexit__  sA     	H 	H %%'33BD9nnT"""s   AAAA)r   r~   N)r   r   r   r   r;   r   r   r   r/   r   r:   r   r     s    +"
#r   r   c                   X    \ rS rSrSrSrSS jr\S 5       rS r	S r
S rSS	 jrS
 rSrg)r{   i  a  A wrapper for the ORM :class:`_orm.SessionTransaction` object.

This object is provided so that a transaction-holding object
for the :meth:`_asyncio.AsyncSession.begin` may be returned.

The object supports both explicit calls to
:meth:`_asyncio.AsyncSessionTransaction.commit` and
:meth:`_asyncio.AsyncSessionTransaction.rollback`, as well as use as an
async context manager.


.. versionadded:: 1.4

)sessionsync_transactionr   c                 *    Xl         X l        S U l        g r   )r   r   r   )r6   r   r   s      r:   r;    AsyncSessionTransaction.__init__  s     $r   c                 h    U R                  5       S L=(       a    U R                  5       R                  $ r   )_sync_transactionr!   r   s    r:   r!   !AsyncSessionTransaction.is_active  s1     ""$D0 3&&(22	
r   c                 \    U R                   (       d  U R                  5         U R                   $ r   )r   _raise_for_not_startedr   s    r:   r   )AsyncSessionTransaction._sync_transaction  s#    $$'')$$$r   c                 f   #    [        U R                  5       R                  5      I Sh  vN   g N7f)z2Roll back this :class:`_asyncio.AsyncTransaction`.N)r   r   r   r   s    r:   r    AsyncSessionTransaction.rollback  s"     T335>>???   '1/1c                 f   #    [        U R                  5       R                  5      I Sh  vN   g N7f)z/Commit this :class:`_asyncio.AsyncTransaction`.N)r   r   r   r   s    r:   r   AsyncSessionTransaction.commit  s$      T335<<===r   c                 @  #    U R                  [        U R                  (       a   U R                  R                  R
                  OU R                  R                  R                  5      I S h  vN 5      U l        U(       a  U R                  R                  5         U $  N07fr   )	r3   r   r   r   r4   r   r   r   	__enter__)r6   is_ctxmanagers     r:   startAsyncSessionTransaction.start  su      $ 4 4 ;; ))66\\..44 !
 !!++-s   A)B+B,1Bc                 j   #    [        U R                  5       R                  XU5      I S h  vN   g  N7fr   )r   r   __exit__)r6   r   r   r   s       r:   r   !AsyncSessionTransaction.__aexit__  s-     ""$--uY
 	
 	
s   )313)r   r   r   N)F)r   r   r   r   r   	__slots__r;   propertyr!   r   r   r   r   r   r   r/   r   r:   r{   r{     sA     :I%
 
 
%
@>


r   r{   c                 6    [        U 5      nUb  [        U5      $ g)aw  Return the :class:`_asyncio.AsyncSession` to which the given instance
belongs.

This function makes use of the sync-API function
:class:`_orm.object_session` to retrieve the :class:`_orm.Session` which
refers to the given instance, and from there links it to the original
:class:`_asyncio.AsyncSession`.

If the :class:`_asyncio.AsyncSession` has been garbage collected, the
return value is ``None``.

This functionality is also available from the
:attr:`_orm.InstanceState.async_session` accessor.

:param instance: an ORM mapped instance
:return: an :class:`_asyncio.AsyncSession` object, or ``None``.

.. versionadded:: 1.4.18

N)r   r   )rA   r   s     r:   async_object_sessionr     s"    , X&GW%%r   c                 *    [         R                  U SS9$ )zReturn the :class:`_asyncio.AsyncSession` which is proxying the given
:class:`_orm.Session` object, if any.

:param session: a :class:`_orm.Session` instance.
:return: a :class:`_asyncio.AsyncSession` instance, or ``None``.

.. versionadded:: 1.4.18

F)
regenerate)r)   r|   )r   s    r:   r   r     s     227u2MMr   )r    r   r   rf   baser   r   r   r
   ormr   r   r   _instance_stateutil.concurrencyr   rN   rP   re   create_proxy_methodsr)   r   r{   r   r   _async_providerr/   r   r:   <module>r      s       ! " '  !  + .%%'7&>? $$&6%=> $"N3	%:I	1? I	1;:I	1X# #$;
o/? ;
|:
N #0 r   