a
    [go                     @  s   U d Z ddlmZ ddlmZ ddlZddlZddlZddlZddlm	Z	 ddlm
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z" ddl m#Z# ddl m$Z$ ddl m%Z% ddlm&Z& ddlm'Z' d d!lm(Z( d d"lm)Z* d d#lm+Z+ d d$lm,Z, d dlmZ d d%l,m-Z- d d&l,m.Z. d d'l/m0Z0 d d(l1m2Z2 d d)l1m3Z3 d d*l1m4Z4 ejr*dd+l5m6Z6 dd,l5m7Z7 dd-lm8Z8 dd.lm9Z9 dd/lm:Z: dd0l;m<Z< dd1l=m>Z> dd2l?m@Z@ dd3lAmBZB dd4lAmCZC dd5lDmEZE d d6lFmGZG d d7lHmIZI d d8lJmKZK d d9lJmLZL d d:l/mMZM d d;l/mNZN d d<lOmPZP d d=lQmRZR d d>lSmTZT d d?l1mUZU d d@l1mVZV d dAl1mWZW d dBl1mXZX edCe	dDZYedEe	dDZZG dFdG dGe$eY Z[ee\dHdIdJdKf Z]edLe	dDZ^e_ Z`dMeadN< G dOdP dPe#e^ e"e[e^ ZbG dQdR dRebeY eeY ZcG dSdT dTe[eY ZdG dUdV dVe[eY ZeG dWdX dXeeeY eeY ZfdS )YzDescriptor properties are more "auxiliary" properties
that exist as configurational elements, but don't participate
as actively in the load/persist ORM loop.

    )annotations)is_dataclassN)Any)Callable)Dict)List)NoReturn)Optional)Sequence)Tuple)Type)TYPE_CHECKING)TypeVar)Union   )
attributes)util)_DeclarativeMapped)LoaderCallableStatus)Mapped)PassiveFlag)SQLORMOperations)_AttributeOptions)_IntrospectsAnnotations)_MapsColumns)MapperProperty)PropComparator)	_none_set)de_stringify_annotation   )event)exc)schema)sql
expression)	operators)BindParameter)get_args)
is_fwd_ref)	is_pep593)_InstanceDict)_RegistryType)History)InstrumentedAttribute)QueryableAttribute)ORMCompileState)_ClassScanMapperConfig)Mapper)ColumnPropertyMappedColumn)InstanceState)
Connection)Row)_DMLColumnArgument)	_InfoType)
ClauseList)ColumnElement)OperatorType)Column)Select)_AnnotationScanType)CallableReference)DescriptorReference)RODescriptorReference_T)bound_PTc                   @  sX   e Zd ZU dZdZded< dZdZded< ej	fdd	d
ddddZ
dddddZdS )DescriptorPropertyzO:class:`.MapperProperty` which proxies access to a
    user-defined descriptor.NOptional[str]docFzDescriptorReference[Any]
