MCPcopy Index your code
hub / github.com/sqlmapproject/sqlmap / HashDB

Class HashDB

lib/utils/hashdb.py:32–221  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

30from thirdparty import six
31
32class HashDB(object):
33 def __init__(self, filepath):
34 self.filepath = filepath
35 self._write_cache = {}
36 self._cache_lock = threading.Lock()
37 self._connections = []
38 self._last_flush_time = time.time()
39
40 def _get_cursor(self):
41 threadData = getCurrentThreadData()
42
43 if threadData.hashDBCursor is None:
44 try:
45 connection = sqlite3.connect(self.filepath, timeout=10, isolation_level=None, check_same_thread=False)
46 self._connections.append(connection)
47 threadData.hashDBCursor = connection.cursor()
48 threadData.hashDBCursor.execute("CREATE TABLE IF NOT EXISTS storage (id INTEGER PRIMARY KEY, value TEXT)")
49 connection.commit()
50 except Exception as ex:
51 errMsg = "error occurred while opening a session "
52 errMsg += "file '%s' ('%s')" % (self.filepath, getSafeExString(ex))
53 raise SqlmapConnectionException(errMsg)
54
55 return threadData.hashDBCursor
56
57 def _set_cursor(self, cursor):
58 threadData = getCurrentThreadData()
59 threadData.hashDBCursor = cursor
60
61 cursor = property(_get_cursor, _set_cursor)
62
63 def close(self):
64 threadData = getCurrentThreadData()
65 try:
66 if threadData.hashDBCursor:
67 threadData.hashDBCursor.connection.commit()
68 threadData.hashDBCursor.close()
69 threadData.hashDBCursor.connection.close()
70 threadData.hashDBCursor = None
71 except:
72 pass
73
74 def closeAll(self):
75 for connection in self._connections:
76 try:
77 connection.commit()
78 connection.close()
79 except:
80 pass
81
82 @staticmethod
83 def hashKey(key):
84 key = getBytes(key if isinstance(key, six.text_type) else repr(key), errors="xmlcharrefreplace")
85 retVal = struct.unpack("<Q", hashlib.md5(key).digest()[:8])[0] & 0x7fffffffffffffff
86 return retVal
87
88 def retrieve(self, key, unserialize=False):
89 retVal = None

Callers 1

_setHashDBFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…