11import asyncio
2- from aiohttp import (
3- web ,
4- ClientSession ,
5- ClientRequest ,
6- ClientResponse ,
7- ClientError ,
8- ClientTimeout ,
9- )
102import json
11- import os
12- from time import sleep
133import uuid
144
155from runners .agent_container import AgentContainer , create_agent_with_args_list
16- from runners .support .agent import DemoAgent
176
187
198######################################################################
209# coroutine utilities
2110######################################################################
2211
2312
24- def run_coroutine (coroutine ):
25- loop = asyncio .get_event_loop ()
26- if not loop :
27- loop = asyncio .new_event_loop ()
28- asyncio .set_event_loop (loop )
29- try :
30- return loop .run_until_complete (coroutine ())
31- finally :
32- pass
33- # loop.close()
34-
35-
36- def run_coroutine_with_args (coroutine , * args ):
37- loop = asyncio .get_event_loop ()
38- if not loop :
39- loop = asyncio .new_event_loop ()
40- asyncio .set_event_loop (loop )
41- try :
42- return loop .run_until_complete (coroutine (* args ))
43- finally :
44- pass
45- # loop.close()
46-
47-
48- def run_coroutine_with_kwargs (coroutine , * args , ** kwargs ):
13+ def run_coroutine (coroutine , * args , ** kwargs ):
4914 loop = asyncio .get_event_loop ()
5015 if not loop :
5116 loop = asyncio .new_event_loop ()
@@ -58,22 +23,22 @@ def run_coroutine_with_kwargs(coroutine, *args, **kwargs):
5823
5924
6025def async_sleep (delay ):
61- run_coroutine_with_args (asyncio .sleep , delay )
26+ run_coroutine (asyncio .sleep , delay )
6227
6328
6429######################################################################
6530# high level aries agent interface
6631######################################################################
6732def create_agent_container_with_args (in_args : list ):
68- return run_coroutine_with_args (create_agent_with_args_list , in_args )
33+ return run_coroutine (create_agent_with_args_list , in_args )
6934
7035
7136def aries_container_initialize (
7237 the_container : AgentContainer ,
7338 schema_name : str = None ,
7439 schema_attrs : list = None ,
7540):
76- run_coroutine_with_kwargs (
41+ run_coroutine (
7742 the_container .initialize ,
7843 schema_name = schema_name ,
7944 schema_attrs = schema_attrs ,
@@ -86,7 +51,7 @@ def agent_container_register_did(
8651 verkey : str ,
8752 role : str ,
8853):
89- run_coroutine_with_args (
54+ run_coroutine (
9055 the_container .register_did ,
9156 did ,
9257 verkey ,
@@ -103,7 +68,7 @@ def aries_container_terminate(
10368def aries_container_generate_invitation (
10469 the_container : AgentContainer ,
10570):
106- return run_coroutine_with_kwargs (
71+ return run_coroutine (
10772 the_container .generate_invitation ,
10873 )
10974
@@ -112,7 +77,7 @@ def aries_container_receive_invitation(
11277 the_container : AgentContainer ,
11378 invite_details : dict ,
11479):
115- return run_coroutine_with_kwargs (
80+ return run_coroutine (
11681 the_container .input_invitation ,
11782 invite_details ,
11883 )
@@ -130,7 +95,7 @@ def aries_container_create_schema_cred_def(
13095 schema_attrs : list ,
13196 version : str = None ,
13297):
133- return run_coroutine_with_kwargs (
98+ return run_coroutine (
13499 the_container .create_schema_and_cred_def ,
135100 schema_name ,
136101 schema_attrs ,
@@ -143,7 +108,7 @@ def aries_container_issue_credential(
143108 cred_def_id : str ,
144109 cred_attrs : list ,
145110):
146- return run_coroutine_with_args (
111+ return run_coroutine (
147112 the_container .issue_credential ,
148113 cred_def_id ,
149114 cred_attrs ,
@@ -155,7 +120,7 @@ def aries_container_receive_credential(
155120 cred_def_id : str ,
156121 cred_attrs : list ,
157122):
158- return run_coroutine_with_args (
123+ return run_coroutine (
159124 the_container .receive_credential ,
160125 cred_def_id ,
161126 cred_attrs ,
@@ -166,7 +131,7 @@ def aries_container_request_proof(
166131 the_container : AgentContainer ,
167132 proof_request : dict ,
168133):
169- return run_coroutine_with_args (
134+ return run_coroutine (
170135 the_container .request_proof ,
171136 proof_request ,
172137 )
@@ -176,7 +141,7 @@ def aries_container_verify_proof(
176141 the_container : AgentContainer ,
177142 proof_request : dict ,
178143):
179- return run_coroutine_with_args (
144+ return run_coroutine (
180145 the_container .verify_proof ,
181146 proof_request ,
182147 )
@@ -228,7 +193,7 @@ def agent_container_GET(
228193 text : bool = False ,
229194 params : dict = None ,
230195) -> dict :
231- return run_coroutine_with_kwargs (
196+ return run_coroutine (
232197 the_container .admin_GET ,
233198 path ,
234199 text = text ,
@@ -243,7 +208,7 @@ def agent_container_POST(
243208 text : bool = False ,
244209 params : dict = None ,
245210) -> dict :
246- return run_coroutine_with_kwargs (
211+ return run_coroutine (
247212 the_container .admin_POST ,
248213 path ,
249214 data = data ,
@@ -259,7 +224,7 @@ def agent_container_PATCH(
259224 text : bool = False ,
260225 params : dict = None ,
261226) -> dict :
262- return run_coroutine_with_kwargs (
227+ return run_coroutine (
263228 the_container .admin_PATCH ,
264229 path ,
265230 data = data ,
@@ -275,7 +240,7 @@ def agent_container_PUT(
275240 text : bool = False ,
276241 params : dict = None ,
277242) -> dict :
278- return run_coroutine_with_kwargs (
243+ return run_coroutine (
279244 the_container .admin_PUT ,
280245 path ,
281246 data = data ,
0 commit comments