descriptorInstanceState[Any]r+   r   r-   statedict_passivereturnc                 C  s
   t  d S N)NotImplementedErrorselfrM   rN   rO    rU   m/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/site-packages/sqlalchemy/orm/descriptor_props.pyget_historyf   s    zDescriptorProperty.get_historyMapper[Any]NonemapperrP   c                   s   G fdddt j}jd u rHt jjd } j|rH|_jd u rddddfdd}dddfd	d
}dddfdd}t|||d_t jj	jjj fddj
d}|j|_ jj| d S )Nc                      sZ   e Zd ZdZdZdZedd fddZddd	d
Ze	j
fddddd fddZdS )z7DescriptorProperty.instrument_class.<locals>._ProxyImplFTboolrP   c                   s    j S rQ   )uses_objectsrT   proprU   rV   r^   v   s    zDDescriptorProperty.instrument_class.<locals>._ProxyImpl.uses_objectsstrkeyc                 S  s
   || _ d S rQ   rc   )rT   rd   rU   rU   rV   __init__z   s    z@DescriptorProperty.instrument_class.<locals>._ProxyImpl.__init__rK   r+   r   r-   rL   c                   s     |||S rQ   )rW   rS   r`   rU   rV   rW   }   s    zCDescriptorProperty.instrument_class.<locals>._ProxyImpl.get_historyN)__name__
__module____qualname__Zaccepts_scalar_loaderZload_on_unexpireZ
collectionpropertyr^   re   r   PASSIVE_OFFrW   rU   r`   rU   rV   
_ProxyImplq   s   rk   r   rY   )objvaluerP   c                   s   t |  j| d S rQ   )setattrname)rl   rm   r_   rU   rV   fset   s    z1DescriptorProperty.instrument_class.<locals>.fset)rl   rP   c                   s   t |  j d S rQ   )delattrro   rl   r_   rU   rV   fdel   s    z1DescriptorProperty.instrument_class.<locals>.fdelc                   s   t |  jS rQ   )getattrro   rr   r_   rU   rV   fget   s    z1DescriptorProperty.instrument_class.<locals>.fget)ru   rp   rs   c                     s
     S rQ   )_comparator_factoryrU   )r[   rT   rU   rV   <lambda>       z5DescriptorProperty.instrument_class.<locals>.<lambda>)rI   Zoriginal_property)r   ZAttributeImplrJ   rt   class_rd   Z_is_userland_descriptorri   Zcreate_proxied_attributeparentrI   implclass_managerZinstrument_attribute)rT   r[   rk   descrp   rs   ru   
proxy_attrrU   )r[   ra   rT   rV   instrument_classn   s*    


z#DescriptorProperty.instrument_class)rf   rg   rh   __doc__rI   __annotations__r^   Z_links_to_entityr   rj   rW   r   rU   rU   rU   rV   rG   [   s   
rG   z
Column[_T]zMappedColumn[_T]zInstrumentedAttribute[_T]z
Mapped[_T]_CCzFweakref.WeakKeyDictionary[Type[Any], Callable[[Any], Tuple[Any, ...]]]_composite_gettersc                      s0  e Zd ZU dZded< ded< ded< ded	< dad
ddd
d
d
ddddddddddd	 fddZddd fddZdddd d!Zdd"d#d$Ze	 Z
dd"d%d&Zed'd(d)d*dd+d,d-d-ddd.
d/d0Zdd"d1d2Zed'ed3d)d*dd+dd4d5d6Zejd7d"d8d9Zejed:d;d"d<d=Zejed:d>d"d?d@ZedAd"dBdCZedDd"dEdFZed:dd"dGdHZdd"dIdJZejdKd"dLdMZdNd"dOdPZejfdQdRdSdTdUdVdWZddXddYdZZ G d[d\ d\e!j"e# Z$G d]d^ d^e%e& Z'd+d"d_d`Z(  Z)S )bCompositePropertyzDefines a "composite" mapped attribute, representing a collection
    of columns as one attribute.

    :class:`.CompositeProperty` is constructed using the :func:`.composite`
    function.

    .. seealso::

        :ref:`mapper_composite`

    z$Union[Type[_CC], Callable[..., _CC]]composite_classz#Tuple[_CompositeAttrType[Any], ...]attrsz=CallableReference[Optional[Callable[[_CC], Tuple[Any, ...]]]]_generated_composite_accessorzType[Comparator[_CC]]comparator_factoryNF)attribute_optionsactive_historydeferredgroupr   infozCUnion[None, Type[_CC], Callable[..., _CC], _CompositeAttrType[Any]]z_CompositeAttrType[Any]Optional[_AttributeOptions]r\   rH   zOptional[Type[Comparator[_CC]]]Optional[_InfoType]r   )	_class_or_attrr   r   r   r   r   r   r   kwargsc          
        s   t  j|d t|tttjfr4|f| | _d | _n|| _|| _|| _	|| _
|| _|d ur^|n| jj| _d | _|d ur| j| t|  |   |   d S N)r   )superre   
isinstancer   rb   r#   r<   r   r   r   r   r   	__class__
Comparatorr   r   r   updater   set_creation_order_create_descriptor_init_accessor)
rT   r   r   r   r   r   r   r   r   r   r   rU   rV   re      s&    
zCompositeProperty.__init__rX   rY   rZ   c                   s   t  | |   d S rQ   )r   r   _setup_event_handlersrT   r[   r   rU   rV   r      s    z"CompositeProperty.instrument_classr   zTuple[Any, ...]rm   rP   c              
   C  sb   | j r|  |S z
|j}W n< tyV } z$td| jj d|W Y d }~nd }~0 0 | S d S )NzComposite class zX is not a dataclass and does not define a __composite_values__() method; can't get state)r   __composite_values__AttributeErrorsa_excInvalidRequestErrorr   rf   )rT   rm   accessorZaerU   rU   rV   _composite_values_from_instance   s    

z1CompositeProperty._composite_values_from_instancer]   c                 C  s   |    dS )zwInitialization which occurs after the :class:`.Composite`
        has been associated with its parent mapper.

        N)_setup_arguments_on_columnsr_   rU   rU   rV   do_init  s    zCompositeProperty.do_initc                   sT   dddfdd dddd fdd}ddd fd	d
}t  ||_dS )ztCreate the Python descriptor that will serve as
        the access point on instances of the mapped class.

        r   )instancerP   c                   s   t  }t  }j|vrx fddjD }j|vrx|jd usPt|sxj| |j< |jj	
|jjg |jd S )Nc                   s   g | ]}t  |qS rU   )rt   .0rd   r   rU   rV   
<listcomp>  s   zFCompositeProperty._create_descriptor.<locals>.fget.<locals>.<listcomp>)r   instance_dictinstance_staterd   _attribute_keysr   
issupersetr   managerdispatchrefresh_COMPOSITE_FGETget)r   rN   rM   valuesr_   r   rV   ru     s     



	
z2CompositeProperty._create_descriptor.<locals>.fgetrY   )r   rm   rP   c                   s   t | }t | }|jj }|jjr2 | }n|jtj	}|jj
D ]}|||||j}qJ||j< |d u rjD ]}t| |d  qxn(tj|D ]\}}t| || qd S rQ   )r   r   r   r   rd   r   _active_historyr   r   NO_VALUEsetr{   r   rn   zipr   )r   rm   rN   rM   attrpreviousfnrd   ru   rT   rU   rV   rp   1  s"    




z2CompositeProperty._create_descriptor.<locals>.fsetc                   s   t | }t | }|jj }|jjr@ | }|jd  n|jtj	}|jj }|j
|||j jD ]}t| |d  qtd S rQ   )r   r   r   r   rd   r   r   popr   r   remover{   r   rn   )r   rM   rN   r   r   rd   r   rU   rV   rs   H  s    


z2CompositeProperty._create_descriptor.<locals>.fdelN)ri   rJ   )rT   rp   rs   rU   r   rV   r     s    z$CompositeProperty._create_descriptorsqlalchemy.orm.propertiesr1   r,   z	Type[Any]rb   zOptional[Type[Mapped[Any]]]zOptional[_AnnotationScanType])
	decl_scanregistryclsoriginating_modulerd   mapped_container
annotationextracted_mapped_annotationis_dataclass_fieldrP   c
                 C  s
  t jjj}
| jd u r(|d u r(| || |}t|r@t|d }|r| jd u rt|t	sdt
|ddr|d u rt|dr||jnt	|}td| d| dt|||dd}|| _t| jr| |||| n0| jD ](}t||
tjfr|jd u rtd	q|   d S )
Nr   T)Zcheck_generic__forward_arg__zCan't use forward ref z9 for composite class argument; set up the type as Mapped[])Zinclude_genericzIComposite class column arguments must be named unless a dataclass is used)r   	preloadedorm_propertiesr5   r   Z_raise_for_requiredr*   r(   r   rb   r)   hasattrr   r   ArgumentErrorr   r   _setup_for_dataclassr   r"   r>   ro   r   )rT   r   r   r   r   rd   r   r   r   r   r5   argumentZstr_argr   rU   rU   rV   declarative_scanZ  sL    


z"CompositeProperty.declarative_scanc                   s   t | jr`t| jds`t| j}tjdd |j D   t	|jdkrZ fdd| _
n | _
| jd urt| jtr| jtvr| j
d ur| j
t| j< nt| jdrdd t| j< d S )Nr   c                 S  s   g | ]
}|j qS rU   )ro   )r   prU   rU   rV   r     rx   z4CompositeProperty._init_accessor.<locals>.<listcomp>r   c                   s
    | fS rQ   rU   rr   getterrU   rV   rw     rx   z2CompositeProperty._init_accessor.<locals>.<lambda>c                 S  s   |   S rQ   r   rr   rU   rU   rV   rw     rx   )r   r   r   inspect	signatureoperator
attrgetter
parametersr   lenr   r   typer   )rT   insprU   r   rV   r     s,    


z CompositeProperty._init_accessorzsqlalchemy.orm.decl_base)r   r   r   rd   rP   c           
   
   C  s   t jjj}t jj}t| j}t	|j
 | jD ]\}}	|d u rntdt| j d| jj dt|j
 |	d u r| }	|  j|	f7  _t|	|r|	|||||j|j q2t|	tjr2||j|	 q2d S )Nznumber of composite attributes z3 exceeds that of the number of attributes in class  )r   r   r   r5   Zorm_decl_baser   r   r   	itertoolszip_longestr   r   r   r   r   r   rf   r   Zdeclarative_scan_for_compositero   r   r"   r>   Z_undefer_column_name)
rT   r   r   r   rd   r5   	decl_baser   paramr   rU   rU   rV   r     s<    	

z&CompositeProperty._setup_for_dataclass!Sequence[QueryableAttribute[Any]]c                   s    fdd j D S )Nc                   s   g | ]}t  jj|jqS rU   )rt   rz   ry   rd   r   ra   r_   rU   rV   r     rx   z:CompositeProperty._comparable_elements.<locals>.<listcomp>propsr_   rU   r_   rV   _comparable_elements  s    z&CompositeProperty._comparable_elementszorm.propertieszSequence[MapperProperty[Any]]c                 C  s   g }t jjj}| jD ]}t|tr4| jj|dd}nLt|t	j
rN| jj| }n2t||rh| jj|j }nt|tjr||j}nd }t|tstd||| q|S )NF)Z_configure_mapperszYComposite expects Column objects or mapped attributes/attribute names as arguments, got: )r   r   r   r5   r   r   rb   rz   Zget_propertyr"   r>   _columntopropertycolumnr   r.   ri   r   r   r   append)rT   r   r5   r   ra   rU   rU   rV   r     s(    




zCompositeProperty.propszSequence[Column[Any]]c                   s   t jjj  fdd| jD S )Nc                   s0   g | ](}t |tj frt | r(|jn|qS rU   )r   r"   r>   r   )r   ar4   rU   rV   r     s   z-CompositeProperty.columns.<locals>.<listcomp>)r   r   r   r5   r   r_   rU   r4   rV   columns  s    

zCompositeProperty.columnszOptional[MapperProperty[_CC]]c                 C  s   | S rQ   rU   r_   rU   rU   rV   mapper_property_to_assign  s    z+CompositeProperty.mapper_property_to_assignz$List[Tuple[schema.Column[Any], int]]c                 C  s   dd | j D S )Nc                 S  s   g | ]}|j d u r|dfqS )Nr   )table)r   crU   rU   rV   r     rx   z7CompositeProperty.columns_to_assign.<locals>.<listcomp>)r   r_   rU   rU   rV   columns_to_assign  s    z#CompositeProperty.columns_to_assignc                 C  sP   t jjj}| jD ]:}t||s"qn|}| j|_| jrB| j|_d|_| j	|_	qdS )zwPropagate configuration arguments made on this composite
        to the target columns, for those that apply.

        ))r   T)Z
instrumentTN)
r   r   r   r3   r   r   r   r   Zstrategy_keyr   )rT   r3   ra   ZcproprU   rU   rV   r   	  s    


z-CompositeProperty._setup_arguments_on_columnsc                   s
  dddd fdd}ddddd fd	d
}ddddddfdd ddddfdd}dddddfdd}t jjd|dd t jjd|dd t jjd|ddd t jjd|ddd t jjd|ddd jjj }|j|j_j|jj_dS ) z>Establish events that populate/expire the composite attribute.rK   r0   rY   )rM   contextrP   c                   s    | |d dd d S )NF
is_refreshrU   )rM   r   )_load_refresh_handlerrU   rV   load_handler   s    z=CompositeProperty._setup_event_handlers.<locals>.load_handlerzOptional[Sequence[str]])rM   r   to_loadrP   c                   s.   |rj hj|r* | ||dd d S )NTr   )rd   unionr   intersection)rM   r   r   r   rT   rU   rV   refresh_handler%  s    z@CompositeProperty._setup_event_handlers.<locals>.refresh_handlerr\   )rM   r   r   r   rP   c                   s`    j }|r|ju r"j|v r"d S jD ]}||vr( d S q(j fddjD  |j< d S )Nc                   s   g | ]} j | qS rU   )dictr   rM   rU   rV   r   O  rx   zZCompositeProperty._setup_event_handlers.<locals>._load_refresh_handler.<locals>.<listcomp>)r   r   rd   r   r   )rM   r   r   r   rN   kr_   r   rV   r   1  s    
zFCompositeProperty._setup_event_handlers.<locals>._load_refresh_handler)rM   keysrP   c                   s,   |d u st  j|r(| j jd  d S rQ   )r   r   r   r   r   rd   )rM   r   r_   rU   rV   expire_handlerR  s    z?CompositeProperty._setup_event_handlers.<locals>.expire_handlerrX   r7   )r[   
connectionrM   rP   c                   s   |j  jd dS )zAfter an insert or update, some columns may be expired due
            to server side defaults, or re-populated due to client side
            defaults.  Pop out the composite value here so that it
            recreates.

            N)r   r   rd   )r[   r   rM   r_   rU   rV   insert_update_handlerX  s    zFCompositeProperty._setup_event_handlers.<locals>.insert_update_handlerZafter_insertT)rawZafter_updateload)r  	propagater   ZexpireN)	r    listenrz   r|   rd   r   r{   r   r   )rT   r   r   r   r  r~   rU   r   rV   r     s.    !


