ó
H`¾Tc           @   sì   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	 „  Z	 d
 Z
 d Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ e ƒ  e _ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(   s@   Path tracking utilities, representing mapper graph traversals.

i   (   t
   inspection(   t   util(   t   exciÿÿÿÿ(   t   chaini   (   t   class_mapperc         C   s   t  j |  ƒ S(   N(   t   PathRegistryt   deserialize(   t   path(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   _unreduce_path   s    t   *t   _sa_defaultR   c           B   sÂ   e  Z d  Z d „  Z d „  Z d „  Z d d „ Z d „  Z e	 d „  ƒ Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z d „  Z d „  Z d „  Z RS(   sÜ  Represent query load paths and registry functions.

    Basically represents structures like:

    (<User mapper>, "orders", <Order mapper>, "items", <Item mapper>)

    These structures are generated by things like
    query options (joinedload(), subqueryload(), etc.) and are
    used to compose keys stored in the query._attributes dictionary
    for various options.

    They are then re-composed at query compile/result row time as
    the query is formed and as rows are fetched, where they again
    serve to compose keys to look up options in the context.attributes
    dictionary, which is copied from query._attributes.

    The path structure has a limited amount of caching, where each
    "root" ultimately pulls from a fixed registry associated with
    the first mapper, that also contains elements for each of its
    property keys.  However paths longer than two elements, which
    are the exception rather than the rule, are generated on an
    as-needed basis.

    c         C   s   | d  k	 o |  j | j k S(   N(   t   NoneR   (   t   selft   other(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   __eq__4   s    c         C   s   | | | |  j  f <d  S(   N(   R   (   R   t
   attributest   keyt   value(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   set8   s    c         C   s   | j  | |  j f | ƒ d  S(   N(   t
   setdefaultR   (   R   R   R   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR   ;   s    c         C   s+   | |  j  f } | | k r# | | S| Sd  S(   N(   R   (   R   R   R   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   get>   s    c         C   s   t  |  j ƒ S(   N(   t   lenR   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   __len__E   s    c         C   s   t  |  j ƒ S(   N(   R   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   lengthH   s    c         c   sG   |  j  } x7 t d t | ƒ d ƒ D] } | | | | d f Vq" Wd  S(   Ni    i   i   (   R   t   rangeR   (   R   R   t   i(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   pairsL   s    	c         C   sd   x] g  t  d t |  j ƒ d ƒ D] } |  j | ^ q D]" } | j r6 | j | ƒ r6 t Sq6 Wt Sd  S(   Ni    i   (   R   R   R   t	   is_mappert   isat   Truet   False(   R   t   mapperR   t   path_mapper(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   contains_mapperQ   s    9	c         C   s   | |  j  f | k S(   N(   R   (   R   R   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   contains[   s    c         C   s   t  |  j ƒ  f f S(   N(   R   t	   serialize(   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt
   __reduce__^   s    c         C   sŽ   |  j  } t t g  g  t d t | ƒ d ƒ D] } | | ^ q+ D] } | j ^ q? g  t d t | ƒ d ƒ D] } | | j ^ qj d  g ƒ ƒ S(   Ni    i   i   (   R   t   listt   zipR   R   t   class_R   R   (   R   R   R   t   m(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR#   a   s    	Bc         C   s™   | d  k r d  St t g  | D]= \ } } t | ƒ | d  k	 rQ t | ƒ j | n d  f ^ q Œ  ƒ } | rŒ | d d  k rŒ | d d !} n  |  j | ƒ S(   Niÿÿÿÿi    (   R   t   tupleR   R   t   attrst   coerce(   t   clsR   t   mclsR   t   p(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR   h   s    	Mc         C   s   t  |  j | ƒ S(   N(   t   EntityRegistryt   root(   R,   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt
   per_mapperu   s    c         C   s   t  j d „  | |  j ƒ S(   Nc         S   s   |  | S(   N(    (   t   prevt   next(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   <lambda>}   s    (   R   t   reduceR0   (   R,   t   raw(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR+   {   s    c         C   sZ   | j  d t ƒ r  t |  | ƒ S| j  d t ƒ rC t |  j | ƒ St j d | ƒ ‚ d  S(   Nt   :s   invalid token: %s(   t   endswitht   _WILDCARD_TOKENt   TokenRegistryt   _DEFAULT_TOKENR0   R   t   ArgumentError(   R   t   token(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR=      s
    c         C   s   t  j d „  | j |  ƒ S(   Nc         S   s   |  | S(   N(    (   R2   R3   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR4   ‰   s    (   R   R5   R   (   R   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   __add__‡   s    c         C   s   d |  j  j |  j f S(   Ns   %s(%r)(   t	   __class__t   __name__R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   __repr__Œ   s    N(   R@   t
   __module__t   __doc__R   R   R   R   R   R   t   propertyR   R   R!   R"   R$   R#   t   classmethodR   R1   R+   R=   R>   RA   (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR      s$   						
					t   RootRegistryc           B   s#   e  Z d  Z d Z e Z d „  Z RS(   sX   Root registry, defers to mappers so that
    paths are maintained per-root-mapper.

    c         C   s   | j  S(   N(   t   _path_registry(   R   t   entity(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   __getitem__˜   s    (    (   R@   RB   RC   R   R   t
   has_entityRI   (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRF      s   R:   c           B   s    e  Z d  „  Z e Z d „  Z RS(   c         C   s)   | |  _  | |  _ | j | f |  _ d  S(   N(   R=   t   parentR   (   R   RK   R=   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   __init__Ÿ   s    		c         C   s   t  ƒ  ‚ d  S(   N(   t   NotImplementedError(   R   RH   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRI   ¦   s    (   R@   RB   RL   R   RJ   RI   (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR:   ž   s   	t   PropRegistryc           B   s’   e  Z d  „  Z e j d „  ƒ Z e j d „  ƒ Z e j d „  ƒ Z e j d „  ƒ Z e j d „  ƒ Z	 e
 d „  ƒ Z e
 d „  ƒ Z d „  Z RS(	   c         C   sÁ   t  j | d ƒ } | j s& | j r9 | j | j } n_ | j r˜ | j r˜ | j | j k	 r˜ | j | j k r˜ | d j | j ƒ } | j | } q˜ n  | |  _ | |  _ | j	 | f |  _	 d  S(   Niÿÿÿÿ(
   R    t   inspectt   is_aliased_classt   _use_mapper_pathRK   t   with_polymorphic_mappersR   t   _entity_for_mappert   propR   (   R   RK   RT   t   inspt   subclass_entity(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRL   «   s    		c         C   s   t  |  j d ƒ S(   NR   (   t   hasattrRT   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRJ   »   s    c         C   s
   |  j  j S(   N(   RT   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRH   ¿   s    c         C   s)   d |  j  j d |  j j t f ƒ j f S(   sÐ   Given a path (mapper A, prop X), replace the prop with the wildcard,
        e.g. (mapper A, 'relationship:.*') or (mapper A, 'column:.*'), then
        return within the ("loader", path) structure.

        t   loaders   %s:%s(   RK   R=   RT   t   strategy_wildcard_keyR9   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   _wildcard_path_loader_keyÃ   s    	c         C   s)   d |  j  j d |  j j t f ƒ j f S(   NRX   s   %s:%s(   RK   R=   RT   RY   R;   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   _default_path_loader_keyÑ   s    	c         C   s   d |  j  f S(   NRX   (   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   _loader_keyÚ   s    c         C   s   |  j  S(   N(   RH   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR   Þ   s    c         C   s   |  |  j  S(   N(   RH   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   entity_pathâ   s    c         C   s1   t  | t t f ƒ r  |  j | St |  | ƒ Sd  S(   N(   t
   isinstancet   intt   sliceR   R/   (   R   RH   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRI   æ   s    (   R@   RB   RL   R   t   memoized_propertyRJ   RH   RZ   R[   R\   RD   R   R]   RI   (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRN   ª   s   		R/   c           B   sM   e  Z e Z e Z d  „  Z e d „  ƒ Z d „  Z	 e	 Z
 d „  Z d „  Z RS(   c         C   sG   | |  _  | |  _ | j |  _ | |  _ | j | f |  _ |  |  _ d  S(   N(   R   RK   RP   RH   R   R]   (   R   RK   RH   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRL   ó   s    			c         C   s   t  j |  j ƒ j S(   N(   R    RO   RH   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR   û   s    c         C   s   t  S(   N(   R   (   R   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   __bool__ÿ   s    c         C   s4   t  | t t f ƒ r  |  j | St j |  | ƒ Sd  S(   N(   R^   R_   R`   R   t   dictRI   (   R   RH   (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyRI     s    c         C   s   t  |  | ƒ |  | <} | S(   N(   RN   (   R   R   t   item(    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   __missing__	  s    (   R@   RB   R   RP   R   RJ   RL   RD   R   Rb   t   __nonzero__RI   Re   (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyR/   ï   s   			N(   RC   t    R    R   R   t	   itertoolsR   t   baseR   R   R9   R;   t   objectR   RF   R0   R:   RN   Rc   R/   (    (    (    sb   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/sqlalchemy/orm/path_registry.pyt   <module>	   s   	vE