Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lms/extractors/imagefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def __init__(self, **kwargs):
)

def can_extract(self) -> bool:
return self.ext in ALLOWED_IMAGES_EXTENSIONS
return self.ext.lower() in ALLOWED_IMAGES_EXTENSIONS

def get_exercise(self, to_extract: bytes) -> Tuple[int, List[File]]:
exercise_id = 0
Expand All @@ -25,7 +25,7 @@ def get_exercise(self, to_extract: bytes) -> Tuple[int, List[File]]:
raise BadUploadFile("Can't resolve exercise id.", self.filename)

decoded = base64.b64encode(to_extract)
return (exercise_id, [File(f'/main.{self.ext}', decoded)])
return (exercise_id, [File(f'/main.{self.ext.lower()}', decoded)])

def get_exercises(self) -> Iterator[Tuple[int, List[File]]]:
exercise_id, files = self.get_exercise(self.file_content)
Expand Down
4 changes: 2 additions & 2 deletions lms/extractors/textfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, **kwargs):
)

def can_extract(self) -> bool:
if self.ext not in ALLOWED_EXTENSIONS:
if self.ext.lower() not in ALLOWED_EXTENSIONS:
return False
if isinstance(self.file_content, str):
return True
Expand All @@ -34,7 +34,7 @@ def get_exercise(self, to_extract: str) -> Tuple[int, List[File]]:
if not exercise_id:
raise BadUploadFile("Can't resolve exercise id.", self.filename)

return (exercise_id, [File(f'/main.{self.ext}', content)])
return (exercise_id, [File(f'/main.{self.ext.lower()}', content)])

def get_exercises(self) -> Iterator[Tuple[int, List[File]]]:
exercise_id, files = self.get_exercise(self.file_content)
Expand Down
4 changes: 2 additions & 2 deletions lms/extractors/ziparchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ def _extract(archive: ZipFile, filename: str, dirname: str = '') -> File:
with archive.open(filename) as current_file:
log.debug(f'Extracting from archive: {filename}')
code = current_file.read()
if filename.rpartition('.')[-1] in ALLOWED_IMAGES_EXTENSIONS:
if filename.rpartition('.')[-1].lower() in ALLOWED_IMAGES_EXTENSIONS:
decoded = base64.b64encode(code)
else:
decoded = code.decode(
'utf-8', errors='replace',
).replace('\x00', '')
filename = filename[len(dirname):]
return File(path=f'/{filename}', code=decoded)
return File(path=f'/{filename.lower()}', code=decoded)

def get_files(
self, archive: ZipFile, filenames: List[Text], dirname: str = '',
Expand Down