Fix utils._get_extension not working in pathlib objects

This was found while testing #1371.
This commit is contained in:
Lonami Exo
2020-01-17 11:11:10 +01:00
parent d09f6a50b0
commit 78ee787310
2 changed files with 40 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ import logging
import math
import mimetypes
import os
import pathlib
import re
import struct
from collections import namedtuple
@@ -741,6 +742,8 @@ def _get_extension(file):
"""
if isinstance(file, str):
return os.path.splitext(file)[-1]
elif isinstance(file, pathlib.Path):
return file.suffix
elif isinstance(file, bytes):
kind = imghdr.what(io.BytesIO(file))
return ('.' + kind) if kind else ''