B
    þ¦†\   ã               @   sd   d 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.

é   )Ú
attributes)Úexc)Úutilc          
   C   sì   | j }|j }xÚ|D ]Ò\}	}
y(|j|	 }| j|j j | |tj¡}W n& tj	k
rh   t
d||	||
ƒ Y nX y(|j|
 }|j|j j |||d ¡ W n& tj	k
r¸   t
d||	||
ƒ Y nX |r|	jr|
jr|
 |	¡rd|jd||
f< qW d S )NFTZpk_cascaded)ÚdictÚ_columntopropertyZmanagerÚkeyÚimplÚgetr   ÚPASSIVE_OFFr   ÚUnmappedColumnErrorÚ_raise_col_to_propÚsetÚprimary_keyZ
references)ÚsourceÚsource_mapperÚdestÚdest_mapperÚsynchronize_pairsÚ	uowcommitZflag_cascaded_pksÚsource_dictZ	dest_dictÚlÚrÚpropÚvalue© r   ú2lib/python3.7/site-packages/sqlalchemy/orm/sync.pyÚpopulate   s&    	


r   c          
   C   s–   x|D ]ˆ\}}y|j | }| |j }W n& tjk
rL   td||||ƒ Y nX y|j | }|| |j< W q tjk
rŒ   td||||ƒ Y qX qW d S )NFT)r   r   r   r   r   )r   r   r   r   r   r   r   r   r   r   Úbulk_populate_inherit_keys=   s    

r   c          
   C   s†   x€|D ]x\}}|j r@| | | j|¡tjkr@td|t | ¡f ƒ‚y| | | j|d ¡ W q tj	k
r|   t
dd |||ƒ Y qX qW d S )NzKDependency rule tried to blank-out primary key column '%s' on instance '%s'T)r   Ú_get_state_attr_by_columnr   Úorm_utilZ	_none_setÚAssertionErrorZ	state_strZ_set_state_attr_by_columnr   r   r   )r   r   r   r   r   r   r   r   ÚclearM   s    r!   c       	   
   C   s€   xz|D ]r\}}y*|  |  ¡ |¡}|j| | j|tjd}W n& tjk
r^   td||d |ƒ Y nX |||j	< ||||j	 < qW d S )N)ÚpassiveF)
Z_get_committed_attr_by_columnÚobjr   r   r   r
   r   r   r   r   )	r   r   r   Z
old_prefixr   r   r   Zoldvaluer   r   r   r   Úupdate_   s    
r$   c          
   C   sb   x\|D ]T\}}y|j | | j|tjd}W n& tjk
rN   td||d |ƒ Y nX |||j< qW d S )N)r"   F)r   r   r   r
   r   r   r   r   )r   r   Zdict_r   r   r   r   r   r   r   Úpopulate_dictn   s    r%   c          
   C   sp   xj|D ]^\}}y|j | }W n& tjk
rB   td||d|ƒ Y nX |  ||jtj¡}t|j	ƒrdS qW dS 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   Zget_attribute_historyr   r   ZPASSIVE_NO_INITIALIZEÚboolZdeleted)r   r   r   r   r   r   r   Úhistoryr   r   r   Úsource_modifiedz   s    
r(   c             C   s0   | rt  d||f ¡‚nt  d|||f ¡‚d S )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   )Zisdestr   Zsource_columnr   Zdest_columnr   r   r   r      s    r   N)Ú__doc__Ú r   r   r   r   r   r   r!   r$   r%   r(   r   r   r   r   r   Ú<module>   s   +