Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def parent(self):
par = self.object.getparent()
return ElementWrapper(par) if par is not None else None
def apply_rules(self, rules):
matches = rules.match(self)
for match in matches:
attr_dict = match[3][1]
for attr, val in attr_dict.items():
if attr not in self.object.attrib:
try:
self.object.attrib[attr] = val
except ValueError:
pass
# Set marker on the node to not apply rules more than once
self.object.set('__rules_applied', '1')
class NodeTracker(ElementWrapper):
"""An object wrapper keeping track of arguments to certain method calls.
Instances wrap an object and store all arguments to one special
method, getAttribute(name), in a list of unique elements, usedAttrs.
"""
def __init__(self, obj):
super().__init__(obj)
self.usedAttrs = []
def __repr__(self):
return '' % self.object
def getAttribute(self, name):
# add argument to the history, if not already present
if name not in self.usedAttrs: