σ
H`ΎTc           @   sy   d  Z  d d l m Z d d l m Z d e f d     YZ i  Z d d  Z d d  Z	 d	   Z
 d
   Z d   Z d S(   s   The :class:`.Annotated` class and related routines; creates hash-equivalent
copies of SQL constructs which contain context-specific markers and
associations.

i   (   t   utili   (   t	   operatorst	   Annotatedc           B   st   e  Z d  Z d   Z d   Z d   Z d   Z d e d  Z	 d   Z
 e d    Z d   Z d	   Z d
   Z RS(   s  clones a ClauseElement and applies an 'annotations' dictionary.

    Unlike regular clones, this clone also mimics __hash__() and
    __cmp__() of the original element so that it takes its place
    in hashed collections.

    A reference to the original element is maintained, for the important
    reason of keeping its hash value current.  When GC'ed, the
    hash value may be reused, causing conflicts.

    c         G   sg   | s t  j |   S| \ } } y t | j }  Wn# t k
 rU t | j |   }  n Xt  j |   Sd  S(   N(   t   objectt   __new__t   annotated_classest	   __class__t   KeyErrort   _new_annotation_type(   t   clst   argst   elementt   values(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR      s    c         C   s(   | j  j   |  _  | |  _ | |  _ d  S(   N(   t   __dict__t   copyt   _Annotated__elementt   _annotations(   t   selfR   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt   __init__-   s    	c         C   s)   |  j  j   } | j |  |  j |  S(   N(   R   R   t   updatet   _with_annotations(   R   R   t   _values(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt	   _annotate2   s    c         C   s4   |  j  j |  j   } |  j j   | _ | | _ | S(   N(   R   R   R   R   R   (   R   R   t   clone(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR   7   s    	c         C   sT   | d  k r |  j S|  j j   } x | D] } | j | d   q) W|  j |  Sd  S(   N(   t   NoneR   R   R   t   popR   (   R   R   R   R   t   v(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt   _deannotate=   s    c         K   s   |  j  j j |  | |  S(   N(   R   R   t   _compiler_dispatch(   R   t   visitort   kw(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR   F   s    c         C   s
   |  j  j S(   N(   R   t   _constructor(   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR   J   s    c         C   sL   |  j  j   } | |  j  k r" |  S| j j |  j  |  j | |  j  Sd  S(   N(   R   t   _cloneR   R   R   R   (   R   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR    N   s
    c         C   s   t  |  j  S(   N(   t   hashR   (   R   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt   __hash__Y   s    c         C   sE   t  |  j t j  r+ |  j j j |  |  St |  t |   k Sd  S(   N(   t
   isinstanceR   R   t   ColumnOperatorsR   t   __eq__R!   (   R   t   other(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR%   \   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   t   TrueR   R   t   propertyR   R    R"   R%   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR      s   								c            s4       f d    |  d k	 r0  |   }  n  |  S(   sΉ   Deep copy the given ClauseElement, annotating each element
    with the given annotations dictionary.

    Elements within the exclude collection will be cloned but not annotated.

    c            sq    r6 t  |  d  r6 |  j j   r6 |  j   } n'  |  j k rW |  j   } n |  } | j d    | S(   Nt	   proxy_setR   (   t   hasattrR,   t   intersectionR    R   R   t   _copy_internals(   t   elemt   newelem(   R   t   excludet   annotations(    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR   p   s    N(   R   (   R   R3   R2   (    (   R2   R   R3   s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt   _deep_annotatei   s    c            s@   t  j        f d     |  d k	 r<   |   }  n  |  S(   s2   Deep copy the given element, removing annotations.c            s]    s |   k rQ |  j  d  d t  } | j d     sM |  |  <n  | S |  Sd  S(   NR   R   (   R   R*   R/   (   R0   R1   (   R   t   clonedR   (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR      s    N(   R    t   column_dictR   (   R   R   (    (   R   R5   R   s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt   _deep_deannotate   s
    c         C   s   |  j  |  }  |  j   |  S(   s  Annotate the given ClauseElement and copy its internals so that
    internal objects refer to the new annotated object.

    Basically used to apply a "dont traverse" annotation to a
    selectable, without digging throughout the whole
    structure wasting time.
    (   R   R/   (   R   R3   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt   _shallow_annotate   s    
c         C   s   t  |  t  r |  S|  t k r' t |  Sx+ |  j D]  } | t k r1 t | } Pq1 q1 Wt d |  j | |  f i   t |  <} | t   d |  j <| S(   Ns   Annotated%s(   t
   issubclassR   R   t   __mro__t   typeR'   t   globals(   R	   t   base_clst   super_t   anno_cls(    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyR   ¨   s    

c         C   sF   |  g } x6 | rA | j    } | j | j    t | |  q Wd  S(   N(   R   t   extendt   __subclasses__R   (   t   target_hierarchyR=   t   stackR	   (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt   _prepare_annotations½   s
    		N(   R)   t    R    R   R   R   R   R   R4   R7   R8   R   RD   (    (    (    s_   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/sql/annotation.pyt   <module>   s   T		