From: Michael Orlitzky Date: Wed, 21 Oct 2009 05:41:50 +0000 (-0400) Subject: Added XML escaping to the KML classes. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=28d3599ef601b5ad3fff3b630cbd2b87f4c65dbd;p=dead%2Fcensus-tools.git Added XML escaping to the KML classes. --- diff --git a/src/KML.py b/src/KML.py index 4b6d12f..f96adb2 100644 --- a/src/KML.py +++ b/src/KML.py @@ -3,6 +3,7 @@ Utility classes for working with the Keyhole Markup Language (KML). """ import sys +from xml.sax.saxutils import escape class KmlObject(object): @@ -36,7 +37,7 @@ class KmlObject(object): def render(self): kml = self.OPEN_TAG - kml += self.text + kml += escape(self.text) for c in self.children: kml += c.to_kml() @@ -53,8 +54,8 @@ class KmlObject(object): def render_to_stdout(self): - if not (len(self.text) == 0): - print self.text + if (len(self.text) > 0): + print escape(self.text) for c in self.children: c.print_kml() @@ -164,4 +165,10 @@ class StyleUrl(KmlObject): class RawText(KmlObject): - pass + + def to_kml(self): + return self.text + + def print_kml(self): + if (len(self.text) > 0): + print self.text