z'CompositeProperty._setup_event_handlersSequence[str]c                 C  s   dd | j D S )Nc                 S  s   g | ]
}|j qS rU   rc   r   rU   rU   rV   r   ~  rx   z5CompositeProperty._attribute_keys.<locals>.<listcomp>r   r_   rU   rU   rV   r   |  s    z!CompositeProperty._attribute_keysz Callable[[Dict[str, Any]], None]c                   sJ   j rj nddddddd jD  dd	d
 fdd}|S )Nr   z
Tuple[Any])valrP   c                 S  s   |   S rQ   r   )r  rU   rU   rV   
get_values  s    zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.get_valuesc                 S  s   g | ]
}|j qS rU   rc   r   rU   rU   rV   r     rx   zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.<listcomp>zDict[str, Any]rY   )	dest_dictrP   c              	     s*   |  dd t | jD  d S )Nc                 S  s   i | ]\}}||qS rU   rU   )r   rd   r  rU   rU   rV   
<dictcomp>  s   zaCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate.<locals>.<dictcomp>)r   r   r   rd   )r	  r   r  rT   rU   rV   populate  s    zMCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate)r   r   )rT   r  rU   r  rV   )_populate_composite_bulk_save_mappings_fn  s    
z;CompositeProperty._populate_composite_bulk_save_mappings_fnrK   r+   r   r-   rL   c                 C  s   g }g }d}| j D ]j}|j}|j| j||}	|	 r<d}|	 }
|
rT||
 n
