관리-도구
편집 파일: scoping.cpython-311.pyc
� �܋f � �@ � 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)�warn�scoped_sessionc �: � e Zd ZdZdZ dd�Zd� Zd� Zd� Zdd�Z 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 �M/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/orm/scoping.py�__init__zscoped_session.__init__! s= � � /���� A�*�?�I�F�F�D�M�M�M�/��@�@�D�M�M�M� 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 �has�sa_exc�InvalidRequestErrorr �set)r �kw�sesss r �__call__zscoped_session.__call__8 s � � � #��}� � �"�"� ��0�9�� � � ,�t�+�1�1�b�1�1��� �!�!�$�'�'�'����=�=�?�?�"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 �close�clear)r s r �removezscoped_session.removeP sN � � �=����� $��M�M�O�O�!�!�#�#�#�� �������r c �z � | j � � � rt d� � | j j di |�� 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 �kwargss r r"