--- VSyncer/BaseSyncer.py 2008/01/02 19:01:35 1.1 +++ VSyncer/BaseSyncer.py 2008/01/04 15:34:43 1.2 @@ -13,6 +13,28 @@ from Products.PageTemplates.PageTemplate # do xml import xmlrpclibBasicAuth +def unicodify(s): + """decode str (utf-8 or latin-1 representation) into unicode object""" + if not s: + return u"" + if isinstance(s, str): + try: + return s.decode('utf-8') + except: + return s.decode('latin-1') + else: + return 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): + return s + else: + return s.encode('utf-8') + class BaseSyncer(SimpleItem.Item, Persistent, Acquisition.Implicit, Role.RoleManager): """This class contains Basic methods, even These methods will be common if we implements Module Syncer""" @@ -185,7 +207,7 @@ class BaseSyncer(SimpleItem.Item, Persis # do any other encoding here # eg twofish, zlib etc # this will do me for now - return base64.encodestring(s) + return base64.encodestring(utf8ify(s)) def _decode(self, s): # do any other encoding here