
    ؄_ܵ                     *   d 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  G d de          Z G d de          Z G d de          Z G d de          Z G d de          Zeee
ee	eiZdS )zRelationship dependencies.

   )
attributes)exc)sync)
unitofwork)util)
MANYTOMANY)	MANYTOONE)	ONETOMANY   )sqlc                       e Zd Zd Zed             Zd Zd Zd Zd Z	d Z
d Zd	 Zd
 Zd Zd Zd Zd ZddZd Zd ZdS )DependencyProcessorc                    || _         |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j        | _        |j	        | _	        | j        rt          j        | _        nt          j        | _        | j        rt          j        | _        nt          j        | _        |j        | _        | j         j        st#          j        d| j         z            d S )Nz|Can't build a DependencyProcessor for relationship %s. No target attributes to populate between parent and child are present)propcascademapperparent	secondary	directionpost_updatepassive_deletespassive_updatesenable_typechecksr   PASSIVE_NO_INITIALIZE_passive_delete_flagPASSIVE_OFF_passive_update_flagkeysynchronize_pairssa_excArgumentError)selfr   s     ^/var/www/book.euthymeo.com/html/venv/lib/python3.11/site-packages/sqlalchemy/orm/dependency.py__init__zDependencyProcessor.__init__   s    	|kk+#3#3!%!7 	?(2(HD%%(2(>D% 	?(2(HD%%(2(>D%8y* 	&$&*i0  	 	    c                 6    t          |j                 |          S N)_direction_to_processorr   )clsr   s     r#   from_relationshipz%DependencyProcessor.from_relationship6   s    &t~6t<<<r%   c                 p    | j         j                            | j                                      |          S )zreturn True if the given object instance has a parent,
        according to the ``InstrumentedAttribute`` handled by this
        ``DependencyProcessor``.

        )r   class_managerget_implr   	hasparentr"   states     r#   r.   zDependencyProcessor.hasparent:   s-     {(11$(;;EEeLLLr%   c                 2    |                     | d           dS )zestablish actions and dependencies related to a flush.

        These actions will operate on all relevant states in
        the aggregate.

        TN)register_preprocessorr"   uows     r#   per_property_preprocessorsz.DependencyProcessor.per_property_preprocessorsB   s      	!!$-----r%   c           	         t          j        || dd          }t          j        || dd          }t          j        || j        j                  }t          j        || j        j                  }t          j        || j        j                  }t          j        || j        j                  }|                     |||||||           d S NFT)r   
ProcessAllSaveUpdateAllr   primary_base_mapperr   	DeleteAllper_property_dependencies)r"   r4   
after_savebefore_deleteparent_saveschild_savesparent_deleteschild_deletess           r#   per_property_flush_actionsz.DependencyProcessor.per_property_flush_actionsK   s    *3eTBB
"-c4tDD!/0
 
 !.0
 
 $-0
 
 #,0
 
 	&&	
 	
 	
 	
 	
r%   c                 n   | j         j        }t          j        ||          }t          j        ||          }|rt          j        || dd          }d|_        nt          j        || dd          }d|_        ||j        vr||j        vsJ |df|dfg}	d}
nd}
|s/t          j        || j        j	                  }dx}}||j        v rd}n.t          j        || j        j	                  }dx}}||j        v rd}|D ];}|j
        | j                 j                            ||j        |r| j        nt           j                  }|sJ|r/t          j        || d|          }|rt          j        ||          }n.t          j        || d|          }|rt          j        ||          }|
rlg }	|D ]g\  }}||j        vrd}nA|j        |         \  }}|rt          j        ||          df}nt          j        ||          df}|	                    |           h|	D ]!\  }}|                     ||||||||           "=dS )zestablish actions and dependencies related to a flush.

        These actions will operate on all relevant states
        individually.    This occurs only if there are cycles
        in the 'aggregated' version of events.

        TFN)NN)r   r:   r   r9   r;   r8   disabledcyclesr   base_mappermanagerr   implget_all_pendingdictr   r   r   ProcessStateDeleteStateSaveUpdateStatestatesappendper_state_dependencies)r"   r4   rO   isdeletechild_base_mapperr@   rB   r>   r=   child_actionschild_in_cyclesr?   rA   parent_in_cyclesr0   sum_child_statechildchild_actiondeletedlistonlychildisdeletes                         r#   per_state_flush_actionsz+DependencyProcessor.per_state_flush_actionsg   s    !K; .s4EFF",S2CDD
  	'&1#tT4HHM%)M""#.sD%FFJ"&J cj((
 !
2222 *51M43HIM#OO"O  	(%3T[, L .21N]sz))#' '1#t{7NOON(,,L:++#'   7	 7	E =*/??
6))5 D   J * 7T4 O O# H%/%;C%G%GN'4S$uMM
# J#-#=c5#I#IL 7 "*. 7 7&K"#*44'3.1j.E+(" 	 * 6sK H H $,LL !+ :3 L L %,L "((6666 0= 
 
+m++ " !!	 	 	 	
[7	 7	r%   c                     dS NF r"   	uowcommitrO   s      r#   presort_deletesz#DependencyProcessor.presort_deletes       ur%   c                     dS r`   ra   rb   s      r#   presort_savesz!DependencyProcessor.presort_saves   re   r%   c                     d S r'   ra   rb   s      r#   process_deletesz#DependencyProcessor.process_deletes       r%   c                     d S r'   ra   rb   s      r#   process_savesz!DependencyProcessor.process_saves   rj   r%   c                 *   |r| j         rt          j        }n'| j        t          u rt          j        }nt          j        }|D ]7}|                    || j        |          }|r|	                                s dS 8|o| j
        j         o| j        |j        v S )NT)r   r   r   r   r	   PASSIVE_NO_FETCH_RELATEDr   get_attribute_historyr   emptyr   _is_self_referentialr   mappers)r"   rc   rO   rR   passiveshistorys          r#   prop_has_changesz$DependencyProcessor.prop_has_changes   s     	-4/ 	- 6GG^y(( 9GG ,G 	 	A  55a7KKG w}} tt  5	665K9#44r%   c                    | j         j        r|t          j        d| j                   || j                            || j                   s| j                            |d          r5t          j        d|j        | j         | j        j        | j        dz            t          j        d|j        | j         | j        j        dz            d S d S )Nz+Can't flush None value found in collection )allow_subtypesTaE  Attempting to flush an item of type %(x)s as a member of collection "%(y)s". Expected an object of type %(z)s or a polymorphic subclass of this type. If %(x)s is a subclass of %(z)s, configure mapper "%(zm)s" to load this subtype polymorphically, or set enable_typechecks=False to allow any subtype to be accepted for flush. )xyzzmzAttempting to flush an item of type %(x)s as a member of collection "%(y)s". Expected an object of type %(z)s or a polymorphic subclass of this type.)ry   rz   r{   )r   uselistr   
FlushErrorr   _canloadr   class_r/   s     r#   _verify_canloadz#DependencyProcessor._verify_canload   s   9 &	..#'99/   t{';';d&<"< (< (
 (
 {##E$#?? n= #\!Y![/"k	   $ n! #\!Y![/ 	  - r%   c                     t                      r'   NotImplementedError)r"   r0   rY   associationrow	clearkeysrc   s         r#   _synchronizez DependencyProcessor._synchronize"      !###r%   c                     | j         j        sd S t          t          | j        gd | j         j        D             z                       }|                    d|ft                    S )Nc                     g | ]	}|j         
S ra   )r   ).0ps     r#   
<listcomp>zCDependencyProcessor._get_reversed_processed_set.<locals>.<listcomp>*  s     L L L1 L L Lr%   reverse_key)r   _reverse_propertytuplesortedr   memoset)r"   r4   process_keys      r#   _get_reversed_processed_setz/DependencyProcessor._get_reversed_processed_set%  sf    y* 	4DH: L L	0K L L LLMM
 
 xx4c:::r%   Fc                 r    |D ]3}|r|-|                     |d | j        j        D                         d S 4d S )Nc                     g | ]\  }}|S ra   ra   )r   lrs      r#   r   z4DependencyProcessor._post_update.<locals>.<listcomp>2  s    FFF$!QAFFFr%   )register_post_updater   r   )r"   r0   rc   relatedis_m2o_deletery   s         r#   _post_updatez DependencyProcessor._post_update.  sf     	 	A  AM..FF$)*EFFF   	 %2	 	r%   c                     t                      r'   r   r"   rc   r0   s      r#   _pks_changedz DependencyProcessor._pks_changed6  r   r%   c                 0    | j         j        d| j        dS )N())	__class____name__r   )r"   s    r#   __repr__zDependencyProcessor.__repr__9  s    >222DIII>>r%   N)F)r   
__module____qualname__r$   classmethodr*   r.   r5   rC   r^   rd   rg   ri   rl   rv   r   r   r   r   r   r   ra   r%   r#   r   r      s,         8 = = [=M M M. . .
 
 
8n n n`          ,' ' 'R$ $ $; ; ;   $ $ $? ? ? ? ?r%   r   c                   >    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	S )
OneToManyDPc           
      N   | j         rnt          j        || j        j        d          }t          j        || j        j        d          }	|j                            ||f||f||f||	f|	|f|	|fg           d S |j                            ||f||f||f||f||f||f||fg           d S r7   r   r   PostUpdateAllr   r:   dependenciesupdate)
r"   r4   r?   r@   rA   rB   r=   r>   child_post_updateschild_pre_updatess
             r#   r<   z%OneToManyDP.per_property_dependencies>  s     	!+!9T[4e" " !+ 8T[4d! ! ## *-!:.!34"$56&7&6	 	 	 	 	 ##!:.-/ .1"N3"K0"M2
 
 
 
 
r%   c	                 D   | j         rt          j        || j        j        d          }	t          j        || j        j        d          }
|sI|r"|j                            ||f||	fg           d S |j                            ||f||f||	fg           d S |r"|j                            ||
f|
|fg           d S |j                            ||
f|
|fg           d S |s%|j                            ||f||f||fg           d S |j                            ||f||fg           d S r7   r   )r"   r4   save_parentdelete_parentrZ   r=   r>   rR   r]   r   r   s              r#   rQ   z"OneToManyDP.per_state_dependenciesg  s     5	!+!9T[4e" " !+ 8T[4d! !    $++):6');<     $++(*5):6');<     ! $++*,=>.>     $++*,=>.>      	## *-. ,/     ##.}0MN    r%   c                    | j         j         o| j        dk     }|D ]}|                    || j        | j                  }|r|j        D ]T}|P|                     |          du r9| j         j        r|	                    |d           ?|	                    |           U|r)|j
        D ]!}||	                    |d| j                   "d S )NallFTrR   delete	operationr   )r   r   r   ro   r   r   r[   r.   delete_orphanregister_object	unchangedr   r"   rc   rO   should_null_fksr0   ru   rY   s          r#   rd   zOneToManyDP.presort_deletes  s   
 ##ID,@E,I(I 	  	 	E55tx!: G  $_ = =E(T^^E-B-Be-K-K<5 =%55ed5KKKK%55e<<<" !(!2   ,%55 %	 6   	 	r%   c           	      h   |                     d| ft                    }| j        j         o| j        dk     }|D ]w}|                     ||          }|r| j        rt          j        }nt          j	        }|
                    || j        |          }|r|j        D ]"}	|	|                    |	dd| j                   #|                    |j                   |j        D ]}	| j        j        s!|r|                    |	dd| j                   /|                     |	          du rX|                    |	dd| j                   | j                            d|	          D ]\  }
}}}|                    |d	           |r2|r0|j        D ](}	|	$|                    |	d| j        d
| j                   )yd S )Nchildren_addedr   Tadd)cancel_deleter   r   Fr   rR   r   r   r   z	pk changer   )r   r   r   r   r   r   r   r   r   r   ro   r   addedr   r   r   r[   r.   r   cascade_iteratorr   )r"   rc   rO   r   r   r0   pks_changedrs   ru   rY   cmst_dct_s                 r#   rg   zOneToManyDP.presort_saves  sW   ")94(@#FF ** 2(E11 	
  4	 4	E++Iu==K 1$"6 1$:$055eTXwOOG J$]  E(!11!*.&+!%	 2    %%gm444$_ J JE<5 J* %55 %).*2%)Y	 6    ..%77!11!%)&.!%	 2    04{/K/K$e0 0 J JOAq#t &55cD5IIII 
 	!(!2   ,%55 % % $ 4*5%)Y 6   ]4	 4	r%   c           
      j   | j         s| j        dk    s|                    d| ft                    }|D ]}|                    || j        | j                  }|r|j        D ]V}|R|                     |          du r;| 	                    ||d d|d           | j         r|r| 
                    |||g           W| j         s| j        j        sgt          |j                                      |          D ]?}|;| 	                    ||d d|d           | j         r|r| 
                    |||g           @d S d S )Nr   r   FT)r   r   r   r   ro   r   r   r[   r.   r   r   r   r   r   
difference)r"   rc   rO   r   r0   ru   rY   s          r#   ri   zOneToManyDP.process_deletes  s     	&4#75#@#@&^^-=t,DcJJN & &#9948T%>   &!( 	M 	M!- $u 5 5 > > -- %udD)U    $/ ME M $ 1 1%UG L L L' &t|/B &%():%;%;%F%F*& & 
& 
&E  %0 $ 1 1$)5$i!" !" !" $(#3 !& !&$($5$5(-y5'%& %& %&9 $A#@& &r%   c           
         | j         j         o| j        dk     }|D ]}|                    || j        t
          j                  }|r|j        D ]=}|                     ||d d|d           || j	        r| 
                    |||g           >|j        D ]?}|r;| j         j        s/|                     |          s|                     ||d d|d           @|                     ||          r$|j        D ]}|                     ||d d|d           d S )Nr   FT)r   r   r   ro   r   r   r   r   r   r   r   r[   r.   r   r   r   s          r#   rl   zOneToManyDP.process_saves/  s   ** 2(E11 	
  	 	E55tx!A G  $] E EE%%udE9e   (T-=())%UGDDD$_  E' $ : !%u 5 5
 ))!5$i   $$Y66 !(!2  ))!5$y$   1	 	r%   c           	      4   |}|}|                      |           || j        s|                    |          rd S |r't          j        || j        | j        j                   d S t          j        || j	        || j        | j        j        || j
        o|           d S r'   )r   r   
is_deletedr   clearr   r   r   populater   r   )	r"   r0   rY   r   r   rc   r   sourcedests	            r#   r   zOneToManyDP._synchronizeQ  s     U###<  %.%9%9$%?%?  F 	JtT[$)*EFFFFFM	+$4    r%   c                 N    t          j        ||| j        | j        j                  S r'   r   source_modifiedr   r   r   r   s      r#   r   zOneToManyDP._pks_changedh  '    #udk49+F
 
 	
r%   N)r   r   r   r<   rQ   rd   rg   ri   rl   r   r   ra   r%   r#   r   r   =  s        ' ' 'RA A AF  6< < <|%& %& %&X     D  .
 
 
 
 
r%   r   c                   B    e Zd Zd Zd Zd Zd Zd Zd Zd Z		 d
d	Z
dS )ManyToOneDPc                     t                               | |           | j        j        D ])}|j                            t          |                     *d S r'   )r   r$   r   self_and_descendants_dependency_processorsrP   DetectKeySwitch)r"   r   r   s      r#   r$   zManyToOneDP.__init__o  s\    $$T4000k6 	H 	HF)001F1FGGGG	H 	Hr%   c           
      B   | j         rqt          j        || j        j        d          }t          j        || j        j        d          }	|j                            ||f||f||f||	f||	f|	|f|	|fg           d S |j                            ||f||f||f||fg           d S r7   r   r   r   r   r:   r   r   )
r"   r4   r?   r@   rA   rB   r=   r>   parent_post_updatesparent_pre_updatess
             r#   r<   z%ManyToOneDP.per_property_dependenciest  s     	",":T[4e# # ",!9T[4d" " ## *-!:.!45!34"$67'7'8
 
 
 
 
 ## *-.!=1#]3	    r%   c	                 @   | j         r|sit          j        || j        j        d          }	|r"|j                            ||	f|	|fg           d S |j                            ||f||f||	fg           d S t          j        || j        j        d          }
|j                            ||
f|
|f|
|fg           d S |sC|s"|j                            ||f||fg           d S |j                            ||fg           d S |r|j                            ||fg           d S d S r7   r   )r"   r4   r   r   rZ   r=   r>   rR   r]   r   r   s              r#   rQ   z"ManyToOneDP.per_state_dependencies  s     ,	I &0&>8%' '# ! $++')<=0,?     $++(*5):6')<=     &0%=8$& &"  ''&(:;+];+\:      
	I  E ''"J/*k1JK      ''*k)B(CDDDDD  I ''-)F(GHHHHHI Ir%   c                    | j         j        s| j         j        r|D ]}|                    || j        | j                  }|r| j         j        r|                                }n|                                }|D ]_}||                    |dd| j	                   | j
                            d|          }|D ]\  }}	}
}|                    |
d           `d S d S )NTr   r   r   )r   r   r   ro   r   r   sumnon_deletedr   r   r   r   )r"   rc   rO   r0   ru   todeleterY   tr   r   r   r   s               r#   rd   zManyToOneDP.presort_deletes  s8   < 	J$,"< 	J J J#9948T%>   J|1 9#*;;==#*#6#6#8#8!) J J =$!11!%)&.!%	 2    !K885II/0 J JOAq#t%55cD5IIIIJ)	J 	JJ Jr%   c                    |D ]}|                     |d| j                   | j        j        r|                    || j        | j                  }|r{|j        D ]s}|                     |          du rZ|                     |dd| j                   | j	        
                    d|          }|D ]\  }}}	}
