From 7a25b3a4e133c660a6a9f9a4f5cf3101209ec6de Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 14 Feb 2019 17:43:44 +0000 Subject: [PATCH] factor out _strip_xml_ns into its own function --- Lib/fontTools/svgLib/path/shapes.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Lib/fontTools/svgLib/path/shapes.py b/Lib/fontTools/svgLib/path/shapes.py index 05255f459..a83274e4b 100644 --- a/Lib/fontTools/svgLib/path/shapes.py +++ b/Lib/fontTools/svgLib/path/shapes.py @@ -10,6 +10,12 @@ def _ntos(n): return ('%.3f' % n).rstrip('0').rstrip('.') +def _strip_xml_ns(tag): + # ElementTree API doesn't provide a way to ignore XML namespaces in tags + # so we here strip them ourselves: cf. https://bugs.python.org/issue18304 + return tag.split('}', 1)[1] if '}' in tag else tag + + class PathBuilder(object): def __init__(self): self.paths = [] @@ -111,9 +117,7 @@ class PathBuilder(object): self.A(r, r, cx - r, cy, large_arc=1) def add_path_from_element(self, el): - tag = el.tag - if '}' in el.tag: - tag = el.tag.split('}', 1)[1] # from https://bugs.python.org/issue18304 + tag = _strip_xml_ns(el.tag) parse_fn = getattr(self, '_parse_%s' % tag.lower(), None) if not callable(parse_fn): return False