o
    Šågo‘  ã                   @  s   U d Z ddlmZ ddlmZ ddlZddlZddlZddlZddlm	Z	 ddlm
Z
 ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl m"Z" ddl m#Z# ddl m$Z$ ddl m%Z% ddlm&Z& ddlm'Z' d d!lm(Z( d d"lm)Z* d d#lm+Z+ d d$lm,Z, d dlmZ d d%l,m-Z- d d&l,m.Z. d d'l/m0Z0 d d(l1m2Z2 d d)l1m3Z3 d d*l1m4Z4 ej�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 )YzŸDescriptor properties are more "auxiliary" properties
that exist as configurational elements, but don't participate
as actively in the load/persist ORM loop.

é    )Úannotations)Úis_dataclassN)ÚAny)ÚCallable)ÚDict)ÚList)ÚNoReturn)ÚOptional)ÚSequence)ÚTuple)ÚType)ÚTYPE_CHECKING)ÚTypeVar)ÚUnioné   )Ú
attributes)Úutil)Ú_DeclarativeMapped)ÚLoaderCallableStatus)ÚMapped)ÚPassiveFlag)ÚSQLORMOperations)Ú_AttributeOptions)Ú_IntrospectsAnnotations)Ú_MapsColumns)ÚMapperProperty)ÚPropComparator)Ú	_none_set)Úde_stringify_annotationé   )Úevent)Úexc)Úschema)Úsql©Ú
expression)Ú	operators)ÚBindParameter)Úget_args)Ú
is_fwd_ref)Ú	is_pep593)Ú_InstanceDict)Ú_RegistryType)ÚHistory)ÚInstrumentedAttribute)ÚQueryableAttribute)ÚORMCompileState)Ú_ClassScanMapperConfig)ÚMapper)ÚColumnProperty©ÚMappedColumn)ÚInstanceState)Ú
Connection)ÚRow)Ú_DMLColumnArgument)Ú	_InfoType)Ú
ClauseList)ÚColumnElement)ÚOperatorType)ÚColumn)ÚSelect)Ú_AnnotationScanType)ÚCallableReference)ÚDescriptorReference)ÚRODescriptorReferenceÚ_T)ÚboundÚ_PTc                   @  sH   e Zd ZU dZdZded< dZdZded< ej	fddd„Z
ddd„ZdS )ÚDescriptorPropertyzO:class:`.MapperProperty` which proxies access to a
    user-defined descriptor.NúOptional[str]ÚdocFzDescriptorReference[Any]Ú
descriptorÚstateúInstanceState[Any]Údict_r+   Úpassiver   Úreturnr-   c                 C  s   t ƒ ‚©N)ÚNotImplementedError©ÚselfrK   rM   rN   © rT   ú[/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/orm/descriptor_props.pyÚget_historyf   s   zDescriptorProperty.get_historyÚmapperúMapper[Any]ÚNonec                   sÜ   ˆ‰G ‡fdd„dt jƒ}ˆjd u r$tˆ jˆjd ƒ}ˆ  ˆj|¡r$|ˆ_ˆjd u rFd‡fdd	„}d‡fd
d„}d‡fdd„}t|||d�ˆ_t  ˆj¡ˆj	jˆjˆj‡ ‡fdd„ˆj
ˆd�}|ˆjƒ|_ˆ j ˆj|¡ d S )Nc                      sH   e Zd ZdZdZdZed‡ fdd„ƒZdd	d
„Ze	j
fd‡ fdd„ZdS )z7DescriptorProperty.instrument_class.<locals>._ProxyImplFTrO   Úboolc                   s   ˆ j S rP   )Úuses_objects©rS   ©ÚproprT   rU   r[   v   s   zDDescriptorProperty.instrument_class.<locals>._ProxyImpl.uses_objectsÚkeyÚstrc                 S  s
   || _ d S rP   ©r_   )rS   r_   rT   rT   rU   Ú__init__z   ó   
