U kf@s<dZddlmZddlZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd lm Z dd lm Z dd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm 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.m0Z0dd-l1m2Z2dd.l3m4Z4dd/l3m5Z5dd0l3m6Z6dd1l3m7Z7dd2l3m8Z8ej9rdd3l*m:Z:dd4l*m;Z;dd5lm?Z?dd7l>m@Z@ed8ed9ZAed:ed;d<ZBed=ed;d>ZCed?ed9ZDed@ed9ZEedAed9ZFddddddBdBe2jGe2jGe2jGe2jGe2jGe2jGdC dDdDdEdFdGdHdIdJdJdKdKdLdMdKdKdNdOdPdQZHGdRdSdSe%ZIGdTdUdUe5eBZJGdVdWdWe5ZKGdXdYdYeKe5eCZLGdZd[d[eKe5eCZMGd\d]d]e5ZNGd^d_d_eNe5eCZOGd`dadaeNe5eCZPGdbdcdce5eAZQGdddedee5ZRGdfdgdge5ZSGdhdidie5ZTGdjdkdke5eAZUGdldmdme&jVe'eAe,eUeAZWedndod9ZXGdpdqdqe)eAZYGdrdsdseYeAZZGdtdudueYeAZ[GdvdwdweYeAZ\GdxdydyeQeAZ]edzd{d9Z^Gd|d}d}e e^Z_Gd~dde_eAZ`Gddde`eAeeAZaGddde_eFeeEeFfZbGddde`eAeeAZcdS)zContain 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) creatorgetset_factory proxy_factoryproxy_bulk_setinfocascade_scalar_deletescreate_on_none_assignmentinitreprdefaultdefault_factorycomparekw_onlystrOptional[_CreatorProtocol] Optional[_GetSetFactoryProtocol]Optional[_ProxyFactoryProtocol]Optional[_ProxyBulkSetProtocol]Optional[_InfoType]boolzUnion[_NoArg, bool] Optional[Any]zUnion[_NoArg, Callable[[], _T]]zAssociationProxy[Any])target_collectionattrrBrCrDrErFrGrHrIrJrKrLrMrNreturnc Cs*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. rBrCrDrErFrGrHattribute_options)AssociationProxyr))rWrXrBrCrDrErFrGrHrIrJrKrLrMrNr]O/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/ext/associationproxy.pyassociation_proxyTs(r_c@seZdZdZdS)AssociationProxyExtensionTypeASSOCIATION_PROXYN)__name__ __module__ __qualname__rar]r]r]r^r`sr`c@seZdZdddddZdS)_GetterProtocolrr;instancerYcCsdSNr])selfrgr]r]r^__call__z_GetterProtocol.__call__Nrbrcrdrjr]r]r]r^resrec@s eZdZdS)_SetterProtocolNrbrcrdr]r]r]r^rmsrmc@seZdZddddddZdS)_PlainSetterProtocolrr=None)rgvaluerYcCsdSrhr])rirgrqr]r]r^rj rkz_PlainSetterProtocol.__call__Nrlr]r]r]r^rosroc@s eZdZdddddddZdS)_DictSetterProtocolrr=rp)rgkeyrqrYcCsdSrhr])rirgrsrqr]r]r^rj rkz_DictSetterProtocol.__call__Nrlr]r]r]r^rr srrc@s eZdZdS)_CreatorProtocolNrnr]r]r]r^rtsrtc@seZdZdddddZdS)_PlainCreatorProtocolr=rrqrYcCsdSrhr]rirqr]r]r^rjrkz_PlainCreatorProtocol.__call__Nrlr]r]r]r^rusruc@seZdZddddddZdS)_KeyCreatorProtocolrzOptional[_T_con]rsrqrYcCsdSrhr]rirsrqr]r]r^rjrkz_KeyCreatorProtocol.__call__Nrlr]r]r]r^rxsrxc@seZdZddddZdS)_LazyCollectionProtocolCUnion[MutableSet[_T], MutableMapping[Any, _T], MutableSequence[_T]]rYcCsdSrhr]rir]r]r^rjsz _LazyCollectionProtocol.__call__Nrlr]r]r]r^r{sr{c@seZdZddddddZdS)_GetSetFactoryProtocolOptional[Type[Any]]AssociationProxyInstance[Any],Tuple[_GetterProtocol[Any], _SetterProtocol])collection_classassoc_instancerYcCsdSrhr])rirrr]r]r^rj%sz_GetSetFactoryProtocol.__call__Nrlr]r]r]r^r$src@s"eZdZddddddddZd S) _ProxyFactoryProtocolz_LazyCollectionProtocol[Any]rtrOrr)lazy_collectionrB value_attrparentrYcCsdSrhr])rirrBrrr]r]r^rj-sz_ProxyFactoryProtocol.__call__Nrlr]r]r]r^r,src@seZdZddddddZdS)_ProxyBulkSetProtocol_AssociationCollection[Any] Iterable[Any]rp)proxy collectionrYcCsdSrhr])rirrr]r]r^rj7sz_ProxyBulkSetProtocol.__call__Nrlr]r]r]r^r6src@seZdZUdZded<ded<ded<ded<ded <ded <d ed <d ed<ded<ejddddZd!ddddddZddddd Z dS)"_AssociationProxyProtocolzpdescribes the interface of :class:`.AssociationProxy` without including descriptor methods in the interface.rPrBrOrsrWrrUrGrHrQrCrRrDrSrEr8r}cCsdSrhr]r~r]r]r^rFJsz_AssociationProxyProtocol.infoN Type[Any]Optional[object]AssociationProxyInstance[_T]class_objrYcCsdSrhr]rirrr]r]r^ for_classMsz#_AssociationProxyProtocol.for_classrrrrYcCsdSrhr])rirr]r]r^_default_getsetQsz)_AssociationProxyProtocol._default_getset)N) rbrcrd__doc____annotations__r#Zro_memoized_propertyrFrrr]r]r]r^r<s rc @seZdZdZdZejZdddddddddddddd d d d d d d ddZe ddddddZ e ddddddZ e ddddddZ ddddddZ ddddd d!Z ddd"d#d$Z d6d%d&dd'd(d)Z dddd'd*d+Zddd,d-d.Zdd/d0d1d2Zdd3d4d5ZdS)7r\zDA descriptor that presents a read/write view of an object attribute.TNFrZrOrPrQrRrSrTrUzOptional[_AttributeOptions]) rWrXrBrCrDrErFrGrHr[c Cs||_||_||_||_||_||_|r6| r6td||_| |_ dt |j |t |f|_ |rf||_| r| tkrd|_| |_n d|_t|_dS)a(Construct a new :class:`.AssociationProxy`. The :class:`.AssociationProxy` object is typically constructed using the :func:`.association_proxy` constructor function. See the description of :func:`.association_proxy` for a description of all parameters. z[The cascade_scalar_deletes and create_on_none_assignment parameters are mutually exclusive.z _%s_%s_%sTFN)rWrrBrCrDrEr ArgumentErrorrGrHtyperbidrsrFr+Z_has_dataclass_argumentsZ_attribute_options) rirWrXrBrCrDrErFrGrHr[r]r]r^__init__as6zAssociationProxy.__init__ Literal[None]r1)rgownerrYcCsdSrhr]rirgrr]r]r^__get__szAssociationProxy.__get__rrcCsdSrhr]rr]r]r^rsobjectr9cCsdSrhr]rr]r]r^rsz=Union[AssociationProxyInstance[_T], _T, AssociationProxy[_T]]cCs6|dkr |S|||}|r&||S|dks2t|Srh) _as_instancegetAssertionError)rirgrinstr]r]r^rs   rp)rgvaluesrYcCs t|}|||||dSrh)rrset)rirgrrr]r]r^__set__szAssociationProxy.__set__rfcCst|}||||dSrh)rrdelete)rirgrr]r]r^ __delete__szAssociationProxy.__delete__rrrcCs |||S)aReturn the internal state local to a specific mapped class. E.g., given a class ``User``:: class User(Base): # ... keywords = association_proxy('kws', 'keyword') If we access this :class:`.AssociationProxy` from :attr:`_orm.Mapper.all_orm_descriptors`, and we want to view the target class for this proxy as mapped by ``User``:: inspect(User).all_orm_descriptors["keywords"].for_class(User).target_class This returns an instance of :class:`.AssociationProxyInstance` that is specific to the ``User`` class. The :class:`.AssociationProxy` object remains agnostic of its parent class. :param class\_: the class that we are returning state for. :param obj: optional, an instance of the class that is required if the attribute refers to a polymorphic target, e.g. where we have to look at the type of the actual destination object to get the complete path. .. versionadded:: 1.3 - :class:`.AssociationProxy` no longer stores any state specific to a particular parent class; the state is now stored in per-class :class:`.AssociationProxyInstance` objects. )rrr]r]r^rs#zAssociationProxy.for_classcCsz|j|jd}Wntk r,d}YnX|dkrn||}|dk rjt|||}t||jd|nd}|dk r|js||S|SdS)N_inst) __dict__rsKeyError _calc_ownerAssociationProxyInstance for_proxysetattr _is_canonical_non_canonical_get_for_object)rirrrrr]r]r^rs   zAssociationProxy._as_instance) target_clsrYcCs4z t|}Wntjk r$YdSX|jjjSdSrh)r!r NoInspectionAvailablemapperZ class_managerr)ririnspr]r]r^rs  zAssociationProxy._calc_ownerrrcsn|jtdddfdd }|tkrLdddddfdd }||fSdddd fd d }||fSdS) NrrVrfcs|dk r|SdSrhr]rg_getterr]r^gettersz0AssociationProxy._default_getset..getterrprgkrqrYcst||dSrhrrgrrqrXr]r^ dict_settersz5AssociationProxy._default_getset..dict_setterovrYcst||dSrhrrrrr]r^ plain_settersz6AssociationProxy._default_getset..plain_setterroperator attrgetterdictrirrrrr]rrXr^r s z AssociationProxy._default_getsetr}cCsd|j|jfS)NzAssociationProxy(%r, %r))rWrr~r]r]r^__repr__!szAssociationProxy.__repr__)N)rbrcrdrZ is_attributer`raZextension_typerrrrrrrrrrr]r]r]r^r\Vs6$8 %r\_Selfrc@sTeZdZUdZded<ded<dddddd d Zded <ed dd ddddZedddddddddZddddZ e ddddZ ddddZ ed ddd d!d"Z ejddd#d$Ze d%dd&d'Ze d(dd)d*Ze d+dd,d-Zejd.dd/d0Zejd.dd1d2Ze d.dd3d4Zd5ed6<d7ed8<d9dd:d;Zd dd?Zejd@ddAdBZedCdDdCdEdFdGZed dHdIdJdGZd dKdIdLdGZd dHd9dMdNdOZd d9dIdPdQZdRdSdTdUdVZdWdXd9dYdZd[Z dWd9d\d]d^Z!dkd`d dadbdcddZ"dld`d dadbdedfZ#dmd`d dadbdgdhZ$dddidjZ%d_S)nraA per-class object that serves class- and object-specific results. This is used by :class:`.AssociationProxy` when it is invoked in terms of a specific class or instance of a class, i.e. when it is used as a regular Python descriptor. When referring to the :class:`.AssociationProxy` as a normal Python descriptor, the :class:`.AssociationProxyInstance` is the object that actually serves the information. Under normal circumstances, its presence is transparent:: >>> User.keywords.scalar False In the special case that the :class:`.AssociationProxy` object is being accessed directly, in order to get an explicit handle to the :class:`.AssociationProxyInstance`, use the :meth:`.AssociationProxy.for_class` method:: proxy_state = inspect(User).all_orm_descriptors["keywords"].for_class(User) # view if proxy object is scalar or not >>> proxy_state.scalar False .. versionadded:: 1.3 rrz_AssociationProxyProtocol[_T]rrrO)r owning_class target_classrcCs2||_|j|_||_|j|_d|_||_||_dSrh)rrsrrWrrr)rirrrrr]r]r^rOsz!AssociationProxyInstance.__init__rzAssociationProxy[_T]rr)rrparent_instancerYc Cs|j}|j}tdt||}t|tjs8tdd|j j }ztd| ||}Wnlt k rxt ||||YStk r} z.td|jd|jd|jd| | W5d} ~ XYnX||||||SdS)Nzorm.RelationshipProperty[_T]zEassociation proxy to a non-relationship intermediary is not supportedrzRAssociation proxy received an unexpected error when trying to retreive attribute ".z" from class "z": )rWrrr" class_mapper get_property isinstanceZRelationshipPropertyNotImplementedErrorrr_cls_unwrap_target_assoc_proxyAttributeError!AmbiguousAssociationProxyInstance Exceptionr InvalidRequestErrorrb_construct_for_assoc) clsrrrrWrpropr target_assocerrr]r]r^rgsL   z"AssociationProxyInstance.for_proxyz&Optional[AssociationProxyInstance[_T]])rrrrrrYcCsb|dk rt||||St||}t|ds8t||||S|j}|rPt||||St||||SdS)NZ_is_internal_proxy)ObjectAssociationProxyInstancegetattrhasattrrZ_impl_uses_objectsColumnAssociationProxyInstance)rrrrrrrXZ is_objectr]r]r^rs:   z-AssociationProxyInstance._construct_for_assoczMapperProperty[Any]r}cCst|j|jSrh)r"rrrrWr~r]r]r^ _get_propertys z&AssociationProxyInstance._get_propertyzPropComparator[Any]cCst|j|jjSrh)rrrW comparatorr~r]r]r^ _comparatorsz$AssociationProxyInstance._comparatorrcCs tddS)NzqThe association proxy can't be used as a plain column expression; it only works inside of a comparison expressionrr~r]r]r^__clause_element__sz+AssociationProxyInstance.__clause_element__)rrrYcCs*t||}t|trtt|tr&|SdSrh)rrr\rr)rrrrXr]r]r^rs   z7AssociationProxyInstance._cls_unwrap_target_assoc_proxycCs||j|jSrh)rrrr~r]r]r^_unwrap_target_assoc_proxysz3AssociationProxyInstance._unwrap_target_assoc_proxySQLORMOperations[_T]cCstdt|j|jS)zThe 'remote' class attribute referenced by this :class:`.AssociationProxyInstance`. .. seealso:: :attr:`.AssociationProxyInstance.attr` :attr:`.AssociationProxyInstance.local_attr` r)rrrrr~r]r]r^ remote_attrs  z$AssociationProxyInstance.remote_attrSQLORMOperations[Any]cCstdt|j|jS)zThe 'local' class attribute referenced by this :class:`.AssociationProxyInstance`. .. seealso:: :attr:`.AssociationProxyInstance.attr` :attr:`.AssociationProxyInstance.remote_attr` r)rrrrWr~r]r]r^ local_attrs  z#AssociationProxyInstance.local_attrz2Tuple[SQLORMOperations[Any], SQLORMOperations[_T]]cCs |j|jfS)aReturn a tuple of ``(local_attr, remote_attr)``. This attribute was originally intended to facilitate using the :meth:`_query.Query.join` method to join across the two relationships at once, however this makes use of a deprecated calling style. To use :meth:`_sql.select.join` or :meth:`_orm.Query.join` with an association proxy, the current method is to make use of the :attr:`.AssociationProxyInstance.local_attr` and :attr:`.AssociationProxyInstance.remote_attr` attributes separately:: stmt = ( select(Parent). join(Parent.proxied.local_attr). join(Parent.proxied.remote_attr) ) A future release may seek to provide a more succinct join pattern for association proxy attributes. .. seealso:: :attr:`.AssociationProxyInstance.local_attr` :attr:`.AssociationProxyInstance.remote_attr` )rrr~r]r]r^rXszAssociationProxyInstance.attrrUcCs|j }|r||S)zsReturn ``True`` if this :class:`.AssociationProxyInstance` proxies a scalar relationship on the local side.)ruselist_initialize_scalar_accessors)riscalarr]r]r^rs zAssociationProxyInstance.scalarcCs|j|jj Srh)rrrrrr~r]r]r^_value_is_scalar s z)AssociationProxyInstance._value_is_scalarcCs tdSrhrr~r]r]r^_target_is_object(sz*AssociationProxyInstance._target_is_objectz_GetterProtocol[_T] _scalar_get_PlainSetterProtocol[_T] _scalar_setrpcCsD|jjr|jd|\}}n|jd\}}|td||_|_dS)Nr)rrCrrrr)rirset_r]r]r^r/sz5AssociationProxyInstance._initialize_scalar_accessorsrrcsn|jtdddfdd }|tkrLdddddfd d }||fSdddd fd d }||fSdS)Nrz Optional[_T]rfcs|dk r|SdSrhr]rrr]r^r>sz8AssociationProxyInstance._default_getset..getterr9rprcst||dSrhrrrr]r^rCsz=AssociationProxyInstance._default_getset..dict_setterrcst||dSrhrrrr]r^rIsz>AssociationProxyInstance._default_getset..plain_setterrrr]rr^r8s z(AssociationProxyInstance._default_getsetr8cCs|jjSrh)rrFr~r]r]r^rFNszAssociationProxyInstance.inforr)rirrYcCsdSrhr]rirr]r]r^rRszAssociationProxyInstance.getr9rrYcCsdSrhr]rr]r]r^rUsz1Union[Optional[_T], AssociationProxyInstance[_T]]cCs|dkr |S|jr(t||j}||Sztdt||j\}}}Wntk rXYn,Xt||krt||kr|jdk st |S| t ||j\|_}t ||jt|t||f|SdS)NzTuple[int, int, _T]) rrrWrrrsrrrr_new_lazy_collectionr)rirtargetZ creator_idZself_idrr]r]r^rXs(    )rrrYcCs|jrtd|jjr|jjn|j}t||j}|dkr^|dkrJ|jjsJdSt||j||q| |||dkr|jj rt||jdn,| |}|j dk st ||k r|||dS)N_PlainCreatorProtocol[_T])rrrrBrrrWrHrrrGrrr _bulk_replace)rirrrBrrr]r]r^rws,    zAssociationProxyInstance.setcCsL|jdkr||d|jrYnFX|j}|j}||jkrb|||z |j|WSt k rYnX|Srh) rrWr!r rrrr$_populate_cacher)rirZ actual_objrrinstance_classr]r]r^rs      z?AmbiguousAssociationProxyInstance._non_canonical_get_for_objectz Mapper[Any]rp)r&rrYcCstt|j|j}||jrp|}z|||j}Wnt k rJYn&X| t d||j |j||j|j |<dS)Nr)r"rrrrWZisarrrrrrrr$)rir&rrrrr]r]r^r%s&  z1AmbiguousAssociationProxyInstance._populate_cache)N)N)rbrcrdrrrrr"r#rrr#rr$rr% __classcell__r]r]r r^rWs rc@sTeZdZUdZdZded<dZdddddd Zddd d d Zddd d dZ dS)rzEan :class:`.AssociationProxyInstance` that has an object as a target.TrUrrr )otherkwrYcKs|j}|dk r.|j|js$||n||kS|jr\|jr\|js\|jt|j |j |S|jrz|jrz|jrzt dn|jjf|j |iSdS)aIProduce a proxied 'contains' expression using EXISTS. This expression will be a composed product using the :meth:`.Relationship.Comparator.any`, :meth:`.Relationship.Comparator.has`, and/or :meth:`.Relationship.Comparator.contains` operators of the underlying proxied attributes. Nz^rkz_AssociationCollection.intr}cCs t|jSrhlenr:r~r]r]r^__len__`sz_AssociationCollection.__len__rUcCs t|jSrh)rUr:r~r]r]r^__bool__csz_AssociationCollection.__bool__rcCs|j|jdS)NrrrAr~r]r]r^r2fsz#_AssociationCollection.__getstate__rpr3cCs$|d|_|d|_|j|dS)Nrr)rrr r5r]r]r^r6is  z#_AssociationCollection.__setstate__cCs tdSrhrr~r]r]r^clearnsz_AssociationCollection.clearN)rbrcrdrrtyping TYPE_CHECKINGrr:r?r@r2r6rBr]r]r]r^r80s    r8c@sPeZdZUded<ded<ddddd Zddd d d Zd dddddZdS)_AssociationSingleItemrrrrBr9rrvcCs ||SrhrBrwr]r]r^_createvsz_AssociationSingleItem._createobject_rYcCs ||SrhrrirIr]r]r^_getysz_AssociationSingleItem._getrz Iterable[_IT]rp assoc_proxyrrYcCs||||dSrh)rBr )rirNrr]r]r^r|sz$_AssociationSingleItem._bulk_replaceN)rbrcrdrrGrLrr]r]r]r^rErs rEc@seZdZUdZded<dddddd Zed dd d d Zeddd dd Zddd dd Zed dddddZeddddddZddddddZed dd ddZ eddd ddZ ddd ddZ dd d!d"d#Z d$d%d&d'Z ddd!d(d)Z dd d!d*d+Z ddd,d-d.Zd dddd/d0Zdhd dd d2d3Zddd!d4d5Zd6d%d7d8Zd6d%d9d:Zdd%d;d<Zdd d=d>d?Zdd d=d@dAZdBd d=dCdDZdBd d=dEdFZdBd d=dGdHZdBd d=dIdJZdBdBd=dKdLZdBdBd=dMdNZdOdBdPdQdRZdOdBdPdSdTZddUdVdWdXZdOdUdPdYdZZ e!j"rbdidd d d d\d]d^Z#ndd d!d_d^Z#dBd%d`daZ$dbd%dcddZ%d6d%dedfZ&e!j"se'e()D]B\Z*Z+e,e+re+je*kre+jse-e'e*re.e'e*je+_q[*[+dgS)jrz(Generic, converting, list-to-list proxy.zMutableSequence[_T]r:rr9rp)rIrqrYcCs|||dSrhr)rirIrqr]r]r^r sz_AssociationList._setr<)indexrYcCsdSrhr]rirPr]r]r^ __getitem__sz_AssociationList.__getitem__slicecCsdSrhr]rQr]r]r^rRszUnion[int, slice]zUnion[_T, MutableSequence[_T]]cs6t|tsj|Sfddj|DSdS)Ncsg|]}|qSr])rL).0memberr~r]r^ sz0_AssociationList.__getitem__..)rrSrLr:rQr]r~r^rRs )rPrqrYcCsdSrhr]rirPrqr]r]r^ __setitem__sz_AssociationList.__setitem__ Iterable[_T]cCsdSrhr]rWr]r]r^rXszUnion[_T, Iterable[_T]]c Cst|ts$||j|td|n|jdkr8t|}n |jdkrRt||j}n|j}|jp`d}|jpjd}t t |jpxd||}t |}|dkr|D] }||=q|}|D]} | || |d7}qnNt|t|krt dt|t|ft ||D]\}} ||j|| qdS)Nr9rzBattempt to assign sequence of size %s to extended slice of size %s)rrSr r:rstopr>stepstartrrangeinsert ValueErrorzip) rirPrqr[r\r]rngZ sized_valueiitemr]r]r^rXs4        cCsdSrhr]rQr]r]r^ __delitem__sz_AssociationList.__delitem__cCsdSrhr]rQr]r]r^reszUnion[slice, int]cCs |j|=dSrhr:rQr]r]r^resrrUrvcCs$|jD]}|||krdSqdSNTFr:rL)rirqrUr]r]r^ __contains__s z_AssociationList.__contains__ Iterator[_T]r}ccs|jD]}||VqdS)zIterate over proxied values. For the actual domain objects, iterate over .col instead or just use the underlying collection directly from its property on the parent. NrhrirUr]r]r^__iter__s z_AssociationList.__iter__cCs|j}||}||dSrh)r:rGappend)rirqr:rdr]r]r^rms z_AssociationList.appendcCs"d}|D]}||kr|d7}q|SNrrZr])rirqcountrr]r]r^ros  z_AssociationList.count)rrYcCs|D]}||qdSrh)rm)rirrr]r]r^rsz_AssociationList.extendcCs||g|j||<dSrh)rGr:rWr]r]r^r_sz_AssociationList.insertcCs||j|Srh)rr:rrQr]r]r^rsz_AssociationList.popcCs4t|D]\}}||kr|j|=dSqtddS)Nzvalue not in list) enumerater:r`)rirqrcvalr]r]r^removes z_AssociationList.removercCs tdS)z#Not supported, use reversed(mylist)Nrr~r]r]r^reversesz_AssociationList.reversecCs tdS)z!Not supported, use sorted(mylist)Nrr~r]r]r^sortsz_AssociationList.sortcCs|jdt|j=dS)Nr)r:r>r~r]r]r^rBsz_AssociationList.clearr+cCs t||kSrhrrir(r]r]r^r" sz_AssociationList.__eq__cCs t||kSrhrvrwr]r]r^r# sz_AssociationList.__ne__zList[_T]cCs t||kSrhrvrwr]r]r^__lt__sz_AssociationList.__lt__cCs t||kSrhrvrwr]r]r^__le__sz_AssociationList.__le__cCs t||kSrhrvrwr]r]r^__gt__sz_AssociationList.__gt__cCs t||kSrhrvrwr]r]r^__ge__sz_AssociationList.__ge__cCs2z t|}Wntk r$tYSXt||Srhr TypeErrorNotImplementedrwr]r]r^__add__s   z_AssociationList.__add__cCs2z t|}Wntk r$tYSX|t|Srhr|rwr]r]r^__radd__"s   z_AssociationList.__radd__r2)nrYcCst|tstSt||Srhrr<r~rrirr]r]r^__mul__)s z_AssociationList.__mul__cCst|tstS|t|Srhrrr]r]r^__rmul__.s z_AssociationList.__rmul__r1)iterablerYcCs|||Srh)r)rirr]r]r^__iadd__3s z_AssociationList.__iadd__cCsDt|tst|dkr"|n|dkr@|t||d|Srn)rr<rrBrrrr]r]r^__imul__7s  z_AssociationList.__imul__.)rqr]r[rYcCsdSrhr])rirqr]r[r]r]r^rPFsz_AssociationList.indexcGst|}|j|f|Srh)rrP)rirqargZlsr]r]r^rPLscCst|Srhrvr~r]r]r^copyPsz_AssociationList.copyrOcCs tt|Srh)rJrr~r]r]r^rSsz_AssociationList.__repr__cCstdt|jdSNz%s objects are unhashabler}rrbr~r]r]r^__hash__Vsz_AssociationList.__hash__N)rp)..)/rbrcrdrrr rrRrXrerirlrmrorr_rrsrtrurBr"r#rxryrzr{rrrrrrrCrDrPrrrrlocalsitems func_namefunccallablerrr]r]r]r^rsz $  rc@seZdZUdZded<ded<ded<dd d d d d Zd ddddZd ddddddZdddddZdddd ddZ dddddZ ddddd Z d!d"d#d$Z dd"d%d&Z ddd'd(d)Zddd'd*d+Zd,d"d-d.Zedd d/d0d1Zedd2d2d3d4d1Zdcdd6d7d8d9d1Zdddd dd8d:d;ZdZd?d"d@dAZdBd"dCdDZeddd/dEdFZededd2d2d3dHdFZdd d d2dIdJdFZdKd"dLdMZedNdddOdPdQZedRdddOdSdQZedddTdUdQZd d ddVdWdQZdXdYddZd[d\Zd]d"d^d_Zd`d"dadbZejsee D]B\Z!Z"e#e"rHe"je!krHe"jsHe$e%e!rHe&e%e!je"_qH[!["d5S)frz(Generic, converting, dict-to-dict proxy.z_DictSetterProtocol[_VT]rz_KeyCreatorProtocol[_VT]rBz"MutableMapping[_KT, Optional[_VT]]r:r@z Optional[_VT]rrycCs |||SrhrFrzr]r]r^rGlsz_AssociationDict._createrArHcCs ||SrhrJrKr]r]r^rLosz_AssociationDict._getrp)rIrsrqrYcCs||||SrhrO)rirIrsrqr]r]r^r rsz_AssociationDict._set)rsrYcCs||j|Srh)rLr:rirsr]r]r^rRusz_AssociationDict.__getitem__cCs6||jkr ||j|||n||||j|<dSrh)r:r rGrzr]r]r^rXxs z_AssociationDict.__setitem__cCs |j|=dSrhrfrr]r]r^re~sz_AssociationDict.__delitem__rrUcCs ||jkSrhrfrr]r]r^risz_AssociationDict.__contains__z Iterator[_KT]r}cCst|jSrh)iterr:keysr~r]r]r^rlsz_AssociationDict.__iter__cCs|jdSrhr:rBr~r]r]r^rBsz_AssociationDict.clearr+cCs t||kSrhrrwr]r]r^r"sz_AssociationDict.__eq__cCs t||kSrhrrwr]r]r^r#sz_AssociationDict.__ne__rOcCs tt|Srh)rJrr~r]r]r^rsz_AssociationDict.__repr__)_AssociationDict__keyrYcCsdSrhr]rirr]r]r^rsz_AssociationDict.getzUnion[_VT, _T])rrKrYcCsdSrhr]rirrKr]r]r^rsNzOptional[Union[_VT, _T]]zUnion[_VT, _T, None])rsrKrYcCs(z ||WStk r"|YSXdSrh)rrirsrKr]r]r^rs cCs,||jkr ||||j|<|S||SdSrh)r:rGrr]r]r^ setdefaults z_AssociationDict.setdefaultz KeysView[_KT]cCs |jSrh)r:rr~r]r]r^rsz_AssociationDict.keyszItemsView[_KT, _VT]cCst|Srhr r~r]r]r^rsz_AssociationDict.itemszValuesView[_VT]cCst|Srhrr~r]r]r^rsz_AssociationDict.valuescCsdSrhr]rr]r]r^rsz_AssociationDict.pop.cCsdSrhr]rr]r]r^rs)rrr)rYcOs|jj|f||}||Srh)r:rrL)rirrr)rUr]r]r^rszTuple[_KT, _VT]cCs |j}|d||dfSrn)r:popitemrL)rirdr]r]r^rs z_AssociationDict.popitemz SupportsKeysAndGetItem[_KT, _VT])_AssociationDict__mrrYcKsdSrhr]rirrr]r]r^r sz_AssociationDict.updatezIterable[tuple[_KT, _VT]]cKsdSrhr]rr]r]r^r s)rrYcKsdSrhr])rirr]r]r^r s)ar)rYcOs.i}|j|||D]\}}|||<qdSrh)r r)rirr)uprsrqr]r]r^r s rzMapping[_KT, _VT]rMc Cs~t|}||pd}t|pd|}||}|p||kr>|||<q>|D] }||=qndSNr])r intersection differencer) rirNrexisting constants additionsremovalsrsrUr]r]r^rs   z_AssociationDict._bulk_replacezDict[_KT, _VT]cCs t|Srh)rrr~r]r]r^rsz_AssociationDict.copyrcCstdt|jdSrrr~r]r]r^rsz_AssociationDict.__hash__)N)N).)'rbrcrdrrrGrLr rRrXrerirlrBr"r#rrrrrrrrrr rrrrCrDrrrrrrrrr]r]r]r^resn  rc@seZdZUdZded<ddddZddd d Zd dd d dZddddZdddddZ dddddZ dddddZ ddddZ ddddd Z d!ddd"d#d$Zd%d&d'd(d)Zd*dd+d,Zd-d&dd.d/Zd%d&d0d1d2Zd3ddd4d5Zd6ddd7d8Zd3ddd9d:Zd6d;ddd?Zd6ddd@dAZd3dddBdCZd6d;ddDdEZddd0dFdGZd%d&ddHdIZd3dd'dJdKZd%d&d'dLdMZd3dd0dNdOZd3dd0dPdQZ dddRdSZ!dTddUdVZ"d dd'dWdXZ#d dd'dYdZZ$d6dd'd[d\Z%d6dd'd]d^Z&d6dd'd_d`Z'd6dd'dadbZ(dcddddeZ)dfddgdhZ*e+j,se-e./D]B\Z0Z1e2e1r|e1je0kr|e1js|e3e4e0r|e5e4e0je1_q|[0[1diS)jrz&Generic, converting, set-to-set proxy.zMutableSet[_T]r:r<r}cCs t|jSrhr=r~r]r]r^r?sz_AssociationSet.__len__rUcCs|jr dSdSdSrgrfr~r]r]r^r@sz_AssociationSet.__bool__r)_AssociationSet__orYcCs$|jD]}|||krdSqdSrgrh)rirrUr]r]r^ri s z_AssociationSet.__contains__rjccs|jD]}||VqdS)zIterate over proxied values. For the actual domain objects, iterate over .col instead or just use the underlying collection directly from its property on the parent. Nrhrkr]r]r^rls z_AssociationSet.__iter__r9rp)_AssociationSet__elementrYcCs||kr|j||dSrh)r:addrG)rirr]r]r^rsz_AssociationSet.addcCs.|jD]"}|||kr|j|q*qdSrh)r:rLdiscardrirrUr]r]r^r$s  z_AssociationSet.discardcCs8|jD]$}|||kr|j|dSqt|dSrh)r:rLrrrr]r]r^rs*s   z_AssociationSet.removecCs"|jstd|j}||S)Nzpop from an empty set)r:rrrLrkr]r]r^r1s z_AssociationSet.poprY)srYcGs"|D]}|D]}||q qdSrh)r)rirrrqr]r]r^r 7sz_AssociationSet.updaterrMc Cst|}||pd}t|pd|}||}|j}|j}|pDdD]&} | |kr\|| qF| |krF|| qF|D] } || qrdSr)rrrrrs) rirNrrrrrZappenderZremoverrUr]r]r^r<s    z_AssociationSet._bulk_replacezAbstractSet[_S]zMutableSet[Union[_T, _S]]r+cCs*t||st|D]}||q|Srh)r$_set_binops_check_strictrr)rir(rqr]r]r^__ior__Ns   z_AssociationSet.__ior__zSet[_T]cCs tt|Srh)rrr~r]r]r^r Wsz_AssociationSet._setz Iterable[_S]cGst|j|Srh)runionrirr]r]r^rZsz_AssociationSet.union)_AssociationSet__srYcCs ||Srh)rrirr]r]r^__or__]sz_AssociationSet.__or__rcGst|j|Srh)rrrr]r]r^r`sz_AssociationSet.differencezAbstractSet[Any]cCs ||Srh)rrr]r]r^__sub__csz_AssociationSet.__sub__cGs"|D]}|D]}||q qdSrh)r)rirr(rqr]r]r^difference_updatefsz!_AssociationSet.difference_updater1cCs*t||st|D]}||q|Srh)r$rrr)rirrqr]r]r^__isub__ks   z_AssociationSet.__isub__cGst|j|Srh)rrrr]r]r^rrsz_AssociationSet.intersectioncCs ||Srh)rrr]r]r^__and__usz_AssociationSet.__and__cGs\|D]R}||t|}}||||}}|D]}||q2|D]}||qFqdSrh)rrrsr)rirr(wanthaversrrqr]r]r^intersection_updatexs z#_AssociationSet.intersection_updatecCsbt||st||}t|}||||}}|D]}||q:|D]}||qN|Srh)r$rrrrrsr)rirrrrsrrqr]r]r^__iand__s    z_AssociationSet.__iand__cCst||Srh)rsymmetric_differencerr]r]r^rsz$_AssociationSet.symmetric_differencecCs ||Srh)rrr]r]r^__xor__sz_AssociationSet.__xor__cCsR||t|}}||||}}|D]}||q*|D]}||q>dSrh)rrrsr)rir(rrrsrrqr]r]r^symmetric_difference_updates  z+_AssociationSet.symmetric_difference_updatecCs t||st|||Srh)r$rrrrwr]r]r^__ixor__s  z_AssociationSet.__ixor__cCst||Srh)rissubsetrr]r]r^rsz_AssociationSet.issubsetcCst||Srh)r issupersetrr]r]r^rsz_AssociationSet.issupersetcCs|jdSrhrr~r]r]r^rBsz_AssociationSet.clearzAbstractSet[_T]cCst|Srhrr~r]r]r^rsz_AssociationSet.copycCs t||kSrhrrwr]r]r^r"sz_AssociationSet.__eq__cCs t||kSrhrrwr]r]r^r#sz_AssociationSet.__ne__cCs t||kSrhrrwr]r]r^rxsz_AssociationSet.__lt__cCs t||kSrhrrwr]r]r^rysz_AssociationSet.__le__cCs t||kSrhrrwr]r]r^rzsz_AssociationSet.__gt__cCs t||kSrhrrwr]r]r^r{sz_AssociationSet.__ge__rOcCs tt|Srh)rJrr~r]r]r^rsz_AssociationSet.__repr__rcCstdt|jdSrrr~r]r]r^rsz_AssociationSet.__hash__N)6rbrcrdrrr?r@rirlrrrsrr rrr rrrrrrrrrrrrrrrrrBrr"r#rxryrzr{rrrCrDrrrrrrrrrr]r]r]r^rsh     r)dr __future__rrrCrrrrrrr r r r rrrrrrrrrrrrrrrrr r!r"r#r$r%r&r'Zorm.baser(Zorm.interfacesr)r*r+sqlr,r-Zsql.baser.Z util.typingr/r0r1r2r3rDr4r5Z orm.mapperr6Z sql._typingr7r8r9r;r=r?r@rAZNO_ARGr_r`rermrorrrtrurxr{rrrrZInspectionAttrInfor\rrrrrrr7r8rErrrr]r]r]r^s                                                        0"   V -h; Bc