o
    þÞh*  ã                   @   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
e
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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
   úQ/var/www/html/premium_crap/venv/lib/python3.10/site-packages/django/utils/tree.pyÚ__init__   s   
zNode.__init__c                 C   s   t ||p| j|ƒ}| |_|S )a  
        Create a new instance using Node() instead of __init__() as some
        subclasses, e.g. django.db.models.query_utils.Q, may implement a custom
        __init__() with a signature that conflicts with the one defined in
        Node.__init__().
        )r   r   Ú	__class__)Úclsr   r   r   Úobjr
   r
   r   Úcreate   s   zNode.createc                 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   | j | j| jd�}| j|_|S ©N)r   r   )r   r   r   r   )r	   r   r
   r
   r   Ú__copy__/   s   zNode.__copy__c                 C   s&   | j | j| jd�}t | j|¡|_|S r   )r   r   r   ÚcopyÚdeepcopyr   )r	   Úmemodictr   r
   r
   r   Ú__deepcopy__6   s   zNode.__deepcopy__c                 C   ó
   t | jƒS )z,Return the number of children this node has.)Úlenr   r   r
   r
   r   Ú__len__;   ó   
zNode.__len__c                 C   r"   )z-Return whether or not this node has children.)Úboolr   r   r
   r
   r   Ú__bool__?   r%   zNode.__bool__c                 C   s
   || j v S )z:Return True if 'other' is a direct child of this instance.)r   ©r	   Úotherr
   r
   r   Ú__contains__C   r%   zNode.__contains__c                 C   s0   | j |j ko| j|jko| j|jko| j|jkS r   )r   r   r   r   r(   r
   r
   r   Ú__eq__G   s   
ÿ
þ
üzNode.__eq__c                 C   s    t | j| j| jgt| jƒ¢R ƒS r   )Úhashr   r   r   r   r   r   r
   r
   r   Ú__hash__O   s   ýüÿzNode.__hash__c                 C   sn   | j |kr|  ¡ }|| _ ||g| _|S t|tƒr/|js/|j |ks&t|ƒdkr/| j |j¡ | S | j |¡ |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.
        é   )	r   r   r   Ú
isinstancer   r   r#   ÚextendÚappend)r	   ÚdataÚ	conn_typer   r
   r
   r   ÚaddY   s   

ÿþzNode.addc                 C   s   | j  | _ dS )z'Negate the sense of the root connector.N)r   r   r
   r
   r   Únegate|   s   zNode.negate)NNF)r   Ú
__module__Ú__qualname__Ú__doc__r   r   Úclassmethodr   r   r   r   r   r!   r$   r'   r*   r+   r-   r4   r5   r
   r
   r
   r   r      s$    

#r   )r8   r   Údjango.utils.hashabler   r   r
   r
   r
   r   Ú<module>   s    