z@DescriptorProperty.instrument_class.<locals>._ProxyImpl.__init__rK   rL   rM   r+   rN   r   r-   c                   s   ˆ   |||¡S rP   )rV   rR   r]   rT   rU   rV   }   s   zCDescriptorProperty.instrument_class.<locals>._ProxyImpl.get_historyN©rO   rZ   )r_   r`   ©rK   rL   rM   r+   rN   r   rO   r-   )Ú__name__Ú
__module__Ú__qualname__Úaccepts_scalar_loaderÚload_on_unexpireÚ
collectionÚpropertyr[   rb   r   ÚPASSIVE_OFFrV   rT   r]   rT   rU   Ú
_ProxyImplq   s    
ürn   Úobjr   ÚvaluerO   rY   c                   s   t | ˆ j|ƒ d S rP   )ÚsetattrÚname)ro   rp   r\   rT   rU   ÚfsetŒ   s   z1DescriptorProperty.instrument_class.<locals>.fsetc                   s   t | ˆ jƒ d S rP   )Údelattrrr   ©ro   r\   rT   rU   Úfdel�   s   z1DescriptorProperty.instrument_class.<locals>.fdelc                   s   t | ˆ jƒS rP   )Úgetattrrr   ru   r\   rT   rU   Úfget’   s   z1DescriptorProperty.instrument_class.<locals>.fget)rx   rs   rv   c                     s
   ˆ  ˆ ¡S rP   )Ú_comparator_factoryrT   )rW   rS   rT   rU   Ú<lambda>›   ó   
 z5DescriptorProperty.instrument_class.<locals>.<lambda>)rI   Úoriginal_property)ro   r   rp   r   rO   rY   )ro   r   rO   rY   )ro   r   rO   r   )r   ÚAttributeImplrJ   rw   Úclass_r_   Ú_is_userland_descriptorrl   Úcreate_proxied_attributeÚparentrI   ÚimplÚclass_managerÚinstrument_attribute)rS   rW   rn   Údescrs   rv   rx   Ú
proxy_attrrT   )rW   r^   rS   rU   Úinstrument_classn   s*   


úz#DescriptorProperty.instrument_classre   ©rW   rX   rO   rY   )rf   rg   rh   Ú__doc__rI   Ú__annotations__r[   Ú_links_to_entityr   rm   rV   r‡   rT   rT   rT   rU   rG   [   s   
 ürG   z
Column[_T]zMappedColumn[_T]zInstrumentedAttribute[_T]z
Mapped[_T]Ú_CCzFweakref.WeakKeyDictionary[Type[Any], Callable[[Any], Tuple[Any, ...]]]Ú_composite_gettersc                      s¬  e Zd ZU dZded< ded< ded< ded	< 	
dpd
ddd
d
d
dœdq‡ fdd„Zdr‡ fd"d#„Zdsd'd(„Zdtd)d*„Ze	ƒ Z
dtd+d,„Ze d-¡dud=d>„ƒZdtd?d@„Ze d-¡e dA¡dvdBdC„ƒƒZejdwdEdF„ƒZeje dG¡dxdIdJ„ƒƒZeje dG¡dydLdM„ƒƒZedzdOdP„ƒZed{dRdS„ƒZe dG¡dtdTdU„ƒZdtdVdW„Zejd|dYdZ„ƒZd}d\d]„Zejfd~dedf„Zddhdi„Z G djdk„ dke!j"e# ƒZ$G dldm„ dme%e& ƒZ'd€dndo„Z(‡  Z)S )�ÚCompositePropertyzöDefines 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_attrúCUnion[None, Type[_CC], Callable[..., _CC], _CompositeAttrType[Any]]ú_CompositeAttrType[Any]r“   úOptional[_AttributeOptions]r”   rZ   r•   r–   rH   úOptional[Type[Comparator[_CC]]]r—   úOptional[_InfoType]Úkwargsr   c          
        s    t ƒ j|d� t|tttjfƒr|f| | _d | _n|| _|| _|| _	|| _
|| _|d ur/|n| jj| _d | _|d urA| j |¡ t | ¡ |  ¡  |  ¡  d S ©N)r“   )Úsuperrb   Ú
isinstancer   r`   r#   r<   r�   r�   r”   r•   r–   Ú	__class__Ú
Comparatorr’   r‘   r—   Úupdater   Úset_creation_orderÚ_create_descriptorÚ_init_accessor)
rS   r˜   r“   r”   r•   r–   r’   r—   r�   rž   ©r¢   rT   rU   rb   Ì   s&   ÿý
zCompositeProperty.__init__rW   rX   rO   rY   c                   s   t ƒ  |¡ |  ¡  d S rP   )r    r‡   Ú_setup_event_handlers©rS   rW   r¨   rT   rU   r‡   ô   s   z"CompositeProperty.instrument_classrp   rŒ   úTuple[Any, ...]c              
   C  sP   | j r|   |¡S z|j}W |ƒ S  ty' } zt d| jj› d�¡|‚d }~ww )NzComposite class zX is not a dataclass and does not define a __composite_values__() method; can't get state)r‘   Ú__composite_values__ÚAttributeErrorÚsa_excÚInvalidRequestErrorr�   rf   )rS   rp   ÚaccessorÚaerT   rT   rU   Ú_composite_values_from_instanceø   s   
ùÿü€ÿz1CompositeProperty._composite_values_from_instancec                 C  s   |   ¡  dS )zwInitialization which occurs after the :class:`.Composite`
        has been associated with its parent mapper.

        N)Ú_setup_arguments_on_columnsr\   rT   rT   rU   Údo_init  s   zCompositeProperty.do_initc                   s@   d‡fdd„‰ d‡ ‡fdd	„}d‡ ‡fd
d„}t ˆ ||ƒˆ_dS )ztCreate the Python descriptor that will serve as
        the access point on instances of the mapped class.

        Úinstancer   rO   c                   s†   t  ˆ ¡}t  ˆ ¡}ˆj|vr<‡ fdd„ˆjD ƒ}ˆj|vr<|jd us(t |¡s<ˆj|Ž |ˆj< |jj	 
|ˆjˆjg¡ | ˆjd ¡S )Nc                   s   g | ]}t ˆ |ƒ‘qS rT   )rw   ©Ú.0r_   ©rµ   rT   rU   Ú
<listcomp>  s    
ÿzFCompositeProperty._create_descriptor.<locals>.fget.<locals>.<listcomp>)r   Úinstance_dictÚinstance_stater_   Ú_attribute_keysr   Ú
issupersetr�   ÚmanagerÚdispatchÚrefreshÚ_COMPOSITE_FGETÚget)rµ   rM   rK   Úvaluesr\   r¸   rU   rx     s   



