dataimport/csv.py
changeset 10612 84468b90e9c1
parent 10589 7c23b7de2b8d
child 10669 155c29e0ed1c
equal deleted inserted replaced
10611:f4dec0cca9a1 10612:84468b90e9c1
    20 
    20 
    21 import csv as csvmod
    21 import csv as csvmod
    22 import warnings
    22 import warnings
    23 import os.path as osp
    23 import os.path as osp
    24 
    24 
       
    25 from six import string_types
       
    26 
    25 from logilab.common import shellutils
    27 from logilab.common import shellutils
    26 
    28 
    27 
    29 
    28 def count_lines(stream_or_filename):
    30 def count_lines(stream_or_filename):
    29     if isinstance(stream_or_filename, basestring):
    31     if isinstance(stream_or_filename, string_types):
    30         f = open(stream_or_filename)
    32         f = open(stream_or_filename)
    31     else:
    33     else:
    32         f = stream_or_filename
    34         f = stream_or_filename
    33         f.seek(0)
    35         f.seek(0)
    34     for i, line in enumerate(f):
    36     for i, line in enumerate(f):
    45         delimiter = separator
    47         delimiter = separator
    46         warnings.warn("[3.20] 'separator' kwarg is deprecated, use 'delimiter' instead")
    48         warnings.warn("[3.20] 'separator' kwarg is deprecated, use 'delimiter' instead")
    47     if quote is not None:
    49     if quote is not None:
    48         quotechar = quote
    50         quotechar = quote
    49         warnings.warn("[3.20] 'quote' kwarg is deprecated, use 'quotechar' instead")
    51         warnings.warn("[3.20] 'quote' kwarg is deprecated, use 'quotechar' instead")
    50     if isinstance(stream_or_path, basestring):
    52     if isinstance(stream_or_path, string_types):
    51         if not osp.exists(stream_or_path):
    53         if not osp.exists(stream_or_path):
    52             raise Exception("file doesn't exists: %s" % stream_or_path)
    54             raise Exception("file doesn't exists: %s" % stream_or_path)
    53         stream = open(stream_or_path)
    55         stream = open(stream_or_path)
    54     else:
    56     else:
    55         stream = stream_or_path
    57         stream = stream_or_path