o
    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rd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                   @  sH   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Z
dddZdS )DescriptorPropertyzO:class:`.MapperProperty` which proxies access to a
    user-defined descriptor.NOptional[str]docFzDescriptorReference[Any]
descriptorstateInstanceState[Any]dict_r+   passiver   returnr-   c                 C  s   t  N)NotImplementedErrorselfrK   rM   rN    rT   Y/var/www/html/api-tag/env/lib/python3.10/site-packages/sqlalchemy/orm/descriptor_props.pyget_historyf   s   zDescriptorProperty.get_historymapperMapper[Any]Nonec                   s   G fdddt j}jd u r$t jjd } j|r$|_jd u rFdfdd	}df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                      sH   e Zd ZdZdZdZed fddZdd	d
Ze	j
fd fddZdS )z7DescriptorProperty.instrument_class.<locals>._ProxyImplFTrO   boolc                   s    j S rP   )uses_objectsrS   proprT   rU   r[   v   s   zDDescriptorProperty.instrument_class.<locals>._ProxyImpl.uses_objectskeystrc                 S  s
   || _ d S rP   r_   )rS   r_   rT   rT   rU   __init__z      
z@DescriptorProperty.instrument_class.<locals>._ProxyImpl.__init__rK   rL   rM   r+   rN   r   r-   c                   s     |||S rP   )rV   rR   r]   rT   rU   rV   }   s   zCDescriptorProperty.instrument_class.<locals>._ProxyImpl.get_historyNrO   rZ   )r_   r`   rK   rL   rM   r+   rN   r   rO   r-   )__name__
__module____qualname__accepts_scalar_loaderload_on_unexpire
collectionpropertyr[   rb   r   PASSIVE_OFFrV   rT   r]   rT   rU   
_ProxyImplq   s    
rn   objr   valuerO   rY   c                   s   t |  j| d S rP   )setattrname)ro   rp   r\   rT   rU   fset   s   z1DescriptorProperty.instrument_class.<locals>.fsetc                   s   t |  j d S rP   )delattrrr   ro   r\   rT   rU   fdel   s   z1DescriptorProperty.instrument_class.<locals>.fdelc                   s   t |  jS rP   )getattrrr   ru   r\   rT   rU   fget   s   z1DescriptorProperty.instrument_class.<locals>.fget)rx   rs   rv   c                     s
     S rP   )_comparator_factoryrT   )rW   rS   rT   rU   <lambda>      
 z5DescriptorProperty.instrument_class.<locals>.<lambda>)rI   original_property)ro   r   rp   r   rO   rY   )ro   r   rO   rY   )ro   r   rO   r   )r   AttributeImplrJ   rw   class_r_   _is_userland_descriptorrl   create_proxied_attributeparentrI   implclass_managerinstrument_attribute)rS   rW   rn   descrs   rv   rx   
proxy_attrrT   )rW   r^   rS   rU   instrument_classn   s*   


z#DescriptorProperty.instrument_classre   rW   rX   rO   rY   )rf   rg   rh   __doc__rI   __annotations__r[   _links_to_entityr   rm   rV   r   rT   rT   rT   rU   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                      s  e Zd ZU dZded< ded< ded< ded	< 	
dpd
ddd
d
d
ddq fddZdr fd"d#Zdsd'd(Zdtd)d*Ze	 Z
dtd+d,Zed-dud=d>Zdtd?d@Zed-edAdvdBdCZejdwdEdFZejedGdxdIdJZejedGdydLdMZedzdOdPZed{dRdSZedGdtdTdUZdtdVdWZejd|dYdZZd}d\d]Zejfd~dedfZddhdiZ G djdk dke!j"e# Z$G dldm dme%e& Z'ddndoZ(  Z)S )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   info_class_or_attrCUnion[None, Type[_CC], Callable[..., _CC], _CompositeAttrType[Any]]_CompositeAttrType[Any]r   Optional[_AttributeOptions]r   rZ   r   r   rH   Optional[Type[Comparator[_CC]]]r   Optional[_InfoType]kwargsr   c          
        s   t  j|d t|tttjfr|f| | _d | _n|| _|| _|| _	|| _
|| _|d ur/|n| jj| _d | _|d urA| j| t|  |   |   d S N)r   )superrb   
isinstancer   r`   r#   r<   r   r   r   r   r   	__class__
Comparatorr   r   r   updater   set_creation_order_create_descriptor_init_accessor)
rS   r   r   r   r   r   r   r   r   r   r   rT   rU   rb      s&   
zCompositeProperty.__init__rW   rX   rO   rY   c                   s   t  | |   d S rP   )r   r   _setup_event_handlersrS   rW   r   rT   rU   r      s   z"CompositeProperty.instrument_classrp   r   Tuple[Any, ...]c              
   C  sP   | j r|  |S z|j}W | S  ty' } ztd| jj d|d }~ww )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   )rS   rp   accessoraerT   rT   rU   _composite_values_from_instance   s   
