U a @sddlmZddlmZddlmZddlmZddlmZddlm Z ddlm Z ddlm Z d d gZ Gd d d e Zeed d dddgdddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+gd,d-d.d/d0d1d2d3d4d5g d6Gd7d d eZeZd8S)9) class_mapper)exc)Session)create_proxy_methods)ScopedRegistry)ThreadLocalRegistry)warnscoped_sessionScopedSessionMixinc@s(eZdZeddZddZddZdS)r cCs|S)N)registryselfrWC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\orm\scoping.py_proxiedszScopedSessionMixin._proxiedcKsD|r8|jrtdq@|jf|}|j||Sn|SdS)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)r hassa_excZInvalidRequestErrorsession_factoryset)rkwsessrrr__call__s    zScopedSessionMixin.__call__cKs$|jrtd|jjf|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.N)r rr r configure)rkwargsrrrr1s  zScopedSessionMixin.configureN)__name__ __module__ __qualname__propertyrrrrrrrr s z:class:`_orm.Session`z$:class:`_orm.scoping.scoped_session`Z close_allZobject_sessionZ identity_key __contains____iter__addZadd_allbeginZ begin_nestedclosecommit connectiondeleteexecuteZexpireZ expire_allZexpungeZ expunge_allflushgetZget_bindZ is_modifiedZbulk_save_objectsZbulk_insert_mappingsZbulk_update_mappingsmergequeryZrefreshrollbackZscalarbindZdirtyZdeletednewZ identity_mapZ is_activeZ autoflushZ no_autoflushinfoZ autocommit)Z classmethodsmethods attributesc@s0eZdZdZdZd ddZddZd ddZdS) r ztProvides scoped management of :class:`.Session` objects. See :ref:`unitofwork_contextual` for a tutorial. NcCs&||_|rt|||_n t||_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)rrr r)rrZ scopefuncrrr__init__szscoped_session.__init__cCs$|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)r rr#clearr rrrremoves  zscoped_session.removecsGfdddt}|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. cseZdZfddZdS)z,scoped_session.query_property..querycsTz6t|}|r4r$|dWS|WSWntjk rNYdSXdS)N)session)rr r+orm_excZUnmappedClassError)sinstanceownerZmapper query_clsrrr__get__sz4scoped_session.query_property..query.__get__N)rrrr<rr:rrr+sr+)object)rr;r+rr:rquery_propertyszscoped_session.query_property)N)N)rrr__doc__rr2r4r>rrrrr Cs 0 N)rrr6r5rrutilrrrr __all__r=r r Z ScopedSessionrrrrsr        //`