Skip to content

Commit

Permalink
Make mime type guessing functions more reader-friendly
Browse files Browse the repository at this point in the history
Leaving an empty "else" execution path, requiring the reader to know
that the default return value is None, seems needlessly confusing.
  • Loading branch information
michaelweiser committed Sep 21, 2018
1 parent 685a24e commit 7da2a9a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions peekaboo/toolbox/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
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):
Expand All @@ -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

0 comments on commit 7da2a9a

Please sign in to comment.