]> gitweb.michael.orlitzky.com - dead/census-tools.git/commitdiff
Added XML escaping to the KML classes.
authorMichael Orlitzky <michael@orlitzky.com>
Wed, 21 Oct 2009 05:41:50 +0000 (01:41 -0400)
committerMichael Orlitzky <michael@orlitzky.com>
Wed, 21 Oct 2009 05:41:50 +0000 (01:41 -0400)
src/KML.py

index 4b6d12f3fdcfcb47eace8548ea3566b1d7e7b999..f96adb26272c56563ced80ef3636623e024db173 100644 (file)
@@ -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