diff --git a/lib/newfol/filemanip.py b/lib/newfol/filemanip.py index 0e3092a..270df2a 100644 --- a/lib/newfol/filemanip.py +++ b/lib/newfol/filemanip.py @@ -446,19 +446,17 @@ class FileStorage: """A file (or file-like object) in a certain format.""" def __init__(self, fmt, filename, txnformat=None, options=None): self._txn = self._make_transaction_store(txnformat, options) - if fmt == "csv": - self._backend = CSVFile(filename, self._txn, options) - elif fmt == "qddb": - self._backend = QDDBFile(filename, self._txn, options) - elif fmt == "pickle": - self._backend = PickleFile(filename, self._txn, options) - elif fmt == "json": - self._backend = JSONFile(filename, self._txn, options) - elif fmt == "yaml": - self._backend = YAMLFile(filename, self._txn, options) - elif fmt == "raw": - self._backend = RawFile(filename, self._txn, options) - else: + backends = { + "csv": CSVFile, + "qddb": QDDBFile, + "pickle": PickleFile, + "json": JSONFile, + "yaml": YAMLFile, + "raw": RawFile + } + try: + self._backend = backends[fmt](filename, self._txn, options) + except KeyError: raise ValueError("{0}: not a supported backend".format(fmt)) @staticmethod def _make_transaction_store(items, options):