diff options
author | Michael Weiser <michael.weiser@gmx.de> | 2018-08-31 14:26:08 +0100 |
---|---|---|
committer | Michael Weiser <michael.weiser@gmx.de> | 2018-09-21 15:11:40 +0100 |
commit | 7da2a9a77808ffa16acdfac841542d56886e7c19 (patch) | |
tree | fc29af1654fe938782240eb5483484aa5d5c59d3 /peekaboo/toolbox/files.py | |
parent | 685a24e62f84153b0baa4c949f77c204b4565226 (diff) |
Make mime type guessing functions more reader-friendly
Leaving an empty "else" execution path, requiring the reader to know
that the default return value is None, seems needlessly confusing.
Diffstat (limited to 'peekaboo/toolbox/files.py')
-rw-r--r-- | peekaboo/toolbox/files.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/peekaboo/toolbox/files.py b/peekaboo/toolbox/files.py index 90503ed..6fe535e 100644 --- a/peekaboo/toolbox/files.py +++ b/peekaboo/toolbox/files.py @@ -36,8 +36,10 @@ logger = logging.getLogger(__name__) def guess_mime_type_from_file_contents(file_path): """ Get type from file magic bytes. """ mt = magic.from_file(file_path, mime=True) - if mt: - return mt + if not mt: + return None + + return mt def guess_mime_type_from_filename(file_path): @@ -47,5 +49,7 @@ def guess_mime_type_from_filename(file_path): mimetypes.add_type('application/javascript', '.jse') mt = mimetypes.guess_type(file_path)[0] - if mt: - return mt + if not mt: + return None + + return mt |