--- ECHO_content/ECHO_helpers.py 2007/07/19 11:02:28 1.83 +++ ECHO_content/ECHO_helpers.py 2007/09/17 16:45:09 1.87 @@ -25,7 +25,7 @@ def logger(txt,method,txt2): """logging""" logging.info(txt+ txt2) -displayTypes = ['ZSQLExtendFolder','ZSQLBibliography','ECHO_group','ECHO_collection','ECHO_resource','ECHO_link','ECHO_sqlElement','ECHO_pageTemplate','ECHO_externalLink','ImageCollectionIFrame','VLP_resource','VLP_essay','ECHO_ZCatalogElement','ImageCollection','versionedFileFolder','ECHO_movie'] +displayTypes = ['ZSQLExtendFolder','ZSQLBibliography','ECHO_group','ECHO_collection','ECHO_resource','ECHO_link','ECHO_sqlElement','ECHO_pageTemplate','ECHO_externalLink','ImageCollectionIFrame','VLP_resource','VLP_essay','ECHO_ZCatalogElement','ImageCollection','versionedFileFolder','extVersionedFileFolder','ECHO_movie'] #decode and compress for xmlrpc communication with OSAS_server @@ -35,6 +35,29 @@ def encodeRPC(string): def decodeRPC(string): return bz2.decompress(base64.decodestring(string)) +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') + + def content_html(self,type): """template fuer content""" #templates = self.ZopeFind(self.aq_parent,obj_ids=[type+"_template"]) @@ -61,6 +84,20 @@ class ECHO_basis: management_page_charset="utf-8" isVisible = True + + def unicodify(self, s): + """return unicode object for string (utf-8 or latin1) or unicode object s""" + return unicodify(s) + + # compatibility of old decode method + decode = unicodify + + + def utf8ify(self, s): + """return utf-8 encoded string object for string or unicode object s""" + return utf8ify(s) + + def manage_addECHO_locale(self,lang,title,label,text=None,content_type=None,RESPONSE=None): return ECHO_collection.manage_addECHO_locale(self,lang,title,label)