diff SrvTxtUtils.py @ 49:e40ff9829108

improved old project inline image handling.
author casties
date Mon, 29 Apr 2013 18:00:46 +0200
parents 54f135c1ed65
children 63184d71c014
line wrap: on
line diff
--- a/SrvTxtUtils.py	Mon Apr 29 16:02:24 2013 +0200
+++ b/SrvTxtUtils.py	Mon Apr 29 18:00:46 2013 +0200
@@ -10,7 +10,9 @@
 import urllib2
 import logging
 
-srvTxtUtilsVersion = "1.6"
+import xml.etree.ElementTree as ET
+
+srvTxtUtilsVersion = "1.7"
 
 map_months = {'en': [u"",
                u"January",
@@ -76,7 +78,7 @@
         return s.encode('utf-8')
 
 def getText(node, recursive=0):
-    """returns all text content of a node and its subnodes"""
+    """returns all text content of a (etree) node and its subnodes"""
     if node is None:
         return ''
     
@@ -99,6 +101,18 @@
     
     return text
 
+
+def serialize(node):
+    """returns a string containing an XML snippet of (etree) node"""
+    s = ET.tostring(node, 'UTF-8')
+    # snip off XML declaration
+    if s.startswith('<?xml'):
+        i = s.find('?>')
+        return s[i+3:]
+
+    return s
+
+
 def getMonthName(mon, lang):
     """returns the name of the month mon in the language lang"""
     return map_months[lang][mon]