2013-02-14 15:32:17 +04:00
|
|
|
#!/usr/bin/env python
|
2012-07-30 13:21:32 +04:00
|
|
|
|
|
|
|
"""
|
2018-01-02 02:48:10 +03:00
|
|
|
Copyright (c) 2006-2018 sqlmap developers (http://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2012-07-30 13:21:32 +04:00
|
|
|
"""
|
|
|
|
|
2018-12-28 20:25:56 +03:00
|
|
|
import functools
|
2017-12-25 01:54:43 +03:00
|
|
|
import hashlib
|
|
|
|
|
2018-04-01 13:45:47 +03:00
|
|
|
from lib.core.threads import getCurrentThreadData
|
|
|
|
|
2012-07-30 12:06:14 +04:00
|
|
|
def cachedmethod(f, cache={}):
|
2012-07-30 13:21:32 +04:00
|
|
|
"""
|
|
|
|
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
|
|
|
|
2018-12-28 20:25:56 +03:00
|
|
|
@functools.wraps(f)
|
2012-07-30 12:06:14 +04:00
|
|
|
def _(*args, **kwargs):
|
2018-05-04 17:29:36 +03:00
|
|
|
key = int(hashlib.md5("|".join(str(_) for _ in (f, args, kwargs))).hexdigest(), 16) & 0x7fffffffffffffff
|
2017-12-25 01:54:43 +03:00
|
|
|
if key not in cache:
|
|
|
|
cache[key] = f(*args, **kwargs)
|
2016-05-14 15:18:34 +03:00
|
|
|
|
2012-07-30 12:06:14 +04:00
|
|
|
return cache[key]
|
2013-01-30 13:38:11 +04:00
|
|
|
|
2012-07-30 12:06:14 +04:00
|
|
|
return _
|
2018-04-01 13:45:47 +03:00
|
|
|
|
|
|
|
def stackedmethod(f):
|
2018-12-28 20:25:56 +03:00
|
|
|
"""
|
|
|
|
Method using pushValue/popValue functions (fallback function for stack realignment)
|
|
|
|
"""
|
|
|
|
|
|
|
|
@functools.wraps(f)
|
2018-04-01 13:45:47 +03:00
|
|
|
def _(*args, **kwargs):
|
|
|
|
threadData = getCurrentThreadData()
|
|
|
|
originalLevel = len(threadData.valueStack)
|
|
|
|
|
|
|
|
try:
|
|
|
|
result = f(*args, **kwargs)
|
|
|
|
finally:
|
|
|
|
if len(threadData.valueStack) > originalLevel:
|
|
|
|
threadData.valueStack = threadData.valueStack[:originalLevel]
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
2018-06-10 00:38:00 +03:00
|
|
|
return _
|