@@ -48,7 +48,8 @@ def __init__(
48
48
self ._retry_after = int (retry_after )
49
49
self ._verify_ssl = bool (safe )
50
50
51
- def _prepare_domain (self , domain : str ) -> str :
51
+ @staticmethod
52
+ def _prepare_domain (domain : str ) -> str :
52
53
"""Normalize user passed domain to a valid one."""
53
54
o = urlparse (domain )
54
55
if not o .scheme or not o .netloc :
@@ -114,7 +115,7 @@ async def request(self, method: str, params: str = None) -> Dict[str, Any]:
114
115
return response
115
116
116
117
async def _call (
117
- self , method : str , params : Dict [str , Any ] = {} , start : int = 0
118
+ self , method : str , params : Dict [str , Any ] = None , start : int = 0
118
119
) -> Dict [str , Any ]:
119
120
"""Async call a REST method with specified parameters.
120
121
@@ -124,6 +125,8 @@ async def _call(
124
125
params (dict): Optional arguments which will be converted to a POST request string
125
126
start (int): Offset for pagination
126
127
"""
128
+ if params is None :
129
+ params = {}
127
130
params ["start" ] = start
128
131
129
132
payload = self ._prepare_params (params )
@@ -138,7 +141,7 @@ async def _call(
138
141
return res ["result" ] + result
139
142
return res ["result" ]
140
143
141
- def callMethod (self , method : str , params : Dict [str , Any ] = {} , ** kwargs ) -> Dict [str , Any ]:
144
+ def callMethod (self , method : str , params : Dict [str , Any ] = None , ** kwargs ) -> Dict [str , Any ]:
142
145
"""Call a REST method with specified parameters.
143
146
144
147
Parameters
@@ -150,6 +153,10 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict
150
153
-------
151
154
Returning the REST method response as an array, an object or a scalar
152
155
"""
156
+
157
+ if params is None :
158
+ params = {}
159
+
153
160
if not method :
154
161
raise BitrixError ("Wrong method name" , 400 )
155
162
@@ -158,14 +165,16 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict
158
165
except RuntimeError :
159
166
warnings .warn (
160
167
"You are using `callMethod` method in a synchronous way. "
161
- "Starting from version 3, this method will be completly asynchronous."
168
+ "Starting from version 3, this method will be completely asynchronous."
162
169
"Please consider updating your code" ,
163
170
DeprecationWarning ,
164
171
)
165
172
loop = asyncio .new_event_loop ()
166
173
asyncio .set_event_loop (loop )
167
- result = loop .run_until_complete (self ._call (method , params or kwargs ))
168
- loop .close ()
174
+ try :
175
+ result = loop .run_until_complete (self ._call (method , params or kwargs ))
176
+ finally :
177
+ loop .close ()
169
178
else :
170
179
result = asyncio .ensure_future (self ._call (method , params or kwargs ))
171
180
return result
0 commit comments