Refactor backend selection.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
This commit is contained in:
parent
17b3afb3cf
commit
e7508bb172
1 changed files with 11 additions and 13 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Reference in a new issue