def setup(self): """ Setup all the required backend stores. This was mostly created to avoid starting any threads during __init__() which is called during python's import phase and dead-locks in some cases. :return: None """ with self._kb_lock: if self.initialized: return self.urls = DiskSet(table_prefix='kb_urls') self.fuzzable_requests = DiskSet(table_prefix='kb_fuzzable_requests') self.db = get_default_persistent_db_instance() self.table_name = 'knowledge_base_' + rand_alpha(30) self.db.create_table(self.table_name, self.COLUMNS) self.db.create_index(self.table_name, ['location_a', 'location_b']) self.db.create_index(self.table_name, ['uniq_id']) self.db.commit() # Only initialize once self.initialized = True
def setup(self): """ Setup all the required backend stores. This was mostly created to avoid starting any threads during __init__() which is called during python's import phase and dead-locks in some cases. :return: None """ with self._kb_lock: if self.initialized: return self.urls = DiskSet(table_prefix='kb_urls') self.fuzzable_requests = DiskSet(table_prefix='kb_fuzzable_requests') self.db = get_default_persistent_db_instance() self.table_name = 'knowledge_base_' + rand_alpha(30) self.db.create_table(self.table_name, self.COLUMNS) self.db.create_index(self.table_name, ['location_a', 'location_b']) self.db.create_index(self.table_name, ['uniq_id']) self.db.commit() # Only initialize once self.initialized = True
def test_drop_table(self): kb = DBKnowledgeBase() table_name = kb.table_name db = get_default_persistent_db_instance() self.assertTrue(db.table_exists(table_name)) kb.remove() self.assertFalse(db.table_exists(table_name))
def __init__(self): super(DBKnowledgeBase, self).__init__() self.urls = DiskSet() self.fuzzable_requests = DiskSet() self.db = get_default_persistent_db_instance() columns = [("location_a", "TEXT"), ("location_b", "TEXT"), ("uniq_id", "TEXT"), ("pickle", "BLOB")] self.table_name = rand_alpha(30) self.db.create_table(self.table_name, columns) self.db.create_index(self.table_name, ["location_a", "location_b"]) self.db.create_index(self.table_name, ["uniq_id"]) self.db.commit() # TODO: Why doesn't this work with a WeakValueDictionary? self.observers = {} # WeakValueDictionary() self.type_observers = {} # WeakValueDictionary() self.url_observers = [] self._observer_id = 0
def __init__(self): super(DBKnowledgeBase, self).__init__() self.urls = DiskSet() self.fuzzable_requests = DiskSet() self.db = get_default_persistent_db_instance() columns = [('location_a', 'TEXT'), ('location_b', 'TEXT'), ('uniq_id', 'TEXT'), ('pickle', 'BLOB')] self.table_name = rand_alpha(30) self.db.create_table(self.table_name, columns) self.db.create_index(self.table_name, ['location_a', 'location_b']) self.db.create_index(self.table_name, [ 'uniq_id', ]) self.db.commit() # TODO: Why doesn't this work with a WeakValueDictionary? self.observers = {} #WeakValueDictionary() self.type_observers = {} #WeakValueDictionary() self.url_observers = [] self._observer_id = 0
def __init__(self): super(DBKnowledgeBase, self).__init__() self.urls = DiskSet(table_prefix='kb_urls') self.fuzzable_requests = DiskSet(table_prefix='kb_fuzzable_requests') self.db = get_default_persistent_db_instance() columns = [('location_a', 'TEXT'), ('location_b', 'TEXT'), ('uniq_id', 'TEXT'), ('pickle', 'BLOB')] self.table_name = 'knowledge_base_' + rand_alpha(30) self.db.create_table(self.table_name, columns) self.db.create_index(self.table_name, ['location_a', 'location_b']) self.db.create_index(self.table_name, ['uniq_id',]) self.db.commit() # TODO: Why doesn't this work with a WeakValueDictionary? self.observers = {} #WeakValueDictionary() self.type_observers = {} #WeakValueDictionary() self.url_observers = [] self._observer_id = 0