aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFoxMaSk <[email protected]>2017-09-05 23:07:24 +0200
committerFoxMaSk <[email protected]>2017-09-05 23:07:24 +0200
commit6ef2724f66fbc9358c13e342a98f7385d25df4a1 (patch)
tree6875e03ab4a06497549974a87457ffe69b5fbfc1 /mastodon/Mastodon.py
parente0e68ccd6a8007fa9fb50aa7e8432505dc93f7b8 (diff)
downloadmastodon.py-6ef2724f66fbc9358c13e342a98f7385d25df4a1.tar.gz
not pep8 compliant #71
Diffstat (limited to 'mastodon/Mastodon.py')
-rw-r--r--mastodon/Mastodon.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py
index c8f90ee..715da12 100644
--- a/mastodon/Mastodon.py
+++ b/mastodon/Mastodon.py
@@ -76,8 +76,9 @@ class Mastodon:
76 ### 76 ###
77 # Authentication, including constructor 77 # Authentication, including constructor
78 ### 78 ###
79 def __init__(self, client_id, client_secret=None, access_token=None, api_base_url=__DEFAULT_BASE_URL, 79 def __init__(self, client_id, client_secret=None, access_token=None,
80 debug_requests=False, ratelimit_method="wait", ratelimit_pacefactor=1.1, 80 api_base_url=__DEFAULT_BASE_URL, debug_requests=False,
81 ratelimit_method="wait", ratelimit_pacefactor=1.1,
81 request_timeout=__DEFAULT_TIMEOUT): 82 request_timeout=__DEFAULT_TIMEOUT):
82 """ 83 """
83 Create a new API wrapper instance based on the given client_secret and client_id. If you 84 Create a new API wrapper instance based on the given client_secret and client_id. If you
@@ -166,7 +167,8 @@ class Mastodon:
166 Will throw a MastodonIllegalArgumentError if username / password 167 Will throw a MastodonIllegalArgumentError if username / password
167 are wrong, scopes are not valid or granted scopes differ from requested. 168 are wrong, scopes are not valid or granted scopes differ from requested.
168 169
169 For OAuth2 documentation, compare https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper 170 For OAuth2 documentation, compare
171 https://github.com/doorkeeper-gem/doorkeeper/wiki/Interacting-as-an-OAuth-client-with-Doorkeeper
170 172
171 Returns the access token. 173 Returns the access token.
172 """ 174 """
@@ -537,7 +539,8 @@ class Mastodon:
537 # Validate visibility parameter 539 # Validate visibility parameter
538 valid_visibilities = ['private', 'public', 'unlisted', 'direct', ''] 540 valid_visibilities = ['private', 'public', 'unlisted', 'direct', '']
539 if params_initial['visibility'].lower() not in valid_visibilities: 541 if params_initial['visibility'].lower() not in valid_visibilities:
540 raise ValueError('Invalid visibility value! Acceptable values are %s' % valid_visibilities) 542 raise ValueError('Invalid visibility value! Acceptable '
543 'values are %s' % valid_visibilities)
541 544
542 if params_initial['sensitive'] is False: 545 if params_initial['sensitive'] is False:
543 del [params_initial['sensitive']] 546 del [params_initial['sensitive']]
@@ -551,7 +554,8 @@ class Mastodon:
551 else: 554 else:
552 media_ids_proper.append(media_id) 555 media_ids_proper.append(media_id)
553 except Exception as e: 556 except Exception as e:
554 raise MastodonIllegalArgumentError("Invalid media dict: %s" % e) 557 raise MastodonIllegalArgumentError("Invalid media "
558 "dict: %s" % e)
555 559
556 params_initial["media_ids"] = media_ids_proper 560 params_initial["media_ids"] = media_ids_proper
557 561
@@ -754,8 +758,9 @@ class Mastodon:
754 media_file = open(media_file, 'rb') 758 media_file = open(media_file, 'rb')
755 759
756 if mime_type is None: 760 if mime_type is None:
757 raise MastodonIllegalArgumentError( 761 raise MastodonIllegalArgumentError('Could not determine mime type'
758 'Could not determine mime type or data passed directly without mime type.') 762 ' or data passed directly '
763 'without mime type.')
759 764
760 random_suffix = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10)) 765 random_suffix = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
761 file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension( 766 file_name = "mastodonpyupload_" + str(time.time()) + "_" + str(random_suffix) + mimetypes.guess_extension(
@@ -996,8 +1001,9 @@ class Mastodon:
996 response = response_object.json() 1001 response = response_object.json()
997 except: 1002 except:
998 raise MastodonAPIError( 1003 raise MastodonAPIError(
999 "Could not parse response as JSON, response code was %s, bad json content was '%s'" % ( 1004 "Could not parse response as JSON, response code was %s, "
1000 response_object.status_code, response_object.content)) 1005 "bad json content was '%s'" % (response_object.status_code,
1006 response_object.content))
1001 1007
1002 # Parse link headers 1008 # Parse link headers
1003 if isinstance(response, list) and \ 1009 if isinstance(response, list) and \
@@ -1006,7 +1012,7 @@ class Mastodon:
1006 tmp_urls = requests.utils.parse_header_links( 1012 tmp_urls = requests.utils.parse_header_links(
1007 response_object.headers['Link'].rstrip('>').replace('>,<', ',<')) 1013 response_object.headers['Link'].rstrip('>').replace('>,<', ',<'))
1008 for url in tmp_urls: 1014 for url in tmp_urls:
1009 if not 'rel' in url: 1015 if 'rel' not in url:
1010 continue 1016 continue
1011 1017
1012 if url['rel'] == 'next': 1018 if url['rel'] == 'next':
Powered by cgit v1.2.3 (git 2.41.0)