|                     |	d           td S )Nr   r   FTr   r   r   )r   r   r   r   ro   r   r   r[   r.   r   r   )r"   rc   rO   r0   ru   rY   r   r   r   r   r   s              r#   rg   zManyToOneDP.presort_saves  s    	N 	NE%%eu49%MMM|) N#9948T%>   N!( N N>>%00E99%55 %)-*2%)Y	 6    !% < <Xu M MA34 N N1c4 ) 9 9# 9 M M M M%	N 	Nr%   c                 8   | j         r| j        j        s| j        dk    sy|D ]x}|                     |d d d|           |rU| j         rN|                    || j        | j                  }|r+|                     |||	                                d           sd S d S d S d S )Nr   T)r   )
r   r   r   r   r   ro   r   r   r   r   )r"   rc   rO   r0   ru   s        r#   ri   zManyToOneDP.process_deletes  s    	L.	 (E11   	 	!!%tT9EEE T- '==tx)B G  ))!9gkkmm4 *   !	 	 	 	 21	 	r%   c           
      Z   |D ]}|                     || j        t          j                  }|r}|j        r%|j        D ]}|                     ||d d|d           n!|j        r|                     |d d d|d           | j        r)|                     |||	                                           d S )NFr   Tr   )
ro   r   r   r   r   r   r[   r   r   r   )r"   rc   rO   r0   ru   rY   s         r#   rl   zManyToOneDP.process_saves  s     	G 	GE55tx!A G  G= !(  ))!5$y%    _ %%tT4H   # G%%eYFFF	G 	Gr%   Nc           	         || j         s|                    |          rd S |S|Q|j                            |          s7t	          j        dt          j        |          d|d| j        d           d S |s|'t          j
        || j        | j        j                   d S |                     |           t          j        || j        || j        | j        j        |d           d S )NObject of type  not in session,  operation along '' won't proceedF)r   r   session_contains_stater   warn
mapperutilstate_class_strr   r   r   r   r   r   r   r   r"   r0   rY   r   r   rc   r   s          r#   r   zManyToOneDP._synchronize*  s    =  %.%9%9%%@%@  F !!%55e<< " II -e4444iiiL  
 F 	Judk49+FGGGGG  '''M	+    r%   r'   )r   r   r   r$   r<   rQ   rd   rg   ri   rl   r   ra   r%   r#   r   r   n  s        H H H
& & &P8I 8I 8ItJ J J0N N N*  *G G G2 & & & & & &r%   r   c                   T    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd ZdS )r   a  For many-to-one relationships with no one-to-many backref,
    searches for parents through the unit of work when a primary
    key has changed and updates them.

    Theoretically, this approach could be expanded to support transparent
    deletion of objects referenced via many-to-one as well, although
    the current attribute system doesn't do enough bookkeeping for this
    to be efficient.

    c                     | j         j        r#| j        rd S dd | j         j        D             v rd S |                    | d           d S )NFc              3   $   K   | ]}|j         V  d S r'   )r   )r   r   s     r#   	<genexpr>z=DetectKeySwitch.per_property_preprocessors.<locals>.<genexpr>d  s9         (     r%   )r   r   r   r2   r3   s     r#   r5   z*DetectKeySwitch.per_property_preprocessors_  sp    9& 	#    $	 ;     F!!$.....r%   c                     t          j        || j        j                  }t          j        || dd          }|j                            ||fg           d S r`   )r   r9   r   rG   r8   r   r   )r"   r4   r?   r=   s       r#   rC   z*DetectKeySwitch.per_property_flush_actionsl  sT    !/T[5LMM*3eUCC
,
!; <=====r%   c                     d S r'   ra   )r"   r4   rO   rR   s       r#   r^   z'DetectKeySwitch.per_state_flush_actionsq  rj   r%   c                     d S r'   ra   rb   s      r#   rd   zDetectKeySwitch.presort_deletest  rj   r%   c                 D    | j         s|                     ||           d S d S r'   r   _process_key_switches)r"   r4   rO   s      r#   rg   zDetectKeySwitch.presort_savesw  s5    # 	4 &&vs33333	4 	4r%   c                 b    |s,| j         r%|                     ||          }t          |          S dS r`   )r   _key_switchersbool)r"   r4   rO   rR   ds        r#   rv   z DetectKeySwitch.prop_has_changes}  s9     	D0 	##C00A77Nur%   c                     J r'   ra   rb   s      r#   ri   zDetectKeySwitch.process_deletes  s    r%   c                 D    | j         sJ |                     ||           d S r'   r   rb   s      r#   rl   zDetectKeySwitch.process_saves  s/    
 ####""6955555r%   c                     |                     d| fd           \  }}|                    |          }|D ]G}||vrA|                     ||          r|                    |           2|                    |           H|S )Npk_switchersc                  :    t                      t                      fS r'   )r   ra   r%   r#   <lambda>z0DetectKeySwitch._key_switchers.<locals>.<lambda>  s    SUUCEEN r%   )r   unionr   r   )r"   r4   rO   switchednotswitched	allstatesrt   s          r#   r  zDetectKeySwitch._key_switchers  s     #T"$:$:!
 !
+ NN;//	 	' 	'A	!!$$S!,, 'LLOOOOOOA&&&r%   c           
      X   |                      ||          }|r|j        j                                        D ]}t	          |j        | j        j                  s"|j        }|                    | j	                  
                    ||| j                  }|t          j        ur|| j        j        r|s}|d         }n|}t          j        |          }||v rO|                    |d| j                   t'          j        || j        || j        | j        j        || j                   d S d S )N)rs       F)r  r   identity_map
all_states
issubclassr   r   rK   r-   r   getr   r   PASSIVE_NO_RESULTr   r}   instance_stater   r   r   r   r   r   )	r"   deplistrc   	switchersr0   dict_r   related_objrelated_states	            r#   r  z%DetectKeySwitch._process_key_switches  s^   ''	7;;	 !	 #*7BBDD  !%,0BCC 
..22665$*C 7   :#???+y( .& %$&-aj&-$.$=k$J$JM$	11!11!5$*>   ) K! K I7% 0  3!	 !	 r%   c                 v    t          |j                  o%t          j        ||| j        | j        j                  S r'   )r  r   r   r   r   r   r   r   s      r#   r   zDetectKeySwitch._pks_changed  s6    EI 
4#7udk49+F$
 $
 	
r%   N)r   r   r   __doc__r5   rC   r^   rd   rg   rv   ri   rl   r  r  r   ra   r%   r#   r   r   S  s        	 	/ / /> > >
    4 4 4    6 6 6  # # #J
 
 
 
 
r%   r   c                   D    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
S )ManyToManyDPc           
      d    |j                             ||f||f||f||f||f||f||fg           d S r'   r   r   )r"   r4   r?   r@   rA   rB   r=   r>   s           r#   r<   z&ManyToManyDP.per_property_dependencies  sh     	z*j)]+ -/.,	
 	
 	
 	
 	
r%   c	                     |sF|r"|j                             ||f||fg           d S |j                             ||f||fg           d S |j                             ||f||fg           d S r'   r"  )	r"   r4   r   r   rZ   r=   r>   rR   r]   s	            r#   rQ   z#ManyToManyDP.per_state_dependencies  s      	  ''!:.\0JK      ''!:.z0JK     ##.0NO    r%   c                 d    | j         s&|D ]%}|                    || j        | j                   $d S d S r'   )r   ro   r   r   )r"   rc   rO   r0   s       r#   rd   zManyToManyDP.presort_deletes  s]     # 	    //48T%>   	 	 r%   c                    | j         sA|D ]>}|                     ||          r&|                    || j        t          j                  }?| j        j        sd S |D ]}|                    || j        t          j                  }|ry|j	        D ]q}| 
                    |          du rX|                    |dd| j                   | j                            d|          D ]\  }}}}	|                    |d           rd S )NFTr   r   r   )r   r   ro   r   r   r   r   r   r   r[   r.   r   r   r   r   )
r"   rc   rO   r0   ru   rY   r   r   r   r   s
             r#   rg   zManyToManyDP.presort_saves
  s^   # 	    $$Y66 '==tx)? G |) 	F  	J 	JE55tx!A G  J$_ J JE~~e,,55!11!%)&.!%	 2    04{/K/K$e0 0 J JOAq#t &55cD5IIII!	J 	Jr%   c           
         g }g }g }|                      |          }t                      }|D ]|                    | j        | j                  }|r|                                D ]?}	|	||	f|v ri }
|                     |	|
d|d          s*|                    |
           @|                    fd|                                D                        ||                    |           | 	                    ||||           d S )NFr   c              3       K   | ]}|fV  	d S r'   ra   r   r   r0   s     r#   r   z/ManyToManyDP.process_deletes.<locals>.<genexpr>K  s'      CC!Au:CCCCCCr%   )
r   r   ro   r   r   	non_addedr   rP   r   	_run_crud)r"   rc   rO   secondary_deletesecondary_insertsecondary_update	processedtmpru   rY   r   r0   s              @r#   ri   zManyToManyDP.process_deletes,  sl   44Y??	ee 	D 	DE  55tx!: G  D$..00 < <E}!-5%.I2M2M %'N,,&!   ! !$++N;;;;

CCCCw/@/@/B/BCCCCCC S!!!')9;K	
 	
 	
 	
 	
r%   c           
         g }g }g }|                      |          }t                      }|D ]| j         o|                     |          }|rt          j        }	nt          j        }	|                    | j        |	          }
|
r)|
j	        D ]=}||f|v ri }| 
                    ||d|d          s(|                    |           >|
j        D ]=}||f|v ri }| 
                    ||d|d          s(|                    |           >|                    fd|
j	        |
j        z   D                        |ro|
j        D ]g}i }t          j        | j        |d| j        j                   t          j        || j        |d| j        j                   |                    |           h||                    |           |                     ||||           d S )NFr   r   c              3       K   | ]}|fV  	d S r'   ra   r(  s     r#   r   z-ManyToManyDP.process_saves.<locals>.<genexpr>~  s'      OO!Au:OOOOOOr%   old_)r   r   r   r   r   r   r   ro   r   r   r   rP   r[   r   r   r   r   r   r   r   secondary_synchronize_pairsr*  )r"   rc   rO   r+  r,  r-  r.  r/  need_cascade_pksrs   ru   rY   r   r0   s                @r#   rl   zManyToManyDP.process_savesT  s   44Y??	ee 7	@ 7	@E#'#77  D<M<M5= =   ;$0$:55eTXwOOG .@$] < <E ,%91L1L %'N,,uneY  ! !$++N;;;;$_ < <E ,%91L1L %'N,,&!   ! !$++N;;;;

OOOOw}w/NOOOOOO# @!(!2 @ @)+! K*" I7   ! K*" IA   )//???? S!!!')9;K	
 	
 	
 	
 	
r%   c                    |j                             | j                  }|r|d         | j                            t          j        fd| j        j        D                        }|                    ||          }|	                                rN|j
        t          |          k    r6t          j        d| j        j        t          |          |j
        fz            |r|d         | j                            t          j        fd| j        j        D                        }|                    ||          }|	                                rN|j
        t          |          k    r6t          j        d| j        j        t          |          |j
        fz            |r1| j                                        }|                    ||           d S d S )Nr  c                 j    g | ]/}|j         v |t          j        |j         |j                   k    0S )type_r   r   	bindparamtyper   r   r   s     r#   r   z*ManyToManyDP._run_crud.<locals>.<listcomp>  sH       5N22 S]15????222r%   zRDELETE statement on table '%s' expected to delete %d row(s); Only %d were matched.c                 p    g | ]2}|j         v |t          j        d |j         z   |j                  k    3S )r2  r7  r9  r<  s     r#   r   z*ManyToManyDP._run_crud.<locals>.<listcomp>  sL       5N22 S]6AE>HHHH222r%   zRUPDATE statement on table '%s' expected to update %d row(s); Only %d were matched.)transaction
connectionr   r   r   r   and_r   executesupports_sane_multi_rowcountrowcountlenr   StaleDataErrordescriptionr   insert)	r"   rc   r,  r-  r+  r?  	statementresultr   s	           @r#   r*  zManyToManyDP._run_crud  s%    *55dkBB
 	-a0N--   !%!1   I  ''	3CDDF 3355/S)9%:%:::(7 2,--    	-a0N--   !%!1   I  ''	3CDDF 3355/S)9%:%:::(7 2,--    	<--//Iy*:;;;;;	< 	<r%   c           	         |                      |           |dS |X|j                            |          s>|j        s5t	          j        dt          j        |          d|d| j        d           dS t          j
        || j        || j        j                   t          j
        || j        || j        j                   dS )NFr   r   r   r   T)r   r   r   r[   r   r   r   r   r   r   populate_dictr   r   r   r3  r   s          r#   r   zManyToManyDP._synchronize  s    
 	U### =5Y%6%F%Fu%M%M= 		 "1%8888)))TYYYP  
 54;	0K	
 	
 	
 	KI1		
 	
 	
 tr%   c                 N    t          j        ||| j        | j        j                  S r'   r   r   s      r#   r   zManyToManyDP._pks_changed  r   r%   N)r   r   r   r<   rQ   rd   rg   ri   rl   r*  r   r   ra   r%   r#   r   r     s        
 
 
8  2
 
 
 J  J  JD&
 &
 &
PF
 F
 F
P;< ;< ;<z  B
 
 
 
 
r%   r   N)r   r   r   r   r   r   r   
interfacesr   r	   r
   r    r   objectr   r   r   r   r   r(   ra   r%   r#   <module>rP     s                                        " " " " " " ! ! ! ! ! ! ! ! ! ! ! !                  a? a? a? a? a?& a? a? a?H	n
 n
 n
 n
 n
% n
 n
 n
b	b b b b b% b b bJr
 r
 r
 r
 r
) r
 r
 r
ju
 u
 u
 u
 u
& u
 u
 u
r	 {{   r%   