Skip to content

Commit

Permalink
assert s_type to be BytesHasher when working with rotated images
Browse files Browse the repository at this point in the history
  • Loading branch information
haianhng31 committed Nov 4, 2024
1 parent 3b83a41 commit 074e3bf
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions python-threatexchange/threatexchange/cli/match_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,15 +278,13 @@ def _match_file(
rotated_images: t.Dict[RotationType, bytes] = PhotoContent.all_simple_rotations(
image_data
)
all_matches = []

assert issubclass(s_type, BytesHasher)

all_matches: t.Sequence[_IndexMatchWithRotation] = []

for rotation_type, rotated_bytes in rotated_images.items():
# Create a temporary file to hold the image bytes
with tempfile.NamedTemporaryFile() as temp_file:
temp_file.write(rotated_bytes)
temp_file_path = pathlib.Path(temp_file.name)
matches = index.query(s_type.hash_from_file(temp_file_path))
temp_file_path.unlink() # Clean up the temporary file
matches = index.query(s_type.hash_from_bytes(rotated_bytes))

# Add rotation information if any matches were found
matches_with_rotations = []
Expand Down

0 comments on commit 074e3bf

Please sign in to comment.