U
    ]g%i                     @  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                   @  sf   e Zd ZU dZdZded< dZdZded< dd	d
dZ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!Sequence[QueryableAttribute[Any]]returnc                 C  s   t dd S )Nz?This MapperProperty does not implement column loader strategiesNotImplementedErrorself rR   ^/var/www/html/api-medvista/venv/lib/python3.8/site-packages/sqlalchemy/orm/descriptor_props.py_column_strategy_attrsf   s    z)DescriptorProperty._column_strategy_attrsInstanceState[Any]r+   r   r-   statedict_passiverM   c                 C  s
   t  d S NrN   rQ   rW   rX   rY   rR   rR   rS   get_historyk   s    zDescriptorProperty.get_historyMapper[Any]NonemapperrM   c                   s   G fdddt j}jd krHt jjd } j|rH|_jd k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boolrL   c                   s    j S rZ   )uses_objectsrP   proprR   rS   rb   {   s    zDDescriptorProperty.instrument_class.<locals>._ProxyImpl.uses_objectsstrkeyc                 S  s
   || _ d S rZ   rf   )rQ   rg   rR   rR   rS   __init__   s    z@DescriptorProperty.instrument_class.<locals>._ProxyImpl.__init__rU   r+   r   r-   rV   c                   s     |||S rZ   )r\   r[   rc   rR   rS   r\      s    zCDescriptorProperty.instrument_class.<locals>._ProxyImpl.get_historyN)__name__
__module____qualname__Zaccepts_scalar_loaderZload_on_unexpireZ
collectionpropertyrb   rh   r   PASSIVE_OFFr\   rR   rc   rR   rS   
_ProxyImplv   s   rn   r   r^   )objvaluerM   c                   s   t |  j| d S rZ   )setattrname)ro   rp   rP   rR   rS   fset   s    z1DescriptorProperty.instrument_class.<locals>.fset)ro   rM   c                   s   t |  j d S rZ   )delattrrr   ro   rP   rR   rS   fdel   s    z1DescriptorProperty.instrument_class.<locals>.fdelc                   s   t |  jS rZ   )getattrrr   ru   rP   rR   rS   fget   s    z1DescriptorProperty.instrument_class.<locals>.fget)rx   rs   rv   c                     s
     S rZ   )_comparator_factoryrR   )r`   rQ   rR   rS   <lambda>       z5DescriptorProperty.instrument_class.<locals>.<lambda>)rI   Zoriginal_property)r   ZAttributeImplrJ   rw   class_rg   Z_is_userland_descriptorrl   Zcreate_proxied_attributeparentrI   implclass_managerZinstrument_attribute)rQ   r`   rn   descrs   rv   rx   
