U
    ÌZjY  ã                !   @   s  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„ deƒZeedddddgddddddddddddddd d!d"d#d$d%d&d'd(d)d*d+d,d-gd.d/d0d1d2d3d4d5d6d7g
d8�G d9d
„ d
eƒƒZeZd:S );é   )Úclass_mapper)Úexc)ÚSessioné   )Úcreate_proxy_methods)ÚScopedRegistry)ÚThreadLocalRegistry)Úwarn)Úwarn_deprecatedÚscoped_sessionÚScopedSessionMixinc                   @   s(   e Zd Zedd„ ƒZdd„ Zdd„ ZdS )r   c                 C   s   |   ¡ S )N)Úregistry©Úself© r   úY/var/www/html/TRUCKING_PROJECT/venv/lib/python3.8/site-packages/sqlalchemy/orm/scoping.pyÚ_proxied   s    zScopedSessionMixin._proxiedc                 K   sV   |r4| j  ¡ rt d¡‚q<| jf |Ž}| j  |¡ n|   ¡ }| jsR|jrRt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.z‰Using `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_excZInvalidRequestErrorÚsession_factoryÚsetÚ_support_asyncZ_is_asyncior
   )r   ÚkwÚsessr   r   r   Ú__call__   s    
ÿüzScopedSessionMixin.__call__c                 K   s$   | j  ¡ rtdƒ | jjf |Ž dS )z�reconfigure 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   r   r	   r   Ú	configure)r   Úkwargsr   r   r   r   9   s
    
ÿzScopedSessionMixin.configureN)Ú__name__Ú
__module__Ú__qualname__Úpropertyr   r   r   r   r   r   r   r      s   
z:class:`_orm.Session`z$:class:`_orm.scoping.scoped_session`Z	close_allZobject_sessionZidentity_keyÚ__contains__Ú__iter__ÚaddZadd_allÚbeginZbegin_nestedÚcloseÚcommitÚ
connectionÚdeleteÚexecuteZexpireZ
expire_allZexpungeZexpunge_allÚflushÚgetZget_bindZis_modifiedZbulk_save_objectsZbulk_insert_mappingsZbulk_update_mappingsÚmergeÚqueryÚrefreshÚrollbackZscalarZscalarsÚbindZdirtyZdeletedÚnewZidentity_mapZ	is_activeZ	autoflushZno_autoflushÚinfoZ
autocommit)ZclassmethodsÚmethodsÚ
attributesc                   @   s4   e Zd ZdZdZdZd
dd„Zdd„ Zddd	„ZdS )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                 C   s&   || _ |rt||ƒ| _n
t|ƒ| _dS )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   Z	scopefuncr   r   r   Ú__init__�   s    zscoped_session.__init__c                 C   s$   | j  ¡ r|   ¡  ¡  | j  ¡  dS )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   r%   Úclearr   r   r   r   Úremove§   s    
zscoped_session.removec                    s   G ‡ ‡fd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                       s   e Zd Z‡ ‡fdd„ZdS )z,scoped_session.query_property.<locals>.queryc                    sT   z6t |ƒ}|r4ˆ r$ˆ |ˆ ¡ d�W S ˆ ¡  |¡W S W n tjk
rN   Y d S X d S )N)Úsession)r   r   r-   Úorm_excZUnmappedClassError)ÚsÚinstanceÚownerZmapper©Ú	query_clsr   r   r   Ú__get__Ó   s    z4scoped_session.query_property.<locals>.query.__get__N)r   r   r   r?   r   r=   r   r   r-   Ò   s   r-   )Úobject)r   r>   r-   r   r=   r   Úquery_property¸   s    zscoped_session.query_property)N)N)	r   r   r   Ú__doc__r   r   r5   r7   rA   r   r   r   r   r   K   s   1
N)Ú r   r   r9   r8   r   r   Úutilr   r   r   r	   r
   Ú__all__r@   r   r   ZScopedSessionr   r   r   r   Ú<module>   sv   6äöÝ0h