--- ZSQLExtend/importFMPXML.py 2007/12/14 21:30:55 1.19 +++ ZSQLExtend/importFMPXML.py 2008/01/09 14:23:26 1.20 @@ -19,7 +19,32 @@ except: fm_ns = 'http://www.filemaker.com/fmpxmlresult' -version_string = "V0.5 ROC 11.12.2007" +version_string = "V0.5.1 ROC 9.1.2008" + +def unicodify(str, withNone=False): + """decode str (utf-8 or latin-1 representation) into unicode object""" + if withNone and str is None: + return None + if not str: + return u"" + if type(str) is StringType: + try: + return str.decode('utf-8') + except: + return str.decode('latin-1') + else: + return str + +def utf8ify(str, withNone=False): + """encode unicode object or string into byte string in utf-8 representation""" + if withNone and str is None: + return None + if not str: + return "" + if type(str) is StringType: + return str + else: + return str.encode('utf-8') def getTextFromNode(nodename): """get the cdata content of a node""" @@ -45,13 +70,11 @@ def SimpleSearch(curs,query, args=None, #logger.debug("executing: "+query) if ascii: # encode all in UTF-8 - query = query.encode("UTF-8") + query = utf8ify(query) if args is not None: encargs = [] for a in args: - if a is not None and isinstance(a, str): - a = a.encode("UTF-8") - encargs.append(a) + encargs.append(utf8ify(a, withNone=True)) args = encargs