proxy_attrrR   )r`   rd   rQ   rS   instrument_classs   s*    


z#DescriptorProperty.instrument_class)ri   rj   rk   __doc__rI   __annotations__rb   Z_links_to_entityrT   r   rm   r\   r   rR   rR   rR   rS   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	< dcd
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+dd4d5d6Zejd7d"d8d9Zejed:d;d"d<d=Zd7d"d>d?Zejed:d@d"dAdBZedCd"dDdEZedFd"dGdHZed:dd"dIdJZdd"dKdLZejdMd"dNdOZdPd"dQdRZejfdSdTdUdVdWdXdYZ ddZdd[d\Z!G d]d^ d^e"j#e$ Z%G d_d` d`e&e' Z(d+d"dadbZ)  Z*S )d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]ra   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 k	r^|n| jj| _d | _|d k	r| j| t|  |   |   d S N)r   )superrh   
isinstancer   re   r#   r<   r   r   r   r   r   	__class__
Comparatorr   r   r   updater   set_creation_order_create_descriptor_init_accessor)
rQ   r   r   r   r   r   r   r   r   r   r   rR   rS   rh      s&    
zCompositeProperty.__init__r]   r^   r_   c                   s   t  | |   d S rZ   )r   r   _setup_event_handlersrQ   r`   r   rR   rS   r      s    z"CompositeProperty.instrument_classr   zTuple[Any, ...]rp   rM   c              
   C  s`   | j r|  |S z
|j}W n: tk
rT } ztd| jj d|W 5 d }~X Y nX | 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   ri   )rQ   rp   accessorZaerR   rR   rS   _composite_values_from_instance   s    

z1CompositeProperty._composite_values_from_instancerL   c                 C  s   |    dS )zwInitialization which occurs after the :class:`.Composite`
        has been associated with its parent mapper.

        N)_setup_arguments_on_columnsrP   rR   rR   rS   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   )instancerM   c                   s   t  }t  }j|krx fddjD }j|krx|jd k	sPt|sxj| |j< |jj	
|jjg |jd S )Nc                   s   g | ]}t  |qS rR   )rw   .0rg   r   rR   rS   
<listcomp>#  s    zFCompositeProperty._create_descriptor.<locals>.fget.<locals>.<listcomp>)r   instance_dictinstance_staterg   _attribute_keysr   
issupersetr   managerdispatchrefresh_COMPOSITE_FGETget)r   rX   rW   valuesrP   r   rS   rx     s$    



	
  z2CompositeProperty._create_descriptor.<locals>.fgetr^   )r   rp   rM   c                   s   t | }t | }|jj }|jjr2 | }n|jtj	}|jj
D ]}|||||j}qJ||j< |d krjD ]}t| |d  qxn(tj|D ]\}}t| || qd S rZ   )r   r   r   r   rg   r   _active_historyr   r   NO_VALUEsetr~   r   rq   zipr   )r   rp   rX   rW   attrpreviousfnrg   rx   rQ   rR   rS   rs   6  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 rZ   )r   r   r   r   rg   r   r   popr   r   remover~   r   rq   )r   rW   rX   r   r   rg   r   rR   rS   rv   M  s    


z2CompositeProperty._create_descriptor.<locals>.fdelN)rl   rJ   )rQ   rs   rv   rR   r   rS   r     s    z$CompositeProperty._create_descriptorsqlalchemy.orm.propertiesr1   r,   z	Type[Any]re   zOptional[Type[Mapped[Any]]]zOptional[_AnnotationScanType])
	decl_scanregistryclsoriginating_modulerg   mapped_container
annotationextracted_mapped_annotationis_dataclass_fieldrM   c
                 C  s  t jjj}
| jd kr(|d kr(| || |}t|r@t|d }|r| jd krt|t	sdt
|ddr|d k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 k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   re   r)   hasattrr   r   ArgumentErrorr   r   _setup_for_dataclassr   r"   r>   rr   r   )rQ   r   r   r   r   rg   r   r   r   r   r5   argumentZstr_argr   rR   rR   rS   declarative_scan_  s\    
    
    
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 k	rt| jtr| jtkr| j
d k	r| j
t| j< nt| jdrdd t| j< d S )Nr   c                 S  s   g | ]
}|j qS rR   )rr   )r   prR   rR   rS   r     s     z4CompositeProperty._init_accessor.<locals>.<listcomp>r   c                   s
    | fS rZ   rR   ru   getterrR   rS   rz     r{   z2CompositeProperty._init_accessor.<locals>.<lambda>c                 S  s   |   S rZ   r   ru   rR   rR   rS   rz     r{   )r   r   r   inspect	signatureoperator
attrgetter
parametersr   lenr   r   typer   )rQ   insprR   r   rS   r     s.     


z CompositeProperty._init_accessorzsqlalchemy.orm.decl_base)r   r   r   r   rg   rM   c              
   C  s   t jjj}t jj}t| j}t	|j
 | jD ]\}	}
|	d krntdt| j d| jj dt|j
 |
d k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   ri   r   Zdeclarative_scan_for_compositerr   r   r"   r>   Z_undefer_column_name)rQ   r   r   r   r   rg   r5   	decl_baser   paramr   rR   rR   rS   r     s4    

 $
	z&CompositeProperty._setup_for_dataclassrK   c                   s    fdd j D S )Nc                   s   g | ]}t  jj|jqS rR   )rw   r}   r|   rg   r   rd   rP   rR   rS   r     s     z:CompositeProperty._comparable_elements.<locals>.<listcomp>propsrP   rR   rP   rS   _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   re   r}   Zget_propertyr"   r>   _columntopropertycolumnr   r.   rl   r   r   r   append)rQ   r   r5   r   rd   rR   rR   rS   r     s$    




zCompositeProperty.propsc                 C  s   | j S rZ   )r   rP   rR   rR   rS   rT      s    z(CompositeProperty._column_strategy_attrsz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 rR   )r   r"   r>   r   )r   ar4   rR   rS   r     s   z-CompositeProperty.columns.<locals>.<listcomp>)r   r   r   r5   r   rP   rR   r4   rS   columns  s    

zCompositeProperty.columnszOptional[MapperProperty[_CC]]c                 C  s   | S rZ   rR   rP   rR   rR   rS   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 kr|dfqS )Nr   )table)r   crR   rR   rS   r     s     
 z7CompositeProperty.columns_to_assign.<locals>.<listcomp>)r   rP   rR   rR   rS   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   )rQ   r3   rd   ZcproprR   rR   rS   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.rU   r0   r^   )rW   contextrM   c                   s    | |d dd d S )NF
is_refreshrR   )rW   r   )_load_refresh_handlerrR   rS   load_handler,  s    z=CompositeProperty._setup_event_handlers.<locals>.load_handlerzOptional[Sequence[str]])rW   r   to_loadrM   c                   s.   |rj hj|r* | ||dd d S )NTr   )rg   unionr   intersection)rW   r   r   r   rQ   rR   rS   refresh_handler1  s    z@CompositeProperty._setup_event_handlers.<locals>.refresh_handlerra   )rW   r   r   r   rM   c                   s`    j }|r|jkr"j|kr"d S jD ]}||kr( d S q(j fddjD  |j< d S )Nc                   s   g | ]} j | qS rR   )dictr   rW   rR   rS   r   [  s     zZCompositeProperty._setup_event_handlers.<locals>._load_refresh_handler.<locals>.<listcomp>)r   r   rg   r   r   )rW   r   r   r   rX   krP   r   rS   r   =  s    
zFCompositeProperty._setup_event_handlers.<locals>._load_refresh_handler)rW   keysrM   c                   s,   |d kst  j|r(| j jd  d S rZ   )r   r   r   r   r   rg   )rW   r   rP   rR   rS   expire_handler^  s    z?CompositeProperty._setup_event_handlers.<locals>.expire_handlerr]   r7   )r`   
connectionrW   rM   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   rg   )r`   r  rW   rP   rR   rS   insert_update_handlerd  s    zFCompositeProperty._setup_event_handlers.<locals>.insert_update_handlerZafter_insertT)rawZafter_updateload)r  	propagater   ZexpireN)	r    listenr}   r   rg   r   r~   r   r   )rQ   r   r   r  r  r   rR   r   rS   r   )  sR    !                  
z'CompositeProperty._setup_event_handlersSequence[str]c                 C  s   dd | j D S )Nc                 S  s   g | ]
}|j qS rR   rf   r   rR   rR   rS   r     s     z5CompositeProperty._attribute_keys.<locals>.<listcomp>r   rP   rR   rR   rS   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])valrM   c                 S  s   |   S rZ   r   )r	  rR   rR   rS   
get_values  s    zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.get_valuesc                 S  s   g | ]
}|j qS rR   rf   r   rR   rR   rS   r     s     zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.<listcomp>zDict[str, Any]r^   )	dest_dictrM   c              	     s*   |  dd t | jD  d S )Nc                 S  s   i | ]\}}||qS rR   rR   )r   rg   r	  rR   rR   rS   
<dictcomp>  s    zaCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate.<locals>.<dictcomp>)r   r   r   rg   )r  r   r
  rQ   rR   rS   populate  s     zMCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate)r   r   )rQ   r  rR   r  rS   )_populate_composite_bulk_save_mappings_fn  s    
