aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--mastodon/Mastodon.py19
-rw-r--r--setup.py3
3 files changed, 21 insertions, 5 deletions
diff --git a/.gitignore b/.gitignore
index e146528..66273be 100644
--- a/.gitignore
+++ b/.gitignore
@@ -91,4 +91,6 @@ ENV/
91# Secret files (for credentials used in testing) 91# Secret files (for credentials used in testing)
92*.secret 92*.secret
93pytooter_clientcred.txt 93pytooter_clientcred.txt
94pytooter_usercred.txt \ No newline at end of file 94pytooter_usercred.txtPipfile
95Pipfile.lock
96Pipfile
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index 7f0f0fd..a5c05b7 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -31,6 +31,11 @@ try:
31except ImportError: 31except ImportError:
32 from urlparse import urlparse 32 from urlparse import urlparse
33 33
34try:
35 import magic
36except ImportError:
37 magic = None
38
34### 39###
35# Version check functions, including decorator and parser 40# Version check functions, including decorator and parser
36### 41###
@@ -1491,7 +1496,7 @@ class Mastodon:
1491 # Load avatar, if specified 1496 # Load avatar, if specified
1492 if not avatar is None: 1497 if not avatar is None:
1493 if avatar_mime_type is None and os.path.isfile(avatar): 1498 if avatar_mime_type is None and os.path.isfile(avatar):
1494 avatar_mime_type = mimetypes.guess_type(avatar)[0] 1499 avatar_mime_type = guess_type(avatar)
1495 avatar = open(avatar, 'rb') 1500 avatar = open(avatar, 'rb')
1496 1501
1497 if avatar_mime_type is None: 1502 if avatar_mime_type is None:
@@ -1500,7 +1505,7 @@ class Mastodon:
1500 # Load header, if specified 1505 # Load header, if specified
1501 if not header is None: 1506 if not header is None:
1502 if header_mime_type is None and os.path.isfile(header): 1507 if header_mime_type is None and os.path.isfile(header):
1503 header_mime_type = mimetypes.guess_type(header)[0] 1508 header_mime_type = guess_type(header)
1504 header = open(header, 'rb') 1509 header = open(header, 'rb')
1505 1510
1506 if header_mime_type is None: 1511 if header_mime_type is None:
@@ -1720,7 +1725,7 @@ class Mastodon:
1720 status_post to attach the media file to a toot. 1725 status_post to attach the media file to a toot.
1721 """ 1726 """
1722 if mime_type is None and os.path.isfile(media_file): 1727 if mime_type is None and os.path.isfile(media_file):
1723 mime_type = mimetypes.guess_type(media_file)[0] 1728 mime_type = guess_type(media_file)
1724 media_file = open(media_file, 'rb') 1729 media_file = open(media_file, 'rb')
1725 elif mime_type and os.path.isfile(media_file): 1730 elif mime_type and os.path.isfile(media_file):
1726 media_file = open(media_file, 'rb') 1731 media_file = open(media_file, 'rb')
@@ -2531,3 +2536,11 @@ class MastodonRatelimitError(MastodonError):
2531class MastodonMalformedEventError(MastodonError): 2536class MastodonMalformedEventError(MastodonError):
2532 """Raised when the server-sent event stream is malformed""" 2537 """Raised when the server-sent event stream is malformed"""
2533 pass 2538 pass
2539
2540def guess_type(media_file):
2541 mime_type = None
2542 if magic:
2543 mime_type = magic.from_file(media_file, mime=True)
2544 else:
2545 mime_type = mimetypes.guess_type(media_file)[0]
2546 return mime_type
diff --git a/setup.py b/setup.py
index e49c26c..009063d 100644
--- a/setup.py
+++ b/setup.py
@@ -13,7 +13,8 @@ setup(name='Mastodon.py',
13 'requests', 13 'requests',
14 'python-dateutil', 14 'python-dateutil',
15 'six', 15 'six',
16 'pytz', 16 'pytz',
17 'python-magic',
17 'decorator>=4.0.0', 18 'decorator>=4.0.0',
18 'http_ece>=1.0.5', 19 'http_ece>=1.0.5',
19 'cryptography>=1.6.0' 20 'cryptography>=1.6.0'
Powered by cgit v1.2.3 (git 2.41.0)