all constructor arguments optional, maintain backward compatibility
This commit is contained in:
pare
2a92376d9b
commit
afc6158385
S'han modificat 1 arxius amb 9 adicions i 12 eliminacions
|
@ -174,7 +174,7 @@ class Mastodon:
|
||||||
###
|
###
|
||||||
# Authentication, including constructor
|
# Authentication, including constructor
|
||||||
###
|
###
|
||||||
def __init__(self, client_id, client_secret=None, access_token=None,
|
def __init__(self, access_token=None, client_id=None, client_secret=None,
|
||||||
api_base_url=__DEFAULT_BASE_URL, debug_requests=False,
|
api_base_url=__DEFAULT_BASE_URL, debug_requests=False,
|
||||||
ratelimit_method="wait", ratelimit_pacefactor=1.1,
|
ratelimit_method="wait", ratelimit_pacefactor=1.1,
|
||||||
request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None,
|
request_timeout=__DEFAULT_TIMEOUT, mastodon_version=None,
|
||||||
|
@ -248,17 +248,14 @@ class Mastodon:
|
||||||
raise MastodonIllegalArgumentError("Invalid ratelimit method.")
|
raise MastodonIllegalArgumentError("Invalid ratelimit method.")
|
||||||
|
|
||||||
# Token loading
|
# Token loading
|
||||||
if os.path.isfile(self.client_id):
|
if self.access_token is None:
|
||||||
with open(self.client_id, 'r') as secret_file:
|
if os.path.isfile(self.client_id):
|
||||||
self.client_id = secret_file.readline().rstrip()
|
with open(self.client_id, 'r') as secret_file:
|
||||||
self.client_secret = secret_file.readline().rstrip()
|
self.client_id = secret_file.readline().rstrip()
|
||||||
else:
|
self.client_secret = secret_file.readline().rstrip()
|
||||||
if self.client_secret is None:
|
if self.access_token is not None and os.path.isfile(self.access_token):
|
||||||
raise MastodonIllegalArgumentError('Specified client id directly, but did not supply secret')
|
with open(self.access_token, 'r') as token_file:
|
||||||
|
self.access_token = token_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()
|
|
||||||
|
|
||||||
def retrieve_mastodon_version(self):
|
def retrieve_mastodon_version(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Referencia en una nova incidència