ÿ
	ÿz2CompositeProperty._create_descriptor.<locals>.fgetrp   rY   c                   sº   t  | ¡}t  | ¡}|jˆj }|jjrˆ | ƒ}n| ˆjtj	¡}|jj
D ]
}|||||jƒ}q%||ˆj< |d u rGˆjD ]}t| |d ƒ q<d S tˆjˆ |¡ƒD ]
\}}t| ||ƒ qPd S rP   )r   rº   r»   r¾   r_   r¿   Ú_active_historyrÂ   r   ÚNO_VALUEÚsetr‚   r¼   rq   Úzipr²   )rµ   rp   rM   rK   ÚattrÚpreviousÚfnr_   ©rx   rS   rT   rU   rs   1  s&   




ÿþüz2CompositeProperty._create_descriptor.<locals>.fsetc                   sŠ   t  | ¡}t  | ¡}|jˆj }|jjr ˆ | ƒ}| ˆjd ¡ n| ˆjtj	¡}|jˆj }|j 
|||j¡ ˆjD ]}t| |d ƒ q:d S rP   )r   r»   rº   r¾   r_   r¿   rÄ   Úpopr   rÅ   Úremover‚   r¼   rq   )rµ   rK   rM   rÈ   rÉ   r_   rË   rT   rU   rv   H  s   


ÿz2CompositeProperty._create_descriptor.<locals>.fdelN)rµ   r   rO   r   )rµ   r   rp   r   rO   rY   )rµ   r   rO   rY   )rl   rJ   )rS   rs   rv   rT   rË   rU   r¦     s   z$CompositeProperty._create_descriptorúsqlalchemy.orm.propertiesÚ	decl_scanr1   Úregistryr,   Úclsú	Type[Any]Úoriginating_moduler_   r`   Úmapped_containerúOptional[Type[Mapped[Any]]]Ú
annotationúOptional[_AnnotationScanType]Úextracted_mapped_annotationÚis_dataclass_fieldc
                 C  s
  t jjj}
| jd u r|d u r|  ||¡ |}t|ƒr t|ƒd }|rY| jd u rYt|t	ƒs2t
|dd�rV|d u rNt|dƒr>|jnt	|ƒ}t d|› d|› d�¡‚t|||dd�}|| _t| jƒrg|  ||||¡ n| jD ]}t||
tjfƒr~|jd u r~t d	¡‚qj|  ¡  d S )
Nr   T)Úcheck_genericÚ__forward_arg__zCan't use forward ref z9 for composite class argument; set up the type as Mapped[ú])Úinclude_genericzIComposite class column arguments must be named unless a dataclass is used)r   Ú	preloadedÚorm_propertiesr5   r�   Ú_raise_for_requiredr*   r(   r¡   r`   r)   ÚhasattrrÛ   r®   ÚArgumentErrorr   r   Ú_setup_for_dataclassr�   r"   r>   rr   r§   )rS   rÏ   rÐ   rÑ   rÓ   r_   rÔ   rÖ   rØ   rÙ   r5   ÚargumentÚstr_argrÈ   rT   rT   rU   Údeclarative_scanZ  sH   

ÿÿýÿÿÿ

ÿ
ÿ€z"CompositeProperty.declarative_scanc                   sÈ   t | jƒr0t| jdƒs0t | j¡}tjdd„ |j ¡ D ƒŽ ‰ t	|jƒdkr-‡ fdd„| _
nˆ | _
| jd ur\t| jtƒr^| jtvr`| j
d urM| j
t| j< d S t| jdƒrbdd„ t| j< d S d S d S d S d S )Nr¬   c                 S  ó   g | ]}|j ‘qS rT   )rr   )r·   ÚprT   rT   rU   r¹   š  ó    z4CompositeProperty._init_accessor.<locals>.<listcomp>r   c                   s
   ˆ | ƒfS rP   rT   ru   ©ÚgetterrT   rU   rz   �  r{   z2CompositeProperty._init_accessor.<locals>.<lambda>c                 S  ó   |   ¡ S rP   ©r¬   ru   rT   rT   rU   rz   ¬  s    )r   r�   rá   ÚinspectÚ	signatureÚoperatorÚ
attrgetterÚ
parametersrÃ   Úlenr‘   r¡   Útyper�   )rS   ÚinsprT   rê   rU   r§   ”  s.   ÿÿ

ÿ

ÿÿ÷z CompositeProperty._init_accessorzsqlalchemy.orm.decl_basec           
   
   C  sÐ   t jjj}t jj}t | j¡}t 	|j
 ¡ | j¡D ]L\}}	|d u r7t dt| jƒ› d| jj› dt|j
ƒ› �¡‚|	d u rF|ƒ }	|  j|	f7  _t|	|ƒrX|	 |||||j|j¡ qt|	tjƒre| |j|	¡ qd S )Nznumber of composite attributes z3 exceeds that of the number of attributes in class ú )r   rÞ   rß   r5   Úorm_decl_baserî   rï   r�   Ú	itertoolsÚzip_longestrò   rÃ   r�   r®   râ   ró   rf   r¡   Údeclarative_scan_for_compositerr   rÖ   r"   r>   Ú_undefer_column_name)
rS   rÐ   rÑ   rÓ   r_   r5   Ú	decl_baserõ   ÚparamrÈ   rT   rT   rU   rã   ¯  s@   
	ÿÿýýÿ
ú€çz&CompositeProperty._setup_for_dataclassú!Sequence[QueryableAttribute[Any]]c                   s   ‡ fdd„ˆ j D ƒS )Nc                   ó   g | ]
}t ˆ jj|jƒ‘qS rT   )rw   r�   r~   r_   ©r·   r^   r\   rT   rU   r¹   Ú  s    z:CompositeProperty._comparable_elements.<locals>.<listcomp>©Úpropsr\   rT   r\   rU   Ú_comparable_elementsØ  ó   z&CompositeProperty._comparable_elementszorm.propertiesúSequence[MapperProperty[Any]]c                 C  sª   g }t jjj}| jD ]H}t|tƒr| jj|dd�}n&t|t	j
ƒr'| jj| }nt||ƒr4| jj|j }nt|tjƒr>|j}nd }t|tƒsMt d|›�¡‚| |¡ q
|S )NF)Ú_configure_mapperszYComposite expects Column objects or mapped attributes/attribute names as arguments, got: )r   rÞ   rß   r5   r�   r¡   r`   r�   Úget_propertyr"   r>   Ú_columntopropertyÚcolumnr   r.   rl   r   r®   râ   Úappend)rS   r  r5   rÈ   r^   rT   rT   rU   r  Ü  s(   




ÿÿzCompositeProperty.propsúSequence[Column[Any]]c                   s   t jjj‰ ‡ fdd„| jD ƒS )Nc                   s0   g | ]}t |tjˆ fƒrt |ˆ ƒr|jn|‘qS rT   )r¡   r"   r>   r	  )r·   Úar4   rT   rU   r¹   û  s    ýÿz-CompositeProperty.columns.<locals>.<listcomp>)r   rÞ   rß   r5   r�   r\   rT   r4   rU   Úcolumns÷  s   

þzCompositeProperty.columnsúOptional[MapperProperty[_CC]]c                 C  s   | S rP   rT   r\   rT   rT   rU   Úmapper_property_to_assign  s   z+CompositeProperty.mapper_property_to_assignú$List[Tuple[schema.Column[Any], int]]c                 C  ó   dd„ | j D ƒS )Nc                 S  s   g | ]}|j d u r|df‘qS )Nr   )Útable)r·   ÚcrT   rT   rU   r¹     s    z7CompositeProperty.columns_to_assign.<locals>.<listcomp>)r  r\   rT   rT   rU   Úcolumns_to_assign  ó   z#CompositeProperty.columns_to_assignc                 C  sN   t jjj}| jD ]}t||ƒsq|}| j|_| jr | j|_d|_| j	|_	qdS )zwPropagate configuration arguments made on this composite
        to the target columns, for those that apply.

        ))r•   T)Ú
instrumentTN)
r   rÞ   rß   r3   r  r¡   r”   r•   Ústrategy_keyr–   )rS   r3   r^   ÚcproprT   rT   rU   r³   	  s   



öz-CompositeProperty._setup_arguments_on_columnsc                   sÚ   d#‡ fdd„}d$‡ ‡fdd„}d%‡fdd„‰ d&‡fdd„}d'‡fdd„}t jˆjd|dd� t jˆjd|dd� t jˆjd|ddd� t jˆjd |ddd� t jˆjd!|ddd� ˆjjˆj }|j|j_ˆj|jj_d"S )(z>Establish events that populate/expire the composite attribute.rK   rL   Úcontextr0   rO   rY   c                   s   ˆ | |d dd� d S )NF©Ú
is_refreshrT   )rK   r  )Ú_load_refresh_handlerrT   rU   Úload_handler   s   z=CompositeProperty._setup_event_handlers.<locals>.load_handlerÚto_loadúOptional[Sequence[str]]c                   s2   |rˆj h ˆj¡ |¡rˆ | ||dd� d S d S )NTr  )r_   Úunionr¼   Úintersection)rK   r  r  ©r  rS   rT   rU   Úrefresh_handler%  s   þýz@CompositeProperty._setup_event_handlers.<locals>.refresh_handlerr  rZ   c                   s`   ˆ j }|r
|ˆju rˆj|v rd S ˆjD ]	}||vr d S qˆj‡ fdd„ˆjD ƒŽ |ˆj< d S )Nc                   s   g | ]}ˆ j | ‘qS rT   )Údictr¶   ©rK   rT   rU   r¹   O  ó    zZCompositeProperty._setup_event_handlers.<locals>._load_refresh_handler.<locals>.<listcomp>)r$  rÁ   r_   r¼   r�   )rK   r  r  r  rM   Úkr\   r%  rU   r  1  s   ÿ


ÿÿzFCompositeProperty._setup_event_handlers.<locals>._load_refresh_handlerÚkeysc                   s0   |d u st ˆ jƒ |¡r| j ˆ jd ¡ d S d S rP   )rÆ   r¼   r!  r$  rÌ   r_   )rK   r(  r\   rT   rU   Úexpire_handlerR  s   ÿz?CompositeProperty._setup_event_handlers.<locals>.expire_handlerrW   rX   Ú
connectionr7   c                   s   |j  ˆ jd¡ dS )zêAfter an insert or update, some columns may be expired due
            to server side defaults, or re-populated due to client side
            defaults.  Pop out the composite value here so that it
            recreates.

            N)r$  rÌ   r_   )rW   r*  rK   r\   rT   rU   Úinsert_update_handlerX  s   zFCompositeProperty._setup_event_handlers.<locals>.insert_update_handlerÚafter_insertT)ÚrawÚafter_updateÚload)r-  Ú	propagaterÀ   ÚexpireN)rK   rL   r  r0   rO   rY   )rK   rL   r  r0   r  r  rO   rY   )
rK   rL   r  r0   r  r  r  rZ   rO   rY   )rK   rL   r(  r  rO   rY   )rW   rX   r*  r7   rK   rL   rO   rY   )	r    Úlistenr�   rƒ   r_   r¿   r‚   r”   rÄ   )rS   r  r#  r)  r+  r†   rT   r"  rU   r©     s.   !
ÿ
ÿÿÿÿ
z'CompositeProperty._setup_event_handlersúSequence[str]c                 C  r  )Nc                 S  rç   rT   ra   r   rT   rT   rU   r¹   ~  ré   z5CompositeProperty._attribute_keys.<locals>.<listcomp>r  r\   rT   rT   rU   r¼   |  r  z!CompositeProperty._attribute_keysú Callable[[Dict[str, Any]], None]c                   s>   ˆj rˆj ‰nddd„‰dd„ ˆjD ƒ‰ d‡ ‡‡fdd„}|S )NÚvalr   rO   ú
Tuple[Any]c                 S  rì   rP   rí   )r5  rT   rT   rU   Ú
get_values‡  s   zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.get_valuesc                 S  rç   rT   ra   r   rT   rT   rU   r¹   Š  ré   zOCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.<listcomp>Ú	dest_dictúDict[str, Any]rY   c              	     s*   |   dd„ tˆ ˆ|  ˆj¡ƒƒD ƒ¡ d S )Nc                 S  s   i | ]\}}||“qS rT   rT   )r·   r_   r5  rT   rT   rU   Ú
<dictcomp>Ž  s    ÿÿzaCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate.<locals>.<dictcomp>)r¤   rÇ   rÌ   r_   )r8  ©r�   r7  rS   rT   rU   ÚpopulateŒ  s   ÿþÿzMCompositeProperty._populate_composite_bulk_save_mappings_fn.<locals>.populate)r5  r   rO   r6  )r8  r9  rO   rY   )r‘   r  )rS   r<  rT   r;  rU   Ú)_populate_composite_bulk_save_mappings_fn€  s   

z;CompositeProperty._populate_composite_bulk_save_mappings_fnrK   rL   rM   r+   rN   r   r-   c                 C  s¶   g }g }d}| j D ]5}|j}|j| j ||¡}	|	 ¡ rd}|	 ¡ }
|
r*| |
¡ n| d¡ |	j	r9| |	j	¡ q	| d¡ q	|rPt
 | j|Ž gd| j|Ž g¡S t
 d| j|Ž gd¡S )z>Provided for userland code that uses attributes.get_history().FTNrT   )r  r_   r¾   r‚   rV   Úhas_changesÚnon_deletedÚextendr
  Údeletedr   r-   r�   )rS   rK   rM   rN   ÚaddedrA  Úhas_historyr^   r_   Úhistr?  rT   rT   rU   rV   ˜  s,   



ýzCompositeProperty.get_historyúComposite.Comparator[_CC]c                 C  s   |   | |¡S rP   )r’   rª   rT   rT   rU   ry   ½  s   z%CompositeProperty._comparator_factoryc                      s(   e Zd Zd‡ fdd„Zddd„Z‡  ZS )z!CompositeProperty.CompositeBundleÚ	property_úComposite[_T]Úexprr;   c                   s    || _ tƒ j|jg|¢R Ž  d S rP   )rl   r    rb   r_   )rS   rF  rH  r¨   rT   rU   rb   Ã  s   z*CompositeProperty.CompositeBundle.__init__ÚqueryúSelect[Any]Úprocsú#Sequence[Callable[[Row[Any]], Any]]Úlabelsr3  rO   úCallable[[Row[Any]], Any]c                   s   d‡ ‡fdd„}|S )NÚrowúRow[Any]rO   r   c                   s   ˆj j‡ fdd„ˆD ƒŽ S )Nc                   s   g | ]}|ˆ ƒ‘qS rT   rT   )r·   Úproc©rO  rT   rU   r¹   Ó  s    zXCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc.<locals>.<listcomp>)rl   r�   rR  ©rK  rS   rR  rU   rQ  Ñ  s   ÿzDCompositeProperty.CompositeBundle.create_row_processor.<locals>.proc)rO  rP  rO   r   rT   )rS   rI  rK  rM  rQ  rT   rS  rU   Úcreate_row_processorË  s   z6CompositeProperty.CompositeBundle.create_row_processor)rF  rG  rH  r;   )rI  rJ  rK  rL  rM  r3  rO   rN  )rf   rg   rh   rb   rT  Ú__classcell__rT   rT   r¨   rU   ÚCompositeBundleÂ  s    rV  c                   @  s¨   e Zd ZU dZdZded< ejd(dd„ƒZd)d
d„Z	ejd)dd„ƒZ
d*dd„Zejd+dd„ƒZd,dd„Zd,dd„Zd,dd„Zd,dd„Zd,d d!„Zd,d"d#„Zd-d&d'„ZdS ).zCompositeProperty.Comparatora·  Produce boolean, comparison, and other operators for
        :class:`.Composite` attributes.

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

        .. seealso::

            :class:`.PropComparator`

            :class:`.ColumnOperators`

            :ref:`types_operators`

            :attr:`.TypeEngine.comparator_factory`

        Nz%RODescriptorReference[Composite[_PT]]r^   rO   r;   c                 C  s   t j| jddiŽS )Nr–   F)r%   r;   r  r\   rT   rT   rU   Úclausesð  s
   ÿÿz$CompositeProperty.Comparator.clausesú&CompositeProperty.CompositeBundle[_PT]c                 C  s   | j S rP   r$   r\   rT   rT   rU   Ú__clause_element__ö  s   z/CompositeProperty.Comparator.__clause_element__c                 C  s*   | j  | j| j| jjdœ¡}t | j|¡S )N)ÚparententityÚparentmapperÚ	proxy_key)rW  Ú	_annotateÚ_parententityr^   r_   rŽ   rV  )rS   rW  rT   rT   rU   r%   ù  s   ýÿz'CompositeProperty.Comparator.expressionrp   r   ú(Sequence[Tuple[_DMLColumnArgument, Any]]c                 C  sz   t |tƒr|j}|d u rdd„ | jjD ƒ}nt | jjtƒr+t || jjƒr+| j |¡}n
t 	d| j|f ¡‚t
t| j|ƒƒS )Nc                 S  s   g | ]}d ‘qS rP   rT   r¶   rT   rT   rU   r¹     s    zDCompositeProperty.Comparator._bulk_update_tuples.<locals>.<listcomp>z)Can't UPDATE composite attribute %s to %r)r¡   r'   rp   r^   r¼   r�   rô   r²   r®   râ   ÚlistrÇ   r  )rS   rp   rÃ   rT   rT   rU   Ú_bulk_update_tuples  s    
ÿÿÿÿz0CompositeProperty.Comparator._bulk_update_tuplesrþ   c                   s$   ˆ j r‡ fdd„ˆ jjD ƒS ˆ jjS )Nc                   rÿ   rT   )rw   Ú_adapt_to_entityÚentityr_   r   r\   rT   rU   r¹     s    ÿÿzECompositeProperty.Comparator._comparable_elements.<locals>.<listcomp>)rb  r^   r  r\   rT   r\   rU   r    s
   
þz1CompositeProperty.Comparator._comparable_elementsÚotherúColumnElement[bool]c                 C  ó   |   tj|¡S rP   )Ú_comparer&   Úeq©rS   rd  rT   rT   rU   Ú__eq__&  ó   z#CompositeProperty.Comparator.__eq__c                 C  rf  rP   )rg  r&   Úneri  rT   rT   rU   Ú__ne__)  rk  z#CompositeProperty.Comparator.__ne__c                 C  rf  rP   )rg  r&   Últri  rT   rT   rU   Ú__lt__,  rk  z#CompositeProperty.Comparator.__lt__c                 C  rf  rP   )rg  r&   Úgtri  rT   rT   rU   Ú__gt__/  rk  z#CompositeProperty.Comparator.__gt__c                 C  rf  rP   )rg  r&   Úleri  rT   rT   rU   Ú__le__2  rk  z#CompositeProperty.Comparator.__le__c                 C  rf  rP   )rg  r&   Úgeri  rT   rT   rU   Ú__ge__5  rk  z#CompositeProperty.Comparator.__ge__rð   r=   c                   st   |d u rd gt ˆjjƒ }nˆj |¡}‡ fdd„tˆjj|ƒD ƒ}ˆjr5ˆjd us,J ‚‡fdd„|D ƒ}tj|Ž S )Nc                   s   g | ]	\}}ˆ ||ƒ‘qS rT   rT   )r·   r  Úb)rð   rT   rU   r¹   G  s    ÿÿz9CompositeProperty.Comparator._compare.<locals>.<listcomp>c                   s   g | ]}ˆ   |¡‘qS rT   )Úadapter)r·   Úxr\   rT   rU   r¹   M  r&  )	ró   r^   r  r²   rÇ   rb  rw  r#   Úand_)rS   rð   rd  rÃ   ÚcomparisonsrT   )rð   rS   rU   rg  ?  s   
þ
z%CompositeProperty.Comparator._compare)rO   r;   )rO   rX  )rp   r   rO   r_  ©rO   rþ   )rd  r   rO   re  )rð   r=   rd  r   rO   re  )rf   rg   rh   r‰   Ú__hash__rŠ   r   Úmemoized_propertyrW  rY  r%   ra  r  rj  rm  ro  rq  rs  ru  rg  rT   rT   rT   rU   r£   Ø  s&   
 



	





r£   c                 C  s   t | jjjƒd | j S )NÚ.)r`   r�   r~   rf   r_   r\   rT   rT   rU   Ú__str__P  s   zCompositeProperty.__str__rP   )r˜   r™   r�   rš   r“   r›   r”   rZ   r•   rZ   r–   rH   r’   rœ   r—   r�   rž   r   rˆ   )rp   rŒ   rO   r«   ©rO   rY   )rÏ   r1   rÐ   r,   rÑ   rÒ   rÓ   rH   r_   r`   rÔ   rÕ   rÖ   r×   rØ   r×   rÙ   rZ   rO   rY   )
rÐ   r,   rÑ   rÒ   rÓ   rH   r_   r`   rO   rY   r{  )rO   r  )rO   r  )rO   r  )rO   r  )rO   r3  )rO   r4  re   )rW   rX   rO   rE  )rO   r`   )*rf   rg   rh   r‰   rŠ   rb   r‡   r²   r´   ÚobjectrÁ   r¦   r   Úpreload_moduleræ   r§   rã   r}  r  r  Únon_memoized_propertyr  rl   r  r  r³   r©   r¼   r=  r   rm   rV   ry   Úorm_utilÚBundlerD   rV  r   rF   r£   r  rU  rT   rT   r¨   rU   rŽ   ´   sd   
 üõ(


J
9'
_
ü
%xrŽ   c                   @  ó   e Zd ZdZdZdS )Ú	CompositeaS  Declarative-compatible front-end for the :class:`.CompositeProperty`
    class.

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

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

    .. seealso::

        :ref:`mapper_composite`

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

    Cases where this occurs include:

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

    rW   rX   rO   úType[PropComparator[_T]]c                 C  sP   d }| j  ¡ D ]}|j| j }t|dd ƒd ur|j} nq|d us#J ‚|||ƒS )Nr’   )r�   Úiterate_to_rootÚ_propsr_   rw   r’   )rS   rW   Úcomparator_callableÚmrè   rT   rT   rU   ry   x  s   þ
z-ConcreteInheritedProperty._comparator_factoryrY   c                   s8   t ƒ  ¡  d‡ fdd„‰G ‡ ‡fdd„dƒ}|ƒ ˆ _d S )NrO   r   c                     s   t dˆ jˆ jˆ jf ƒ‚)NzgConcrete %s does not implement attribute %r at the instance level.  Add this property explicitly to %s.)r­   r�   r_   rT   r\   rT   rU   Úwarnˆ  s
   ýÿz0ConcreteInheritedProperty.__init__.<locals>.warnc                      s8   e Zd Zd‡fdd„Zd‡fd	d
„Zd‡ ‡fdd„ZdS )zDConcreteInheritedProperty.__init__.<locals>.NoninheritedConcretePropÚsr   ro   rp   rO   r   c                   ó
   ˆ ƒ  d S rP   rT   )r‘  ro   rp   ©r�  rT   rU   Ú__set__‘  rc   zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__set__c                   r’  rP   rT   )r‘  ro   r“  rT   rU   Ú
__delete__”  rc   zOConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__delete__Úownerc                   s   |d u rˆ j S ˆƒ  d S rP   )rJ   )r‘  ro   r–  ©rS   r�  rT   rU   Ú__get__—  s   
zLConcreteInheritedProperty.__init__.<locals>.NoninheritedConcreteProp.__get__N)r‘  r   ro   r   rp   r   rO   r   )r‘  r   ro   r   rO   r   )r‘  r   ro   r   r–  r   rO   r   )rf   rg   rh   r”  r•  r˜  rT   r—  rT   rU   ÚNoninheritedConcreteProp�  s    r™  )rO   r   )r    rb   rJ   )rS   r™  r¨   r—  rU   rb   …  s   
z"ConcreteInheritedProperty.__init__)rW   rX   rO   r‹  r€  )rf   rg   rh   r‰   ry   rb   rU  rT   rT   r¨   rU   rŠ  g  s    
rŠ  c                      sŠ   e Zd ZU dZded< 						d.d/‡ fdd„Zes"ed0dd„ƒZe	j
d1dd„ƒZd2dd„Zejfd3d&d'„Ze	 d(¡d4d,d-„ƒZ‡  ZS )5ÚSynonymPropertya8  Denote an attribute name as a synonym to a mapped property,
    in that the attribute will mirror the value and expression behavior
    of another attribute.

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

    .. seealso::

        :ref:`synonyms` - Overview of synonyms

    ú"Optional[Type[PropComparator[_T]]]r’   Nrr   r`   Ú