z;CompositeProperty._populate_composite_bulk_save_mappings_fnrU   r+   r   r-   rV   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().FTNrR   )r   rg   r   r~   r\   Zhas_changesnon_deletedextendr   deletedr   r-   r   )rQ   rW   rX   rY   addedr  Zhas_historyrd   rg   histr  rR   rR   rS   r\     s,    



zCompositeProperty.get_historyzComposite.Comparator[_CC]c                 C  s   |  | |S rZ   )r   r   rR   rR   rS   ry     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f|  d S rZ   )rl   r   rh   rg   )rQ   r  r  r   rR   rS   rh     s    z*CompositeProperty.CompositeBundle.__init__zSelect[Any]z#Sequence[Callable[[Row[Any]], Any]]r  zCallable[[Row[Any]], Any])queryprocslabelsrM   c                   s   ddd fdd}|S )NzRow[Any]r   )rowrM   c                   s   j j fddD  S )Nc                   s   g | ]}| qS rR   rR   )r   procr  rR   rS   r     s     zXCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc.<locals>.<listcomp>)rl   r   r  r  rQ   r  rS   r    s    zDCompositeProperty.CompositeBundle.create_row_processor.<locals>.procrR   )rQ   r  r  r  r  rR   r  rS   create_row_processor  s    z6CompositeProperty.CompositeBundle.create_row_processor)ri   rj   rk   rh   r  __classcell__rR   rR   r   rS   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]]rd   r;   rL   c                 C  s   t j| jddiS )Nr   F)r%   r;   r   rP   rR   rR   rS   clauses  s
    z$CompositeProperty.Comparator.clausesz&CompositeProperty.CompositeBundle[_PT]c                 C  s   | j S rZ   r$   rP   rR   rR   rS   __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_parententityrd   rg   r   r   )rQ   r!  rR   rR   rS   r%     s    z'CompositeProperty.Comparator.expressionr   z(Sequence[Tuple[_DMLColumnArgument, Any]]r   c                 C  sz   t |tr|j}|d k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 rZ   rR   r   rR   rR   rS   r     s     zDCompositeProperty.Comparator._bulk_update_tuples.<locals>.<listcomp>z)Can't UPDATE composite attribute %s to %r)r   r'   rp   rd   r   r   r   r   r   r   listr   r   )rQ   rp   r   rR   rR   rS   _bulk_update_tuples  s"    
 z0CompositeProperty.Comparator._bulk_update_tuplesrK   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 rR   )rw   _adapt_to_entityentityrg   r   rP   rR   rS   r   +  s   zECompositeProperty.Comparator._comparable_elements.<locals>.<listcomp>)r&  rd   r   rP   rR   rP   rS   r   (  s
    
z1CompositeProperty.Comparator._comparable_elementszColumnElement[bool])otherrM   c                 C  s   |  tj|S rZ   )_comparer&   eqrQ   r(  rR   rR   rS   __eq__2  s    z#CompositeProperty.Comparator.__eq__c                 C  s   |  tj|S rZ   )r)  r&   ner+  rR   rR   rS   __ne__5  s    z#CompositeProperty.Comparator.__ne__c                 C  s   |  tj|S rZ   )r)  r&   ltr+  rR   rR   rS   __lt__8  s    z#CompositeProperty.Comparator.__lt__c                 C  s   |  tj|S rZ   )r)  r&   gtr+  rR   rR   rS   __gt__;  s    z#CompositeProperty.Comparator.__gt__c                 C  s   |  tj|S rZ   )r)  r&   ler+  rR   rR   rS   __le__>  s    z#CompositeProperty.Comparator.__le__c                 C  s   |  tj|S rZ   )r)  r&   ger+  rR   rR   rS   __ge__A  s    z#CompositeProperty.Comparator.__ge__r=   )r   r(  rM   c                   st   |d krd gt jj }nj|} fddtjj|D }jrjjd k	sXtfdd|D }tj	| S )Nc                   s   g | ]\}} ||qS rR   rR   )r   r   b)r   rR   rS   r   S  s   z9CompositeProperty.Comparator._compare.<locals>.<listcomp>c                   s   g | ]}  |qS rR   )adapter)r   xrP   rR   rS   r   Y  s     )
r   rd   r   r   r   r&  r8  AssertionErrorr#   and_)rQ   r   r(  r   ZcomparisonsrR   )r   rQ   rS   r)  K  s    
z%CompositeProperty.Comparator._compare)ri   rj   rk   r   __hash__r   r   memoized_propertyr!  r"  r%   r%  r   r,  r.  r0  r2  r4  r6  r)  rR   rR   rR   rS   r     s$   

	
r   c                 C  s   t | jjjd | j S )N.)re   r}   r|   ri   rg   rP   rR   rR   rS   __str__\  s    zCompositeProperty.__str__)N)+ri   rj   rk   r   r   rh   r   r   r   objectr   r   r   preload_moduler   r   r   r=  r   r   rT   Znon_memoized_propertyr   rl   r   r   r   r   r   r  r   rm   r\   ry   orm_utilZBundlerD   r   r   rF   r   r?  r  rR   rR   r   rS   r      sd   
 &(J";)_%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ri   rj   rk   r   Zinherit_cacherR   rR   rR   rS   rC  `  s   rC  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.

    r]   zType[PropComparator[_T]]r_   c                 C  sP   d }| j  D ]*}|j| j }t|dd d k	r|j} q:q|d k	sFt|||S )Nr   )r}   Ziterate_to_rootZ_propsrg   rw   r   r:  )rQ   r`   Zcomparator_callablemr   rR   rR   rS   ry     s    z-ConcreteInheritedProperty._comparator_factoryr^   rL   c                   s<   t    dd fddG  fddd}|  _d S )Nr   rL   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   r}   rg   rR   rP   rR   rS   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   )sro   rp   rM   c                   s
      d S rZ   rR   )rH  ro   rp   rG  rR   rS   __set__  s    zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__set__)rH  ro   rM   c                   s
      d S rZ   rR   )rH  ro   rI  rR   rS   
__delete__  s    zOConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__delete__)rH  ro   ownerrM   c                   s   |d kr j S   d S rZ   )rJ   )rH  ro   rL  rQ   rG  rR   rS   __get__  s    zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__get__N)ri   rj   rk   rJ  rK  rN  rR   rM  rR   rS   NoninheritedConcreteProp  s   rO  )r   rh   rJ   )rQ   rO  r   rM  rS   rh     s    
z"ConcreteInheritedProperty.__init__)ri   rj   rk   r   ry   rh   r  rR   rR   r   rS   rE  s  s   rE  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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   Nre   zOptional[bool]zOptional[Any]r   r   rH   )rr   
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   rh   rr   rQ  rJ   r   rI   r   r   r   r   r   )rQ   rr   rQ  rJ   r   r   r   rI   r   rR   rS   rh     s    


zSynonymProperty.__init__ra   rL   c                 C  s   t | jj| jjjS rZ   )rw   r}   r|   rr   r~   rb   rP   rR   rR   rS   rb     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 )Nrl   zGsynonym() attribute "%s.%s" only supports ORM mapped attributes, got %r)rw   r}   r|   rr   r   r   rl   r   r   r/   Z
comparatorr   r   r   ri   )rQ   r   rR   rR   rS   _proxied_object  s     
zSynonymProperty._proxied_objectrK   c                 C  s   t | jj| jfS rZ   )rw   r}   r|   rr   rP   rR   rR   rS   rT     s    z&SynonymProperty._column_strategy_attrsr]   zSQLORMOperations[_T]r_   c                 C  s<   | j }t|tr4| jr$| ||}n|||}|S |S d S rZ   )rR  r   r   r   )rQ   r`   rd   comprR   rR   rS   ry     s    
z#SynonymProperty._comparator_factoryrU   r+   r   r-   rV   c                 C  s"   t | jj| j}|jj|||dS )N)rY   )rw   r}   r|   rr   r~   r\   )rQ   rW   rX   rY   r   rR   rR   rS   r\     s    zSynonymProperty.get_historyr   r^   )r}   initrM   c                 C  s   t jj}| jr| j|jjkr:td| j	|jj
| jf nN|jj| j |jk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)rT  Z	setparent)r   r   r   rQ  rg   Zpersist_selectabler   r   r   rr   descriptionr   r3   Z_configure_propertyZ_mapped_by_synonymr}   )rQ   r}   rT  
propertiesr   rR   rR   rS   
set_parent  s@    
zSynonymProperty.set_parent)NNNNNN)ri   rj   rk   r   r   rh   r   rl   rb   r   r=  rR  rT   ry   r   rm   r\   rA  rW  r  rR   rR   r   rS   rP    s(   
       	rP  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

    TNrD  rR   rR   rR   rS   rX  5  s   rX  )gr   
__future__r   dataclassesr   r   r   r   typingr   r   r   r   r   r	   r
   r   r   r   r   r   weakref r   r   rB  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   rV  r3   r5   rW   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   re   Z_CompositeAttrTyper   WeakKeyDictionaryr   r   r   rC  rE  rP  rX  rR   rR   rR   rS   <module>   s   M	

       ,8 