o
     h0                     @  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                   @  sR   e Zd ZU dZdZded< dZdZded< dd
dZ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return!Sequence[QueryableAttribute[Any]]c                 C  s   t d)Nz?This MapperProperty does not implement column loader strategiesNotImplementedErrorself rQ   R/var/www/html/venv/lib/python3.10/site-packages/sqlalchemy/orm/descriptor_props.py_column_strategy_attrsf   s   z)DescriptorProperty._column_strategy_attrsstateInstanceState[Any]dict_r+   passiver   r-   c                 C  s   t  NrM   rP   rT   rV   rW   rQ   rQ   rR   get_historyk   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>._ProxyImplFTrK   boolc                   s    j S rX   )uses_objectsrO   proprQ   rR   r_   {   s   zDDescriptorProperty.instrument_class.<locals>._ProxyImpl.uses_objectskeystrc                 S  s
   || _ d S rX   rb   )rP   rb   rQ   rQ   rR   __init__      
z@DescriptorProperty.instrument_class.<locals>._ProxyImpl.__init__rT   rU   rV   r+   rW   r   r-   c                   s     |||S rX   )rZ   rY   r`   rQ   rR   rZ      s   zCDescriptorProperty.instrument_class.<locals>._ProxyImpl.get_historyNrK   r^   )rb   rc   rT   rU   rV   r+   rW   r   rK   r-   )__name__
__module____qualname__accepts_scalar_loaderload_on_unexpire
collectionpropertyr_   re   r   PASSIVE_OFFrZ   rQ   r`   rQ   rR   
_ProxyImplv   s    
rq   objr   valuerK   r]   c                   s   t |  j| d S rX   )setattrname)rr   rs   rO   rQ   rR   fset      z1DescriptorProperty.instrument_class.<locals>.fsetc                   s   t |  j d S rX   )delattrru   rr   rO   rQ   rR   fdel   s   z1DescriptorProperty.instrument_class.<locals>.fdelc                   s   t |  jS rX   )getattrru   ry   rO   rQ   rR   fget   s   z1DescriptorProperty.instrument_class.<locals>.fget)r|   rv   rz   c                     s
     S rX   )_comparator_factoryrQ   )r[   rP   rQ   rR   <lambda>      
 z5DescriptorProperty.instrument_class.<locals>.<lambda>)rI   original_property)rr   r   rs   r   rK   r]   )rr   r   rK   r]   )rr   r   rK   r   )r   AttributeImplrJ   r{   class_rb   _is_userland_descriptorro   create_proxied_attributeparentrI   implclass_managerinstrument_attribute)rP   r[   rq   descrv   rz   r|   
proxy_attrrQ   )r[   ra   rP   rR   instrument_classs   s*   


z#DescriptorProperty.instrument_classrK   rL   rh   r[   r\   rK   r]   )ri   rj   rk   __doc__rI   __annotations__r_   _links_to_entityrS   r   rp   rZ   r   rQ   rQ   rQ   rR   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	< 	
drd
ddd
d
d
dds fddZdt fd"d#Zdud'd(Zdvd)d*Ze	 Z
dvd+d,Zed-dwd=d>Zdvd?d@Zed-edAdxdBdCZejdydEdFZejedGdzdIdJZdydKdLZejedGd{dNdOZed|dQdRZed}dTdUZedGdvdVdWZdvdXdYZejd~d[d\Zdd^d_ZejfddgdhZ ddjdkZ!G dldm dme"j#e$ Z%G dndo doe&e' Z(ddpdq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   r^   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   )superre   
isinstancer   rc   r#   r<   r   r   r   r   r   	__class__
Comparatorr   r   r   updater   set_creation_order_create_descriptor_init_accessor)
rP   r   r   r   r   r   r   r   r   r   r   rQ   rR   re      s&   
zCompositeProperty.__init__r[   r\   rK   r]   c                   s   t  | |   d S rX   )r   r   _setup_event_handlersrP   r[   r   rQ   rR   r      s   z"CompositeProperty.instrument_classrs   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   ri   )rP   rs   accessoraerQ   rQ   rR   _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_columnsrO   rQ   rQ   rR   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   rK   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 rQ   )r{   .0rb   r   rQ   rR   
<listcomp>#  s    
zFCompositeProperty._create_descriptor.<locals>.fget.<locals>.<listcomp>)r   instance_dictinstance_staterb   _attribute_keysr   
issupersetr   managerdispatchrefresh_COMPOSITE_FGETget)r   rV   rT   valuesrO   r   rR   r|     s   




	z2CompositeProperty._create_descriptor.<locals>.fgetrs   r]   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 rX   )r   r   r   r   rb   r   _active_historyr   r   NO_VALUEsetr   r   rt   zipr   )r   rs   rV   rT   attrpreviousfnrb   r|   rP   rQ   rR   rv   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  q:d S rX   )r   r   r   r   rb   r   r   popr   r   remover   r   rt   )r   rT   rV   r   r   rb   r   rQ   rR   rz   M  s   