map_columnúOptional[bool]rJ   úOptional[Any]r“   r›   r—   r�   rI   rH   c                   sj   t ƒ j|d� || _|| _|| _|| _|r|| _n|r#|jr#|j| _nd | _|r.| j 	|¡ t
 | ¡ d S rŸ   )r    rb   rr   rœ  rJ   r’   rI   r‰   r—   r¤   r   r¥   )rS   rr   rœ  rJ   r’   r“   r—   rI   r¨   rT   rU   rb   ¯  s   


zSynonymProperty.__init__rO   rZ   c                 C  s   t | jj| jƒjjS rP   )rw   r�   r~   rr   r‚   r[   r\   rT   rT   rU   r[   Ì  r  zSynonymProperty.uses_objectsú/Union[MapperProperty[_T], SQLORMOperations[_T]]c                 C  sh   t | jj| jƒ}t|dƒrt|jtƒs1t|tj	ƒr|j
S t|tƒr#|S t d| jjj| j|f ¡‚|jS )Nrl   zGsynonym() attribute "%s.%s" only supports ORM mapped attributes, got %r)rw   r�   r~   rr   rá   r¡   rl   r   r   r/   Ú
comparatorr   r®   r¯   rf   )rS   rÈ   rT   rT   rU   Ú_proxied_objectÓ  s   ÿ
þÿzSynonymProperty._proxied_objectrW   rX   úSQLORMOperations[_T]c                 C  s:   | j }t|tƒr| jr|  ||¡}|S | ||¡}|S |S rP   )r¡  r¡   r   r’   )rS   rW   r^   ÚcomprT   rT   rU   ry   ê  s   
ÿz#SynonymProperty._comparator_factoryrK   rL   rM   r+   rN   r   r-   c                 C  s"   t | jj| jƒ}|jj|||d�S )N)rN   )rw   r�   r~   rr   r‚   rV   )rS   rK   rM   rN   rÈ   rT   rT   rU   rV   ö  s   zSynonymProperty.get_historyrÎ   r�   ÚinitrY   c                 C  sÀ   t jj}| jr[| j|jjvrt d| j	|jj
| jf ¡‚|jj| j |jv rC|j|jj| j  j| j	krCt d| j| j	| j	| jf ¡‚| |jj| j ¡}|j| j	||dd� | j|_|| _d S )Nz>Can't compile synonym '%s': no column on table '%s' named '%s'zpCan't call map_column=True for synonym %r=%r, a ColumnProperty already exists keyed to the name %r for column %rT)r¤  Ú	setparent)r   rÞ   rß   rœ  r_   Úpersist_selectabler  r®   râ   rr   Údescriptionr  r3   Ú_configure_propertyÚ_mapped_by_synonymr�   )rS   r�   r¤  Ú
propertiesrè   rT   rT   rU   Ú
set_parentÿ  s>   ýþÿ
ÿÿýýÿÿ
zSynonymProperty.set_parent)NNNNNN)rr   r`   rœ  r�  rJ   rž  r’   r›  r“   r›   r—   r�   rI   rH   rd   )rO   rŸ  )rW   rX   rO   r¢  re   )r�   rX   r¤  rZ   rO   rY   )rf   rg   rh   r‰   rŠ   rb   r   rl   r[   r   r}  r¡  ry   r   rm   rV   r‚  r«  rU  rT   rT   r¨   rU   rš  Ÿ  s(   
 ø
ü	rš  c                   @  r†  )ÚSynonymaK  Declarative front-end for the :class:`.SynonymProperty` class.

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

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

    .. seealso::

        :ref:`synonyms` - Overview of synonyms

    TNrˆ  rT   rT   rT   rU   r¬  &  s    r¬  )gr‰   Ú
__future__r   Údataclassesr   rî   rø   rð   Útypingr   r   r   r   r   r	   r
   r   r   r   r   r   ÚweakrefÚ r   r   r„  Úbaser   r   r   r   r   Ú
interfacesr   r   r   r   r   r   r   r    r!   r®   r"   r#   r%   r&   Úsql.elementsr'   Úutil.typingr(   r)   r*   Ú_typingr+   r,   r-   r.   r/   r  r0   rü   r1   rW   r2   rª  r3   r5   rK   r6   Úengine.baser7   Ú
engine.rowr8   Úsql._typingr9   r:   r;   r<   Úsql.operatorsr=   Ú
sql.schemar>   Úsql.selectabler?   r@   rA   rB   rC   rD   rF   rG   r`   Ú_CompositeAttrTyperŒ   ÚWeakKeyDictionaryr�   rŠ   rŽ   r‡  rŠ  rš  r¬  rT   rT   rT   rU   Ú<module>   sÂ   Hüÿ	
þ
ÿ     %8 