importers: Catch and handle CSV parse errors in can_import.
import2ledger bailed on one of these exceptions when trying to import a recent XLS file that had a null byte on a line.
This commit is contained in:
parent
cc0082814b
commit
b33c83af0a
2 changed files with 7 additions and 3 deletions
|
@ -63,8 +63,12 @@ class CSVImporterBase:
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def can_import(cls, input_file):
|
def can_import(cls, input_file):
|
||||||
_, fields = cls._read_header(input_file)
|
try:
|
||||||
return cls._NEEDED_KEYS.issubset(fields or ())
|
_, fields = cls._read_header(input_file)
|
||||||
|
except csv.Error:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return cls._NEEDED_KEYS.issubset(fields or ())
|
||||||
|
|
||||||
def __init__(self, input_file):
|
def __init__(self, input_file):
|
||||||
self.entry_seed, fields = self._read_header(input_file)
|
self.entry_seed, fields = self._read_header(input_file)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -30,7 +30,7 @@ REQUIREMENTS['tests_require'] = [
|
||||||
setup(
|
setup(
|
||||||
name='import2ledger',
|
name='import2ledger',
|
||||||
description="Import different sources of financial data to Ledger",
|
description="Import different sources of financial data to Ledger",
|
||||||
version='0.3',
|
version='0.4',
|
||||||
author='Brett Smith',
|
author='Brett Smith',
|
||||||
author_email='brettcsmith@brettcsmith.org',
|
author_email='brettcsmith@brettcsmith.org',
|
||||||
license='GNU AGPLv3+',
|
license='GNU AGPLv3+',
|
||||||
|
|
Loading…
Reference in a new issue