-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d09a20a
commit a52a9de
Showing
3 changed files
with
11 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import filetype | ||
|
||
def check_file(file, file_extension, allowed_extensions, check_mime): | ||
def check_file(file, file_extension, allowed_extensions, check_mime=True): | ||
if not file_extension in allowed_extensions: | ||
return "not_allowed_extension" | ||
|
||
# Проверяем MIME тип (библиотека автоматически умеет переводить MIME в реальное расширение файла). | ||
if check_mime and file_extension != filetype.guess_extension(file): | ||
return "mime_type_does_not_match_extension" | ||
if check_mime: | ||
if file_extension == 'md': | ||
if file.mimetype != 'text/plain': | ||
return "mime_type_does_not_match_extension" | ||
else: | ||
if file_extension != filetype.guess_extension(file): | ||
return "mime_type_does_not_match_extension" | ||
|
||
return "ok" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters