관리-도구
편집 파일: associationproxy.cpython-38.pyc
U -?�f� � @ s< d Z ddlmZ ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ ddlm Z dd lm Z dd lmZ ddlmZ ddlm Z dd lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z dd lm!Z! dd!lm"Z" dd"lm#Z# dd#l"m$Z$ dd$l"m%Z% dd%l"m&Z& dd&l"m'Z' dd'l(m)Z) dd(l*m+Z+ dd)l*m,Z, dd*l*m-Z- dd+l.m/Z/ dd,l.m0Z0 dd-l1m2Z2 dd.l3m4Z4 dd/l3m5Z5 dd0l3m6Z6 dd1l3m7Z7 dd2l3m8Z8 ej9�r�dd3l*m:Z: dd4l*m;Z; dd5l<m=Z= dd6l>m?Z? dd7l>m@Z@ ed8ed9�ZAed:ed;d<�ZBed=ed;d>�ZCed?ed9�ZDed@ed9�ZEedAed9�ZFddddddBdBe2jGe2jGe2jGe2jGe2jGe2jGdC� dDdDdEdFdGdHdIdJdJdKdKdLdMdKdKdNdO�dPdQ�ZHG dRdS� dSe%�ZIG dTdU� dUe5eB �ZJG dVdW� dWe5�ZKG dXdY� dYeKe5eC �ZLG dZd[� d[eKe5eC �ZMG d\d]� d]e5�ZNG d^d_� d_eNe5eC �ZOG d`da� daeNe5eC �ZPG dbdc� dce5eA �ZQG ddde� dee5�ZRG dfdg� dge5�ZSG dhdi� die5�ZTG djdk� dke5eA �ZUG dldm� dme&jVe'eA e,eUeA �ZWedndod9�ZXG dpdq� dqe)eA �ZYG drds� dseYeA �ZZG dtdu� dueYeA �Z[G dvdw� dweYeA �Z\G dxdy� dyeQeA �Z]edzd{d9�Z^G d|d}� d}ee^ �Z_G d~d� de_eA �Z`G d�d�� d�e`eA eeA �ZaG d�d�� d�e_eF eeEeFf �ZbG d�d�� d�e`eA eeA �ZcdS )�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``. � )�annotationsN)�AbstractSet)�Any)�Callable)�cast)� Collection)�Dict)�Generic�� ItemsView)�Iterable)�Iterator)�KeysView)�List)�Mapping)�MutableMapping)�MutableSequence)� MutableSet)�NoReturn)�Optional)�overload)�Set)�Tuple)�Type)�TypeVar)�Union�� ValuesView� )� ColumnElement)�exc)�inspect)�orm)�util)�collections)�InspectionAttrExtensionType)� interfaces)� ORMDescriptor)�SQLORMOperations)�_AttributeOptions)�_DCAttributeOptions)�_DEFAULT_ATTRIBUTE_OPTIONS)� operators)�or_)�_NoArg)�Literal)�Protocol)�Self)� SupportsIndex)�SupportsKeysAndGetItem)�MapperProperty)�PropComparator)�Mapper)�_ColumnExpressionArgument)� _InfoType�_T)�bound�_T_coT)r: � covariant�_T_con)r: � contravariant�_S�_KT�_VTF) �creator�getset_factory� proxy_factory�proxy_bulk_set�info�cascade_scalar_deletes�create_on_none_assignment�init�repr�default�default_factory�compare�kw_only�str�Optional[_CreatorProtocol]� Optional[_GetSetFactoryProtocol]�Optional[_ProxyFactoryProtocol]�Optional[_ProxyBulkSetProtocol]�Optional[_InfoType]�boolzUnion[_NoArg, bool]� Optional[Any]zUnion[_NoArg, Callable[[], _T]]zAssociationProxy[Any])�target_collection�attrrB rC rD rE rF rG rH rI rJ rK rL rM rN �returnc C s* t | ||||||||t| | ||| |�d� 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 that is the immediate target. 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 that are available on instances of the target object. :param creator: optional. Defines custom behavior when new items are added to the proxied collection. By default, adding new items to the collection will trigger a construction of an instance of the target object, passing the given item as a positional argument to the target constructor. For cases where this isn't sufficient, :paramref:`.association_proxy.creator` can supply a callable that will construct the object in the appropriate way, given the item that was passed. For list- and set- oriented collections, a single argument is passed to the callable. For dictionary oriented collections, two arguments are passed, corresponding to the key and value. The :paramref:`.association_proxy.creator` callable is also invoked for scalar (i.e. many-to-one, one-to-one) relationships. If the current value of the target relationship attribute is ``None``, the callable is used to construct a new object. If an object value already exists, the given attribute value is populated onto that object. .. seealso:: :ref:`associationproxy_creator` :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 create_on_none_assignment: when True, indicates that setting the proxied value to ``None`` should **create** the source object if it does not exist, using the creator. Only applies to scalar attributes. This is mutually exclusive vs. the :paramref:`.assocation_proxy.cascade_scalar_deletes`. .. versionadded:: 2.0.18 :param init: Specific to :ref:`orm_declarative_native_dataclasses`, specifies if the mapped attribute should be part of the ``__init__()`` method as generated by the dataclass process. .. versionadded:: 2.0.0b4 :param repr: Specific to :ref:`orm_declarative_native_dataclasses`, specifies if the attribute established by this :class:`.AssociationProxy` should be part of the ``__repr__()`` method as generated by the dataclass process. .. versionadded:: 2.0.0b4 :param default_factory: Specific to :ref:`orm_declarative_native_dataclasses`, specifies a default-value generation function that will take place as part of the ``__init__()`` method as generated by the dataclass process. .. versionadded:: 2.0.0b4 :param compare: Specific to :ref:`orm_declarative_native_dataclasses`, indicates if this field should be included in comparison operations when generating the ``__eq__()`` and ``__ne__()`` methods for the mapped class. .. versionadded:: 2.0.0b4 :param kw_only: Specific to :ref:`orm_declarative_native_dataclasses`, indicates if this field should be marked as keyword-only when generating the ``__init__()`` method as generated by the dataclass process. .. versionadded:: 2.0.0b4 :param info: optional, will be assigned to :attr:`.AssociationProxy.info` if present. The following additional parameters involve injection of custom behaviors within the :class:`.AssociationProxy` object and are for advanced use only: :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. �rB rC rD rE rF rG rH �attribute_options)�AssociationProxyr) )rW rX rB rC rD rE rF rG rH rI rJ rK rL rM rN � r] �O/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/ext/associationproxy.py�association_proxyT s( ��r_ c @ s e Zd ZdZdS )�AssociationProxyExtensionType�ASSOCIATION_PROXYN)�__name__� __module__�__qualname__ra r] r] r] r^ r` � s r` c @ s e Zd Zddd�dd�ZdS )�_GetterProtocolr r; ��instancerY c C s d S �Nr] )�selfrg r] r] r^ �__call__ � z_GetterProtocol.__call__N�rb rc rd rj r] r] r] r^ re s re c @ s e Zd ZdS )�_SetterProtocolN�rb rc rd r] r] r] r^ rm s rm c @ s e Zd Zdddd�dd�ZdS )�_PlainSetterProtocolr r= �None)rg �valuerY c C s d S rh r] )ri rg rq r] r] r^ rj rk z_PlainSetterProtocol.__call__Nrl r] r] r] r^ ro s ro c @ s e Zd Zddddd�dd�ZdS )�_DictSetterProtocolr r= rp )rg �keyrq rY c C s d S rh r] )ri rg rs rq r] r] r^ rj rk z_DictSetterProtocol.__call__Nrl r] r] r] r^ rr s rr c @ s e Zd ZdS )�_CreatorProtocolNrn r] r] r] r^ rt s rt c @ s e Zd Zddd�dd�ZdS )�_PlainCreatorProtocolr= r �rq rY c C s d S rh r] �ri rq r] r] r^ rj rk z_PlainCreatorProtocol.__call__Nrl r] r] r] r^ ru s ru c @ s e Zd Zdddd�dd�ZdS )�_KeyCreatorProtocolr zOptional[_T_con]�rs rq rY c C s d S rh r] �ri rs rq r] r] r^ rj rk z_KeyCreatorProtocol.__call__Nrl r] r] r] r^ rx s rx c @ s e Zd Zdd�dd�ZdS )�_LazyCollectionProtocol�CUnion[MutableSet[_T], MutableMapping[Any, _T], MutableSequence[_T]]�rY c C s d S rh r] �ri r] r] r^ rj s z _LazyCollectionProtocol.__call__Nrl r] r] r] r^ r{ s r{ c @ s e Zd Zdddd�dd�ZdS )�_GetSetFactoryProtocol�Optional[Type[Any]]�AssociationProxyInstance[Any]�,Tuple[_GetterProtocol[Any], _SetterProtocol])�collection_class�assoc_instancerY c C s d S rh r] )ri r� r� r] r] r^ rj % s z_GetSetFactoryProtocol.__call__Nrl r] r] r] r^ r $ s r c @ s"