mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 16:26:40 -04:00
limit auto-detected delimiter to a known-good set
This commit is contained in:
parent
a6a7782030
commit
1ae05a8bc7
1 changed files with 5 additions and 2 deletions
|
@ -89,12 +89,15 @@ class TextImporter(Importer):
|
||||||
type="encodingError",
|
type="encodingError",
|
||||||
info=_("File is not encoded in UTF-8."))
|
info=_("File is not encoded in UTF-8."))
|
||||||
self.dialect = None
|
self.dialect = None
|
||||||
|
sniffer = csv.Sniffer()
|
||||||
|
delims = [',', '\t', ';', ':']
|
||||||
if not self.delimiter:
|
if not self.delimiter:
|
||||||
try:
|
try:
|
||||||
self.dialect = csv.Sniffer().sniff("\n".join(self.data[:10]))
|
self.dialect = sniffer.sniff("\n".join(self.data[:10]),
|
||||||
|
delims)
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
self.dialect = csv.Sniffer().sniff(self.data[0])
|
self.dialect = sniffer.sniff(self.data[0], delims)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
if self.dialect:
|
if self.dialect:
|
||||||
|
|
Loading…
Reference in a new issue