Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"Unable to resolve image path '%s' as the SVG source is not "
"a file system path." % iri
)
return None
path = os.path.normpath(os.path.join(os.path.dirname(self.source_path), iri))
if not os.access(path, os.R_OK):
return None
if path == self.source_path:
# Self-referencing, ignore the IRI part
iri = None
if iri:
if path.endswith('.svg'):
if path in self._parent_chain:
logger.error("Circular reference detected in file.")
raise CircularRefError()
if path not in self._external_svgs:
self._external_svgs[path] = ExternalSVG(path, self)
ext_svg = self._external_svgs[path]
if ext_svg.root_node is not None:
if fragment:
ext_frag = ext_svg.get_fragment(fragment)
if ext_frag is not None:
return ext_svg.renderer, ext_frag
else:
return ext_svg.renderer, ext_svg.root_node
else:
# A raster image path
try:
# This will catch invalid images
PDFImage(path, 0, 0)
except IOError:
def renderUse(self, node, group=None, clipping=None):
if group is None:
group = Group()
try:
item = self.xlink_href_target(node, group=group)
except CircularRefError:
node.parent.object.remove(node.object)
return group
if item is None:
return
elif isinstance(item, str):
logger.error(" nodes cannot reference bitmap image files")
return
elif item is DELAYED:
return group
else:
item = item[1] # [0] is the renderer, not used here.
if clipping:
group.add(clipping)
if len(node.getchildren()) == 0:
# Append a copy of the referenced node as the child (if not already done)