aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason McBrayer <[email protected]>2018-11-12 10:04:15 -0500
committerJason McBrayer <[email protected]>2018-11-12 10:04:15 -0500
commit4b7bbe72cd58487612543543fec6dba6c6fe0566 (patch)
tree5e0bf3b278479b6b78a6f05764ebf93790853fdb
parent7e2259e3ee5984bbcc27c4810cad301f96106e12 (diff)
downloadmastodon.py-4b7bbe72cd58487612543543fec6dba6c6fe0566.tar.gz
Use magic for guessing mime type if available
Replace uses of mimetypes.guess_type with guess_type wrapper that uses magic if available, and falls back to mimetypes if not.
-rw-r--r--mastodon/Mastodon.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index a2035c9..c8dc6e4 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -1496,7 +1496,7 @@ class Mastodon:
1496 # Load avatar, if specified 1496 # Load avatar, if specified
1497 if not avatar is None: 1497 if not avatar is None:
1498 if avatar_mime_type is None and os.path.isfile(avatar): 1498 if avatar_mime_type is None and os.path.isfile(avatar):
1499 avatar_mime_type = mimetypes.guess_type(avatar)[0] 1499 avatar_mime_type = guess_type(avatar)
1500 avatar = open(avatar, 'rb') 1500 avatar = open(avatar, 'rb')
1501 1501
1502 if avatar_mime_type is None: 1502 if avatar_mime_type is None:
@@ -1505,7 +1505,7 @@ class Mastodon:
1505 # Load header, if specified 1505 # Load header, if specified
1506 if not header is None: 1506 if not header is None:
1507 if header_mime_type is None and os.path.isfile(header): 1507 if header_mime_type is None and os.path.isfile(header):
1508 header_mime_type = mimetypes.guess_type(header)[0] 1508 header_mime_type = guess_type(header)
1509 header = open(header, 'rb') 1509 header = open(header, 'rb')
1510 1510
1511 if header_mime_type is None: 1511 if header_mime_type is None:
@@ -1725,7 +1725,7 @@ class Mastodon:
1725 status_post to attach the media file to a toot. 1725 status_post to attach the media file to a toot.
1726 """ 1726 """
1727 if mime_type is None and os.path.isfile(media_file): 1727 if mime_type is None and os.path.isfile(media_file):
1728 mime_type = mimetypes.guess_type(media_file)[0] 1728 mime_type = guess_type(media_file)
1729 media_file = open(media_file, 'rb') 1729 media_file = open(media_file, 'rb')
1730 1730
1731 if mime_type is None: 1731 if mime_type is None:
Powered by cgit v1.2.3 (git 2.41.0)