diff --git a/README.md b/README.md index aba1882..a0e47cb 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ List methods return all available items at once. For large collections of data u ## Development -New contributers and pull requests are welcome. If you have any questions or suggestions, feel free to open an issue. +New contributors and pull requests are welcome. If you have any questions or suggestions, feel free to open an issue. Code comes with makefile for easy code base management. You can check `make help` for more details. diff --git a/bitrix24/bitrix24.py b/bitrix24/bitrix24.py index f8e5a27..85e11c5 100644 --- a/bitrix24/bitrix24.py +++ b/bitrix24/bitrix24.py @@ -48,7 +48,8 @@ def __init__( self._retry_after = int(retry_after) self._verify_ssl = bool(safe) - def _prepare_domain(self, domain: str) -> str: + @staticmethod + def _prepare_domain(domain: str) -> str: """Normalize user passed domain to a valid one.""" o = urlparse(domain) if not o.scheme or not o.netloc: @@ -114,7 +115,7 @@ async def request(self, method: str, params: str = None) -> Dict[str, Any]: return response async def _call( - self, method: str, params: Dict[str, Any] = {}, start: int = 0 + self, method: str, params: Dict[str, Any] = None, start: int = 0 ) -> Dict[str, Any]: """Async call a REST method with specified parameters. @@ -124,6 +125,8 @@ async def _call( params (dict): Optional arguments which will be converted to a POST request string start (int): Offset for pagination """ + if params is None: + params = {} params["start"] = start payload = self._prepare_params(params) @@ -138,7 +141,7 @@ async def _call( return res["result"] + result return res["result"] - def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict[str, Any]: + def callMethod(self, method: str, params: Dict[str, Any] = None, **kwargs) -> Dict[str, Any]: """Call a REST method with specified parameters. Parameters @@ -150,6 +153,10 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict ------- Returning the REST method response as an array, an object or a scalar """ + + if params is None: + params = {} + if not method: raise BitrixError("Wrong method name", 400) @@ -158,14 +165,16 @@ def callMethod(self, method: str, params: Dict[str, Any] = {}, **kwargs) -> Dict except RuntimeError: warnings.warn( "You are using `callMethod` method in a synchronous way. " - "Starting from version 3, this method will be completly asynchronous." + "Starting from version 3, this method will be completely asynchronous." "Please consider updating your code", DeprecationWarning, ) loop = asyncio.new_event_loop() asyncio.set_event_loop(loop) - result = loop.run_until_complete(self._call(method, params or kwargs)) - loop.close() + try: + result = loop.run_until_complete(self._call(method, params or kwargs)) + finally: + loop.close() else: result = asyncio.ensure_future(self._call(method, params or kwargs)) return result diff --git a/setup.py b/setup.py index e3f0895..b666409 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ from os import path from setuptools import find_packages -dir = path.abspath(path.dirname(__file__)) +directory = path.abspath(path.dirname(__file__)) setup( name="bitrix24-rest", @@ -36,7 +36,7 @@ author="Akop Kesheshyan", author_email="hello@akop.dev", description="Easy way to communicate with bitrix24 portal over REST without OAuth", - long_description=open(path.join(dir, "README.md"), encoding="utf-8").read(), + long_description=open(path.join(directory, "README.md"), encoding="utf-8").read(), long_description_content_type="text/markdown", keywords="bitrix24 api rest", classifiers=[