|d |	j	rr||	j	 q|d q|rt
| j| gd| j| gS t
d| j| gdS dS )z>Provided for userland code that uses attributes.get_history().FTNrU   )r   rd   r   r{   rW   Zhas_changesnon_deletedextendr   deletedr   r-   r   )rT   rM   rN   rO   addedr  Zhas_historyra   rd   histr  rU   rU   rV   rW     s,    



zCompositeProperty.get_historyzComposite.Comparator[_CC]c                 C  s   |  | |S rQ   )r   r   rU   rU   rV   rv     s    z%CompositeProperty._comparator_factoryc                      s8   e Zd Zddd fddZdddd	d
ddZ  ZS )z!CompositeProperty.CompositeBundlezComposite[_T]r;   )	property_exprc                   s    || _ t j|jg|R   d S rQ   )ri   r   re   rd   )rT   r  r  r   rU   rV   re     s    z*CompositeProperty.CompositeBundle.__init__zSelect[Any]z#Sequence[Callable[[Row[Any]], Any]]r  zCallable[[Row[Any]], Any])queryprocslabelsrP   c                   s   ddd fdd}|S )NzRow[Any]r   )rowrP   c                   s   j j fddD  S )Nc                   s   g | ]}| qS rU   rU   )r   procr  rU   rV   r     rx   zXCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc.<locals>.<listcomp>)ri   r   r  r  rT   r  rV   r    s    zDCompositeProperty.CompositeBundle.create_row_processor.<locals>.procrU   )rT   r  r  r  r  rU   r  rV   create_row_processor  s    z6CompositeProperty.CompositeBundle.create_row_processor)rf   rg   rh   re   r  __classcell__rU   rU   r   rV   CompositeBundle  s   r  c                   @  s   e Zd ZU dZdZded< ejddddZd	dd
dZ	ejd	dddZ
dddddZejddddZdddddZdddddZdddddZdddddZdddd d!Zdddd"d#Zd$ddd%d&d'ZdS )(zCompositeProperty.Comparatora  Produce boolean, comparison, and other operators for
        :class:`.Composite` attributes.

        See the example in :ref:`composite_operations` for an overview
        of usage , as well as the documentation for :class:`.PropComparator`.

        .. seealso::

            :class:`.PropComparator`

            :class:`.ColumnOperators`

            :ref:`types_operators`

            :attr:`.TypeEngine.comparator_factory`

        Nz%RODescriptorReference[Composite[_PT]]ra   r;   r]   c                 C  s   t j| jddiS )Nr   F)r%   r;   r   r_   rU   rU   rV   clauses  s
    z$CompositeProperty.Comparator.clausesz&CompositeProperty.CompositeBundle[_PT]c                 C  s   | j S rQ   r$   r_   rU   rU   rV   __clause_element__  s    z/CompositeProperty.Comparator.__clause_element__c                 C  s*   | j | j| j| jjd}t| j|S )N)ZparententityZparentmapper	proxy_key)r  Z	_annotateZ_parententityra   rd   r   r  )rT   r  rU   rU   rV   r%     s    z'CompositeProperty.Comparator.expressionr   z(Sequence[Tuple[_DMLColumnArgument, Any]]r   c                 C  sz   t |tr|j}|d u r,dd | jjD }n>t | jjtrVt || jjrV| j|}nt	d| j|f t
