summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2003-04-25 14:27:00 (GMT)
committerFred Drake <fdrake@acm.org>2003-04-25 14:27:00 (GMT)
commit7c852f33a2b095503c9b745a0798d5c9deee6982 (patch)
tree020416f379701e95b01bd604669abf7f0541b049 /Lib
parent376e636f186e22ad479f35da4b973114d11ff2d9 (diff)
downloadcpython-7c852f33a2b095503c9b745a0798d5c9deee6982.zip
cpython-7c852f33a2b095503c9b745a0798d5c9deee6982.tar.gz
cpython-7c852f33a2b095503c9b745a0798d5c9deee6982.tar.bz2
Attempt to deal with some obvious errors in the code. These were all
due to using a single module-level namespace where multiple namespaces were used before. There *really* need to be tests for the sniffer stuff. This could have been avoided. Skip, please review, and add sniffer tests!
Diffstat (limited to 'Lib')
-rw-r--r--Lib/csv.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/Lib/csv.py b/Lib/csv.py
index c510c70..89d86d6 100644
--- a/Lib/csv.py
+++ b/Lib/csv.py
@@ -161,7 +161,6 @@ class Sniffer:
"""
Takes a file-like object and returns a dialect (or None)
"""
-
self.fileobj = fileobj
data = fileobj.read(self.sample)
@@ -171,17 +170,17 @@ class Sniffer:
if delimiter is None:
delimiter, skipinitialspace = self._guessDelimiter(data)
- class Dialect(csv.Dialect):
+ class SniffedDialect(Dialect):
_name = "sniffed"
lineterminator = '\r\n'
- quoting = csv.QUOTE_MINIMAL
+ quoting = QUOTE_MINIMAL
# escapechar = ''
doublequote = False
- Dialect.delimiter = delimiter
- Dialect.quotechar = quotechar
- Dialect.skipinitialspace = skipinitialspace
+ SniffedDialect.delimiter = delimiter
+ SniffedDialect.quotechar = quotechar
+ SniffedDialect.skipinitialspace = skipinitialspace
- self.dialect = Dialect
+ self.dialect = SniffedDialect
return self.dialect
@@ -189,8 +188,8 @@ class Sniffer:
return self._hasHeaders(self.fileobj, self.dialect)
- def register_dialect(self, name = 'sniffed'):
- csv.register_dialect(name, self.dialect)
+ def register_dialect(self, name='sniffed'):
+ register_dialect(name, self.dialect)
def _guessQuoteAndDelimiter(self, data):
@@ -378,19 +377,19 @@ class Sniffer:
# objects...
fileobj.seek(0)
- reader = csv.reader(fileobj,
- delimiter = dialect.delimiter,
- quotechar = dialect.quotechar,
- skipinitialspace = dialect.skipinitialspace)
+ r = csv.reader(fileobj,
+ delimiter=dialect.delimiter,
+ quotechar=dialect.quotechar,
+ skipinitialspace=dialect.skipinitialspace)
- header = reader.next() # assume first row is header
+ header = r.next() # assume first row is header
columns = len(header)
columnTypes = {}
for i in range(columns): columnTypes[i] = None
checked = 0
- for row in reader:
+ for row in r:
# arbitrary number of rows to check, to keep it sane
if checked > 20:
break