U
    a                     @   s*   d Z ddlZddlmZ G dd dZdS )zT
A class for storing a tree graph. Primarily used for filter constructs in the
ORM.
    N)make_hashablec                   @   s~   e Zd ZdZdZdddZedddZd	d
 Zdd Z	dd Z
dd Zdd Zdd Zdd Zdd Zd ddZdd ZdS )!Nodez
    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.
    DEFAULTNFc                 C   s,   |r|dd ng | _ |p| j| _|| _dS )z@Construct a new Node. If no connector is given, use the default.N)childrendefault	connectornegated)selfr   r   r    r
   /home/adriano.carvalho/ftp/files/BrinquedotecaVirtual/brinquedotecavirtual/venv/lib/python3.8/site-packages/django/utils/tree.py__init__   s    zNode.__init__c                 C   s   t |||}| |_|S )a  
        Create a new instance of this class when new Nodes (or subclasses) are
        needed in the internal code in this class. Normally, it just shadows
        __init__(). However, subclasses with an __init__ signature that aren't
        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   	__class__)clsr   r   r   objr
   r
   r   _new_instance   s    
zNode._new_instancec                 C   s.   | j r
dnd}|| jddd | jD f S )Nz(NOT (%s: %s))z(%s: %s)z, c                 s   s   | ]}t |V  qd S N)str).0cr
   r
   r   	<genexpr>-   s     zNode.__str__.<locals>.<genexpr>)r   r   joinr   )r	   templater
   r
   r   __str__+   s    zNode.__str__c                 C   s   d| j j| f S )Nz<%s: %s>)r   __name__r	   r
   r
   r   __repr__/   s    zNode.__repr__c                 C   s,   t | j| jd}| j|_t| j||_|S )N)r   r   )r   r   r   r   copydeepcopyr   )r	   Zmemodictr   r
   r
   r   __deepcopy__2   s    zNode.__deepcopy__c                 C   s
   t | jS )z,Return the number of children this node has.)lenr   r   r
   r
   r   __len__8   s    zNode.__len__c                 C   s
   t | jS )z-Return whether or not this node has children.)boolr   r   r
   r
   r   __bool__<   s    zNode.__bool__c                 C   s
   || j kS )z:Return True if 'other' is a direct child of this instance.)r   r	   otherr
   r
   r   __contains__@   s    zNode.__contains__c                 C   s0   | j |j ko.| j| jf|j|jfko.| j|jkS r   )r   r   r   r   r#   r
   r
   r   __eq__D   s
    
zNode.__eq__c                 C   s   t | j| j| jft| jS r   )hashr   r   r   r   r   r   r
   r
   r   __hash__K   s    zNode.__hash__Tc                 C   s   || j kr|S |s"| j | |S | j|krvt|trd|jsd|j|ksRt|dkrd| j |j  | S | j | |S n(| | j | j| j}|| _||g| _ |S dS )a/  
        Combine 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.

        Return 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.
           N)	r   appendr   
isinstancer   r   r   extendr   )r	   dataZ	conn_typeZsquashr   r
   r
   r   addN   s*    



zNode.addc                 C   s   | j  | _ dS )z'Negate the sense of the root connector.N)r   r   r
   r
   r   negatez   s    zNode.negate)NNF)NNF)T)r   
__module____qualname____doc__r   r   classmethodr   r   r   r   r    r"   r%   r&   r(   r.   r/   r
   r
   r
   r   r      s   

,r   )r2   r   Zdjango.utils.hashabler   r   r
   r
   r
   r   <module>   s   