z1CompositeProperty._composite_values_from_instancec                 C  s   |    dS )zwInitialization which occurs after the :class:`.Composite`
        has been associated with its parent mapper.

        N)_setup_arguments_on_columnsr\   rT   rT   rU   do_init  s   zCompositeProperty.do_initc                   s@   dfdd d f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.

        instancer   rO   c                   s   t  }t  }j|vr< fddjD }j|vr<|jd us(t|s<j| |j< |jj	
|jjg |jd S )Nc                   s   g | ]}t  |qS rT   )rw   .0r_   r   rT   rU   
<listcomp>  s    
zFCompositeProperty._create_descriptor.<locals>.fget.<locals>.<listcomp>)r   instance_dictinstance_stater_   _attribute_keysr   
issupersetr   managerdispatchrefresh_COMPOSITE_FGETget)r   rM   rK   valuesr\   r   rU   rx     s   




	z2CompositeProperty._create_descriptor.<locals>.fgetrp   rY   c                   s   t | }t | }|jj }|jjr | }n|jtj	}|jj
D ]
}|||||j}q%||j< |d u rGjD ]}t| |d  q<d S tj|D ]
\}}t| || qPd S rP   )r   r   r   r   r_   r   _active_historyr   r   NO_VALUEsetr   r   rq   zipr   )r   rp   rM   rK   attrpreviousfnr_   rx   rS   rT   rU   rs   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  q:d S rP   )r   r   r   r   r_   r   r   popr   r   remover   r   rq   )r   rK   rM   r   r   r_   r   rT   rU   rv   H  s   


z2CompositeProperty._create_descriptor.<locals>.fdelN)r   r   rO   r   )r   r   rp   r   rO   rY   )r   r   rO   rY   )rl   rJ   )rS   rs   rv   rT   r   rU   r     s   z$CompositeProperty._create_descriptorsqlalchemy.orm.properties	decl_scanr1   registryr,   cls	Type[Any]originating_moduler_   r`   mapped_containerOptional[Type[Mapped[Any]]]
annotationOptional[_AnnotationScanType]extracted_mapped_annotationis_dataclass_fieldc
                 C  s
  t jjj}
| jd u r|d u r| || |}t|r t|d }|rY| jd u rYt|t	s2t
|ddrV|d u rNt|dr>|jnt	|}td| d| dt|||dd}|| _t| jrg| |||| n| jD ]}t||
tjfr~|jd u r~td	qj|   d S )
Nr   T)check_generic__forward_arg__zCan't use forward ref z9 for composite class argument; set up the type as Mapped[])include_genericzIComposite class column arguments must be named unless a dataclass is used)r   	preloadedorm_propertiesr5   r   _raise_for_requiredr*   r(   r   r`   r)   hasattrr   r   ArgumentErrorr   r   _setup_for_dataclassr   r"   r>   rr   r   )rS   r   r   r   r   r_   r   r   r   r   r5   argumentstr_argr   rT   rT   rU   declarative_scanZ  sH   




