diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-07-20 19:07:26 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2017-07-20 19:07:26 +0200 |
commit | 4e94cc1af7e816450940ba1a675c94bc10f1cd99 (patch) | |
tree | cacf5415cf4667c2384d13c312d339312fa4b194 /ishtar_common | |
parent | 80bc7eeb8da755c0c54471f6714a1ce33a89e3e2 (diff) | |
parent | bc959913ada31882c49bbfe510933edc9f043444 (diff) | |
download | Ishtar-4e94cc1af7e816450940ba1a675c94bc10f1cd99.tar.bz2 Ishtar-4e94cc1af7e816450940ba1a675c94bc10f1cd99.zip |
Merge branch 'master' into develop
Diffstat (limited to 'ishtar_common')
-rw-r--r-- | ishtar_common/models.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 6082fb4e0..01b46b7ae 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -2532,20 +2532,20 @@ class Import(models.Model): tmpdir = tempfile.mkdtemp(prefix='tmp-ishtar-') imported_file = z.extract(filename, tmpdir) - with open(imported_file) as csv_file: - encodings = [self.encoding] - encodings += [coding for coding, c in ENCODINGS] - for encoding in encodings: - try: + encodings = [self.encoding] + encodings += [coding for coding, c in ENCODINGS + if coding != self.encoding] + for encoding in encodings: + try: + with open(imported_file) as csv_file: vals = [line for line in unicodecsv.reader(csv_file, encoding=encoding)] if tmpdir: shutil.rmtree(tmpdir) return vals - except UnicodeDecodeError: - if encoding != encodings[-1]: - csv_file.seek(0) + except UnicodeDecodeError: + pass # try the next encoding if tmpdir: shutil.rmtree(tmpdir) return [] |