o
    Šåg“  ã                   @  sp   d Z ddlmZ ddlmZ ddlmZ ddlmZ dd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )zgprivate module containing functions used for copying data
between instances based on join conditions.

é    )Úannotationsé   )Úexc)Úutil)ÚPassiveFlagc                 C  s  | j }|j }|D ]{\}	}
z|j|	 }| j|j j | |tj¡}W n tj	y< } zt
d||	||
|ƒ W Y d }~nd }~ww z|j|
 }|j|j j |||d ¡ W n tj	ym } zt
d||	||
|ƒ W Y d }~nd }~ww |rƒ|	jrƒ|
jrƒ|
 |	¡rƒd|jd||
f< qd S )NFTÚpk_cascaded)ÚdictÚ_columntopropertyÚmanagerÚkeyÚimplÚgetr   ÚPASSIVE_OFFr   ÚUnmappedColumnErrorÚ_raise_col_to_propÚsetÚprimary_keyÚ
referencesÚ
attributes)ÚsourceÚsource_mapperÚdestÚdest_mapperÚsynchronize_pairsÚ	uowcommitÚflag_cascaded_pksÚsource_dictÚ	dest_dictÚlÚrÚpropÚvalueÚerr© r#   úO/var/www/html/flaskapp/venv/lib/python3.10/site-packages/sqlalchemy/orm/sync.pyÚpopulate   s<   	
ÿ€ÿ
€ÿ	ÿþýü€är%   c                 C  s´   |D ]U\}}z|j | }| |j }W n tjy. } ztd|||||ƒ W Y d }~nd }~ww z|j | }|| |j< W q tjyW } ztd|||||ƒ W Y d }~qd }~ww d S )NFT)r	   r   r   r   r   )r   r   r   r   r   r    r!   r"   r#   r#   r$   Úbulk_populate_inherit_keysA   s    
€ÿ
€ÿör&   c                 C  sž   |D ]J\}}|j r%| | | j|¡tjvr%td|› d|› dt | ¡› d�ƒ‚z| | | j|d ¡ W q tj	yL } zt
dd ||||ƒ W Y d }~qd }~ww d S )NzDependency rule on column 'z)' tried to blank-out primary key column 'z' on instance 'ú'T)r   Ú_get_state_attr_by_columnr   Úorm_utilÚ	_none_setÚAssertionErrorÚ	state_strÚ_set_state_attr_by_columnr   r   r   )r   r   r   r   r   r"   r#   r#   r$   ÚclearQ   s(   ÿÿþþÿ€ÿór.   c           
      C  sŽ   |D ]B\}}z|  |  ¡ |¡}|j| | j|tjd�}W n tjy7 }	 ztd||d ||	ƒ W Y d }	~	nd }	~	ww |||j	< ||||j	 < qd S ©N)ÚpassiveF)
Ú_get_committed_attr_by_columnÚobjr(   r   r   r   r   r   r   r   )
r   r   r   Ú
old_prefixr   r   r   Úoldvaluer!   r"   r#   r#   r$   Úupdatec   s   ÿ
ÿ€ÿ
õr5   c                 C  sp   |D ]3\}}z|j | | j|tjd�}W n tjy/ } ztd||d ||ƒ W Y d }~nd }~ww |||j< qd S r/   )r(   r   r   r   r   r   r   r   )r   r   Údict_r   r   r   r!   r"   r#   r#   r$   Úpopulate_dictr   s   
ÿ€ÿør7   c           	      C  s|   |D ]9\}}z|j | }W n tjy) } ztd||d||ƒ W Y d}~nd}~ww |  ||jtj¡}t|j	ƒr; dS qdS )zpreturn true if the source object has changes from an old to a
    new value on the given synchronize pairs

    FNT)
r	   r   r   r   Úget_attribute_historyr   r   ÚPASSIVE_NO_INITIALIZEÚboolÚdeleted)	r   r   r   r   r   r   r    r"   Úhistoryr#   r#   r$   Úsource_modified~   s   €ÿ
ÿ
ÿr=   c                 C  s.   | rt  d||f ¡|‚t  d|||f ¡|‚)NzÑCan't execute sync rule for destination column '%s'; mapper '%s' does not map this column.  Try using an explicit `foreign_keys` collection which does not include this column (or use a viewonly=True relation).zØCan't execute sync rule for source column '%s'; mapper '%s' does not map this column.  Try using an explicit `foreign_keys` collection which does not include destination column '%s' (or use a viewonly=True relation).)r   r   )Úisdestr   Úsource_columnr   Údest_columnr"   r#   r#   r$   r   ‘   s   üÿúûÿùr   N)Ú__doc__Ú
__future__r   Ú r   r   r)   Úbaser   r%   r&   r.   r5   r7   r=   r   r#   r#   r#   r$   Ú<module>   s   	+