z"CompositeProperty.declarative_scanc                   s   t | jr0t| jds0t| j}tjdd |j D   t	|jdkr- fdd| _
n | _
| jd ur\t| jtr^| jtvr`| j
d urM| j
t| j< d S t| jdrbdd t| j< d S d S d S d S d S )Nr   c                 S     g | ]}|j qS rT   )rr   )r   prT   rT   rU   r         z4CompositeProperty._init_accessor.<locals>.<listcomp>r   c                   s
    | fS rP   rT   ru   getterrT   rU   rz     r{   z2CompositeProperty._init_accessor.<locals>.<lambda>c                 S     |   S rP   r   ru   rT   rT   rU   rz     s    )r   r   r   inspect	signatureoperator
attrgetter
parametersr   lenr   r   typer   )rS   insprT   r   rU   r     s.   



z CompositeProperty._init_accessorzsqlalchemy.orm.decl_basec           
   
   C  s   t jjj}t jj}t| j}t	|j
 | jD ]L\}}	|d u r7tdt| j d| jj dt|j
 |	d u rF| }	|  j|	f7  _t|	|rX|	|||||j|j qt|	tjre||j|	 qd S )Nznumber of composite attributes z3 exceeds that of the number of attributes in class  )r   r   r   r5   orm_decl_baser   r   r   	itertoolszip_longestr   r   r   r   r   r   rf   r   declarative_scan_for_compositerr   r   r"   r>   _undefer_column_name)
rS   r   r   r   r_   r5   	decl_baser   paramr   rT   rT   rU   r     s@   
	
z&CompositeProperty._setup_for_dataclass!Sequence[QueryableAttribute[Any]]c                   s    fdd j D S )Nc                      g | ]
}t  jj|jqS rT   )rw   r   r~   r_   r   r^   r\   rT   rU   r     s    z:CompositeProperty._comparable_elements.<locals>.<listcomp>propsr\   rT   r\   rU   _comparable_elements     z&CompositeProperty._comparable_elementszorm.propertiesSequence[MapperProperty[Any]]c                 C  s   g }t jjj}| jD ]H}t|tr| jj|dd}n&t|t	j
r'| jj| }nt||r4| jj|j }nt|tjr>|j}nd }t|tsMtd||| q
|S )NF)_configure_mapperszYComposite expects Column objects or mapped attributes/attribute names as arguments, got: )r   r   r   r5   r   r   r`   r   get_propertyr"   r>   _columntopropertycolumnr   r.   rl   r   r   r   append)rS   r  r5   r   r^   rT   rT   rU   r    s(   




zCompositeProperty.props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 rT   )r   r"   r>   r	  )r   ar4   rT   rU   r     s    z-CompositeProperty.columns.<locals>.<listcomp>)r   r   r   r5   r   r\   rT   r4   rU   columns  s   

zCompositeProperty.columnsOptional[MapperProperty[_CC]]c                 C  s   | S rP   rT   r\   rT   rT   rU   mapper_property_to_assign  s   z+CompositeProperty.mapper_property_to_assign$List[Tuple[schema.Column[Any], int]]c                 C     dd | j D S )Nc                 S  s   g | ]}|j d u r|dfqS )Nr   )table)r   crT   rT   rU   r     s    z7CompositeProperty.columns_to_assign.<locals>.<listcomp>)r  r\   rT   rT   rU   columns_to_assign     z#CompositeProperty.columns_to_assignc                 C  sN   t jjj}| jD ]}t||sq|}| j|_| jr | j|_d|_| j	|_	qdS )zwPropagate configuration arguments made on this composite
        to the target columns, for those that apply.

        ))r   T)
instrumentTN)
r   r   r   r3   r  r   r   r   strategy_keyr   )rS   r3   r^   cproprT   rT   rU   r   	  s   



