o
    E6df                     @  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)
is_fwd_ref)	is_pep593)typing_get_args)_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   vC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\sqlalchemy/orm/descriptor_props.pyget_historye   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[   u   s   zDDescriptorProperty.instrument_class.<locals>._ProxyImpl.uses_objectskeystrc                 S  s
   || _ d S rP   r_   )rS   r_   rT   rT   rU   __init__y      
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__Zaccepts_scalar_loaderZload_on_unexpireZ
collectionpropertyr[   rb   r   PASSIVE_OFFrV   rT   r]   rT   rU   
_ProxyImplp   s    
rk   objr   valuerO   rY   c                   s   t |  j| d S rP   )setattrname)rl   rm   r\   rT   rU   fset   s   z1DescriptorProperty.instrument_class.<locals>.fsetc                   s   t |  j d S rP   )delattrro   rl   r\   rT   rU   fdel   s   z1DescriptorProperty.instrument_class.<locals>.fdelc                   s   t |  jS rP   )getattrro   rr   r\   rT   rU   fget   s   z1DescriptorProperty.instrument_class.<locals>.fget)ru   rp   rs   c                     s
     S rP   )_comparator_factoryrT   )rW   rS   rT   rU   <lambda>      
 z5DescriptorProperty.instrument_class.<locals>.<lambda>)rI   Zoriginal_property)rl   r   rm   r   rO   rY   )rl   r   rO   rY   )rl   r   rO   r   )r   ZAttributeImplrJ   rt   class_r_   Z_is_userland_descriptorri   Zcreate_proxied_attributeparentrI   implclass_managerZinstrument_attribute)rS   rW   rk   descrp   rs   ru   
proxy_attrrT   )rW   r^   rS   rU   instrument_classm   s*   


z#DescriptorProperty.instrument_classre   rW   rX   rO   rY   )rf   rg   rh   __doc__rI   __annotations__r[   Z_links_to_entityr   rj   rV   r   rT   rT   rT   rU   rG   Z   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_classrm   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   rm   accessorZ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   )rt   .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   ru     s   




	z2CompositeProperty._create_descriptor.<locals>.fgetrm   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   rn   zipr   )r   rm   rM   rK   attrpreviousfnr_   ru   rS   rT   rU   rp   0  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   rn   )r   rK   rM   r   r   r_   r   rT   rU   rs   G  s   


z2CompositeProperty._create_descriptor.<locals>.fdelN)r   r   rO   r   )r   r   rm   r   rO   rY   )r   r   rO   rY   )ri   rJ   )rS   rp   rs   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)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   r`   r(   hasattrr   r   ArgumentErrorr   r   _setup_for_dataclassr   r"   r>   ro   r   )rS   r   r   r   r   r_   r   r   r   r   r5   ZargumentZstr_argr   rT   rT   rU   declarative_scanY  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   )ro   )r   prT   rT   rU   r         z4CompositeProperty._init_accessor.<locals>.<listcomp>r   c                   s
    | fS rP   rT   rr   getterrT   rU   rw     rx   z2CompositeProperty._init_accessor.<locals>.<lambda>c                 S     |   S rP   r   rr   rT   rT   rU   rw     s    )r   r   r   inspect	signatureoperator
attrgetter
parametersr   lenr   r   typer   )rS   insprT   r   rU   r     s6   



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   Zorm_decl_baser   r   r   	itertoolszip_longestr   r   r   r   r   r   rf   r   Zdeclarative_scan_for_compositero   r   r"   r>   Z_undefer_column_name)
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   )rt   rz   ry   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)Z_configure_mapperszYComposite expects Column objects or mapped attributes/attribute names as arguments, got: )r   r   r   r5   r   r   r`   rz   Zget_propertyr"   r>   _columntopropertycolumnr   r.   ri   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)Z
instrumentTN)
r   r   r   r3   r   r   r   r   Zstrategy_keyr   )rS   r3   r^   Z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   N      zZCompositeProperty._setup_event_handlers.<locals>._load_refresh_handler.<locals>.<listcomp>)r  r   r_   r   r   )rK   r  r  r  rM   kr\   r  rU   r  0  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_handlerQ  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_handlerW  s   zFCompositeProperty._setup_event_handlers.<locals>.insert_update_handlerZafter_insertT)rawZafter_updateload)r  	propagater   Z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    listenrz   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   )r  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_   r  rT   rT   rU   
<dictcomp>  s    zaCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate.<locals>.<dictcomp>)r   r   r   r_   )r  r   r  rS   rT   rU   populate  s   zMCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate)r  r   rO   r  )r  r  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   Zhas_changesnon_deletedextendr   deletedr   r-   r   )rS   rK   rM   rN   addedr&  Z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   rv     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   )ri   r   rb   r_   )rS   r*  r,  r   rT   rU   rb     s   z*CompositeProperty.CompositeBundle.__init__querySelect[Any]procs#Sequence[Callable[[Row[Any]], Any]]labelsr  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r3  rT   rU   r     s    zXCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc.<locals>.<listcomp>)ri   r   r6  r/  rS   r6  rU   r5    s   zDCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc)r3  r4  rO   r   rT   )rS   r-  r/  r1  r5  rT   r7  rU   create_row_processor  s   z6CompositeProperty.CompositeBundle.create_row_processor)r*  r+  r,  r;   )r-  r.  r/  r0  r1  r  rO   r2  )rf   rg   rh   rb   r8  __classcell__rT   rT   r   rU   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]]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)ZparententityZparentmapper	proxy_key)r;  Z	_annotateZ_parententityr^   r_   r   r:  )rS   r;  rT   rT   rU   r%     s   z'CompositeProperty.Comparator.expressionrm   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'   rm   r^   r   r   r   r   r   r   listr   r   )rS   rm   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   )rt   _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__/  rK  z#CompositeProperty.Comparator.__le__c                 C  rF  rP   )rG  r&   gerI  rT   rT   rU   __ge__2  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   D  s    z9CompositeProperty.Comparator._compare.<locals>.<listcomp>c                   s   g | ]}  |qS rT   )adapter)r   xr\   rT   rU   r   J  r  )	r   r^   r   r   r   rB  rW  r#   and_)rS   r   rD  r   ZcomparisonsrT   )r   rS   rU   rG  <  s   

