Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Final 2 tests passing, thanks for the boost, EightMedia.

  • Loading branch information...
commit 02343aac6283ffe1d582e7e7cfdd38efe5c593a5 1 parent 3dbb1b1
@jdunck authored
Showing with 18 additions and 5 deletions.
  1. +4 −1 runtests.py
  2. +14 −4 unicodecsv/__init__.py
View
5 runtests.py
@@ -9,4 +9,7 @@ def get_suite():
return suite
if __name__ == '__main__':
- get_suite().run()
+ result = unittest2.TestResult()
+ get_suite().run(result)
+ for error in result.errors:
+ print error
View
18 unicodecsv/__init__.py
@@ -55,13 +55,23 @@ def dialect(self):
writer = UnicodeWriter
class UnicodeReader(object):
- def __init__(self, f, dialect=csv.excel, encoding="utf-8", *args, **kwds):
- self.reader = csv.reader(f, dialect, *args, **kwds)
+ def __init__(self, f, dialect=None, encoding="utf-8", **kwds):
+ format_params = ['delimiter', 'doublequote', 'escapechar', 'lineterminator', 'quotechar', 'quoting', 'skipinitialspace']
+ if dialect is None:
+ if not any([kwd_name in format_params for kwd_name in kwds.keys()]):
+ dialect = csv.excel
+ self.reader = csv.reader(f, dialect, **kwds)
self.encoding = encoding
def next(self):
row = self.reader.next()
- return [unicode(s, self.encoding) for s in row]
+ results = []
+ for value in row:
+ if isinstance(value, float):
+ results.append(value)
+ else:
+ results.append(unicode(value, self.encoding))
+ return results
def __iter__(self):
return self
@@ -92,7 +102,7 @@ class UnicodeDictWriter(csv.DictWriter):
>>> print r.next() == {'a': u'\xc3\xa9', 'r': [u'\xc3\xae']}
True
"""
- def __init__(self, csvfile, fieldnames=None, restval='', extrasaction='raise', dialect='excel', encoding='utf-8', *args, **kwds):
+ def __init__(self, csvfile, fieldnames, restval='', extrasaction='raise', dialect='excel', encoding='utf-8', *args, **kwds):
csv.DictWriter.__init__(self, csvfile, fieldnames, restval, extrasaction, dialect, *args, **kwds)
self.writer = UnicodeWriter(csvfile, dialect, encoding=encoding, *args, **kwds)
Please sign in to comment.
Something went wrong with that request. Please try again.