File indexing completed on 2025-01-19 03:59:53

0001 import enum
0002 from xml.etree import ElementTree
0003 
0004 
0005 class SvgHandler:
0006     ns_map = {
0007         "dc": "http://purl.org/dc/elements/1.1/",
0008         "cc": "http://creativecommons.org/ns#",
0009         "rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
0010         "svg": "http://www.w3.org/2000/svg",
0011         "sodipodi": "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd",
0012         "inkscape": "http://www.inkscape.org/namespaces/inkscape",
0013         "xlink": "http://www.w3.org/1999/xlink",
0014     }
0015 
0016     def init_etree(self):
0017         for n, u in self.ns_map.items():
0018             ElementTree.register_namespace(n, u)
0019 
0020     def qualified(self, ns, name):
0021         return "{%s}%s" % (self.ns_map[ns], name)
0022 
0023     def simplified(self, name):
0024         for k, v in self.ns_map.items():
0025             name = name.replace("{%s}" % v, k+":")
0026         return name
0027 
0028     def unqualified(self, name):
0029         return name.split("}")[-1]
0030 
0031     def __init__(self):
0032         self.init_etree()
0033 
0034 
0035 class NameMode(enum.Enum):
0036     NoName = 0
0037     Id = 1
0038     Inkscape = 2