MultiRegExScanner: Results are always bytes and never strings

This commit is contained in:
Mike Auty
2019-11-27 11:30:14 +00:00
committed by ikelos
parent af43e506fb
commit 1f4498be37
2 changed files with 2 additions and 3 deletions
@@ -53,7 +53,7 @@ class MultiStringScanner(layers.ScannerInterface):
self._patterns.add_pattern(pattern)
self._patterns.preprocess()
def __call__(self, data: bytes, data_offset: int) -> Generator[Tuple[int, Union[str, bytes]], None, None]:
def __call__(self, data: bytes, data_offset: int) -> Generator[Tuple[int, bytes], None, None]:
"""Runs through the data looking for the needles."""
for offset, pattern in self._patterns.search(data):
if offset < self.chunk_size:
@@ -21,8 +21,7 @@ class MultiRegexp(object):
raise ValueError("No strings to compile into a regular expression")
self._regex = re.compile(b'|'.join(map(re.escape, self._pattern_strings)))
def search(self, haystack: bytes) \
-> Generator[Tuple[int, Union[str, bytes]], None, None]:
def search(self, haystack: bytes) -> Generator[Tuple[int, bytes], None, None]:
if not isinstance(haystack, bytes):
raise TypeError("Search haystack must be a byte string")
if not self._regex.pattern: