
    [h                    4   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 ddlmZ  G d d          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.

    )annotations   )
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                2   || _         |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        d|j        | _        |j        | _        | j         j        st'          j        d| j         z            d S )N_z|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	_sort_keykeysort_keysynchronize_pairssa_excArgumentError)selfr   s     h/var/www/api.easyaligner.net/htdocs/venv_linux/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#8#8$((C8y* 	&$&*i0  	 	    c                6    t          |j                 |          S N)_direction_to_processorr   )clsr   s     r(   from_relationshipz%DependencyProcessor.from_relationship;   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(   r3   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_preprocessorsG   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'   r9   
after_savebefore_deleteparent_saveschild_savesparent_deleteschild_deletess           r(   per_property_flush_actionsz.DependencyProcessor.per_property_flush_actionsP   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   r>   r@   r=   disabledcyclesr   base_mappermanagerr"   implget_all_pendingdictr   r   r   ProcessStateDeleteStateSaveUpdateStatestatesappendper_state_dependencies)r'   r9   rT   isdeletechild_base_mapperrE   rG   rC   rB   child_actionschild_in_cyclesrD   rF   parent_in_cyclesr5   sum_child_statechildchild_actiondeletedlistonlychildisdeletes                         r(   per_state_flush_actionsz+DependencyProcessor.per_state_flush_actionsl   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:++#'   9	 9	E =*/??
  :D--#9 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++ " !!	 	 	 	
_9	 9	r*   c                    dS NF r'   	uowcommitrT   s      r(   presort_deletesz#DependencyProcessor.presort_deletes       ur*   c                    dS re   rf   rg   s      r(   presort_savesz!DependencyProcessor.presort_saves   rj   r*   c                    d S r,   rf   rg   s      r(   process_deletesz#DependencyProcessor.process_deletes       r*   c                    d S r,   rf   rg   s      r(   process_savesz!DependencyProcessor.process_saves   ro   r*   c                ^   |r| j         rt          j        t          j        z  }n4| j        t
          u rt          j        }nt          j        t          j        z  }|D ]7}|                    || j	        |          }|r|
                                s dS 8|o| j        j         o| j        |j        v S )NT)r   r   r   INCLUDE_PENDING_MUTATIONSr   r   PASSIVE_NO_FETCH_RELATEDr   get_attribute_historyr"   emptyr   _is_self_referentialr   mappers)r'   rh   rT   rW   passiveshistorys          r(   prop_has_changesz$DependencyProcessor.prop_has_changes   s     	4/ 	067 G ^y(( !9GG &)MM   	 	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.)r   r   r   )r   uselistr   
