Changeset 2264 for pykota/trunk/pykota/dumper.py
- Timestamp:
- 05/19/05 23:26:05 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/dumper.py
r2219 r2264 25 25 import os 26 26 import pwd 27 from xml.sax import saxutils 28 27 29 from mx import DateTime 28 30 … … 113 115 """Dumps datas with a separator.""" 114 116 for entry in entries : 115 line = separator.join([ '"%s"' % field for field in entry ]) 117 line = [] 118 for value in entry : 119 if type(value).__name__ in ("str", "NoneType") : 120 line.append('"%s"' % str(value).replace(separator, "\\%s" % separator).replace('"', '\\"')) 121 else : 122 line.append(str(value)) 116 123 try : 117 self.outfile.write("%s\n" % line)124 self.outfile.write("%s\n" % separator.join(line)) 118 125 except IOError, msg : 119 126 sys.stderr.write("%s : %s\n" % (_("PyKota data dumper failed : I/O error"), msg)) … … 165 172 x._push() 166 173 x.entry() 167 for i in range(len(entry)) : 168 value = str(entry[i]) 169 typval = type(entry[i]).__name__ 170 try : 171 value = unicode(value, self.getCharset()).encode("UTF-8") 172 except UnicodeError : 173 pass 174 x.attribute(value, type=typval, name=headers[i]) 174 for (header, value) in zip(headers, entry) : 175 strvalue = str(value) 176 typval = type(value).__name__ 177 if header in ("filename", "title", "options", "billingcode") \ 178 and (typval == "str") : 179 try : 180 strvalue = unicode(strvalue, self.getCharset()).encode("UTF-8") 181 except UnicodeError : 182 pass 183 strvalue = saxutils.escape(strvalue, { "'" : "'", \ 184 '"' : """ }) 185 x.attribute(strvalue, type=typval, name=header) 175 186 x._pop() 176 187 x._output(self.outfile)