Refactor backend selection.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
brian m. carlson 2014-01-11 00:42:55 +00:00
parent 17b3afb3cf
commit e7508bb172
No known key found for this signature in database
GPG key ID: BF535D811F52F68B

View file

@ -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):