diff options
author | Jason McBrayer <[email protected]> | 2018-11-12 09:44:57 -0500 |
---|---|---|
committer | Jason McBrayer <[email protected]> | 2018-11-12 09:44:57 -0500 |
commit | 7e2259e3ee5984bbcc27c4810cad301f96106e12 (patch) | |
tree | 0474eeafad5e9dd722ab0fe4c6b9ca8527a4fa04 | |
parent | 191ad84cef0b37e8d8a708812336858d447304c5 (diff) | |
download | mastodon.py-7e2259e3ee5984bbcc27c4810cad301f96106e12.tar.gz |
Add requirement for python-magic, and add wrappers to Mastodon.py
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | mastodon/Mastodon.py | 13 | ||||
-rw-r--r-- | setup.py | 3 |
3 files changed, 18 insertions, 2 deletions
@@ -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 |
93 | pytooter_clientcred.txt | 93 | pytooter_clientcred.txt |
94 | pytooter_usercred.txt \ No newline at end of file | 94 | pytooter_usercred.txtPipfile |
95 | Pipfile.lock | ||
96 | Pipfile | ||
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index e6d8268..a2035c9 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py | |||
@@ -31,6 +31,11 @@ try: | |||
31 | except ImportError: | 31 | except ImportError: |
32 | from urlparse import urlparse | 32 | from urlparse import urlparse |
33 | 33 | ||
34 | try: | ||
35 | import magic | ||
36 | except 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 | ### |
@@ -2529,3 +2534,11 @@ class MastodonRatelimitError(MastodonError): | |||
2529 | class MastodonMalformedEventError(MastodonError): | 2534 | class MastodonMalformedEventError(MastodonError): |
2530 | """Raised when the server-sent event stream is malformed""" | 2535 | """Raised when the server-sent event stream is malformed""" |
2531 | pass | 2536 | pass |
2537 | |||
2538 | def guess_type(media_file): | ||
2539 | mime_type = None | ||
2540 | if magic: | ||
2541 | mime_type = magic.from_file(media_file, mime=True) | ||
2542 | else: | ||
2543 | mime_type = mimetypes.guess_type(media_file)[0] | ||
2544 | return mime_type | ||
@@ -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' |