ó
Ñ7ec           @   sB   d  Z  d d l Z d d l m Z m 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˙˙˙˙N(   t	   force_strt
   force_textt   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;   /usr/local/lib/python2.7/dist-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;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   _new_instance    s    
	c         C   sB   |  j  r d n d } t | |  j d j d   |  j D  f  S(   Ns   (NOT (%s: %s))s   (%s: %s)s   , c         s   s   |  ] } t  |  Vq d  S(   N(   R   (   t   .0t   c(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pys	   <genexpr>0   s    (   R   R    R   t   joinR   (   R   t   template(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   __str__.   s    c         C   s   t  d  |  j j |  f S(   Ns   <%s: %s>(   t   strR
   t   __name__(   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   __repr__2   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;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   __deepcopy__5   s    c         C   s   t  |  j  S(   sF   
        The size of a node if the number of children it has.
        (   t   lenR   (   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   __len__>   s    c         C   s   t  |  j  S(   s*   
        For truth value testing.
        (   t   boolR   (   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   __bool__D   s    c         C   s   t  |   j |   S(   N(   t   typeR   (   R   (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   __nonzero__J   s    c         C   s   | |  j  k S(   sM   
        Returns True is 'other' is a direct child of this instance.
        (   R   (   R   t   other(    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   __contains__M   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;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   addS   s"    !	c         C   s   |  j  |  _  d S(   s9   
        Negate the sense of the root connector.
        N(   R   (   R   (    (    s;   /usr/local/lib/python2.7/dist-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;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyR      s   								,(   R+   R   t   django.utils.encodingR    R   t   objectR   (    (    (    s;   /usr/local/lib/python2.7/dist-packages/django/utils/tree.pyt   <module>   s   