@@ -48,7 +48,8 @@ def __init__(
4848 self ._retry_after = int (retry_after )
4949 self ._verify_ssl = bool (safe )
5050
51- def _prepare_domain (self , domain : str ) -> str :
51+ @staticmethod
52+ def _prepare_domain (domain : str ) -> str :
5253 """Normalize user passed domain to a valid one."""
5354 o = urlparse (domain )
5455 if not o .scheme or not o .netloc :
@@ -114,7 +115,7 @@ async def request(self, method: str, params: str = None) -> Dict[str, Any]:
114115 return response
115116
116117 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
118119 ) -> Dict [str , Any ]:
119120 """Async call a REST method with specified parameters.
120121
@@ -124,6 +125,8 @@ async def _call(
124125 params (dict): Optional arguments which will be converted to a POST request string
125126 start (int): Offset for pagination
126127 """
128+ if params is None :
129+ params = {}
127130 params ["start" ] = start
128131
129132 payload = self ._prepare_params (params )
@@ -138,7 +141,7 @@ async def _call(
138141 return res ["result" ] + result
139142 return res ["result" ]
140143
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 ]:
142145 """Call a REST method with specified parameters.
143146
144147 Parameters
@@ -150,6 +153,10 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict
150153 -------
151154 Returning the REST method response as an array, an object or a scalar
152155 """
156+
157+ if params is None :
158+ params = {}
159+
153160 if not method :
154161 raise BitrixError ("Wrong method name" , 400 )
155162
@@ -158,14 +165,16 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict
158165 except RuntimeError :
159166 warnings .warn (
160167 "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."
162169 "Please consider updating your code" ,
163170 DeprecationWarning ,
164171 )
165172 loop = asyncio .new_event_loop ()
166173 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 ()
169178 else :
170179 result = asyncio .ensure_future (self ._call (method , params or kwargs ))
171180 return result
0 commit comments