Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""Search an attribute with some name in some node or above.
First the node is searched, then its style attribute, then
the search continues in the node's parent node. If no such
attribute is found, '' is returned.
"""
# This needs also to lookup values like "url(#SomeName)"...
if not svgNode.attrib.get('__rules_applied', False):
# Apply global styles...
if self.css_rules is not None:
if isinstance(svgNode, NodeTracker):
svgNode.apply_rules(self.css_rules)
else:
ElementWrapper(svgNode).apply_rules(self.css_rules)
# ...and locally defined
if svgNode.attrib.get("style"):
attrs = self.parseMultiAttributes(svgNode.attrib.get("style"))
for key, val in attrs.items():
# lxml nodes cannot accept attributes starting with '-'
if not key.startswith('-'):
svgNode.attrib[key] = val
svgNode.attrib['__rules_applied'] = '1'
attr_value = svgNode.attrib.get(name, '').strip()
if attr_value and attr_value != "inherit":
return attr_value
if svgNode.getparent() is not None:
return self.findAttr(svgNode.getparent(), name)
return ''