FlushErrorr   _canloadr   class_r4   s     r(   _verify_canloadz#DependencyProcessor._verify_canload
  s   9 &	..#'99/   t{';';d&<"< (< (
 (
 {##E$#?? n= #\!Y![/"k	   $ n! #\!Y![/ 	  - r*   c                    t                      r,   NotImplementedError)r'   r5   r^   associationrow	clearkeysrh   s         r(   _synchronizez DependencyProcessor._synchronize3      !###r*   c                    | j         j        sd S t          t          | j        gd | j         j        D             z                       }|                    d|ft                    S )Nc                    g | ]	}|j         
S rf   )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'   r9   process_keys      r(   _get_reversed_processed_setz/DependencyProcessor._get_reversed_processed_set6  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 rf   rf   )r   lrs      r(   r   z4DependencyProcessor._post_update.<locals>.<listcomp>C  s    FFF$!QAFFFr*   )register_post_updater   r$   )r'   r5   rh   relatedis_m2o_deleter   s         r(   _post_updatez DependencyProcessor._post_update?  sf     	 	A  AM..FF$)*EFFF   	 %2	 	r*   c                    t                      r,   r   r'   rh   r5   s      r(   _pks_changedz DependencyProcessor._pks_changedG  r   r*   c                0    | j         j        d| j        dS )N())	__class____name__r   )r'   s    r(   __repr__zDependencyProcessor.__repr__J  s    >222DIII>>r*   N)F)r   
__module____qualname__r)   classmethodr/   r3   r:   rH   rc   ri   rl   rn   rq   r|   r   r   r   r   r   r   rf   r*   r(   r   r      s-         : = = [=M M M. . .
 
 
8p p pd          @' ' '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 r<   r   r   PostUpdateAllr   r?   dependenciesupdate)
r'   r9   rD   rE   rF   rG   rB   rC   child_post_updateschild_pre_updatess
             r(   rA   z%OneToManyDP.per_property_dependenciesO  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 r<   r   )r'   r9   save_parentdelete_parentr_   rB   rC   rW   rb   r   r   s              r(   rV   z"OneToManyDP.per_state_dependenciesx  s     4	!+!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rW   delete	operationr   )r   r   r   ru   r"   r   r`   r3   delete_orphanregister_object	unchangedr   r'   rh   rT   should_null_fksr5   r{   r^   s          r(   ri   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           	        |                     d| ft                    }| j        j         o| j        dk     }|D ]}|                     ||          }|r| j        rt          j        t          j	        z  }nt          j
        t          j	        z  }|                    || 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                   )d S )Nchildren_addedr   Tadd)cancel_deleter   r   Fr   rW   r   r   r   z	pk changer   )r   r   r   r   r   r   r   r   r   rs   r   ru   r"   addedr   r   r   r`   r3   r   cascade_iteratorr   )r'   rh   rT   r   r   r5   pks_changedry   r{   r^   cmst_dct_s                 r(   rl   zOneToManyDP.presort_saves  sw   ")94(@#FF ** 2(E11 	
  :	 :	E++Iu==K 	$"6 	4 :;  * :; 
  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   i:	 :	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   ru   r"   r   r`   r3   r   r   r   r   r   
difference)r'   rh   rT   r   r5   r{   r^   s          r(   rn   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   ru   r"   r   r   r   r   r   r   r`   r3   r   r   r   s          r(   rq   zOneToManyDP.process_savesD  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'   r5   r^   r   r   rh   r   sourcedests	            r(   r   zOneToManyDP._synchronizef  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_changed}  '    #udk49+F
 
 	
r*   N)r   r   r   rA   rV   ri   rl   rn   rq   r   r   rf   r*   r(   r   r   N  s        ' ' 'R? ? ?B  6B B BH%& %& %&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_processorsrU   DetectKeySwitch)r'   r   r   s      r(   r)   zManyToOneDP.__init__  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 r<   r   r   r   r   r?   r   r   )
r'   r9   rD   rE   rF   rG   rB   rC   parent_post_updatesparent_pre_updatess
             r(   rA   z%ManyToOneDP.per_property_dependencies  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 r<   r   )r'   r9   r   r   r_   rB   rC   rW   rb   r   r   s              r(   rV   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   ru   r"   r   sumnon_deletedr   r   r   r   )r'   rh   rT   r5   r{   todeleter^   tr   r   r   r   s               r(   ri   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   ru   r"   r   r`   r3   r   r   )r'   rh   rT   r5   r{   r^   r   r   r   r   r   s              r(   rl   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   ru   r"   r   r   r   )r'   rh   rT   r5   r{   s        r(   rn   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   )
ru   r"   r   r   r   r   r`   r   r   r   )r'   rh   rT   r5   r{   r^   s         r(   rq   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'   r5   r^   r   r   rh   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)   rA   rV   ri   rl   rn   rq   r   rf   r*   r(   r   r     s        H H H
% % %N6I 6I 6Ip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>u  s9         (     r*   )r   r   r   r7   r8   s     r(   r:   z*DetectKeySwitch.per_property_preprocessorsp  sp    9& 	#    $	 ;     F!!$.....r*   c                    t          j        || j        j                  }t          j        || dd          }|j                            ||fg           d S re   )r   r>   r   rL   r=   r   r   )r'   r9   rD   rB   s       r(   rH   z*DetectKeySwitch.per_property_flush_actions}  sT    !/T[5LMM*3eUCC
,
!; <=====r*   c                    d S r,   rf   )r'   r9   rT   rW   s       r(   rc   z'DetectKeySwitch.per_state_flush_actions  ro   r*   c                    d S r,   rf   rg   s      r(   ri   zDetectKeySwitch.presort_deletes  ro   r*   c                D    | j         s|                     ||           d S d S r,   r   _process_key_switches)r'   r9   rT   s      r(   rl   zDetectKeySwitch.presort_saves  s5    # 	4 &&vs33333	4 	4r*   c                b    |s,| j         r%|                     ||          }t          |          S dS re   )r   _key_switchersbool)r'   r9   rT   rW   ds        r(   r|   z DetectKeySwitch.prop_has_changes  s9     	D0 	##C00A77Nur*   c                    J r,   rf   rg   s      r(   rn   zDetectKeySwitch.process_deletes  s    r*   c                D    | j         sJ |                     ||           d S r,   r  rg   s      r(   rq   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   rf   r*   r(   <lambda>z0DetectKeySwitch._key_switchers.<locals>.<lambda>  s    SUUCEEN r*   )r   unionr   r   )r'   r9   rT   switchednotswitched	allstatesrz   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)ry   r   F)r	  r   identity_map
all_states
issubclassr   r   rP   r2   r"   getr    r   PASSIVE_NO_RESULTr   r   instance_stater   r   r   r   r   r$   )	r'   deplistrh   	switchersr5   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__r:   rH   rc   ri   rl   r|   rn   rq   r	  r  r   rf   r*   r(   r   r   d  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'   r9   rD   rE   rF   rG   rB   rC   s           r(   rA   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'   r9   r   r   r_   rB   rC   rW   rb   s	            r(   rV   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   ru   r"   r   )r'   rh   rT   r5   s       r(   ri   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   ru   r"   r   r   r   r   r   r`   r3   r   r   r   r   )
r'   rh   rT   r5   r{   r^   r   r   r   r   s
             r(   rl   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,   rf   r   r   r5   s     r(   r  z/ManyToManyDP.process_deletes.<locals>.<genexpr>[  s'      CC!Au:CCCCCCr*   )
r   r   ru   r"   r   	non_addedr   rU   r   	_run_crud)r'   rh   rT   secondary_deletesecondary_insertsecondary_update	processedtmpr{   r^   r   r5   s              @r(   rn   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        t          j        z  }	nt          j        t          j        z  }	|                    | 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,   rf   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   rs   r   ru   r"   r   r   rU   r`   r   r   r   r   r   r$   r   secondary_synchronize_pairsr/  )r'   rh   rT   r0  r1  r2  r3  r4  need_cascade_pksry   r{   r^   r   r5   s                @r(   rq   zManyToManyDP.process_savesd  s   44Y??	ee <	@ <	@E#'#77  D<M<M5= =   	* :;  4 :;   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 )r7  r<  r>  rA  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   wherer   and_r   executesupports_sane_multi_rowcountrowcountlenr   StaleDataErrordescriptionr   insert)	r'   rh   r1  r2  r0  rD  	statementresultr   s	           @r(   r/  zManyToManyDP._run_crud  s=    *55dkBB
 	-a0N--//55   !%!1   I  ''	3CDDF 3355/S)9%:%:::(7 2,--    	-a0N--//55   !%!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   r8  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   rA   rV   ri   rl   rn   rq   r/  r   r   rf   r*   r(   r%  r%    s        
 
 
6  2
 
 
 J  J  JD&
 &
 &
PK
 K
 K
Z;< ;< ;<z  @
 
 
 
 
r*   r%  N)r#  
__future__r    r   r   r   r   r	   r   
interfacesr
   r   r   r%   r   r   r   r   r   r%  r-   rf   r*   r(   <module>rV     s	    # " " " " "                                     " " " " " " ! ! ! ! ! ! ! ! ! ! ! !                  n? n? n? n? n? n? n? n?b	r
 r
 r
 r
 r
% r
 r
 r
j	^ ^ ^ ^ ^% ^ ^ ^Br
 r
 r
 r
 r
) r
 r
 r
jx
 x
 x
 x
 x
& x
 x
 x
x	 {{   r*   