관리-도구
편집 파일: associationproxy.cpython-37.pyc
B ��4]7� � @ s0 d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd lmZ dd l m Z ddlmZ dd � Z e�d�ZG dd� dej�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� dee�ZG dd� de�ZG dd� de�ZG dd� de�Ze�d�ZG d d!� d!e�ZG d"d#� d#e�ZdS )$z�Contain the ``AssociationProxy`` class. The ``AssociationProxy`` is a Python property object which provides transparent proxied access to the endpoint of an association object. See the example ``examples/association/proxied_association.py``. � N� )�exc)�inspect)�orm)�util)�collections)� interfaces)�or_)�ColumnOperatorsc K s t | |f|�S )a� Return a Python property implementing a view of a target attribute which references an attribute on members of the target. The returned value is an instance of :class:`.AssociationProxy`. Implements a Python property representing a relationship as a collection of simpler values, or a scalar value. The proxied property will mimic the collection type of the target (list, dict or set), or, in the case of a one to one relationship, a simple scalar value. :param target_collection: Name of the attribute we'll proxy to. This attribute is typically mapped by :func:`~sqlalchemy.orm.relationship` to link to a target collection, but can also be a many-to-one or non-scalar relationship. :param attr: Attribute on the associated instance or instances we'll proxy for. For example, given a target collection of [obj1, obj2], a list created by this proxy property would look like [getattr(obj1, *attr*), getattr(obj2, *attr*)] If the relationship is one-to-one or otherwise uselist=False, then simply: getattr(obj, *attr*) :param creator: optional. When new items are added to this proxied collection, new instances of the class collected by the target collection will be created. For list and set collections, the target class constructor will be called with the 'value' for the new instance. For dict types, two arguments are passed: key and value. If you want to construct instances differently, supply a *creator* function that takes arguments as above and returns instances. For scalar relationships, creator() will be called if the target is None. If the target is present, set operations are proxied to setattr() on the associated object. If you have an associated object with multiple attributes, you may set up multiple association proxies mapping to different attributes. See the unit tests for examples, and for examples of how creator() functions can be used to construct the scalar relationship on-demand in this situation. :param \*\*kw: Passes along any other keyword arguments to :class:`.AssociationProxy`. )�AssociationProxy)�target_collection�attr�kw� r �R/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/ext/associationproxy.py�association_proxy s 4r �ASSOCIATION_PROXYc @ sd e Zd ZdZdZeZddd�Zdd� Zd d � Z dd� Z dd d�Zdd� Zdd� Z dd� Zdd� ZdS )r zDA descriptor that presents a read/write view of an object attribute.TNFc C sR || _ || _|| _|| _|| _|| _|| _dt| �j|t | �f | _ |rN|| _dS )a Construct a new :class:`.AssociationProxy`. The :func:`.association_proxy` function is provided as the usual entrypoint here, though :class:`.AssociationProxy` can be instantiated and/or subclassed directly. :param target_collection: Name of the collection we'll proxy to, usually created with :func:`.relationship`. :param attr: Attribute on the collected instances we'll proxy for. For example, given a target collection of [obj1, obj2], a list created by this proxy property would look like [getattr(obj1, attr), getattr(obj2, attr)] :param creator: Optional. When new items are added to this proxied collection, new instances of the class collected by the target collection will be created. For list and set collections, the target class constructor will be called with the 'value' for the new instance. For dict types, two arguments are passed: key and value. If you want to construct instances differently, supply a 'creator' function that takes arguments as above and returns instances. :param cascade_scalar_deletes: when True, indicates that setting the proxied value to ``None``, or deleting it via ``del``, should also remove the source object. Only applies to scalar attributes. Normally, removing the proxied target will not remove the proxy source, as this object may have other state that is still to be kept. .. versionadded:: 1.3 .. seealso:: :ref:`cascade_scalar_deletes` - complete usage example :param getset_factory: Optional. Proxied attribute access is automatically handled by routines that get and set values based on the `attr` argument for this proxy. If you would like to customize this behavior, you may supply a `getset_factory` callable that produces a tuple of `getter` and `setter` functions. The factory is called with two arguments, the abstract type of the underlying collection and this proxy instance. :param proxy_factory: Optional. The type of collection to emulate is determined by sniffing the target collection. If your collection type can't be determined by duck typing or you'd like to use a different collection implementation, you may supply a factory function to produce those collections. Only applicable to non-scalar relationships. :param proxy_bulk_set: Optional, use with proxy_factory. See the _set() method for details. :param info: optional, will be assigned to :attr:`.AssociationProxy.info` if present. .. versionadded:: 1.0.9 z _%s_%s_%sN)r � value_attr�creator�getset_factory� proxy_factory�proxy_bulk_set�cascade_scalar_deletes�type�__name__�id�key�info) �selfr r r r r r r r r r r �__init__c s IzAssociationProxy.__init__c C s* |d kr| S | � ||�}|r&|�|�S | S )N)�_as_instance�get)r �obj�class_�instr r r �__get__� s zAssociationProxy.__get__c C s t |�}| �||��||�S )N)r r �set)r r"