ó
i4Vdc           @   s,   d  Z  d d l Z d e f d „  ƒ  YZ d S(   sT   
A class for storing a tree graph. Primarily used for filter constructs in the
ORM.
iÿÿÿÿNt   Nodec           B   s’   e  Z d  Z d Z d d e d „ Z e d d e d „ ƒ Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d	 „  Z d
 „  Z e d „ Z d „  Z RS(   s±   
    A single internal node in the tree graph. A Node should be viewed as a
    connection (the root) with the children being either leaf nodes or other
    Node instances.
    t   DEFAULTc         C   s5   | r | n g  |  _  | p" |  j |  _ | |  _ d S(   sd   
        Constructs a new Node. If no connector is given, the default will be
        used.
        N(   t   childrent   defaultt	   connectort   negated(   t   selfR   R   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   __init__   s    c         C   s   t  | | | ƒ } |  | _ | S(   s¹  
        This is called to create a new instance of this class when we need new
        Nodes (or subclasses) in the internal code in this class. Normally, it
        just shadows __init__(). However, subclasses with an __init__ signature
        that is not an extension of Node.__init__ might need to implement this
        method to allow a Node to create a new instance of them (if they have
        any extra setting up to do).
        (   R    t	   __class__(   t   clsR   R   R   t   obj(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   _new_instance   s    
	c         C   sW   |  j  r0 d |  j d j d „  |  j Dƒ ƒ f Sd |  j d j d „  |  j Dƒ ƒ f S(   Ns   (NOT (%s: %s))s   , c         s   s   |  ] } t  | ƒ Vq d  S(   N(   t   str(   t   .0t   c(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pys	   <genexpr>.   s    s   (%s: %s)c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R   (   R   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pys	   <genexpr>0   s    (   R   R   t   joinR   (   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   __str__,   s
    	c         C   s   d |  j  j |  f S(   Ns   <%s: %s>(   R   t   __name__(   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   __repr__3   s    c         C   sC   t  d |  j d |  j ƒ } |  j | _ t j |  j | ƒ | _ | S(   s9   
        Utility method used by copy.deepcopy().
        R   R   (   R    R   R   R   t   copyt   deepcopyR   (   R   t   memodictR
   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   __deepcopy__6   s    c         C   s   t  |  j ƒ S(   sF   
        The size of a node if the number of children it has.
        (   t   lenR   (   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   __len__?   s    c         C   s   t  |  j ƒ S(   s*   
        For truth value testing.
        (   t   boolR   (   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   __bool__E   s    c         C   s   t  |  ƒ j |  ƒ S(   N(   t   typeR   (   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   __nonzero__K   s    c         C   s   | |  j  k S(   sM   
        Returns True is 'other' is a direct child of this instance.
        (   R   (   R   t   other(    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   __contains__N   s    c         C   sâ   | |  j  k r | S| s- |  j  j | ƒ | S|  j | k r¤ t | t ƒ r | j r | j | k sv t | ƒ d k r |  j  j | j  ƒ |  S|  j  j | ƒ | Sn: |  j |  j  |  j |  j ƒ } | |  _ | | g |  _  | Sd S(   s>  
        Combines this tree and the data represented by data using the
        connector conn_type. The combine is done by squashing the node other
        away if possible.

        This tree (self) will never be pushed to a child node of the
        combined tree, nor will the connector or negated properties change.

        The function returns a node which can be used in place of data
        regardless if the node other got squashed or not.

        If `squash` is False the data is prepared and added as a child to
        this tree without further logic.
        i   N(	   R   t   appendR   t
   isinstanceR    R   R   t   extendR   (   R   t   datat	   conn_typet   squashR
   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   addT   s"    !	c         C   s   |  j  |  _  d S(   s9   
        Negate the sense of the root connector.
        N(   R   (   R   (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   negate€   s    N(   R   t
   __module__t   __doc__R   t   Nonet   FalseR   t   classmethodR   R   R   R   R   R   R   R   t   TrueR%   R&   (    (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyR    	   s   								,(   R(   R   t   objectR    (    (    (    s_   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/utils/tree.pyt   <module>   s   