diff options
author | Thomas Bruederli <bruederli@kolabsys.com> | 2015-03-26 10:22:43 +0100 |
---|---|---|
committer | Thomas Bruederli <bruederli@kolabsys.com> | 2015-03-26 10:22:43 +0100 |
commit | 035978ff20b1336ec2db06e3f73a4449ea9ddb72 (patch) | |
tree | a2c2ee7cbdcd04d49375f9cef1660f2600b914f1 | |
parent | 7566d1439506543bdf885a3350e4363dde109fdd (diff) | |
download | pykolab-035978ff20b1336ec2db06e3f73a4449ea9ddb72.tar.gz |
Move ustr() to xml utilities module
-rw-r--r-- | pykolab/xml/utils.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/pykolab/xml/utils.py b/pykolab/xml/utils.py index 261e33c..9d80f9c 100644 --- a/pykolab/xml/utils.py +++ b/pykolab/xml/utils.py @@ -127,6 +127,24 @@ def dates_equal(a, b): return type(a) == type(b) and a.strftime(date_format) == b.strftime(date_format) +def ustr(s): + """ + Force the given (unicode) string into UTF-8 encoding + """ + if not isinstance(s, unicode): + for cs in ['utf-8','latin-1']: + try: + s = unicode(s, cs) + break + except: + pass + + if isinstance(s, unicode): + return s.encode('utf-8') + + return s + + property_labels = { "name": N_("Name"), "summary": N_("Summary"), |