From cbcf3b12375d5f8ef238fe4bccf4e9bcc5fd5c11 Mon Sep 17 00:00:00 2001 From: Joel Gil Leon Date: Mon, 14 May 2018 19:24:14 +0300 Subject: [PATCH] Revert "all constructor arguments optional, maintain backward compatibility" This reverts commit afc61583853ebe8fbc3da21b890533c0dd94957b. --- mastodon/Mastodon.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mastodon/Mastodon.py b/mastodon/Mastodon.py index b0d5a39..b186344 100644 --- a/mastodon/Mastodon.py +++ b/mastodon/Mastodon.py @@ -174,7 +174,7 @@ class Mastodon: ### # Authentication, including constructor ### - def __init__(self, access_token=None, client_id=None, client_secret=None, + def __init__(self, client_id, client_secret=None, access_token=None, api_base_url=__DEFAULT_BASE_URL, debug_requests=False, ratelimit_method="wait", ratelimit_pacefactor=1.1, request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None, @@ -248,14 +248,17 @@ class Mastodon: raise MastodonIllegalArgumentError("Invalid ratelimit method.") # Token loading - if self.access_token is None: - if os.path.isfile(self.client_id): - with open(self.client_id, 'r') as secret_file: - self.client_id = secret_file.readline().rstrip() - self.client_secret = secret_file.readline().rstrip() - if self.access_token is not None and os.path.isfile(self.access_token): - with open(self.access_token, 'r') as token_file: - self.access_token = token_file.readline().rstrip() + if os.path.isfile(self.client_id): + with open(self.client_id, 'r') as secret_file: + self.client_id = secret_file.readline().rstrip() + self.client_secret = secret_file.readline().rstrip() + else: + if self.client_secret is None: + raise MastodonIllegalArgumentError('Specified client id directly, but did not supply secret') + + if self.access_token is not None and os.path.isfile(self.access_token): + with open(self.access_token, 'r') as token_file: + self.access_token = token_file.readline().rstrip() def retrieve_mastodon_version(self): """