t| j|S )Nc                 S  s   g | ]}d qS rQ   rU   r   rU   rU   rV   r     rx   zDCompositeProperty.Comparator._bulk_update_tuples.<locals>.<listcomp>z)Can't UPDATE composite attribute %s to %r)r   r'   rm   ra   r   r   r   r   r   r   listr   r   )rT   rm   r   rU   rU   rV   _bulk_update_tuples  s     
z0CompositeProperty.Comparator._bulk_update_tuplesr   c                   s(    j r fdd jjD S  jjS d S )Nc                   s   g | ]}t  jj|jqS rU   )rt   _adapt_to_entityentityrd   r   r_   rU   rV   r     s   zECompositeProperty.Comparator._comparable_elements.<locals>.<listcomp>)r$  ra   r   r_   rU   r_   rV   r     s
    
z1CompositeProperty.Comparator._comparable_elementszColumnElement[bool])otherrP   c                 C  s   |  tj|S rQ   )_comparer&   eqrT   r&  rU   rU   rV   __eq__&  s    z#CompositeProperty.Comparator.__eq__c                 C  s   |  tj|S rQ   )r'  r&   ner)  rU   rU   rV   __ne__)  s    z#CompositeProperty.Comparator.__ne__c                 C  s   |  tj|S rQ   )r'  r&   ltr)  rU   rU   rV   __lt__,  s    z#CompositeProperty.Comparator.__lt__c                 C  s   |  tj|S rQ   )r'  r&   gtr)  rU   rU   rV   __gt__/  s    z#CompositeProperty.Comparator.__gt__c                 C  s   |  tj|S rQ   )r'  r&   ler)  rU   rU   rV   __le__2  s    z#CompositeProperty.Comparator.__le__c                 C  s   |  tj|S rQ   )r'  r&   ger)  rU   rU   rV   __ge__5  s    z#CompositeProperty.Comparator.__ge__r=   )r   r&  rP   c                   st   |d u rd gt jj }nj|} fddtjj|D }jrjjd usXJ fdd|D }tj| S )Nc                   s   g | ]\}} ||qS rU   rU   )r   r   b)r   rU   rV   r   G  s   z9CompositeProperty.Comparator._compare.<locals>.<listcomp>c                   s   g | ]}  |qS rU   )adapter)r   xr_   rU   rV   r   M  rx   )	r   ra   r   r   r   r$  r6  r#   and_)rT   r   r&  r   ZcomparisonsrU   )r   rT   rV   r'  ?  s    
z%CompositeProperty.Comparator._compare)rf   rg   rh   r   __hash__r   r   memoized_propertyr  r   r%   r#  r   r*  r,  r.  r0  r2  r4  r'  rU   rU   rU   rV   r     s$   

	
r   c                 C  s   t | jjjd | j S )N.)rb   rz   ry   rf   rd   r_   rU   rU   rV   __str__P  s    zCompositeProperty.__str__)N)*rf   rg   rh   r   r   re   r   r   r   objectr   r   r   preload_moduler   r   r   r:  r   r   Znon_memoized_propertyr   ri   r   r   r   r   r   r  r   rj   rW   rv   orm_utilZBundlerD   r  r   rF   r   r<  r  rU   rU   r   rV   r      sb   
 &(J"9'_%xr   c                   @  s   e Zd ZdZdZdS )	CompositeaS  Declarative-compatible front-end for the :class:`.CompositeProperty`
    class.

    Public constructor is the :func:`_orm.composite` function.

    .. versionchanged:: 2.0 Added :class:`_orm.Composite` as a Declarative
       compatible subclass of :class:`_orm.CompositeProperty`.

    .. seealso::

        :ref:`mapper_composite`

    TNrf   rg   rh   r   Zinherit_cacherU   rU   rU   rV   r@  T  s   r@  c                      s6   e Zd ZdZdddddZdd fd	d
Z  ZS )ConcreteInheritedPropertya4  A 'do nothing' :class:`.MapperProperty` that disables
    an attribute on a concrete subclass that is only present
    on the inherited mapper, not the concrete classes' mapper.

    Cases where this occurs include:

    * When the superclass mapper is mapped against a
      "polymorphic union", which includes all attributes from
      all subclasses.
    * When a relationship() is configured on an inherited mapper,
      but not on the subclass mapper.  Concrete mappers require
      that relationship() is configured explicitly on each
      subclass.

    rX   zType[PropComparator[_T]]rZ   c                 C  sP   d }| j  D ]*}|j| j }t|dd d ur|j} q:q|d usFJ |||S )Nr   )rz   Ziterate_to_rootZ_propsrd   rt   r   )rT   r[   Zcomparator_callablemr   rU   rU   rV   rv   x  s    z-ConcreteInheritedProperty._comparator_factoryrY   r]   c                   s<   t    dd fddG  fddd}|  _d S )Nr   r]   c                     s   t d j j jf d S )NzgConcrete %s does not implement attribute %r at the instance level.  Add this property explicitly to %s.)r   rz   rd   rU   r_   rU   rV   warn  s
    z0ConcreteInheritedProperty.__init__.<locals>.warnc                      sT   e Zd ZdddddfddZddddfddZddddd	 fd
