# HG changeset patch # User RĂ©mi Cardona # Date 1396527436 -7200 # Node ID 09878c2f862189a9338da3f7e280d6b287d9d237 # Parent 0aebb1c0f849b469fe986c4e018b754ca489805a [dataimport] Have ucsvreader's API match that of csv.reader (closes #3705701) 'separator' and 'quote' are replaced with 'delimiter' and 'quotechar'. diff -r 0aebb1c0f849 -r 09878c2f8621 dataimport.py --- a/dataimport.py Wed Nov 19 12:13:32 2014 +0100 +++ b/dataimport.py Thu Apr 03 14:17:16 2014 +0200 @@ -99,9 +99,16 @@ f.seek(0) return i+1 -def ucsvreader_pb(stream_or_path, encoding='utf-8', separator=',', quote='"', - skipfirst=False, withpb=True, skip_empty=True): +def ucsvreader_pb(stream_or_path, encoding='utf-8', delimiter=',', quotechar='"', + skipfirst=False, withpb=True, skip_empty=True, separator=None, + quote=None): """same as :func:`ucsvreader` but a progress bar is displayed as we iter on rows""" + if separator is not None: + delimiter = separator + warnings.warn("[3.20] 'separator' kwarg is deprecated, use 'delimiter' instead") + if quote is not None: + quotechar = quote + warnings.warn("[3.20] 'quote' kwarg is deprecated, use 'quotechar' instead") if isinstance(stream_or_path, basestring): if not osp.exists(stream_or_path): raise Exception("file doesn't exists: %s" % stream_or_path) @@ -113,15 +120,16 @@ rowcount -= 1 if withpb: pb = shellutils.ProgressBar(rowcount, 50) - for urow in ucsvreader(stream, encoding, separator, quote, + for urow in ucsvreader(stream, encoding, delimiter, quotechar, skipfirst=skipfirst, skip_empty=skip_empty): yield urow if withpb: pb.update() print ' %s rows imported' % rowcount -def ucsvreader(stream, encoding='utf-8', separator=',', quote='"', - skipfirst=False, ignore_errors=False, skip_empty=True): +def ucsvreader(stream, encoding='utf-8', delimiter=',', quotechar='"', + skipfirst=False, ignore_errors=False, skip_empty=True, + separator=None, quote=None): """A csv reader that accepts files with any encoding and outputs unicode strings @@ -129,7 +137,13 @@ separators) will be skipped. This is useful for Excel exports which may be full of such lines. """ - it = iter(csv.reader(stream, delimiter=separator, quotechar=quote)) + if separator is not None: + delimiter = separator + warnings.warn("[3.20] 'separator' kwarg is deprecated, use 'delimiter' instead") + if quote is not None: + quotechar = quote + warnings.warn("[3.20] 'quote' kwarg is deprecated, use 'quotechar' instead") + it = iter(csv.reader(stream, delimiter=delimiter, quotechar=quotechar)) if not ignore_errors: if skipfirst: it.next() diff -r 0aebb1c0f849 -r 09878c2f8621 doc/3.20.rst --- a/doc/3.20.rst Wed Nov 19 12:13:32 2014 +0100 +++ b/doc/3.20.rst Thu Apr 03 14:17:16 2014 +0200 @@ -16,6 +16,17 @@ .. _CWEP-002: http://hg.logilab.org/review/cwep/file/tip/CWEP-002.rst + +API Changes +----------- + +* ``ucsvreader()`` and ``ucsvreader_pb()`` from the ``dataimport`` module have + 2 new keyword arguments ``delimiter`` and ``quotechar`` to replace the + ``separator`` and ``quote`` arguments respectively. This makes the API match + that of Python's ``csv.reader()``. The old arguments are still supported + though deprecated. + + Deprecated Code Drops ----------------------