Skip to content

Commit 2fa117d

Browse files
committed
Replace binaryornot library with a simple magic bytes check
The library has not been updated and does not have proper Python 3.13 support. This same approach is used by Git internally to detect binary files.
1 parent 2ed9758 commit 2fa117d

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

exercise/submission_models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import IO, Dict, Iterable, List, Tuple, TYPE_CHECKING, Callable
77
from urllib.parse import urlparse
88

9-
from binaryornot.check import is_binary
109
from django.conf import settings
1110
from django.db import models, DatabaseError
1211
from django.db.models import F
@@ -865,9 +864,15 @@ def get_mime(self):
865864

866865
def is_passed(self):
867866
if self.file_object.path.endswith(".pdf"):
868-
# PDF files are sometimes incorrectly classified as non-binary by the 'binaryornot' library
869867
return True
870-
return is_binary(self.file_object.path)
868+
# Simple magic bytes check
869+
path = self.file_object.path
870+
try:
871+
with open(path, 'rb') as f:
872+
chunk = f.read(1024)
873+
return b'\x00' in chunk
874+
except OSError:
875+
return False
871876

872877

873878
ABSOLUTE_URL_NAME = "submission-file"

requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ markdown ~= 3.3.4
3030
aplus-auth ~= 0.2.0
3131
celery >= 5.2.1, < 6
3232
redis >= 4
33-
binaryornot ~= 0.4.4
3433
django-model-utils ~= 4.2.0
3534
format_cef ~= 0.0.4
3635
PyLTI1p3 ~= 2.0.0

0 commit comments

Comments
 (0)