Best Python code snippet using dbt-osmosis_python
binarytree.py
Source:binarytree.py
...155 if parent._leftchild is self: # Set parent's child ref to None156 parent._leftchild = None157 elif parent._rightchild is self:158 parent._rightchild = None159 self._clear_node() # Clear the current node160 elif not self._rightchild:161 leftchild = self._leftchild162 self._element = leftchild._element # Move item from left to self163 if leftchild._leftchild: # Link leftchild's leftchild to self164 self._leftchild = leftchild._leftchild165 leftchild._leftchild._parent = self166 else:167 self._leftchild = None168 if leftchild._rightchild: # Link leftchild's rightchild to self169 self._rightchild = leftchild._rightchild170 leftchild._rightchild._parent = self171 else:172 self._rightchild = None173 leftchild._clear_node() # Clear the node that was removed174 else:175 rightchild = self._rightchild176 self._element = rightchild._element177 if rightchild._leftchild:178 rightchild._leftchild._parent = self179 self._leftchild = rightchild._leftchild180 else:181 self._leftchild = None182 if rightchild._rightchild:183 rightchild._rightchild._parent = self184 self._rightchild = rightchild._rightchild185 else:186 self._rightchild = None187 rightchild._clear_node() # Clear the node that was removed188 if parent:189 parent._rebalance()190 return original_item191 def _rebalance(self):192 """Check if the node needs rebalancing.193 Update the height of the current node and, if necessary, rebalance194 the tree, maintaining BST properties.195 """196 prev_height = self._height # Save current height for comparison later197 self._height = self.height() # Update the height of the node198 if self._unbalanced():199 if self.full():200 if self._leftchild._height > self._rightchild._height:201 self._restructure_leftchild() # If left causes unbalance202 else:203 self._restructure_rightchild()204 elif self._leftchild and not self._rightchild:205 self._restructure_leftchild()206 else:207 self._restructure_rightchild()208 if self._parent:209 self._parent._rebalance() # Rebalance the node's parent210 elif self._height != prev_height and self._parent:211 self._parent._rebalance() # Rebalance parent if height changed212 def _restructure_leftchild(self):213 """Restructure the leftchild, doing a double rotation if necessary."""214 left = self._leftchild215 if left.full(): # If left has both children216 if left._rightchild._height > left._leftchild._height:217 left._rotate_rightchild() # Double rotate if right unbalanced218 elif left._rightchild and not left._leftchild:219 left._rotate_rightchild()220 self._rotate_leftchild()221 def _restructure_rightchild(self):222 """Restructure the rightchild, doing a double rotation if necessary."""223 right = self._rightchild224 if right.full(): # If right has both children225 if right._leftchild._height > right._rightchild._height:226 right._rotate_leftchild() # Double rotate if left unbalanced227 elif right._leftchild and not right._rightchild:228 right._rotate_leftchild()229 self._rotate_rightchild()230 def _rotate_leftchild(self):231 """Rotate the leftchild into the node."""232 left = self._leftchild233 self_item = self._element # Save current item in self234 self._element = left._element # Move item from leftchild into self235 left._element = self_item # Move item from self into leftchild236 if left._leftchild: # Link to self if left has leftchild237 self._leftchild = left._leftchild238 left._leftchild._parent = self # Update parent link239 else:240 self._leftchild = None241 if left._rightchild: # Move rightchild into leftchild242 left._leftchild = left._rightchild243 else:244 left._leftchild = None245 if self._rightchild: # If self had a rightchild246 left._rightchild = self._rightchild # Link to the other node247 self._rightchild._parent = left # Update parent link248 else:249 left._rightchild = None250 self._rightchild = left # Now link the rotated node to self251 self._height = self.height() # Self changed position, update height252 left._height = left.height()253 def _rotate_rightchild(self):254 """Rotate the rightchild into the node."""255 right = self._rightchild256 self_item = self._element257 self._element = right._element258 right._element = self_item259 if right._rightchild:260 self._rightchild = right._rightchild261 right._rightchild._parent = self262 else:263 self._rightchild = None264 if right._leftchild:265 right._rightchild = right._leftchild266 else:267 right._rightchild = None268 if self._leftchild:269 right._leftchild = self._leftchild270 self._leftchild._parent = right271 else:272 right._leftchild = None273 self._leftchild = right274 self._height = self.height()275 right._height = right.height()276 def _unbalanced(self):277 """Check if the node is unbalanced.278 Returns:279 True if the difference between the heights of the node's children280 is greater that or equal to 2, False otherwise281 """282 if self.internal():283 if self.full():284 if abs(self._leftchild._height-self._rightchild._height) >= 2:285 return True286 elif self._leftchild and not self._rightchild:287 if self._leftchild._height >= 2:288 return True289 elif self._rightchild._height >= 2:290 return True291 return False292 def _clear_node(self):293 """Set all attributes in node to None."""294 self._element = None295 self._parent = None296 self._leftchild = None297 self._rightchild = None...
node_view.py
Source:node_view.py
...84 self._tree.collexp(self._node_id)85 def _set_loading_mode(self):86 node = self._tree.node(self._node_id)87 data = node["data"]88 self._clear_node()89 # label title90 label_title = tk.Label(self._body, name="label_info_title",91 text="{}: ".format(data["name"]))92 #label_title.pack(side=tk.LEFT, padx=0)93 label_title.grid(column=0, row=0, sticky="w", padx=0)94 # label info95 label_info = tk.Label(self._body, text="Loading...")96 #label_info.pack(side=tk.LEFT, padx=0)97 label_info.grid(column=1, row=0, sticky="w", padx=0)98 def _clear_node(self):99 for child in self._body.winfo_children():100 child.destroy()101 def _set_description_layout(self, data):102 self._clear_node()103 # title104 text = self._tree.node(self._node_id)["data"]["name"]105 label_title = tk.Label(self._body, name="label_info_title", text=text)106 label_title.grid(column=0, row=0, sticky="w")107 # description108 text = data["description"]109 text = "- No description -" if text is None else text110 entry_description = tk.Entry(self._body, name="entry_repo_description",111 width=70)112 entry_description.insert(0, text)113 entry_description.config(state="readonly")114 entry_description.grid(column=0, row=1, sticky="w")115 # creation date116 text = "Created on {} UTC".format(data["created_at"])117 label_date = tk.Label(self._body, text=text)118 label_date.grid(column=0, row=2, sticky="w")119 # stargazers/subscribers120 stargazers_count = data["stargazers_count"]121 subscribers_count = data["subscribers_count"]122 suffix_str_stargazers = "s" if stargazers_count > 1 else ""123 suffix_str_subscribers = "s" if subscribers_count > 1 else ""124 text = "{} Stargazer{} and {} Subscriber{}".format(stargazers_count,125 suffix_str_stargazers,126 subscribers_count,127 suffix_str_subscribers)128 label_stargazers = tk.Label(self._body, name="label_counts",129 text=text)130 label_stargazers.grid(column=0, row=3, sticky="w")131 # button refresh132 button_refresh = tk.Button(self._body, name="button_refresh",133 text="Refresh", command=self.populate)134 button_refresh.grid(column=0, row=4, sticky="w", pady=5)135 def _set_latest_release_layout(self, data):136 self._clear_node()137 # title138 text = self._tree.node(self._node_id)["data"]["name"]139 label_title = tk.Label(self._body, name="label_info_title", text=text)140 label_title.grid(column=0, row=0, sticky="w")141 # name142 text = "Tag name: {}".format(data["tag_name"])143 label_name = tk.Label(self._body, text=text)144 label_name.grid(column=0, row=1, sticky="w")145 # creation date146 text = "Published on {} UTC".format(data["published_at"])147 label_date = tk.Label(self._body, text=text)148 label_date.grid(column=0, row=2, sticky="w")149 # downloads150 downloads_count = data["downloads_count"]151 suffix_str_downloads = "s" if downloads_count > 1 else ""152 text = "{} Download{}".format(downloads_count, suffix_str_downloads)153 label_downloads = tk.Label(self._body, name="label_counts",154 text=text)155 label_downloads.grid(column=0, row=3, sticky="w")156 # button refresh157 button_refresh = tk.Button(self._body,158 name="button_refresh",159 text="Refresh", command=self.populate)160 button_refresh.grid(column=0, row=4, sticky="w", pady=5)161 def _set_total_downloads_layout(self, data):162 self._clear_node()163 # title164 text = self._tree.node(self._node_id)["data"]["name"]165 label_title = tk.Label(self._body, name="label_info_title", text=text)166 label_title.grid(column=0, row=0, sticky="w")167 # name168 suffix_str_downloads = "s" if data > 1 else ""169 text = "{} Download{}".format(data, suffix_str_downloads)170 label_downloads = tk.Label(self._body, name="label_counts",171 text=text)172 label_downloads.grid(column=0, row=1, sticky="w")173 # button refresh174 button_refresh = tk.Button(self._body, name="button_refresh",175 text="Refresh", command=self.populate)176 button_refresh.grid(column=0, row=2, sticky="w", pady=5)177 def _set_failure_layout(self, datatype, status_code, status_text):178 self._clear_node()179 name = self._tree.node(self._node_id)["data"]["name"]180 # frame181 frame_title = tk.Frame(self._body)182 frame_title.grid(column=0, row=0, sticky="w")183 # label title failure184 label_title = tk.Label(frame_title, name="label_info_title",185 text="{}: ".format(name))186 label_title.pack(side=tk.LEFT, padx=0)187 # label info188 label_info = tk.Label(frame_title, name="label_error",189 text=status_text)190 label_info.pack(side=tk.LEFT, padx=0)191 # button192 button_retry = tk.Button(self._body, name="button_retry",...
priberam.py
Source:priberam.py
...89 return res90 def _parse(self, xml):91 root = ET.fromstring(xml)92 word = root[3][0][0][0].text93 def _clear_node(n):94 n.attrib = {}95 n._children = []96 n.text = ''97 map(_clear_node, root.findall('.//*[@class="varpb"]'))98 map(_clear_node, root.findall('.//*[@class="dAO"]'))99 for n in root.findall('.//*[@style]'):100 if 'visibility:hidden' in n.attrib['style']:101 _clear_node(n)102 t = ''103 tag = ''104 for c in root[3][0][1:]:105 if c.tag == 'span':106 if len(c) > 0:107 t += '_%s_\n' % c[0].attrib.get('title')108 elif c.tag == 'div':109 if c.text:110 t += '%s\n' % c.text.strip()111 else:112 prefix = ''113 tail = ''114 for d in c:115 if tail:...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!