z-CompositeProperty._setup_arguments_on_columnsc                   s   d# fdd}d$ fdd}d%fdd d&f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   rL   contextr0   rO   rY   c                   s    | |d dd d S )NF
is_refreshrT   )rK   r  )_load_refresh_handlerrT   rU   load_handler   s   z=CompositeProperty._setup_event_handlers.<locals>.load_handlerto_loadOptional[Sequence[str]]c                   s2   |rj hj|r | ||dd d S d S )NTr  )r_   unionr   intersection)rK   r  r  r  rS   rT   rU   refresh_handler%  s   z@CompositeProperty._setup_event_handlers.<locals>.refresh_handlerr  rZ   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 rT   )dictr   rK   rT   rU   r   O      zZCompositeProperty._setup_event_handlers.<locals>._load_refresh_handler.<locals>.<listcomp>)r$  r   r_   r   r   )rK   r  r  r  rM   kr\   r%  rU   r  1  s   


zFCompositeProperty._setup_event_handlers.<locals>._load_refresh_handlerkeysc                   s0   |d u st  j|r| j jd  d S d S rP   )r   r   r!  r$  r   r_   )rK   r(  r\   rT   rU   expire_handlerR  s   z?CompositeProperty._setup_event_handlers.<locals>.expire_handlerrW   rX   
connectionr7   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   r_   )rW   r*  rK   r\   rT   rU   insert_update_handlerX  s   zFCompositeProperty._setup_event_handlers.<locals>.insert_update_handlerafter_insertT)rawafter_updateload)r-  	propagater   expireN)rK   rL   r  r0   rO   rY   )rK   rL   r  r0   r  r  rO   rY   )
rK   rL   r  r0   r  r  r  rZ   rO   rY   )rK   rL   r(  r  rO   rY   )rW   rX   r*  r7   rK   rL   rO   rY   )	r    listenr   r   r_   r   r   r   r   )rS   r  r#  r)  r+  r   rT   r"  rU   r     s.   !


z'CompositeProperty._setup_event_handlersSequence[str]c                 C  r  )Nc                 S  r   rT   ra   r   rT   rT   rU   r   ~  r   z5CompositeProperty._attribute_keys.<locals>.<listcomp>r  r\   rT   rT   rU   r   |  r  z!CompositeProperty._attribute_keys Callable[[Dict[str, Any]], None]c                   s>   j rj nddddd jD  d fdd}|S )Nvalr   rO   
Tuple[Any]c                 S  r   rP   r   )r5  rT   rT   rU   
get_values  s   zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.get_valuesc                 S  r   rT   ra   r   rT   rT   rU   r     r   zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.<listcomp>	dest_dictDict[str, Any]rY   c              	     s*   |  dd t | jD  d S )Nc                 S  s   i | ]\}}||qS rT   rT   )r   r_   r5  rT   rT   rU   
<dictcomp>  s    zaCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate.<locals>.<dictcomp>)r   r   r   r_   )r8  r   r7  rS   rT   rU   populate  s   zMCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate)r5  r   rO   r6  )r8  r9  rO   rY   )r   r  )rS   r<  rT   r;  rU   )_populate_composite_bulk_save_mappings_fn  s   

z;CompositeProperty._populate_composite_bulk_save_mappings_fnrK   rL   rM   r+   rN   r   r-   c                 C  s   g }g }d}| j D ]5}|j}|j| j||}	|	 rd}|	 }
|
r*||
 n|d |	j	r9||	j	 q	|d q	|rPt
| j| gd| j| gS t
d| j| gdS )z>Provided for userland code that uses attributes.get_history().FTNrT   )r  r_   r   r   rV   has_changesnon_deletedextendr
  deletedr   r-   r   )rS   rK   rM   rN   addedrA  has_historyr^   r_   histr?  rT   rT   rU   rV     s,   