z%CompositeProperty.Comparator._compare)rO   r;   )rO   r<  )rm   r   rO   r?  rO   r   )rD  r   rO   rE  )r   r=   rD  r   rO   rE  )rf   rg   rh   r   __hash__r   r   memoized_propertyr;  r=  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`   rz   ry   rf   r_   r\   rT   rT   rU   __str__M  s   zCompositeProperty.__str__rP   )r   r   r   r   r   r   r   rZ   r   rZ   r   rH   r   r   r   r   r   r   r   )rm   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   rZ  )rO   r   )rO   r   )rO   r   )rO   r   )rO   r  )rO   r  re   )rW   rX   rO   r)  )rO   r`   )*rf   rg   rh   r   r   rb   r   r   r   objectr   r   r   preload_moduler   r   r   r\  r   r   Znon_memoized_propertyr   ri   r   r   r   r   r   r#  r   rj   rV   rv   orm_utilZBundlerD   r:  r   rF   r   r^  r9  rT   rT   r   rU   r      sd   
 (


J
9'
_

%vr   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   Zinherit_cacherT   rT   rT   rU   rd  Q  s    rd  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   )rz   Ziterate_to_rootZ_propsr_   rt   r   )rS   rW   Zcomparator_callablemr   rT   rT   rU   rv   u  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   rz   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   rl   rm   rO   r   c                   
      d S rP   rT   )rj  rl   rm   ri  rT   rU   __set__  rc   zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__set__c                   rk  rP   rT   )rj  rl   rl  rT   rU   
__delete__  rc   zOConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__delete__ownerc                   s   |d u r j S   d S rP   )rJ   )rj  rl   ro  rS   ri  rT   rU   __get__  s   
zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__get__N)rj  r   rl   r   rm   r   rO   r   )rj  r   rl   r   rO   r   )rj  r   rl   r   ro  r   rO   r   )rf   rg   rh   rm  rn  rq  rT   rp  rT   rU   NoninheritedConcreteProp  s    rr  )rO   r   )r   rb   rJ   )rS   rr  r   rp  rU   rb     s   
z"ConcreteInheritedProperty.__init__)rW   rX   rO   rg  r_  )rf   rg   rh   r   rv   rb   r9  rT   rT   r   rU   rf  d  s    
rf  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   Nro   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   ro   ru  rJ   r   rI   r   r   r   r   r   )rS   ro   ru  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   )rt   rz   ry   ro   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 )Nri   zGsynonym() attribute "%s.%s" only supports ORM mapped attributes, got %r)rt   rz   ry   ro   r   r   ri   r   r   r/   Z
comparatorr   r   r   rf   )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   )ry  r   r   r   )rS   rW   r^   comprT   rT   rU   rv     s   
z#SynonymProperty._comparator_factoryrK   rL   rM   r+   rN   r   r-   c                 C  s"   t | jj| j}|jj|||dS )N)rN   )rt   rz   ry   ro   r{   rV   )rS   rK   rM   rN   r   rT   rT   rU   rV     s   zSynonymProperty.get_historyr   rz   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|  Z	setparent)r   r   r   ru  r_   Zpersist_selectabler   r   r   ro   descriptionr   r3   Z_configure_propertyZ_mapped_by_synonymrz   )rS   rz   r|  
propertiesr   rT   rT   rU   
set_parent  s>   

zSynonymProperty.set_parent)NNNNNN)ro   r`   ru  rv  rJ   rw  r   rt  r   r   r   r   rI   rH   rd   )rO   rx  )rW   rX   rO   rz  re   )rz   rX   r|  rZ   rO   rY   )rf   rg   rh   r   r   rb   r   ri   r[   r   r\  ry  rv   r   rj   rV   ra  r  r9  rT   rT   r   rU   rs    s(   
 
	rs  c                   @  rc  )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

    TNre  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   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   rW   r2   r~  r3   r5   rK   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   r`   Z_CompositeAttrTyper   WeakKeyDictionaryr   r   r   rd  rf  rs  r  rT   rT   rT   rU   <module>   s   H	

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