z2CompositeProperty._create_descriptor.<locals>.fdelN)r   r   rK   r   )r   r   rs   r   rK   r]   )r   r   rK   r]   )ro   rJ   )rP   rv   rz   rQ   r   rR   r     s   z$CompositeProperty._create_descriptorsqlalchemy.orm.properties	decl_scanr1   registryr,   cls	Type[Any]originating_modulerb   rc   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   rc   r)   hasattrr   r   ArgumentErrorr   r   _setup_for_dataclassr   r"   r>   ru   r   )rP   r   r   r   r   rb   r   r   r   r   r5   argumentstr_argr   rQ   rQ   rR   declarative_scan_  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 rQ   )ru   )r   prQ   rQ   rR   r         z4CompositeProperty._init_accessor.<locals>.<listcomp>r   c                   s
    | fS rX   rQ   ry   getterrQ   rR   r~     r   z2CompositeProperty._init_accessor.<locals>.<lambda>c                 S     |   S rX   r   ry   rQ   rQ   rR   r~     s    )r   r   r   inspect	signatureoperator
attrgetter
parametersr   lenr   r   typer   )rP   insprQ   r   rR   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   ri   r   declarative_scan_for_compositeru   r   r"   r>   _undefer_column_name)
rP   r   r   r   rb   r5   	decl_baser   paramr   rQ   rQ   rR   r     s@   
	
z&CompositeProperty._setup_for_dataclassrL   c                   s    fdd j D S )Nc                      g | ]
}t  jj|jqS rQ   )r{   r   r   rb   r   ra   rO   rQ   rR   r     s    z:CompositeProperty._comparable_elements.<locals>.<listcomp>propsrO   rQ   rO   rR   _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   rc   r   get_propertyr"   r>   _columntopropertycolumnr   r.   ro   r   r   r   append)rP   r  r5   r   ra   rQ   rQ   rR   r    s(   




zCompositeProperty.propsc                 C     | j S rX   )r  rO   rQ   rQ   rR   rS        z(CompositeProperty._column_strategy_attrs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 rQ   )r   r"   r>   r  )r   ar4   rQ   rR   r     s    z-CompositeProperty.columns.<locals>.<listcomp>)r   r   r   r5   r   rO   rQ   r4   rR   columns  s   

zCompositeProperty.columnsOptional[MapperProperty[_CC]]c                 C  s   | S rX   rQ   rO   rQ   rQ   rR   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   crQ   rQ   rR   r     s    z7CompositeProperty.columns_to_assign.<locals>.<listcomp>)r  rO   rQ   rQ   rR   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   )rP   r3   ra   cproprQ   rQ   rR   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.rT   rU   contextr0   rK   r]   c                   s    | |d dd d S )NF
is_refreshrQ   )rT   r  )_load_refresh_handlerrQ   rR   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   )rb   unionr   intersection)rT   r  r$  r"  rP   rQ   rR   refresh_handler-  s   z@CompositeProperty._setup_event_handlers.<locals>.refresh_handlerr!  r^   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 rQ   )dictr   rT   rQ   rR   r   W      zZCompositeProperty._setup_event_handlers.<locals>._load_refresh_handler.<locals>.<listcomp>)r*  r   rb   r   r   )rT   r  r$  r!  rV   krO   r+  rR   r"  9  s   