zCompositeProperty.get_historyComposite.Comparator[_CC]c                 C  s   |  | |S rP   )r   r   rT   rT   rU   ry     s   z%CompositeProperty._comparator_factoryc                      s(   e Zd Zd fddZdddZ  ZS )z!CompositeProperty.CompositeBundle	property_Composite[_T]exprr;   c                   s    || _ t j|jg|R   d S rP   )rl   r   rb   r_   )rS   rF  rH  r   rT   rU   rb     s   z*CompositeProperty.CompositeBundle.__init__querySelect[Any]procs#Sequence[Callable[[Row[Any]], Any]]labelsr3  rO   Callable[[Row[Any]], Any]c                   s   d fdd}|S )NrowRow[Any]rO   r   c                   s   j j fddD  S )Nc                   s   g | ]}| qS rT   rT   )r   procrO  rT   rU   r     s    zXCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc.<locals>.<listcomp>)rl   r   rR  rK  rS   rR  rU   rQ    s   zDCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc)rO  rP  rO   r   rT   )rS   rI  rK  rM  rQ  rT   rS  rU   create_row_processor  s   z6CompositeProperty.CompositeBundle.create_row_processor)rF  rG  rH  r;   )rI  rJ  rK  rL  rM  r3  rO   rN  )rf   rg   rh   rb   rT  __classcell__rT   rT   r   rU   CompositeBundle  s    rV  c                   @  s   e Zd ZU dZdZded< ejd(ddZd)d
dZ	ejd)ddZ
d*ddZejd+ddZd,ddZd,ddZd,ddZd,ddZd,d d!Zd,d"d#Z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]]r^   rO   r;   c                 C  s   t j| jddiS )Nr   F)r%   r;   r  r\   rT   rT   rU   clauses  s
   z$CompositeProperty.Comparator.clauses&CompositeProperty.CompositeBundle[_PT]c                 C  s   | j S rP   r$   r\   rT   rT   rU   __clause_element__  s   z/CompositeProperty.Comparator.__clause_element__c                 C  s*   | j | j| j| jjd}t| j|S )N)parententityparentmapper	proxy_key)rW  	_annotate_parententityr^   r_   r   rV  )rS   rW  rT   rT   rU   r%     s   z'CompositeProperty.Comparator.expressionrp   r   (Sequence[Tuple[_DMLColumnArgument, Any]]c                 C  sz   t |tr|j}|d u rdd | jjD }nt | jjtr+t || jjr+| j|}n
t	d| j|f t
t| j|S )Nc                 S  s   g | ]}d qS rP   rT   r   rT   rT   rU   r     s    zDCompositeProperty.Comparator._bulk_update_tuples.<locals>.<listcomp>z)Can't UPDATE composite attribute %s to %r)r   r'   rp   r^   r   r   r   r   r   r   listr   r  )rS   rp   r   rT   rT   rU   _bulk_update_tuples  s    
z0CompositeProperty.Comparator._bulk_update_tuplesr   c                   s$    j r fdd jjD S  jjS )Nc                   r   rT   )rw   _adapt_to_entityentityr_   r   r\   rT   rU   r     s    zECompositeProperty.Comparator._comparable_elements.<locals>.<listcomp>)rb  r^   r  r\   rT   r\   rU   r    s
   
