1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-01-31 10:11:14 +00:00

Merge pull request #458 from scorphus/anydbm

#439 #447 Except anydbm instead of gdbm for PY2
This commit is contained in:
Vladimir Iakovlev 2016-02-15 14:21:37 +03:00
commit ce959b2a8b

View File

@ -1,4 +1,3 @@
import dbm
import os import os
import pickle import pickle
import pkg_resources import pkg_resources
@ -16,10 +15,12 @@ from warnings import warn
DEVNULL = open(os.devnull, 'w') DEVNULL = open(os.devnull, 'w')
shelve_open_errors = (dbm.error, )
if six.PY2: if six.PY2:
import gdbm import anydbm
shelve_open_errors += (gdbm.error, ) shelve_open_error = anydbm.error
else:
import dbm
shelve_open_error = dbm.error
def memoize(fn): def memoize(fn):
@ -227,7 +228,7 @@ def cache(*depends_on):
value = fn(*args, **kwargs) value = fn(*args, **kwargs)
db[key] = {'etag': etag, 'value': value} db[key] = {'etag': etag, 'value': value}
return value return value
except shelve_open_errors: except shelve_open_error:
# Caused when going from Python 2 to Python 3 and vice-versa # Caused when going from Python 2 to Python 3 and vice-versa
warn("Removing possibly out-dated cache") warn("Removing possibly out-dated cache")
os.remove(cache_path) os.remove(cache_path)