Skip to content

Commit

Permalink
Merge pull request #175 from jcushman/hyperscan-update
Browse files Browse the repository at this point in the history
Add compatibility for hyperscan 0.7.7
  • Loading branch information
mlissner authored Apr 4, 2024
2 parents 3e7836a + d72bb35 commit a1d7b8f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion eyecite/tokenizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,20 @@ def convert_regex(regex):
cache_dir.mkdir(exist_ok=True)
cache = cache_dir / fingerprint
if cache.exists():
hyperscan_db = hyperscan.loadb(cache.read_bytes())
cache_bytes = cache.read_bytes()
try:
# hyperscan >= 0.5.0 added a mandatory mode argument
hyperscan_db = hyperscan.loadb(
cache_bytes, mode=hyperscan.HS_MODE_BLOCK
)
except TypeError:
hyperscan_db = hyperscan.loadb(cache_bytes)
try:
# at some point Scratch became necessary --
# https://github.com/darvid/python-hyperscan/issues/50#issuecomment-1386243477
hyperscan_db.scratch = hyperscan.Scratch(hyperscan_db)
except AttributeError:
pass

if not hyperscan_db:
# No cache, so compile database.
Expand Down

0 comments on commit a1d7b8f

Please sign in to comment.