sqlmap/lib/core/decorators.py

25 lines
608 B
Python
Raw Normal View History

#!/usr/bin/env python
"""
2016-01-06 02:06:12 +03:00
Copyright (c) 2006-2016 sqlmap developers (http://sqlmap.org/)
See the file 'doc/COPYING' for copying permission
"""
2012-07-30 12:06:14 +04:00
def cachedmethod(f, cache={}):
"""
Method with a cached content
Reference: http://code.activestate.com/recipes/325205-cache-decorator-in-python-24/
"""
2013-01-30 13:38:11 +04:00
2012-07-30 12:06:14 +04:00
def _(*args, **kwargs):
try:
key = (f, tuple(args), frozenset(kwargs.items()))
except:
key = "".join(str(_) for _ in (f, args, kwargs))
2012-07-30 12:06:14 +04:00
if key not in cache:
cache[key] = f(*args, **kwargs)
return cache[key]
2013-01-30 13:38:11 +04:00
2012-07-30 12:06:14 +04:00
return _