mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 07:04:12 +00:00 
			
		
		
		
	Fix cache problem when going from Python 2 to 3
This commit is contained in:
		| @@ -1,18 +1,17 @@ | |||||||
| from difflib import get_close_matches | import dbm | ||||||
| from functools import wraps |  | ||||||
| import shelve |  | ||||||
| from warnings import warn |  | ||||||
| from decorator import decorator |  | ||||||
| from contextlib import closing |  | ||||||
|  |  | ||||||
| import os | import os | ||||||
| import pickle | import pickle | ||||||
| import re |  | ||||||
| from inspect import getargspec |  | ||||||
|  |  | ||||||
| from pathlib import Path |  | ||||||
| import pkg_resources | import pkg_resources | ||||||
|  | import re | ||||||
|  | import shelve | ||||||
| from .conf import settings | from .conf import settings | ||||||
|  | from contextlib import closing | ||||||
|  | from decorator import decorator | ||||||
|  | from difflib import get_close_matches | ||||||
|  | from functools import wraps | ||||||
|  | from inspect import getargspec | ||||||
|  | from pathlib import Path | ||||||
|  | from warnings import warn | ||||||
|  |  | ||||||
| DEVNULL = open(os.devnull, 'w') | DEVNULL = open(os.devnull, 'w') | ||||||
|  |  | ||||||
| @@ -210,6 +209,7 @@ def cache(*depends_on): | |||||||
|         etag = '.'.join(_get_mtime(name) for name in depends_on) |         etag = '.'.join(_get_mtime(name) for name in depends_on) | ||||||
|         cache_path = _get_cache_path() |         cache_path = _get_cache_path() | ||||||
|  |  | ||||||
|  |         try: | ||||||
|             with closing(shelve.open(cache_path)) as db: |             with closing(shelve.open(cache_path)) as db: | ||||||
|                 if db.get(key, {}).get('etag') == etag: |                 if db.get(key, {}).get('etag') == etag: | ||||||
|                     return db[key]['value'] |                     return db[key]['value'] | ||||||
| @@ -217,6 +217,16 @@ 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 dbm.error: | ||||||
|  |             # Caused when going from Python 2 to Python 3 | ||||||
|  |             warn("Removing possibly out-dated cache") | ||||||
|  |             os.remove(cache_path) | ||||||
|  |  | ||||||
|  |             with closing(shelve.open(cache_path)) as db: | ||||||
|  |                 value = fn(*args, **kwargs) | ||||||
|  |                 db[key] = {'etag': etag, 'value': value} | ||||||
|  |                 return value | ||||||
|  |  | ||||||
|     return _cache |     return _cache | ||||||
| cache.disabled = False | cache.disabled = False | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user