MCPcopy
hub / github.com/django/django / add

Method add

django/utils/tree.py:89–122  ·  view source on GitHub ↗

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

(self, data, conn_type)

Source from the content-addressed store, hash-verified

87 )
88
89 def add(self, data, conn_type):
90 """
91 Combine this tree and the data represented by data using the
92 connector conn_type. The combine is done by squashing the node other
93 away if possible.
94
95 This tree (self) will never be pushed to a child node of the
96 combined tree, nor will the connector or negated properties change.
97
98 Return a node which can be used in place of data regardless if the
99 node other got squashed or not.
100 """
101 if self.connector != conn_type:
102 obj = self.copy()
103 self.connector = conn_type
104 self.children = [obj, data]
105 return data
106 elif (
107 isinstance(data, Node)
108 and not data.negated
109 and (data.connector == conn_type or len(data) == 1)
110 ):
111 # We can squash the other node's children directly into this node.
112 # We are just doing (AB)(CD) == (ABCD) here, with the addition that
113 # if the length of the other node is 1 the connector doesn't
114 # matter. However, for the len(self) == 1 case we don't want to do
115 # the squashing, as it would alter self.connector.
116 self.children.extend(data.children)
117 return self
118 else:
119 # We could use perhaps additional logic here to see if some
120 # children could be used for pushdown here.
121 self.children.append(data)
122 return data
123
124 def negate(self):
125 """Negate the sense of the root connector."""

Callers 15

test_addMethod · 0.95
iter_modules_and_filesFunction · 0.45
watch_dirMethod · 0.45
snapshot_filesMethod · 0.45
patch_cache_controlFunction · 0.45
_populateMethod · 0.45
do_translateFunction · 0.45
reorder_testsFunction · 0.45
get_catalogMethod · 0.45
css_classesMethod · 0.45

Calls 3

extendMethod · 0.80
copyMethod · 0.45
appendMethod · 0.45

Tested by 2

test_addMethod · 0.76