om> @ d dl mZ d dl mZ d dlmZ ddl mZ ddlmZ ddlm Z ddlm
Z
dgZ G d de Z
e
Z d
Zej D ]Z ee
e ee d ZdD ]Z ee
e ee d
ZdD ]Z ee
e ee dS ) )class_mapper)exc)Session )ScopedRegistry)ThreadLocalRegistry)warnscoped_sessionc : e Zd ZdZdZ ddZd Zd Zd ZddZ dS ) r
ztProvides scoped management of :class:`.Session` objects.
See :ref:`unitofwork_contextual` for a tutorial.
Nc n || _ |rt || | _ dS t | | _ dS )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)session_factoryr registryr )selfr
scopefuncs j/builddir/build/BUILD/cloudlinux-venv-1.0.10/venv/lib64/python3.11/site-packages/sqlalchemy/orm/scoping.py__init__zscoped_session.__init__! s= / A*?IFFDMMM/@@DMMM c |rV| j rt j d | j di |}| j | |S | 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.N )r hassa_excInvalidRequestErrorr
set)r kwsesss r __call__zscoped_session.__call__8 s #} ""
09
,t+11b11
!!$'''==??"r c | j r&| | j dS )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 closeclear)r s r removezscoped_session.removeP sN = $MMOO!!###
r c z | j rt d | j j di | dS )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" zscoped_session.configurea sU = (
'&0000000r c F G fddt } | 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 Zd Z fdZdS ),scoped_session.query_property.