--- ZSQLExtend/importFMPXML.py 2007/12/11 19:35:34 1.17 +++ ZSQLExtend/importFMPXML.py 2008/02/04 19:06:34 1.22 @@ -19,7 +19,32 @@ except: fm_ns = 'http://www.filemaker.com/fmpxmlresult' -version_string = "V0.5 ROC 11.12.2007" +version_string = "V0.5.2 ROC 4.2.2008" + +def unicodify(text, withNone=False): + """decode str (utf-8 or latin-1 representation) into unicode object""" + if withNone and text is None: + return None + if not text: + return u"" + if isinstance(text, str): + try: + return text.decode('utf-8') + except: + return text.decode('latin-1') + else: + return text + +def utf8ify(text, withNone=False): + """encode unicode object or string into byte string in utf-8 representation""" + if withNone and text is None: + return None + if not text: + return "" + if isinstance(text, unicode): + return text.encode('utf-8') + else: + return text 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 @@ -412,7 +435,7 @@ class xml_handler: args = [] for fn in self.xml_update_list: # do not update id_field - if self.id_field and fn == self.xml_id: + if update and fn == self.xml_id: continue f = self.xml_field_map[fn] @@ -438,7 +461,6 @@ class xml_handler: else: # create new row self.logger.debug("insert: %s"%args) - sys.exit(1) SimpleSearch(self.db, self.addQuery, args, ascii=self.ascii_db) #self.logger.info(" row:"+"%d (%s)"%(self.rowcnt,id_val))