changeset 628:447251b5af65

make sure utf8ify and unicodify output text.
author casties
date Wed, 11 Feb 2015 17:18:23 +0100
parents 98fe8e168c01
children e36bf3226fde
files SrvTxtUtils.py
diffstat 1 files changed, 8 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/SrvTxtUtils.py	Mon Dec 15 17:59:59 2014 +0100
+++ b/SrvTxtUtils.py	Wed Feb 11 17:18:23 2015 +0100
@@ -22,7 +22,7 @@
 
 import xml.etree.ElementTree as ET
 
-srvTxtUtilsVersion = "1.13"
+srvTxtUtilsVersion = "1.13.1"
 
 map_months = {'en': [u"",
                      u"January",
@@ -94,18 +94,22 @@
             return s.decode('utf-8')
         except:
             return s.decode('latin-1')
+    elif isinstance(s, unicode):
+        return s
     else:
-        return s
+        return unicode(s)
 
 def utf8ify(s):
     """encode unicode object or string into byte string in utf-8 representation.
        assumes string objects to be utf-8"""
     if not s:
         return ""
-    if isinstance(s, str):
+    if isinstance(s, unicode):
+        return s.encode('utf-8')
+    elif isinstance(s, str):
         return s
     else:
-        return s.encode('utf-8')
+        return str(s)
 
 
 def getTextFromNode(node, recursive=False, length=0):