Show
Ignore:
Timestamp:
01/13/08 01:22:35 (16 years ago)
Author:
jerome
Message:

Database backends now convert from and to unicode instead of UTF-8.
The data dumper now expects unicode datas from the database.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/pykota/dumper.py

    r3288 r3291  
    244244                line = [] 
    245245                for value in entry : 
    246                     if type(value).__name__ in ("str", "NoneType") : 
    247                         line.append('"%s"' % str(value).replace(separator, "\\%s" % separator).replace('"', '\\"')) 
    248                     else :     
    249                         line.append(str(value)) 
     246                    try : 
     247                        strvalue = '"%s"' % value.encode(self.charset, \ 
     248                                                         "replace").replace(separator, "\\%s" % separator).replace('"', '\\"') 
     249                    except AttributeError : 
     250                        if value is None : 
     251                            strvalue = '"None"' # Double quotes around None to prevent spreadsheet from failing 
     252                        else :     
     253                            strvalue = str(value) 
     254                    line.append(strvalue) 
    250255                try : 
    251256                    self.outfile.write("%s\n" % separator.join(line)) 
     
    313318                x.entry() 
    314319                for (header, value) in zip(headers, entry) : 
    315                     strvalue = str(value) 
    316                     typval = type(value).__name__ 
    317                     if header in ("filename", "title", "options", "billingcode") \ 
    318                               and (typval == "str") : 
    319                         try : 
    320                             strvalue = unicode(strvalue, self.charset).encode("UTF-8") 
    321                         except UnicodeError :     
    322                             pass 
    323                         strvalue = saxutils.escape(strvalue, { "'" : "'", \ 
    324                                                                '"' : """ }) 
    325                     x.attribute(strvalue, type=typval, name=header) 
     320                    try : 
     321                        strvalue = saxutils.escape(value.encode("UTF-8", \ 
     322                                                                "replace"), \ 
     323                                                   { "'" : "'", \ 
     324                                                     '"' : """ }) 
     325                    except AttributeError :     
     326                        strvalue = str(value) 
     327                    # We use 'str' instead of 'unicode' below to be compatible 
     328                    # with older releases of PyKota. 
     329                    # The XML dump will contain UTF-8 encoded strings,  
     330                    #�not unicode strings anyway. 
     331                    x.attribute(strvalue, \ 
     332                                type=type(value).__name__.replace("unicode", "str"), \ 
     333                                name=header) 
    326334                x._pop()     
    327335            x._pop()