diff options
author | Patrick Cloke <clokep@users.noreply.github.com> | 2020-09-01 11:03:49 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-01 11:03:49 -0400 |
commit | 7d103a594e10f4040096bf38716c9cdddf42eca0 (patch) | |
tree | 121ec76a75a4c2c4827ab8e3f9d952af226db940 /synapse/appservice | |
parent | Rename `_get_e2e_device_keys_txn` (#8222) (diff) | |
download | synapse-7d103a594e10f4040096bf38716c9cdddf42eca0.tar.xz |
Convert appservice code to async/await. (#8207)
Diffstat (limited to 'synapse/appservice')
-rw-r--r-- | synapse/appservice/api.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/synapse/appservice/api.py b/synapse/appservice/api.py index e72a0b9ac0..bb6fa8299a 100644 --- a/synapse/appservice/api.py +++ b/synapse/appservice/api.py @@ -14,18 +14,20 @@ # limitations under the License. import logging import urllib +from typing import TYPE_CHECKING, Optional from prometheus_client import Counter -from twisted.internet import defer - from synapse.api.constants import EventTypes, ThirdPartyEntityKind from synapse.api.errors import CodeMessageException from synapse.events.utils import serialize_event from synapse.http.client import SimpleHttpClient -from synapse.types import ThirdPartyInstanceID +from synapse.types import JsonDict, ThirdPartyInstanceID from synapse.util.caches.response_cache import ResponseCache +if TYPE_CHECKING: + from synapse.appservice import ApplicationService + logger = logging.getLogger(__name__) sent_transactions_counter = Counter( @@ -163,19 +165,20 @@ class ApplicationServiceApi(SimpleHttpClient): logger.warning("query_3pe to %s threw exception %s", uri, ex) return [] - def get_3pe_protocol(self, service, protocol): + async def get_3pe_protocol( + self, service: "ApplicationService", protocol: str + ) -> Optional[JsonDict]: if service.url is None: return {} - @defer.inlineCallbacks - def _get(): + async def _get() -> Optional[JsonDict]: uri = "%s%s/thirdparty/protocol/%s" % ( service.url, APP_SERVICE_PREFIX, urllib.parse.quote(protocol), ) try: - info = yield defer.ensureDeferred(self.get_json(uri, {})) + info = await self.get_json(uri, {}) if not _is_valid_3pe_metadata(info): logger.warning( @@ -196,7 +199,7 @@ class ApplicationServiceApi(SimpleHttpClient): return None key = (service.id, protocol) - return self.protocol_meta_cache.wrap(key, _get) + return await self.protocol_meta_cache.wrap(key, _get) async def push_bulk(self, service, events, txn_id=None): if service.url is None: |