
H`Tc           @   s&  d  Z  d d l Z d d l m Z d d l m Z m Z m Z m	 Z	 d d l m
 Z
 m Z m Z m Z d d l m Z m Z m Z d d	 l m Z d d
 l m 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   Z" d   Z# d   Z$ d   Z% d   Z& d   Z' d e( f d     YZ) d  e) f d!     YZ* d" e) f d#     YZ+ d$ e) f d%     YZ, d& e) f d'     YZ- d( e* e, f d)     YZ. d* e* e- f d+     YZ/ d, e+ e, f d-     YZ0 d. e+ e- f d/     YZ1 d S(0   s   private module containing functions used to emit INSERT, UPDATE
and DELETE statements on behalf of a :class:`.Mapper` and its descending
mappers.

The functions here are called only by the unit of work functions
in unitofwork.py.

iN(   t   groupbyi   (   t   sqlt   utilt   exct   schemai   (   t
   attributest   syncR   t	   evaluator(   t   _state_mappert	   state_strt   _attr_as_key(   t
   expression(   t   loadingc      	   C   s  | rE |  j  rE x- t |  D] } t |  | g | d t q Wd St |  | |  \ } } t |   } x |  j j   D]z \ } }	 t |  | | |  }
 t	 |  | | |  } | r t
 |  | | |	 | |  n  |
 ry t |  | | |	 | |
  qy qy Wt |  | | |  d S(   s;  Issue ``INSERT`` and/or ``UPDATE`` statements for a list
    of objects.

    This is called within the context of a UOWTransaction during a
    flush operation, given a list of states to be flushed.  The
    base mapper in an inheritance hierarchy handles the inserts/
    updates for all descendant mappers.

    t   singleN(   t   batcht   _sort_statest   save_objt   Truet   _organize_states_for_savet   _cached_connection_dictt   _sorted_tablest   itemst   _collect_insert_commandst   _collect_update_commandst   _emit_update_statementst   _emit_insert_statementst    _finalize_insert_update_commands(   t   base_mappert   statest   uowtransactionR   t   statet   states_to_insertt   states_to_updatet   cached_connectionst   tablet   mappert   insertt   update(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR      s0    					c   	      C   s|   t  |   } t |  | |  } xW |  j j   D]F \ } } t |  | | | |  } | r. t |  | | | | |  q. q. Wd S(   s\   Issue UPDATE statements on behalf of a relationship() which
    specifies post_update.

    N(   R   t    _organize_states_for_post_updateR   R   t   _collect_post_update_commandst   _emit_post_update_statements(	   R   R   R   t   post_update_colsR!   R    R"   R#   R%   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   post_updateG   s    			c         C   s   t  |   } t |  | |  } |  j } xX t t | j     D]> } t |  | | |  } | | } t |  | | | | |  q@ Wx3 | D]+ \ }	 }
 } } } | j j	 | | |	  q Wd S(   s   Issue ``DELETE`` statements for a list of objects.

    This is called within the context of a UOWTransaction during a
    flush operation.

    N(
   R   t   _organize_states_for_deleteR   t   reversedt   listt   keyst   _collect_delete_commandst   _emit_delete_statementst   dispatcht   after_delete(   R   R   R   R!   t   states_to_deletet   table_to_mapperR"   t   deleteR#   R   t
   state_dictt   has_identityt
   connection(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt
   delete_obj]   s    			
	c         C   s  g  } g  } xt  |  | |  D]\ } } } } t | j  }	 | j pU | j |  }
 d } |	 s} | j j | | |  n | j j | | |  | j r | j | | |  n  |	 r\|
 | j	 j
 k r\| j	 j
 |
 } t j |  } | j |  s$t j d t |  |
 t |  f   n  |  j d |
 t |  t |   | j |  | } n  |	 r| r| j | | | | |	 |
 | f  q | j | | | | |	 |
 | f  q W| | f S(   sT  Make an initial pass across a set of states for INSERT or
    UPDATE.

    This includes splitting out into distinct lists for
    each, calling before_insert/before_update, obtaining
    key information for each state including its dictionary,
    mapper, the connection to use for the execution per state,
    and the identity flag.

    sJ   New instance %s with identity key %s conflicts with persistent instance %ssP   detected row switch for identity %s.  will update %s, remove %s from transactionN(   t   _connections_for_statest   boolt   keyt   _identity_key_from_statet   NoneR1   t   before_insertt   before_updatet   _validate_polymorphic_identityt   sessiont   identity_mapR   t   instance_statet
   is_deletedt   orm_exct
   FlushErrorR	   t
   _log_debugt   remove_state_actionst   append(   R   R   R   R   R    R   t   dict_R#   R8   R7   t   instance_keyt
   row_switcht   instancet   existing(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   |   sH    		c         C   s   t  t |  | |   S(   s   Make an initial pass across a set of states for UPDATE
    corresponding to post_update.

    This includes obtaining key information for each state
    including its dictionary, mapper, the connection to use for
    the execution per state.

    (   R-   R:   (   R   R   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR&      s    
c         C   sn   g  } xa t  |  | |  D]M \ } } } } | j j | | |  | j | | | t | j  | f  q W| S(   s   Make an initial pass across a set of states for DELETE.

    This includes calling out before_delete and obtaining
    key information for each state including its dictionary,
    mapper, the connection to use for the execution per state.

    (   R:   R1   t   before_deleteRJ   R;   R<   (   R   R   R   R3   R   RK   R#   R8   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR+      s    c      
   C   s  g  } x| D]\ } } } } }	 }
 } | | j  k r= q n  | j  | } i  } i  } t } t } x| j | D]} | | j k r | j t k	 r | j d  } | | | j <qp | j | } | j	 | j d  } | d k rK| | k r t } qw| j
 d k r$| j d k r$| | | j <qw| j d k	 rw| j j rwt } qwqp t | t j  rj| | | <qp | | | j <qp W| j | | | | | | | | f  q W| S(   sS   Identify sets of values to use in INSERT statements for a
    list of states.

    N(   t   _pks_by_tableR   t   _cols_by_tablet   version_id_colt   version_id_generatort   FalseR>   R<   t   _columntopropertyt   gett   defaultt   server_defaultR   t   eager_defaultst
   isinstanceR   t   ClauseElementRJ   (   R   R   R"   R   R$   R   R6   R#   R8   R7   RL   RM   t   pkst   paramst   value_paramst   has_all_pkst   has_all_defaultst   colt   valt   propt   value(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR      sB    		c      
   C   s  g  } x| D]\ } } } } }	 }
 } | | j  k r= q n  | j  | } i  } i  } t } } x| j | D]} | | j k r| j | p | | r | j p | |  | | j <| j | } | j | j	 j
 j | | t j  } | j r| j d | | j	 <t } qN| j t k	 rN| j | | j  } | | | j	 <xQ | j j   D]= } | j | j	 j
 j | | t j  } | j rNt } qNqNWqNqn | j | } | j | j	 j
 j | | t j  } | j rt | j d t j  r| j d | | <n | j d } | | | j	 <| | k r| j r| rd | | f | j k rh| j d } | | | j <n | j d } | | | j <t } n$ | | j	 =| j d } | | | j <| d k rt } qqNt } qn | | k r | j | j	 j
 j | |  } | d k rt } n  | | | j <qn | rn | j d g k rn d | | j	 <t } qn qn W| r | rpt j d   n  | j | | | | | | f  q q W| S(   st  Identify sets of values to use in UPDATE statements for a
    list of states.

    This function works intricately with the history system
    to determine exactly what values should be updated
    as well as how the row should be matched within an UPDATE
    statement.  Includes some tricky scenarios where the primary
    key of an object might have been changed.

    i    t   pk_cascadeds3   Can't update table using NULL for primary key valueN(   RQ   RU   RR   RS   t#   _get_committed_state_attr_by_columnt   dictt   _labelRV   t   managerR<   t   implt   get_historyR   t   PASSIVE_NO_INITIALIZEt   addedR   RT   t   valuesR[   R   R\   t   deletedR>   RW   t	   unchangedRF   RG   RJ   (   R   R   R"   R    R%   R   R6   R#   R8   R7   RL   RM   R]   R^   R_   t   hasdatat   hasnullRb   Rd   t   historyRc   Re   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    
							
		c         C   s*  g  } x| D]\ } } } }	 | | j  k r4 q n  | j  | }
 i  } t } x | j | D] } | |
 k r | j | | |  | | j <q[ | | k r[ | j | } | j | j j j	 | | t
 j  } | j r | j d } | | | j <t } q q[ q[ W| r | j | | | | |	 f  q q W| S(   sr   Identify sets of values to use in UPDATE statements for a
    list of states within a post_update operation.

    i    (   RQ   RU   RR   t   _get_state_attr_by_columnRi   RV   Rj   R<   Rk   Rl   R   Rm   Rn   R   RJ   (   R   R   R"   R    R)   R%   R   R6   R#   R8   R]   R^   Rr   Rb   Rd   Rt   Re   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR'     s2    	c         C   s  t  j t  } x | D] \ } } } } }	 | s | | j k rG q n  i  }
 | |	 j |
  xS | j | D]D } | j | | |  |
 | j <} | d k rl t j	 d   ql ql W| j
 d k	 r | j j | j
  r | j | | | j
  |
 | j
 j <q q W| S(   sS   Identify values to use in DELETE statements for a list of
    states to be deleted.s8   Can't delete from table using NULL for primary key valueN(   R   t   defaultdictR-   RQ   RJ   Rg   R<   R>   RF   RG   RS   t   ct   contains_column(   R   R   R"   R3   R5   R   R6   R#   R7   R8   R^   Rb   Re   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR/     s&    c            s]    j  d k	 o!  j j   j        f d   } |  j d  f |  } d } x | D] \ }	 }
 }   } } | r | j | j |  |  } n | | j | |  } t   |  |	 |
 | | j j	 d |  | | j
 7} q^ W| j j r3| t |  k rYt j d  j t |  | f   qYn&  rYt j d | j j d d n  d S(	   s`   Emit UPDATE statements corresponding to value lists collected
    by _collect_update_commands().c             s   t  j   }  x@   j  D]1 } |  j j | t  j | j d | j k  q W r |  j j   j t  j   j j d   j j k  n   j	 |   }   j
 j r | j   } n$   j d  k	 r | j   j  } n  | S(   Nt   type_(   R   t   and_RQ   t   clausesRJ   t	   bindparamRi   t   typeRS   R%   R   RZ   t   return_defaultsR>   (   t   clauseRb   t   stmt(   R#   R"   t   needs_version_id(    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   update_stmt  s    	R%   i    sM   UPDATE statement on table '%s' expected to update %d row(s); %d were matched.sM   Dialect %s does not support updated rowcount - versioning cannot be verified.t
   stackleveli   N(   RS   R>   Rw   Rx   t   _memot   executeRo   t
   _postfetcht   contextt   compiled_parameterst   rowcountt   dialectt   supports_sane_rowcountt   lenRF   t   StaleDataErrort   descriptionR   t   warnt   dialect_description(   R   R   R!   R#   R"   R%   R   t	   statementt   rowsR   R6   R^   R8   R_   Rw   (    (   R#   R"   R   s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s@    
"	c         C   si  |  j  d | f | j  } xGt | d    D]3\ \ } } }	 }
 } } | sf |  j sf | j j r|
 r|	 rt |  } g  | D] } | d ^ q } | | j | |  } xt | | j	 j
  D]C \ \ } } } } } } }
 } } t | | | | | | | |  q Wq. | r1|  j r1| j   } n$ | j d k	 rU| j | j  } n  x	| D]\ } } } } } } }
 } | r| j | j |  |  } n | | j | |  } | j	 j } | d k	 r4xe t | | j |  D]J \ } } | j | } | j | j  d k r| j | | | |  qqWn  t | | | | | | | j	 j
 d |  q\Wq. Wd S(   s`   Emit INSERT statements corresponding to value lists collected
    by _collect_insert_commands().R$   c         S   s9   |  d t  |  d j    t |  d  |  d |  d f S(   Ni   i   i   i   i   (   R-   R.   R;   (   t   rec(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   <lambda>*  s   i   i    N(   R   R$   R    RZ   R   t   implicit_returningR-   R   t   zipR   R   R   R~   RS   R>   Ro   t   inserted_primary_keyRQ   RV   RW   R<   t   _set_state_attr_by_column(   R   R   R!   R#   R"   R$   R   R8   t   pkeyst   hasvalueR`   Ra   t   recordsR   t   multiparamsRw   R   R6   R^   t
   mapper_rect   connR_   t   last_inserted_paramst   resultt   primary_keyt   pkRb   Rd   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   !  sl    %

7"
	c            s      f d   } |  j  d  f |  } xf t | d    D]R \ } }	 | d }
 g  |	 D] \ } } }   } | ^ qZ } | |
 j | |  q= Wd S(   se   Emit UPDATE statements corresponding to value lists collected
    by _collect_post_update_commands().c             s\   t  j   }  x@   j  D]1 } |  j j | t  j | j d | j k  q W j |   S(   NRy   (	   R   Rz   RQ   R{   RJ   R|   Ri   R}   R%   (   R   Rb   (   R#   R"   (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   {  s
    R*   c         S   s   |  d t  |  d j    f S(   Ni   i   (   R-   R.   (   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    i    N(   R   R    R   (   R   R   R!   R#   R"   R%   R   R   R<   t   grouperR8   R   R6   R^   R   R   (    (   R#   R"   s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR(   v  s    	
%
c      	      s   j  d	 k	 o!   j j  j        f d   } x| j   D]s\ } } |  j d   f |  }	 | | } t |  }
 d } t } | j j	 r | j
 |	 |  }  s t } n  | j } n  r@| j j rd } x] | D]% } | j
 |	 |  } | | j 7} q WqPt j d | j j d d | j
 |	 |  n | j
 |	 |  |  j rF | d k rF |
 | k rF | rt j d   j |
 | f  qt j d   j |
 | f   qF qF Wd	 S(
   s`   Emit DELETE statements corresponding to value lists collected
    by _collect_delete_commands().c             s   t  j   }  x@   j  D]1 } |  j j | t  j | j d | j k  q W r |  j j   j t  j   j j d   j j k  n   j	 |   S(   NRy   (
   R   Rz   RQ   R{   RJ   R|   R<   R}   RS   R5   (   R   Rb   (   R#   t   need_version_idR"   (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   delete_stmt  s    	&	R5   ii    sM   Dialect %s does not support deleted rowcount - versioning cannot be verified.R   i   s   DELETE statement on table '%s' expected to delete %d row(s); %d were matched.  Please set confirm_deleted_rows=False within the mapper configuration to prevent this warning.N(   RS   R>   Rw   Rx   R   R   R   RU   R   t   supports_sane_multi_rowcountR   R   R   R   R   R   R   t   confirm_deleted_rowsR   RF   R   (   R   R   R!   R#   R"   R5   R   R8   t   del_objectsR   t   expectedt   rows_matchedt	   only_warnRw   R^   (    (   R"   R   R#   s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR0     sF    
		c      	   C   s  x| | D]|\ } } } } } }	 }
 | j  r | j g  | j  D]* } | j s` | j | j k r? | j ^ q?  } | r | j | j |  q n  g  } |  j r | j | j  nY | j	 d k	 r| j t k r| j | j	 } | j | j k r| j | j g  qn  | rR|  j |  | _ t j | j j |   | j d | d | n  | sq| j j | | |  q | j j | | |  q Wd S(   sz   finalize state on states that have been inserted or updated,
    including calling after_insert/after_update events.

    t   refresh_statet   only_load_propsN(   t   _readonly_propst   unmodified_intersectiont   expire_on_flushR<   Rh   t   _expire_attributesRZ   t   extendt   _unloaded_non_objectRS   R>   RT   RU   RV   t   unloadedR=   R   t   load_on_identRB   t   queryR1   t   after_insertt   after_update(   R   R   R   R    R   R6   R#   R8   R7   RL   RM   t   pt   readonlyt
   toload_nowRd   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s4     	-	
c      	   C   s  | j  j } | j  j }	 | j  j }
 |  j d k	 rL t |  |  j g } n  |
 r | j  j } | d k	 r x: |
 D]/ } | j r qq n  |  j	 | | | | |  qq Wq n  xL | D]D } | j
 | k r | |  j k r |  j	 | | | | | j
  q q W|	 rA| j | j g  |	 D]% } | |  j k r|  j | j
 ^ q n  x= |  j | D]. \ } } t j | | | | | | |  j  qOWd S(   s   Expire attributes in need of newly persisted database state,
    after an INSERT or UPDATE statement has proceeded for that
    state.N(   R   t   prefetch_colst   postfetch_colst   returning_colsRS   R>   R-   t   returned_defaultsR   R   R<   RV   R   Rh   t   _table_to_equatedR   t   populatet   passive_updates(   R#   R   R"   R   RK   R   R^   R_   R   R   R   t   rowRb   Rw   t   mt   equated_pairs(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s2    	$$&c         c   s   | j  j r | j  j } n d } d } xm t |  D]_ } | rX | |  | j    } n | ss | j j |   } n  t |  } | | j | | f Vq4 Wd S(   s   Return an iterator of (state, state.dict, mapper, connection).

    The states are sorted according to _sort_states, then paired
    with the connection they should be using for the given
    unit of work transaction.

    N(	   RB   t   connection_callableR>   R   t   objt   transactionR8   R   Rh   (   R   R   R   R   R8   R   R#   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR:   :  s    	c            s   t  j   f d    S(   Nc            s   |  j  d   j  S(   Nt   compiled_cache(   t   execution_optionst   _compiled_cache(   R   (   R   (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   [  s   	(   R   t   PopulateDict(   R   (    (   R   s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   X  s    c         C   s[   t  |   } t  d   | D  } | j |  t | d t j d  t | d d   S(   Nc         s   s$   |  ] } | j  d  k	 r | Vq d  S(   N(   R<   R>   (   t   .0t   s(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pys	   <genexpr>b  s    R<   t   insert_orderc         S   s   |  j  d S(   Ni   (   R<   (   t   q(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   e  s    (   t   sett   difference_updatet   sortedt   operatort
   attrgetter(   R   t   pendingt
   persistent(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   `  s
    t   BulkUDc           B   sY   e  Z d  Z d   Z e d    Z e d    Z d   Z d   Z	 d   Z
 d   Z RS(   s5   Handle bulk update and deletes via a :class:`.Query`.c         C   s   | j  t  |  _ d  S(   N(   t   enable_eagerloadsRU   R   (   t   selfR   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   __init__k  s    c         C   s
   |  j  j S(   N(   R   RB   (   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyRB   n  s    c         G   s\   y | | } Wn= t  k
 rM t j d d j t d   | D     n X| |   Sd  S(   Ns3   Valid strategies for session synchronization are %ss   , c         s   s   |  ] } t  |  Vq d  S(   N(   t   repr(   R   t   x(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pys	   <genexpr>y  s   (   t   KeyErrort   sa_exct   ArgumentErrort   joinR   (   t   clst   lookupt   synchronize_sessiont   argt   klass(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   _factoryr  s    c         C   s6   |  j    |  j   |  j   |  j   |  j   d  S(   N(   t   _do_pret   _do_pre_synchronizet   _do_exect   _do_post_synchronizet   _do_post(   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   exec_~  s
    



c         C   s   |  j  } | j   |  _ } t | j j  d k sQ t | j j d t j  rl | j	 d  j
 j |  _ n | j j d |  _ | j } | j r | j   n  d  S(   Ni   i    sL   This operation requires only one Table or entity be specified as the target.(   R   t   _compile_contextR   R   R   t   fromsR[   R   t   Tablet   _only_entity_zeroR#   t   local_tablet   primary_tableRB   t
   _autoflush(   R   R   R   RB   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    			c         C   s   d  S(   N(    (   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    c         C   s   d  S(   N(    (   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    (   t   __name__t
   __module__t   __doc__R   t   propertyRB   t   classmethodR   R   R   R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   h  s   				t   BulkEvaluatec           B   s    e  Z d  Z d   Z d   Z RS(   sD   BulkUD which does the 'evaluate' method of session state resolution.c         C   s   d  S(   N(    (   R   t   evaluator_compiler(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   _additional_evaluators  s    c         C   s   |  j  } | j   j } yM t j |  } | j d  k	 rN | j | j  } n	 d   } |  j |  Wn# t j	 k
 r t
 j d   n Xg  | j j j   D]3 \ \ } } } t | |  r | |  r | ^ q |  _ d  S(   Nc         S   s   t  S(   N(   R   (   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   eval_condition  s    sn   Could not evaluate current criteria in Python. Specify 'fetch' or False for the synchronize_session parameter.(   R   t   _mapper_zerot   class_R   t   EvaluatorCompilert   whereclauseR>   t   processR   t   UnevaluatableErrorR   t   InvalidRequestErrorRB   RC   R   t
   issubclasst   matched_objects(   R   R   t
   target_clsR   R   R   R   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s     		"(   R   R   R   R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s   	t	   BulkFetchc           B   s   e  Z d  Z d   Z RS(   sA   BulkUD which does the 'fetch' method of session state resolution.c         C   sR   |  j  } | j } |  j j j |  j j  } | j | d | j j	   |  _
 d  S(   NR^   (   R   RB   R   R   t   with_only_columnsR   R   R   t   _paramst   fetchallt   matched_rows(   R   R   RB   t   select_stmt(    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    		(   R   R   R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR    s   t
   BulkUpdatec           B   s8   e  Z d  Z d   Z e d    Z d   Z d   Z RS(   s   BulkUD which handles UPDATEs.c         C   s3   t  t |   j |  |  j j d  | |  _ d  S(   NR%   (   t   superR  R   R   t   _no_select_modifiersRo   (   R   R   Ro   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    c         C   s+   t  j i t d 6t d 6t t 6| | |  S(   Nt   evaluatet   fetch(   R   R   t   BulkUpdateEvaluatet   BulkUpdateFetchR  RU   (   R   R   R   Ro   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   factory  s
    	c         C   sX   t  j |  j |  j j |  j  } |  j j j | d |  j j	 |  _
 |  j
 j |  _ d  S(   NR^   (   R   R%   R   R   R  Ro   R   RB   R   R
  R   R   (   R   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s
    c         C   s    |  j  j } | j j |   d  S(   N(   R   RB   R1   t   after_bulk_update(   R   RB   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    (   R   R   R   R   R   R  R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR    s
   		t
   BulkDeletec           B   s8   e  Z d  Z d   Z e d    Z d   Z d   Z RS(   s   BulkUD which handles DELETEs.c         C   s*   t  t |   j |  |  j j d  d  S(   NR5   (   R  R  R   R   R  (   R   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    c         C   s(   t  j i t d 6t d 6t t 6| |  S(   NR  R  (   R   R   t   BulkDeleteEvaluatet   BulkDeleteFetchR  RU   (   R   R   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR    s
    	c         C   sR   t  j |  j |  j j  } |  j j j | d |  j j |  _	 |  j	 j
 |  _
 d  S(   NR^   (   R   R5   R   R   R  R   RB   R   R
  R   R   (   R   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s
    c         C   s    |  j  j } | j j |   d  S(   N(   R   RB   R1   t   after_bulk_delete(   R   RB   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s    (   R   R   R   R   R   R  R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR    s
   		R  c           B   s    e  Z d  Z d   Z d   Z RS(   sS   BulkUD which handles UPDATEs using the "evaluate"
    method of session resolution.c         C   sX   i  |  _  xH |  j j   D]7 \ } } t |  } | j t j |   |  j  | <q Wd  S(   N(   t   value_evaluatorsRo   R   R
   R  R   t   _literal_as_binds(   R   R   R<   Re   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s
    	c   	      C   s   |  j  j } t   } t |  j j    } x |  j D] } t j |  t j	 |  } } | j
 j |  } x% | D] } |  j | |  | | <qr W| j | t |   | j | t |  j |   | j |  q4 W| j |  d  S(   N(   R   RB   R   R-   R  R.   R  R   RD   t   instance_dictt
   unmodifiedt   intersectiont   _commitR   t
   differencet   addt   _register_altered(	   R   RB   R   t   evaluated_keysR   R   RK   t   to_evaluateR<   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR     s     				
(   R   R   R   R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR    s   	R  c           B   s   e  Z d  Z d   Z RS(   sS   BulkUD which handles DELETEs using the "evaluate"
    method of session resolution.c         C   s6   |  j  j j g  |  j D] } t j |  ^ q  d  S(   N(   R   RB   t   _remove_newly_deletedR  R   RD   (   R   R   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   /  s    (   R   R   R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR  +  s   R  c           B   s   e  Z d  Z d   Z RS(   sP   BulkUD which handles UPDATEs using the "fetch"
    method of session resolution.c   	      C   s   |  j  j } |  j  j   } t g  g  |  j D] } | j t |   ^ q+ D]+ } | | j k rJ t j	 | j |  ^ qJ  } g  |  j
 D] } t |  ^ q } x | D] } | j | |  q W| j |  d  S(   N(   R   RB   R   R   R  t   identity_key_from_primary_keyR-   RC   R   RD   Ro   R
   t   _expire_stateR#  (	   R   RB   t   target_mapperR   t   identity_keyR   t   kt   attribR   (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   9  s    ,."(   R   R   R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR  5  s   R  c           B   s   e  Z d  Z d   Z RS(   sP   BulkUD which handles DELETEs using the "fetch"
    method of session resolution.c         C   sz   |  j  j } |  j  j   } xX |  j D]M } | j t |   } | | j k r% | j t j	 | j |  g  q% q% Wd  S(   N(
   R   RB   R   R  R'  R-   RC   R&  R   RD   (   R   RB   R)  R   R*  (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR   P  s    (   R   R   R   R   (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyR  L  s   (2   R   R   t	   itertoolsR    t    R   R   R   R   R   R   R   RF   R   t   baseR   R	   R
   R   R   RU   R   R*   R9   R   R&   R+   R   R   R'   R/   R   R   R(   R0   R   R   R:   R   R   t   objectR   R   R  R  R  R  R  R  R  (    (    (    s`   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/persistence.pyt   <module>   sF   ""-			I			3	{	%	"	D	U		O	-	*			6#$
