DSV -> csv
Mike Rovner <[email protected]>
| Newsgroups | gmane.comp.mobile.bitpim.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all, Sorry for the long delay, I've managed to clean up my csv patch (current cvs). It works fine for my Samsung A670 (the only phone I can test against). Thanks, Mike
csv.diff
(text/plain, 5.1 KB)
Index: com_samsung.py
===================================================================
RCS file: /cvsroot/bitpim/bitpim/com_samsung.py,v
retrieving revision 1.57
diff -r1.57 com_samsung.py
17,19c17
<
< # site-packages
< from DSV import DSV
---
> import csv
368c366
< # double quotes? DSV strips these quotes, so we have to do it to
---
> # double quotes? csv strips these quotes, so we have to do it to
372,374c370,373
< e=DSV.importDSV([line[col+2:]])[0]
< i=0
< while i<len(e):
---
> from StringIO import StringIO
> f=StringIO(line[col+2:])
> e=csv.reader(f).next()
> for i in xrange(len(e)):
379,380d377
< i+=1
<
Index: com_samsungscha310.py
===================================================================
RCS file: /cvsroot/bitpim/bitpim/com_samsungscha310.py,v
retrieving revision 1.12
diff -r1.12 com_samsungscha310.py
560c560
< # DSV took " out, need put them back in
---
> # csv took " out, need put them back in
Index: com_samsungscha650.py
===================================================================
RCS file: /cvsroot/bitpim/bitpim/com_samsungscha650.py,v
retrieving revision 1.60
diff -r1.60 com_samsungscha650.py
507c507
< # DSV took the " out, need to put them back in for comparison
---
> # csv took the " out, need to put them back in for comparison
Index: com_samsungscha670.py
===================================================================
RCS file: /cvsroot/bitpim/bitpim/com_samsungscha670.py,v
retrieving revision 1.57
diff -r1.57 com_samsungscha670.py
679c679
< # DSV took the " out, need to put them back in for comparison
---
> # csv took the " out, need to put them back in for comparison
Index: importexport.py
===================================================================
RCS file: /cvsroot/bitpim/bitpim/importexport.py,v
retrieving revision 1.80
diff -r1.80 importexport.py
16a17
> import csv
23,25d23
< # Others
< from DSV import DSV
<
745,767c743,757
< data=common.opentextfile(self.filename).read()
< # turn all EOL chars into \n and then ensure only one \n terminates each line
< data=data.replace("\r", "\n")
< oldlen=-1
< while len(data)!=oldlen:
< oldlen=len(data)
< data=data.replace("\n\n", "\n")
<
< self.rawdata=data
<
< self.qualifier=DSV.guessTextQualifier(self.rawdata)
< if self.qualifier is None or len(self.qualifier)==0:
< self.qualifier='"'
< self.data=DSV.organizeIntoLines(self.rawdata, textQualifier=self.qualifier)
< self.delimiter=DSV.guessDelimiter(self.data)
< # sometimes it picks the letter 'w'
< if self.delimiter is not None and self.delimiter.lower() in "abcdefghijklmnopqrstuvwxyz":
< self.delimiter=None
< if self.delimiter is None:
< if self.filename.lower().endswith("tsv"):
< self.delimiter="\t"
< else:
< self.delimiter=","
---
> if 0:
> data=common.opentextfile(self.filename).read()
> # turn all EOL chars into \n and then ensure only one \n terminates each line
> data=data.replace("\r", "\n")
> oldlen=-1
> while len(data)!=oldlen:
> oldlen=len(data)
> data=data.replace("\n\n", "\n")
>
> self.rawdata=common.opentextfile(self.filename).read()
>
> sniffer=csv.Sniffer()
> dialect=sniffer.sniff(self.rawdata)
> self.qualifier=dialect.quotechar
> self.delimiter=dialect.delimiter
769c759
< self.data=DSV.importDSV(self.data, delimiter=self.delimiter, textQualifier=self.qualifier, errorHandler=DSV.padRow)
---
> self.data=csv.reader(common.opentextfile(self.filename), dialect)
785c775
< self.wfirstisheader.SetValue(DSV.guessHeaders(self.data))
---
> self.wfirstisheader.SetValue(sniffer.has_header(self.rawdata))
890,891c880,884
< self.data=DSV.organizeIntoLines(self.rawdata, textQualifier=self.qualifier)
< self.data=DSV.importDSV(self.data, delimiter=self.delimiter, textQualifier=self.qualifier, errorHandler=DSV.padRow)
---
> from StringIO import StringIO
> f=StringIO(self.rawdata)
> #self.data=DSV.organizeIntoLines(self.rawdata, textQualifier=self.qualifier)
> #self.data=DSV.importDSV(self.data, delimiter=self.delimiter, textQualifier=self.qualifier, errorHandler=DSV.padRow)
> self.data = list(csv.reader(f))
Index: experiments/gentestdata.py
===================================================================
RCS file: /cvsroot/bitpim/bitpim/experiments/gentestdata.py,v
retrieving revision 1.7
diff -r1.7 gentestdata.py
18,19c18
<
< from DSV import DSV
---
> import csv
180c179,182
< return DSV.exportDSV(op, quoteall=random.choice([0,1]))
---
> csvoutdata = cStringIO.StringIO()
> csvout = csv.writer(csvoutdata, quoting=random.choice([0,1]) and csv.QUOTE_ALL or csv.QUOTE_MINIMAL)
> csvout.writelines(op)
> return csvoutdata.getvalue()