Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testPartialStyleName(self):
doc = ElementTree.fromstring(self.svg).find('./' + dom.ns('g'))
ruleset = style._parse_css(self.css1)
dom.apply_rule(doc, ruleset.rules[0])
svg = ElementTree.tostring(doc, encoding='utf-8').decode('utf-8')
self.assertNotIn('orange', svg)
inlined = style.inline(self.svg, self.css1)
self.assertNotIn('orange', inlined)
* ``.class``
* ``tag``
* ``tag.class``
* ``#layer .class``
* ``#layer tag``
Args:
svg (string): An SVG document.
css (string): CSS to use, instead of the CSS in the
root, ext = os.path.splitext(style)
if ext == '.css' or root == '/dev/stdin':
with open(style) as f:
style = _uncomment(f.read())
try:
svg = ElementTree.parse(svgfile).getroot()
except IOError:
try:
svg = ElementTree.fromstring(svgfile)
except UnicodeDecodeError:
svg = ElementTree.fromstring(svgfile.encode('utf-8'))
if svg.find(dom.ns('defs')) is not None:
defs = svg.find(dom.ns('defs'))
else:
defs = ElementTree.Element(dom.ns('defs'))
svg.insert(0, defs)
if defs.find(dom.ns('style')) is not None:
style_element = defs.find(dom.ns('style'))
if not replace:
# Append CSS.
style = (style_element.text or '') + ' ' + style
style_element.text = ''
else:
style_element = ElementTree.Element(dom.ns('style'))
else:
defs = ElementTree.Element(dom.ns('defs'))
svg.insert(0, defs)
if defs.find(dom.ns('style')) is not None:
style_element = defs.find(dom.ns('style'))
if not replace:
# Append CSS.
style = (style_element.text or '') + ' ' + style
style_element.text = ''
else:
style_element = ElementTree.Element(dom.ns('style'))
defs.append(style_element)
style_element.append(dom.cdata(style))
return ElementTree.tostring(svg, encoding='utf-8').decode('utf-8')
svg = ElementTree.parse(svgfile).getroot()
except IOError:
try:
svg = ElementTree.fromstring(svgfile)
except UnicodeDecodeError:
svg = ElementTree.fromstring(svgfile.encode('utf-8'))
if svg.find(dom.ns('defs')) is not None:
defs = svg.find(dom.ns('defs'))
else:
defs = ElementTree.Element(dom.ns('defs'))
svg.insert(0, defs)
if defs.find(dom.ns('style')) is not None:
style_element = defs.find(dom.ns('style'))
if not replace:
# Append CSS.
style = (style_element.text or '') + ' ' + style
style_element.text = ''
else:
style_element = ElementTree.Element(dom.ns('style'))
defs.append(style_element)
style_element.append(dom.cdata(style))
return ElementTree.tostring(svg, encoding='utf-8').decode('utf-8')
with open(style) as f:
style = _uncomment(f.read())
try:
svg = ElementTree.parse(svgfile).getroot()
except IOError:
try:
svg = ElementTree.fromstring(svgfile)
except UnicodeDecodeError:
svg = ElementTree.fromstring(svgfile.encode('utf-8'))
if svg.find(dom.ns('defs')) is not None:
defs = svg.find(dom.ns('defs'))
else:
defs = ElementTree.Element(dom.ns('defs'))
svg.insert(0, defs)
if defs.find(dom.ns('style')) is not None:
style_element = defs.find(dom.ns('style'))
if not replace:
# Append CSS.
style = (style_element.text or '') + ' ' + style
style_element.text = ''
else:
style_element = ElementTree.Element(dom.ns('style'))
defs.append(style_element)
style_element.append(dom.cdata(style))
def rescale(svgfile, factor):
_register()
svg = ElementTree.parse(svgfile)
scalar = 'scale({})'.format(factor)
g = svg.getroot().find(dom.ns('g'))
g.attrib['transform'] = (g.attrib.get('transform') + ' ' + scalar).strip()
return ElementTree.tostring(svg.getroot(), encoding='utf-8').decode('utf-8')