dZdS )zDConcreteInheritedProperty.__init__.<locals>.NoninheritedConcretePropr   r   )srl   rm   rP   c                   s
      d S rQ   rU   )rE  rl   rm   rD  rU   rV   __set__  s    zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__set__)rE  rl   rP   c                   s
      d S rQ   rU   )rE  rl   rF  rU   rV   
__delete__  s    zOConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__delete__)rE  rl   ownerrP   c                   s   |d u r j S   d S rQ   )rJ   )rE  rl   rI  rT   rD  rU   rV   __get__  s    zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__get__N)rf   rg   rh   rG  rH  rK  rU   rJ  rU   rV   NoninheritedConcreteProp  s   rL  )r   re   rJ   )rT   rL  r   rJ  rV   re     s    
z"ConcreteInheritedProperty.__init__)rf   rg   rh   r   rv   re   r  rU   rU   r   rV   rB  g  s   rB  c                	      s   e Zd ZU dZded< d&dddddd	d
d fddZesLeddddZe	j
ddddZdddddZejfddddddd Ze	d!ddd"d#d$d%Z  ZS )'SynonymPropertya8  Denote an attribute name as a synonym to a mapped property,
    in that the attribute will mirror the value and expression behavior
    of another attribute.

    :class:`.Synonym` is constructed using the :func:`_orm.synonym`
    function.

    .. seealso::

        :ref:`synonyms` - Overview of synonyms

    z"Optional[Type[PropComparator[_T]]]r   Nrb   zOptional[bool]zOptional[Any]r   r   rH   )ro   
