def search(self, words: str, disk_loader: DiskCacheLoader = None, limit: int = -1, is_url: bool = False) -> SearchResult: ti = time.time() self._wait_to_be_ready() res = SearchResult.empty() if self.context.is_internet_available(): norm_query = sanitize_command_input(words).lower() self.logger.info(f"Search query: {norm_query}") if norm_query: is_url = bool(RE_IS_URL.match(norm_query)) disk_loader = self.disk_loader_factory.new() disk_loader.start() threads = [] for man in self.managers: t = Thread(target=self._search, args=(norm_query, is_url, man, disk_loader, res)) t.start() threads.append(t) for t in threads: t.join() if disk_loader: disk_loader.stop_working() disk_loader.join() # res.installed = self._sort(res.installed, norm_word) # res.new = self._sort(res.new, norm_word) else: raise NoInternetException() res.update_total() tf = time.time() self.logger.info(f'Took {tf - ti:.8f} seconds') return res
def test__must_remove_double_dash_parameters(self): input_ = '--cat abc-def --user -system ghi--jkl --xpto ' res = sanitize_command_input(input_) self.assertEqual('abc-def ghi--jkl', res)
def test__must_remove_several_operator(self): input_ = ' abc | ls /home/xpto && cat /home/xpto/secret.txt' res = sanitize_command_input(input_) self.assertEqual('abc', res)
def test__must_remove_double_quotes(self): input_ = ' "abc"-"xpto" ' res = sanitize_command_input(input_) self.assertEqual('abc-xpto', res)
def test__must_remove_single_quotes(self): input_ = " 'abc'-'xpto' " res = sanitize_command_input(input_) self.assertEqual('abc-xpto', res)
def test__must_remove_any_forbidden_symbols(self): input_ = ' #$%* abc-def@ #%<<>> ' res = sanitize_command_input(input_) self.assertEqual('abc-def@', res)