Dashboard
PHP:
8.2.30
OS:
Linux
User:
dh_nv8b2m
/
/
usr
/
local
/
lib
/
python3.10
/
dist-packages
/
sqlalchemy
/
orm
/
__pycache__
📤 Upload
📝 New File
📁 New Folder
Close
Editing: scoping.cpython-310.pyc
o [�h� � @ s� d dl mZ d dl mZ d dlmZ ddl mZ ddlmZ ddlm Z ddlm Z dgZG d d� de�Z e Z d d� ZejD ] Zee eee�� q?dd � ZdD ] Zee eee�� qPdd� ZdD ] Zee eee�� qadS )� )�class_mapper)�exc)�Session� )�ScopedRegistry)�ThreadLocalRegistry)�warn�scoped_sessionc @ sB e Zd ZdZdZ d dd�Zdd� Zdd� Zd d � Zd dd�Z dS )r ztProvides scoped management of :class:`.Session` objects. See :ref:`unitofwork_contextual` for a tutorial. Nc C s( || _ |r t||�| _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 � scopefunc� r �A/usr/local/lib/python3.10/dist-packages/sqlalchemy/orm/scoping.py�__init__! s zscoped_session.__init__c K s@ |r| j �� rt�d��| jdi |��}| 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.Nr )r �has�sa_exc�InvalidRequestErrorr �set)r �kw�sessr r r �__call__8 s �zscoped_session.__call__c C s$ | 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 �close�clear�r r r r �removeP s zscoped_session.removec K s( | j �� r td� | jjdi |�� dS )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.Nr )r r r r � configure)r �kwargsr r r r a s �zscoped_session.configurec s G � �fdd�dt �}|� S )a" return a class property which produces a :class:`.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 Zd Z� �fdd�ZdS )z,scoped_session.query_property.<locals>.queryc sP zt |�}|r� r� |��� d�W S ��� �|�W S W d S tjy' Y d S w )N)�session)r r �query�orm_exc�UnmappedClassError)�s�instance�owner�mapper�� query_clsr r r �__get__� s ��z4scoped_session.query_property.<locals>.query.__get__N)�__name__� __module__�__qualname__r( r r&