
    +hY              	           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gZ G d de      Z eeddg dg dg d       G d d
e             ZeZy)   )class_mapper)exc)Session   )create_proxy_methods)ScopedRegistry)ThreadLocalRegistry)warn)warn_deprecatedscoped_sessionScopedSessionMixinc                   (    e Zd Zed        Zd Zd Zy)r   c                 "    | j                         S N)registryselfs    I/var/www/html/venv/lib/python3.12/site-packages/sqlalchemy/orm/scoping.py_proxiedzScopedSessionMixin._proxied   s    }}    c                 ,   |r]| j                   j                         rt        j                  d       | j                  di |}| j                   j                  |       n| j                         }| j                  s|j                  rt        dd       |S )a  Return the current :class:`.Session`, creating it
        using the :attr:`.scoped_session.session_factory` if not present.

        :param \**kw: Keyword arguments will be passed to the
         :attr:`.scoped_session.session_factory` callable, if an existing
         :class:`.Session` is not present.  If the :class:`.Session` is present
         and keyword arguments have been passed,
         :exc:`~sqlalchemy.exc.InvalidRequestError` is raised.

        zEScoped session is already present; no new arguments may be specified.zUsing `scoped_session` with asyncio is deprecated and will raise an error in a future version. Please use `async_scoped_session` instead.z1.4.23 )	r   hassa_excInvalidRequestErrorsession_factoryset_support_async_is_asyncior   )r   kwsesss      r   __call__zScopedSessionMixin.__call__   s     }}  "009 
 ,t++1b1!!$'==?D""t'7'7= 	 r   c                     | j                   j                         rt        d        | j                  j                  di | y)zreconfigure the :class:`.sessionmaker` used by this
        :class:`.scoped_session`.

        See :meth:`.sessionmaker.configure`.

        ztAt least one scoped session is already present.  configure() can not affect sessions that have already been created.Nr   )r   r   r
   r   	configure)r   kwargss     r   r$   zScopedSessionMixin.configure9   s<     ==( 	'&&00r   N)__name__
__module____qualname__propertyr   r"   r$   r   r   r   r   r      s     >1r   z:class:`_orm.Session`z$:class:`_orm.scoping.scoped_session`)	close_allobject_sessionidentity_key)__contains____iter__addadd_allbeginbegin_nestedclosecommit
connectiondeleteexecuteexpire
expire_allexpungeexpunge_allflushgetget_bindis_modifiedbulk_save_objectsbulk_insert_mappingsbulk_update_mappingsmergequeryrefreshrollbackscalarscalars)
binddirtydeletednewidentity_map	is_active	autoflushno_autoflushinfo
autocommit)classmethodsmethods
attributesc                   0    e Zd ZdZdZdZ	 ddZd ZddZy)r   a4  Provides scoped management of :class:`.Session` objects.

    See :ref:`unitofwork_contextual` for a tutorial.

    .. note::

       When using :ref:`asyncio_toplevel`, the async-compatible
       :class:`_asyncio.async_scoped_session` class should be
       used in place of :class:`.scoped_session`.

    FNc                 Z    || _         |rt        ||      | _        yt        |      | _        y)a  Construct a new :class:`.scoped_session`.

        :param session_factory: a factory to create new :class:`.Session`
         instances. This is usually, but not necessarily, an instance
         of :class:`.sessionmaker`.
        :param scopefunc: optional function which defines
         the current scope.   If not passed, the :class:`.scoped_session`
         object assumes "thread-local" scope, and will use
         a Python ``threading.local()`` in order to maintain the current
         :class:`.Session`.  If passed, the function should return
         a hashable token; this token will be used as the key in a
         dictionary in order to store and retrieve the current
         :class:`.Session`.

        N)r   r   r   r	   )r   r   	scopefuncs      r   __init__zscoped_session.__init__   s)       /*?IFDM/@DMr   c                     | j                   j                         r| j                         j                          | j                   j                          y)a  Dispose of the current :class:`.Session`, if present.

        This will first call :meth:`.Session.close` method
        on the current :class:`.Session`, which releases any existing
        transactional/connection resources still being held; transactions
        specifically are rolled back.  The :class:`.Session` is then
        discarded.   Upon next usage within the same scope,
        the :class:`.scoped_session` will produce a new
        :class:`.Session` object.

        N)r   r   r3   clearr   s    r   removezscoped_session.remove   s6     ==MMO!!#r   c                 8      G  fddt               } |       S )a0  return a class property which produces a :class:`_query.Query`
        object
        against the class and the current :class:`.Session` when called.

        e.g.::

            Session = scoped_session(sessionmaker())

            class MyClass(object):
                query = Session.query_property()

            # after mappers are defined
            result = MyClass.query.filter(MyClass.name=='foo').all()

        Produces instances of the session's configured query class by
        default.  To override and use a custom implementation, provide
        a ``query_cls`` callable.  The callable will be invoked with
        the class's mapper as a positional argument and a session
        keyword argument.

        There is no limit to the number of query properties placed on
        a class.

        c                       e Zd Z fdZy),scoped_session.query_property.<locals>.queryc                     	 t        |      }|r9r |j                               S j                         j                  |      S y # t        j                  $ r Y y w xY w)N)session)r   r   rD   orm_excUnmappedClassError)sinstanceownermapper	query_clsr   s       r   __get__z4scoped_session.query_property.<locals>.query.__get__   sc    
 )%0F$#,VT]]_#MM $(==?#8#8#@@  11   s   &A
 A
 
A A N)r&   r'   r(   ri   )rh   r   s   r   rD   r_      s     r   rD   )object)r   rh   rD   s   `` r   query_propertyzscoped_session.query_property   s    4	 F 	  wr   r   )	r&   r'   r(   __doc__r   r   rY   r\   rk   r   r   r   r   r   K   s)    b
 NO
A."(r   N) r   r   rb   ra   r   r   utilr   r   r	   r
   r   __all__rj   r   r   ScopedSessionr   r   r   <module>rq      s        ' ! &  "1
231 31l *@<G/`e' ea/`eP  +r   