Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
synapse
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maunium
synapse
Commits
7d103a59
Unverified
Commit
7d103a59
authored
4 years ago
by
Patrick Cloke
Committed by
GitHub
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Convert appservice code to async/await. (#8207)
parent
5615eb5c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
changelog.d/8207.misc
+1
-0
1 addition, 0 deletions
changelog.d/8207.misc
synapse/appservice/api.py
+11
-8
11 additions, 8 deletions
synapse/appservice/api.py
with
12 additions
and
8 deletions
changelog.d/8207.misc
0 → 100644
+
1
−
0
View file @
7d103a59
Convert various parts of the codebase to async/await.
This diff is collapsed.
Click to expand it.
synapse/appservice/api.py
+
11
−
8
View file @
7d103a59
...
@@ -14,18 +14,20 @@
...
@@ -14,18 +14,20 @@
# limitations under the License.
# limitations under the License.
import
logging
import
logging
import
urllib
import
urllib
from
typing
import
TYPE_CHECKING
,
Optional
from
prometheus_client
import
Counter
from
prometheus_client
import
Counter
from
twisted.internet
import
defer
from
synapse.api.constants
import
EventTypes
,
ThirdPartyEntityKind
from
synapse.api.constants
import
EventTypes
,
ThirdPartyEntityKind
from
synapse.api.errors
import
CodeMessageException
from
synapse.api.errors
import
CodeMessageException
from
synapse.events.utils
import
serialize_event
from
synapse.events.utils
import
serialize_event
from
synapse.http.client
import
SimpleHttpClient
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
from
synapse.util.caches.response_cache
import
ResponseCache
if
TYPE_CHECKING
:
from
synapse.appservice
import
ApplicationService
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
sent_transactions_counter
=
Counter
(
sent_transactions_counter
=
Counter
(
...
@@ -163,19 +165,20 @@ class ApplicationServiceApi(SimpleHttpClient):
...
@@ -163,19 +165,20 @@ class ApplicationServiceApi(SimpleHttpClient):
logger
.
warning
(
"
query_3pe to %s threw exception %s
"
,
uri
,
ex
)
logger
.
warning
(
"
query_3pe to %s threw exception %s
"
,
uri
,
ex
)
return
[]
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
:
if
service
.
url
is
None
:
return
{}
return
{}
@defer.inlineCallbacks
async
def
_get
()
->
Optional
[
JsonDict
]:
def
_get
():
uri
=
"
%s%s/thirdparty/protocol/%s
"
%
(
uri
=
"
%s%s/thirdparty/protocol/%s
"
%
(
service
.
url
,
service
.
url
,
APP_SERVICE_PREFIX
,
APP_SERVICE_PREFIX
,
urllib
.
parse
.
quote
(
protocol
),
urllib
.
parse
.
quote
(
protocol
),
)
)
try
:
try
:
info
=
yield
defer
.
ensureDeferred
(
self
.
get_json
(
uri
,
{})
)
info
=
await
self
.
get_json
(
uri
,
{})
if
not
_is_valid_3pe_metadata
(
info
):
if
not
_is_valid_3pe_metadata
(
info
):
logger
.
warning
(
logger
.
warning
(
...
@@ -196,7 +199,7 @@ class ApplicationServiceApi(SimpleHttpClient):
...
@@ -196,7 +199,7 @@ class ApplicationServiceApi(SimpleHttpClient):
return
None
return
None
key
=
(
service
.
id
,
protocol
)
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
):
async
def
push_bulk
(
self
,
service
,
events
,
txn_id
=
None
):
if
service
.
url
is
None
:
if
service
.
url
is
None
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment