o 3a6@s*dZddlZddlmZGdddZdS)zT A class for storing a tree graph. Primarily used for filter constructs in the ORM. N) make_hashablec@s~eZdZdZdZdddZedddZd d Zd d Z d dZ ddZ ddZ ddZ ddZddZdddZddZdS) 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. DEFAULTNFcCs,|r|ddng|_|p|j|_||_dS)z@Construct a new Node. If no connector is given, use the default.N)childrendefault connectornegated)selfrrrr 3/usr/lib/python3/dist-packages/django/utils/tree.py__init__s  z Node.__init__cCst|||}||_|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__)clsrrrobjr r r _new_instances zNode._new_instancecCs.|jrdnd}||jddd|jDfS)Nz(NOT (%s: %s))z(%s: %s)z, css|]}t|VqdSN)str).0cr r r -szNode.__str__..)rrjoinr)r templater r r __str__+s z Node.__str__cCsd|jj|fS)Nz<%s: %s>)r __name__r r r r __repr__/sz Node.__repr__cCs,t|j|jd}|j|_t|j||_|S)N)rr)rrrr copydeepcopyr)r memodictrr r r __deepcopy__2szNode.__deepcopy__cC t|jS)z,Return the number of children this node has.)lenrrr r r __len__8 z Node.__len__cCr )z-Return whether or not this node has children.)boolrrr r r __bool__<r#z Node.__bool__cCs ||jvS)z:Return True if 'other' is a direct child of this instance.)rr otherr r r __contains__@r#zNode.__contains__cCs0|j|jko|j|jf|j|jfko|j|jkSr)r rrrr&r r r __eq__Ds  z Node.__eq__cCs t|j|j|jgt|jRSr)hashr rrrrrr r r __hash__Ks z Node.__hash__TcCs|j|kr ||jvr |S|s|j||S|j|kr?t|tr7|js7|j|ks.t|dkr7|j|j|S|j||S||j|j|j}||_||g|_|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. ) rrappend isinstancerrr!extendr)r data conn_typesquashrr r r addNs$     zNode.addcCs|j |_dS)z'Negate the sense of the root connector.N)rrr r r negatezsz Node.negate)NNF)T)r __module__ __qualname____doc__rr classmethodrrrrr"r%r(r)r+r3r4r r r r r s      ,r)r7rdjango.utils.hashablerrr r r r s