id@ddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z dgZ Gd de Z e Z d ZejD]Zee eeed Zd D]Zee eeed ZdD]Zee eeedS)) class_mapper)exc)Session)ScopedRegistry)ThreadLocalRegistry)warnscoped_sessionc:eZdZdZdZ ddZdZdZdZddZ dS) r ztProvides scoped management of :class:`.Session` objects. See :ref:`unitofwork_contextual` for a tutorial. Ncn||_|rt|||_dSt||_dS)aConstruct 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_factoryrregistryr)selfr scopefuncs K/opt/cloudlinux/venv/lib/python3.11/site-packages/sqlalchemy/orm/scoping.py__init__zscoped_session.__init__!s= /  A*?IFFDMMM/@@DMMMc |rV|jrtjd|jdi|}|j||S|S)aReturn 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)rhassa_excInvalidRequestErrorr set)rkwsesss r__call__zscoped_session.__call__8s  #}  "" 09 ,t+11b11 !!$''' ==?? "rc|jr&||jdS)aDispose 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)rrcloseclear)rs rremovezscoped_session.removePsN =     $ MMOO ! ! # # # rc z|jrtd|jjdi|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)rrr r configure)rkwargss rr"zscoped_session.configureasU =      (    '&0000000rcFGfddt}|S)a0return 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. ceZdZfdZdS),scoped_session.query_property..queryc t|}|rHr|S|SdS#tj$rYdSwxYw)N)session)rrqueryorm_excUnmappedClassError)sinstanceownermapper query_clsrs r__get__z4scoped_session.query_property..query.__get__s  )%00FA$A#,9VT]]__#M#M#MM$(==??#8#8#@#@@ AA1   44 s1A&AA10A1N)__name__ __module__ __qualname__r1)r0rsrr)r&s3 rr))object)rr0r)s`` rquery_propertyzscoped_session.query_propertyrsJ4 F uwwrN) r2r3r4__doc__r rrr r"r6rrrr r s O AAAA.###0"111"((((((rcfd}|S)NcTt||i|Sr7getattrr)rargsr#names rdozinstrument..dos*-wt}}--t>v>>>rrr>r?s` r instrumentrAs#????? Irc8fd}fd}t||S)NcNt||dSr7)setattrr)rattrr>s rset_zmakeprop..set_s# t,,,,,rcHt|Sr7r;)rr>s rgetzmakeprop..getst}}---r)property)r>rFrHs` rmakeproprJsG-----..... C  r) binddirtydeletednew identity_map is_active autoflush no_autoflushinfo autocommitc,fd}t|S)Nc:tt|i|Sr7)r<r)clsr=r#r>s rr?zclslevel..dos"%ww%%t6v666r) classmethodr@s` rclslevelrYs*77777 r??r) close_allobject_session identity_keyN)rrr*r(rrutilrrr __all__r5r ScopedSessionrApublic_methodsmethrDrJproprYrrrrds!!!!!!&&&&&&  FFFFFVFFFR +  "44D GND**T"2"23333  2 2D GND((4..1111 <22D GND((4..111122r