zFCompositeProperty._setup_event_handlers.<locals>._load_refresh_handlerkeysc                   s0   |d u st  j|r| j jd  d S d S rX   )r   r   r'  r*  r   rb   )rT   r.  rO   rQ   rR   expire_handlerZ  s   z?CompositeProperty._setup_event_handlers.<locals>.expire_handlerr[   r\   
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   rb   )r[   r0  rT   rO   rQ   rR   insert_update_handler`  s   zFCompositeProperty._setup_event_handlers.<locals>.insert_update_handlerafter_insertT)rawafter_updateload)r3  	propagater   expireN)rT   rU   r  r0   rK   r]   )rT   rU   r  r0   r$  r%  rK   r]   )
rT   rU   r  r0   r$  r%  r!  r^   rK   r]   )rT   rU   r.  r%  rK   r]   )r[   r\   r0  r7   rT   rU   rK   r]   )	r    listenr   r   rb   r   r   r   r   )rP   r#  r)  r/  r1  r   rQ   r(  rR   r   %  s.   !


z'CompositeProperty._setup_event_handlersSequence[str]c                 C  r  )Nc                 S  r   rQ   rd   r  rQ   rQ   rR   r     r   z5CompositeProperty._attribute_keys.<locals>.<listcomp>r  rO   rQ   rQ   rR   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   rK   
Tuple[Any]c                 S  r   rX   r   )r;  rQ   rQ   rR   
get_values  s   zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.get_valuesc                 S  r   rQ   rd   r  rQ   rQ   rR   r     r   zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.<listcomp>	dest_dictDict[str, Any]r]   c              	     s*   |  dd t | jD  d S )Nc                 S  s   i | ]\}}||qS rQ   rQ   )r   rb   r;  rQ   rQ   rR   
<dictcomp>  s    zaCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate.<locals>.<dictcomp>)r   r   r   rb   )r>  r   r=  rP   rQ   rR   populate  s   zMCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate)r;  r   rK   r<  )r>  r?  rK   r]   )r   r  )rP   rB  rQ   rA  rR   )_populate_composite_bulk_save_mappings_fn  s   

z;CompositeProperty._populate_composite_bulk_save_mappings_fnrT   rU   rV   r+   rW   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().FTNrQ   )r  rb   r   r   rZ   has_changesnon_deletedextendr  deletedr   r-   r   )rP   rT   rV   rW   addedrG  has_historyra   rb   histrE  rQ   rQ   rR   rZ     s,   



zCompositeProperty.get_historyComposite.Comparator[_CC]c                 C  s   |  | |S rX   )r   r   rQ   rQ   rR   r}     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 rX   )ro   r   re   rb   )rP   rL  rN  r   rQ   rR   re     s   z*CompositeProperty.CompositeBundle.__init__querySelect[Any]procs#Sequence[Callable[[Row[Any]], Any]]labelsr9  rK   Callable[[Row[Any]], Any]c                   s   d fdd}|S )NrowRow[Any]rK   r   c                   s   j j fddD  S )Nc                   s   g | ]}| qS rQ   rQ   )r   procrU  rQ   rR   r     s    zXCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc.<locals>.<listcomp>)ro   r   rX  rQ  rP   rX  rR   rW    s   zDCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc)rU  rV  rK   r   rQ   )rP   rO  rQ  rS  rW  rQ   rY  rR   create_row_processor  s   z6CompositeProperty.CompositeBundle.create_row_processor)rL  rM  rN  r;   )rO  rP  rQ  rR  rS  r9  rK   rT  )ri   rj   rk   re   rZ  __classcell__rQ   rQ   r   rR   CompositeBundle  s    r\  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]]ra   rK   r;   c                 C  s   t j| jddiS )Nr   F)r%   r;   r  rO   rQ   rQ   rR   clauses  s
   z$CompositeProperty.Comparator.clauses&CompositeProperty.CompositeBundle[_PT]c                 C  r  rX   r$   rO   rQ   rQ   rR   __clause_element__  r  z/CompositeProperty.Comparator.__clause_element__c                 C  s*   | j | j| j| jjd}t| j|S )N)parententityparentmapper	proxy_key)r]  	_annotate_parententityra   rb   r   r\  )rP   r]  rQ   rQ   rR   r%     s   z'CompositeProperty.Comparator.expressionrs   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 rX   rQ   r   rQ   rQ   rR   r     s    zDCompositeProperty.Comparator._bulk_update_tuples.<locals>.<listcomp>z)Can't UPDATE composite attribute %s to %r)r   r'   rs   ra   r   r   r   r   r   r   listr   r  )rP   rs   r   rQ   rQ   rR   _bulk_update_tuples  s    
z0CompositeProperty.Comparator._bulk_update_tuplesrL   c                   s$    j r fdd jjD S  jjS )Nc                   r  rQ   )r{   _adapt_to_entityentityrb   r  rO   rQ   rR   r   '  s    zECompositeProperty.Comparator._comparable_elements.<locals>.<listcomp>)rh  ra   r  rO   rQ   rO   rR   r  $  s
   
z1CompositeProperty.Comparator._comparable_elementsotherColumnElement[bool]c                 C     |  tj|S rX   )_comparer&   eqrP   rj  rQ   rQ   rR   __eq__.     z#CompositeProperty.Comparator.__eq__c                 C  rl  rX   )rm  r&   nero  rQ   rQ   rR   __ne__1  rq  z#CompositeProperty.Comparator.__ne__c                 C  rl  rX   )rm  r&   ltro  rQ   rQ   rR   __lt__4  rq  z#CompositeProperty.Comparator.__lt__c                 C  rl  rX   )rm  r&   gtro  rQ   rQ   rR   __gt__7  rq  z#CompositeProperty.Comparator.__gt__c                 C  rl  rX   )rm  r&   lero  rQ   rQ   rR   __le__:  rq  z#CompositeProperty.Comparator.__le__c                 C  rl  rX   )rm  r&   gero  rQ   rQ   rR   __ge__=  rq  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 rQ   rQ   )r   r  b)r   rQ   rR   r   O  s    z9CompositeProperty.Comparator._compare.<locals>.<listcomp>c                   s   g | ]}  |qS rQ   )adapter)r   xrO   rQ   rR   r   U  r,  )	r   ra   r  r   r   rh  r}  r#   and_)rP   r   rj  r   comparisonsrQ   )r   rP   rR   rm  G  s   

z%CompositeProperty.Comparator._compare)rK   r;   )rK   r^  )rs   r   rK   re  r   )rj  r   rK   rk  )r   r=   rj  r   rK   rk  )ri   rj   rk   r   __hash__r   r   memoized_propertyr]  r_  r%   rg  r  rp  rs  ru  rw  ry  r{  rm  rQ   rQ   rQ   rR   r     s&   
 



	





r   c                 C  s   t | jjjd | j S )N.)rc   r   r   ri   rb   rO   rQ   rQ   rR   __str__X  s   zCompositeProperty.__str__rX   )r   r   r   r   r   r   r   r^   r   r^   r   rH   r   r   r   r   r   r   r   )rs   r   rK   r   rK   r]   )r   r1   r   r,   r   r   r   rH   rb   rc   r   r   r   r   r   r   r   r^   rK   r]   )
r   r,   r   r   r   rH   rb   rc   rK   r]   r   )rK   r	  )rK   r  )rK   r  )rK   r  )rK   r9  )rK   r:  rh   )r[   r\   rK   rK  )rK   rc   )+ri   rj   rk   r   r   re   r   r   r   objectr   r   r   preload_moduler   r   r   r  r  r  rS   non_memoized_propertyr  ro   r  r  r   r   r   rC  r   rp   rZ   r}   orm_utilBundlerD   r\  r   rF   r   r  r[  rQ   rQ   r   rR   r      sf   
 (


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ri   rj   rk   r   inherit_cacherQ   rQ   rQ   rR   r  \  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.

    r[   r\   rK   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_propsrb   r{   r   )rP   r[   comparator_callablemr   rQ   rQ   rR   r}     s   
z-ConcreteInheritedProperty._comparator_factoryr]   c                   s8   t    d fddG  fddd}|  _d S )NrK   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   rb   rQ   rO   rQ   rR   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   rr   rs   rK   r   c                   
      d S rX   rQ   )r  rr   rs   r  rQ   rR   __set__  rf   zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__set__c                   r  rX   rQ   )r  rr   r  rQ   rR   
__delete__  rf   zOConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__delete__ownerc                   s   |d u r j S   d S rX   )rJ   )r  rr   r  rP   r  rQ   rR   __get__  s   
zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__get__N)r  r   rr   r   rs   r   rK   r   )r  r   rr   r   rK   r   )r  r   rr   r   r  r   rK   r   )ri   rj   rk   r  r  r  rQ   r  rQ   rR   NoninheritedConcreteProp  s    r  )rK   r   )r   re   rJ   )rP   r  r   r  rR   re     s   
z"ConcreteInheritedProperty.__init__)r[   r\   rK   r  r  )ri   rj   rk   r   r}   re   r[  rQ   rQ   r   rR   r  o  s    
r  c                      s   e Zd ZU dZded< 						d1d2 fddZes"ed3ddZe	j
d4ddZd5ddZd6d d!Zejfd7d)d*Ze	d+d8d/d0Z  ZS )9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   Nru   rc   
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   re   ru   r  rJ   r   rI   r   r   r   r   r   )rP   ru   r  rJ   r   r   r   rI   r   rQ   rR   re     s   


zSynonymProperty.__init__rK   r^   c                 C  s   t | jj| jjjS rX   )r{   r   r   ru   r   r_   rO   rQ   rQ   rR   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 )Nro   zGsynonym() attribute "%s.%s" only supports ORM mapped attributes, got %r)r{   r   r   ru   r   r   ro   r   r   r/   
comparatorr   r   r   ri   )rP   r   rQ   rQ   rR   _proxied_object  s   
zSynonymProperty._proxied_objectrL   c                 C  s   t | jj| jfS rX   )r{   r   r   ru   rO   rQ   rQ   rR   rS     rw   z&SynonymProperty._column_strategy_attrsr[   r\   SQLORMOperations[_T]c                 C  s:   | j }t|tr| jr| ||}|S |||}|S |S rX   )r  r   r   r   )rP   r[   ra   comprQ   rQ   rR   r}     s   
z#SynonymProperty._comparator_factoryrT   rU   rV   r+   rW   r   r-   c                 C  s"   t | jj| j}|jj|||dS )N)rW   )r{   r   r   ru   r   rZ   )rP   rT   rV   rW   r   rQ   rQ   rR   rZ     s   zSynonymProperty.get_historyr   r   initr]   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  rb   persist_selectabler  r   r   ru   descriptionr  r3   _configure_property_mapped_by_synonymr   )rP   r   r  
propertiesr   rQ   rQ   rR   
set_parent
  s>   

zSynonymProperty.set_parent)NNNNNN)ru   rc   r  r  rJ   r  r   r  r   r   r   r   rI   rH   rg   )rK   r  r   )r[   r\   rK   r  rh   )r   r\   r  r^   rK   r]   )ri   rj   rk   r   r   re   r   ro   r_   r   r  r  rS   r}   r   rp   rZ   r  r  r[  rQ   rQ   r   rR   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  rQ   rQ   rQ   rR   r  1  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   r[   r2   r  r3   r5   rT   r6   engine.baser7   
engine.rowr8   sql._typingr9   r:   r;   r<   sql.operatorsr=   
sql.schemar>   sql.selectabler?   r@   rA   rB   rC   rD   rF   rG   rc   _CompositeAttrTyper   WeakKeyDictionaryr   r   r   r  r  r  r  rQ   rQ   rQ   rR   <module>   s   M	

     (8 