Fix python 2 support

This commit is contained in:
nvbn
2015-09-02 11:54:58 +03:00
parent 4129ff2717
commit 9a02e821cd
2 changed files with 35 additions and 21 deletions
+4 -1
View File
@@ -2,6 +2,7 @@ from difflib import get_close_matches
from functools import wraps
import shelve
from decorator import decorator
from contextlib import closing
import tempfile
import os
@@ -176,11 +177,13 @@ def cache(*depends_on):
return fn(*args, **kwargs)
cache_path = os.path.join(tempfile.gettempdir(), '.thefuck-cache')
# A bit obscure, but simplest way to generate unique key for
# functions and methods in python 2 and 3:
key = '{}.{}'.format(fn.__module__, repr(fn).split('at')[0])
etag = '.'.join(_get_mtime(name) for name in depends_on)
with shelve.open(cache_path) as db:
with closing(shelve.open(cache_path)) as db:
if db.get(key, {}).get('etag') == etag:
return db[key]['value']
else: