def __init__(self, use_unicode=True, ignore_case=False, titles=None): """ :param use_unicode: whether to use `titles` as unicode or bytestrings :param ignore_case: if True ignore case in all matches :param titles: if given, overrides default `load_titles()` values """ titles = titles if titles else load_titles() titles = (titles if use_unicode else (s.encode('ascii') for s in titles)) builder = AcoraBuilder() builder.update(titles) self.ac = builder.build(ignore_case=ignore_case)
def __init__(self, content: List[str], ignore_case: bool): """ Acora matcher factory :param content: a list of items to search :param ignore_case: True to match any case :return: a built matcher """ # start with a string in case content is empty # otherwise it builds a binary Acora matcher builder = AcoraBuilder("!@#$%%^&*") if len(content) > 0: builder.update(content) self.matcher = builder.build(ignore_case=ignore_case)
def __init__(self, keywords: Optional[Iterable[str]] = []): non_empty_keywords = [] if keywords is not None: for w in keywords: if w.strip() != "": non_empty_keywords.append(w) self._keywords = set(non_empty_keywords) if len(self._keywords) > 0: ac_builder = AcoraBuilder() ac_builder.update(keywords) self._finder = ac_builder.build() else: self._finder = None
def test_acora_python(self): builder = AcoraBuilder() builder.update([s for (s,) in SQL_ERRORS]) ac = builder.build(acora=PyAcora) i = 0 # # This takes around 9 seconds in my workstation. # for j in xrange(self.ITERATIONS): for _ in ac.finditer(HTTP_RESPONSE): i += 1 self.assertEqual(i, self.ITERATIONS * 2)