z1CompositeProperty.Comparator._comparable_elementsotherColumnElement[bool]c                 C     |  tj|S rP   )_comparer&   eqrS   rd  rT   rT   rU   __eq__&     z#CompositeProperty.Comparator.__eq__c                 C  rf  rP   )rg  r&   neri  rT   rT   rU   __ne__)  rk  z#CompositeProperty.Comparator.__ne__c                 C  rf  rP   )rg  r&   ltri  rT   rT   rU   __lt__,  rk  z#CompositeProperty.Comparator.__lt__c                 C  rf  rP   )rg  r&   gtri  rT   rT   rU   __gt__/  rk  z#CompositeProperty.Comparator.__gt__c                 C  rf  rP   )rg  r&   leri  rT   rT   rU   __le__2  rk  z#CompositeProperty.Comparator.__le__c                 C  rf  rP   )rg  r&   geri  rT   rT   rU   __ge__5  rk  z#CompositeProperty.Comparator.__ge__r   r=   c                   st   |d u rd gt jj }nj|} fddtjj|D }jr5jd us,J fdd|D }tj| S )Nc                   s   g | ]	\}} ||qS rT   rT   )r   r  b)r   rT   rU   r   G  s    z9CompositeProperty.Comparator._compare.<locals>.<listcomp>c                   s   g | ]}  |qS rT   )adapter)r   xr\   rT   rU   r   M  r&  )	r   r^   r  r   r   rb  rw  r#   and_)rS   r   rd  r   comparisonsrT   )r   rS   rU   rg  ?  s   

z%CompositeProperty.Comparator._compare)rO   r;   )rO   rX  )rp   r   rO   r_  rO   r   )rd  r   rO   re  )r   r=   rd  r   rO   re  )rf   rg   rh   r   __hash__r   r   memoized_propertyrW  rY  r%   ra  r  rj  rm  ro  rq  rs  ru  rg  rT   rT   rT   rU   r     s&   
 



	





r   c                 C  s   t | jjjd | j S )N.)r`   r   r~   rf   r_   r\   rT   rT   rU   __str__P  s   zCompositeProperty.__str__rP   )r   r   r   r   r   r   r   rZ   r   rZ   r   rH   r   r   r   r   r   r   r   )rp   r   rO   r   rO   rY   )r   r1   r   r,   r   r   r   rH   r_   r`   r   r   r   r   r   r   r   rZ   rO   rY   )
r   r,   r   r   r   rH   r_   r`   rO   rY   r{  )rO   r  )rO   r  )rO   r  )rO   r  )rO   r3  )rO   r4  re   )rW   rX   rO   rE  )rO   r`   )*rf   rg   rh   r   r   rb   r   r   r   objectr   r   r   preload_moduler   r   r   r}  r  r  non_memoized_propertyr  rl   r  r  r   r   r   r=  r   rm   rV   ry   orm_utilBundlerD   rV  r   rF   r   r  rU  rT   rT   r   rU   r      sd   
 (


J
9'
_

%xr   c                   @     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   inherit_cacherT   rT   rT   rU   r  T  s    r  c                      s,   e Zd ZdZdddZ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.

    rW   rX   rO   Type[PropComparator[_T]]c                 C  sP   d }| j  D ]}|j| j }t|dd d ur|j} nq|d us#J |||S )Nr   )r   iterate_to_root_propsr_   rw   r   )rS   rW   comparator_callablemr   rT   rT   rU   ry   x  s   
z-ConcreteInheritedProperty._comparator_factoryrY   c                   s8   t    d fddG  fddd}|  _d S )NrO   r   c                     s   t d j j jf )NzgConcrete %s does not implement attribute %r at the instance level.  Add this property explicitly to %s.)r   r   r_   rT   r\   rT   rU   warn  s
   z0ConcreteInheritedProperty.__init__.<locals>.warnc                      s8   e Zd ZdfddZdfd	d
Zd fddZdS )zDConcreteInheritedProperty.__init__.<locals>.NoninheritedConcretePropsr   ro   rp   rO   r   c                   
      d S rP   rT   )r  ro   rp   r  rT   rU   __set__  rc   zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__set__c                   r  rP   rT   )r  ro   r  rT   rU   