map_columnrJ   r   r   r   rI   c                   sj   t  j|d || _|| _|| _|| _|r2|| _n|rF|jrF|j| _nd | _|r\| j	| t
|  d S r   )r   re   ro   rN  rJ   r   rI   r   r   r   r   r   )rT   ro   rN  rJ   r   r   r   rI   r   rU   rV   re     s    


zSynonymProperty.__init__r\   r]   c                 C  s   t | jj| jjjS rQ   )rt   rz   ry   ro   r{   r^   r_   rU   rU   rV   r^     s    zSynonymProperty.uses_objectsz/Union[MapperProperty[_T], SQLORMOperations[_T]]c                 C  sh   t | jj| j}t|dr&t|jtsbt|tj	r8|j
S t|trF|S td| jjj| j|f |jS )Nri   zGsynonym() attribute "%s.%s" only supports ORM mapped attributes, got %r)rt   rz   ry   ro   r   r   ri   r   r   r/   Z
comparatorr   r   r   rf   )rT   r   rU   rU   rV   _proxied_object  s    
zSynonymProperty._proxied_objectrX   zSQLORMOperations[_T]rZ   c                 C  s<   | j }t|tr4| jr$| ||}n|||}|S |S d S rQ   )rO  r   r   r   )rT   r[   ra   comprU   rU   rV   rv     s    
z#SynonymProperty._comparator_factoryrK   r+   r   r-   rL   c                 C  s"   t | jj| j}|jj|||dS )N)rO   )rt   rz   ry   ro   r{   rW   )rT   rM   rN   rO   r   rU   rU   rV   rW     s    zSynonymProperty.get_historyr   rY   )rz   initrP   c                 C  s   t jj}| jr| j|jjvr:td| j	|jj
| jf nN|jj| j |jv r|j|jj| j  j| j	krtd| j| j	| j	| jf ||jj| j }|j| j	||dd | j|_|| _d S )Nz>Can't compile synonym '%s': no column on table '%s' named '%s'zpCan't call map_column=True for synonym %r=%r, a ColumnProperty already exists keyed to the name %r for column %rT)rQ  Z	setparent)r   r   r   rN  rd   Zpersist_selectabler   r   r   ro   descriptionr   r3   Z_configure_propertyZ_mapped_by_synonymrz   )rT   rz   rQ  
propertiesr   rU   rU   rV   
set_parent  s@    
zSynonymProperty.set_parent)NNNNNN)rf   rg   rh   r   r   re   r   ri   r^   r   r:  rO  rv   r   rj   rW   r>  rT  r  rU   rU   r   rV   rM    s&   
       	rM  c                   @  s   e Zd ZdZdZdS )SynonymaK  Declarative front-end for the :class:`.SynonymProperty` class.

    Public constructor is the :func:`_orm.synonym` function.

    .. versionchanged:: 2.0 Added :class:`_orm.Synonym` as a Declarative
       compatible subclass for :class:`_orm.SynonymProperty`

    .. seealso::

        :ref:`synonyms` - Overview of synonyms

    TNrA  rU   rU   rU   rV   rU  &  s   rU  )gr   
__future__r   dataclassesr   r   r   r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   weakref r   r   r?  baser   r   r   r   r   Z
interfacesr   r   r   r   r   r   r   r    r!   r   r"   r#   r%   r&   Zsql.elementsr'   Zutil.typingr(   r)   r*   Z_typingr+   r,   r-   r.   r/   r   r0   r   r1   r[   r2   rS  r3   r5   rM   r6   Zengine.baser7   Z
engine.rowr8   Zsql._typingr9   r:   r;   r<   Zsql.operatorsr=   Z
sql.schemar>   Zsql.selectabler?   r@   rA   rB   rC   rD   rF   rG   rb   Z_CompositeAttrTyper   WeakKeyDictionaryr   r   r   r@  rB  rM  rU  rU   rU   rU   rV   <module>   s   H	

     %8 