Update of /cvsroot/webware/Webware/MiscUtils
In directory usw-pr-cvs1:/tmp/cvs-serv9809
Modified Files:
CSVParser.py
Log Message:
added joinCSVFields()
Index: CSVParser.py
===================================================================
RCS file: /cvsroot/webware/Webware/MiscUtils/CSVParser.py,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** CSVParser.py 2001/12/20 21:23:05 1.1
--- CSVParser.py 2002/01/07 00:07:46 1.2
***************
*** 243,244 ****
--- 243,265 ----
_parser = CSVParser()
parse = _parser.parse
+
+
+ import types
+ def joinCSVFields(fields):
+ '''
+ Returns a CSV record (eg a string) from a sequence of fields.
+ Fields containing commands (,) or double quotes (") are quoted
+ and double quotes are escaped (""). The terminating newline is
+ NOT included.
+ '''
+ newFields = []
+ for field in fields:
+ assert type(field) is types.StringType
+ if field.find('"')!=-1:
+ newField = '"' + field.replace('"', '""') + '"'
+ elif field.find(',')!=-1:
+ newField = '"' + field + '"'
+ else:
+ newField = field
+ newFields.append(newField)
+ return ','.join(newFields)
|