kopia lustrzana https://github.com/halcy/Mastodon.py
make streaming work with Sharkey (maybe)
rodzic
181f2a72c5
commit
c460d3c965
|
@ -20,3 +20,12 @@ This function allows for easy basic decoding of blurhash strings to images.
|
|||
This requires Mastodon.pys optional "blurhash" feature dependencies.
|
||||
|
||||
.. automethod:: Mastodon.decode_blurhash
|
||||
|
||||
Cache control
|
||||
-------------
|
||||
.. automethod:: Mastodon.clear_caches
|
||||
|
||||
Other utilities
|
||||
---------------
|
||||
.. automethod:: Mastodon.get_approx_server_time
|
||||
.. automethod:: Mastodon.set_language
|
|
@ -242,6 +242,9 @@ class Mastodon(Internals):
|
|||
if not mastodon_version is None:
|
||||
self.version_check_tried = True
|
||||
|
||||
# Cached version check
|
||||
self.__streaming_base = None
|
||||
|
||||
# Versioning
|
||||
if mastodon_version is None and self.version_check_mode != 'none':
|
||||
self.retrieve_mastodon_version()
|
||||
|
@ -255,6 +258,16 @@ class Mastodon(Internals):
|
|||
if ratelimit_method not in ["throw", "wait", "pace"]:
|
||||
raise MastodonIllegalArgumentError("Invalid ratelimit method.")
|
||||
|
||||
def clear_caches(self):
|
||||
"""
|
||||
Clear cached data:
|
||||
* Mastodon version
|
||||
* Streaming base URL
|
||||
"""
|
||||
self.version_check_worked = None
|
||||
self.version_check_tried = False
|
||||
self.__streaming_base = None
|
||||
|
||||
def auth_request_url(self, client_id: Optional[Union[str, PurePath]] = None, redirect_uris: str = "urn:ietf:wg:oauth:2.0:oob",
|
||||
scopes: List[str] =_DEFAULT_SCOPES, force_login: bool = False, state: Optional[str] = None,
|
||||
lang: Optional[str] = None) -> str:
|
||||
|
|
|
@ -343,9 +343,22 @@ class Mastodon():
|
|||
Internal streaming API helper.
|
||||
|
||||
Returns the correct URL for the streaming API.
|
||||
|
||||
Caches the URL.
|
||||
"""
|
||||
instance = self.__instance()
|
||||
if "streaming_api" in instance["urls"] and instance["urls"]["streaming_api"] != self.api_base_url:
|
||||
# Try to support implementations that have no v1 endpoint (Sharkey does this)
|
||||
streaming_api_url = None
|
||||
try:
|
||||
instance = self.__instance()
|
||||
if "streaming_api" in instance["urls"]:
|
||||
streaming_api_url = instance["urls"]["streaming_api"]
|
||||
except:
|
||||
try:
|
||||
streaming_api_url = self.instance_v2().configuration.urls.streaming
|
||||
except:
|
||||
pass
|
||||
|
||||
if not streaming_api_url is None and streaming_api_url != self.api_base_url:
|
||||
# This is probably a websockets URL, which is really for the browser, but requests can't handle it
|
||||
# So we do this below to turn it into an HTTPS or HTTP URL
|
||||
parse = urlparse(instance["urls"]["streaming_api"])
|
||||
|
|
Ładowanie…
Reference in New Issue