Skip to content

Commit

Permalink
Merge pull request nvbn#458 from scorphus/anydbm
Browse files Browse the repository at this point in the history
nvbn#439 nvbn#447 Except anydbm instead of gdbm for PY2
  • Loading branch information
nvbn committed Feb 15, 2016
2 parents 470c0ef + 3cc4940 commit ce959b2
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions thefuck/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dbm
import os
import pickle
import pkg_resources
Expand All @@ -16,10 +15,12 @@

DEVNULL = open(os.devnull, 'w')

shelve_open_errors = (dbm.error, )
if six.PY2:
import gdbm
shelve_open_errors += (gdbm.error, )
import anydbm
shelve_open_error = anydbm.error
else:
import dbm
shelve_open_error = dbm.error


def memoize(fn):
Expand Down Expand Up @@ -227,7 +228,7 @@ def _cache(fn, *args, **kwargs):
value = fn(*args, **kwargs)
db[key] = {'etag': etag, 'value': value}
return value
except shelve_open_errors:
except shelve_open_error:
# Caused when going from Python 2 to Python 3 and vice-versa
warn("Removing possibly out-dated cache")
os.remove(cache_path)
Expand Down

0 comments on commit ce959b2

Please sign in to comment.