__delete__  rc   zOConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__delete__ownerc                   s   |d u r j S   d S rP   )rJ   )r  ro   r  rS   r  rT   rU   __get__  s   
zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__get__N)r  r   ro   r   rp   r   rO   r   )r  r   ro   r   rO   r   )r  r   ro   r   r  r   rO   r   )rf   rg   rh   r  r  r  rT   r  rT   rU   NoninheritedConcreteProp  s    r  )rO   r   )r   rb   rJ   )rS   r  r   r  rU   rb     s   
z"ConcreteInheritedProperty.__init__)rW   rX   rO   r  r  )rf   rg   rh   r   ry   rb   rU  rT   rT   r   rU   r  g  s    
r  c                      s   e Zd ZU dZded< 						d.d/ fddZes"ed0ddZe	j
d1ddZd2ddZejfd3d&d'Ze	d(d4d,d-Z  ZS )5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

    "Optional[Type[PropComparator[_T]]]r   Nrr   r`   
map_columnOptional[bool]rJ   Optional[Any]r   r   r   r   rI   rH   c                   sj   t  j|d || _|| _|| _|| _|r|| _n|r#|jr#|j| _nd | _|r.| j	| t
|  d S r   )r   rb   rr   r  rJ   r   rI   r   r   r   r   r   )rS   rr   r  rJ   r   r   r   rI   r   rT   rU   rb     s   


zSynonymProperty.__init__rO   rZ   c                 C  s   t | jj| jjjS rP   )rw   r   r~   rr   r   r[   r\   rT   rT   rU   r[     r  zSynonymProperty.uses_objects/Union[MapperProperty[_T], SQLORMOperations[_T]]c                 C  sh   t | jj| j}t|drt|jts1t|tj	r|j
S t|tr#|S td| jjj| j|f |jS )Nrl   zGsynonym() attribute "%s.%s" only supports ORM mapped attributes, got %r)rw   r   r~   rr   r   r   rl   r   r   r/   
comparatorr   r   r   rf   )rS   r   rT   rT   rU   _proxied_object  s   
zSynonymProperty._proxied_objectrW   rX   SQLORMOperations[_T]c                 C  s:   | j }t|tr| jr| ||}|S |||}|S |S rP   )r  r   r   r   )rS   rW   r^   comprT   rT   rU   ry     s   
z#SynonymProperty._comparator_factoryrK   rL   rM   r+   rN   r   r-   c                 C  s"   t | jj| j}|jj|||dS )N)rN   )rw   r   r~   rr   r   rV   )rS   rK   rM   rN   r   rT   rT   rU   rV     s   zSynonymProperty.get_historyr   r   initrY   c                 C  s   t jj}| jr[| j|jjvrtd| j	|jj
| jf |jj| j |jv rC|j|jj| j  j| j	krCt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)r  	setparent)r   r   r   r  r_   persist_selectabler  r   r   rr   descriptionr  r3   _configure_property_mapped_by_synonymr   )rS   r   r  
propertiesr   rT   rT   rU   
set_parent  s>   

zSynonymProperty.set_parent)NNNNNN)rr   r`   r  r  rJ   r  r   r  r   r   r   r   rI   rH   rd   )rO   r  )rW   rX   rO   r  re   )r   rX   r  rZ   rO   rY   )rf   rg   rh   r   r   rb   r   rl   r[   r   r}  r  ry   r   rm   rV   r  r  rU  rT   rT   r   rU   r    s(   
 
	r  c                   @  r  )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

    TNr  rT   rT   rT   rU   r  &  s    r  )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   
interfacesr   r   r   r   r   r   r   r    r!   r   r"   r#   r%   r&   sql.elementsr'   util.typingr(   r)   r*   _typingr+   r,   r-   r.   r/   r  r0   r   r1   rW   r2   r  r3   r5   rK   r6   engine.baser7   
engine.rowr8   sql._typingr9   r:   r;   r<   sql.operatorsr=   
sql.schemar>   sql.selectabler?   r@   rA   rB   rC   rD   rF   rG   r`   _CompositeAttrTyper   WeakKeyDictionaryr   r   r   r  r  r  r  rT   rT   rT   rU   <module>   s   H	

     %8 