From 38343482f99a21538f84b5148305b169bacb6648 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 1 Jul 2024 21:29:51 +0200 Subject: [PATCH 1/5] fix typos --- README.md | 2 +- bitrix24/bitrix24.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 588c462..7096eb3 100644 --- a/bitrix24/bitrix24.py +++ b/bitrix24/bitrix24.py @@ -158,7 +158,7 @@ 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, ) From 24aa3179588bccecd703dbe82546e8fc92893467 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 1 Jul 2024 21:46:22 +0200 Subject: [PATCH 2/5] pep-8 --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index cf642ff..82b77d1 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=[ From 87e55590c4982819eb3b55c340d07abf26974844 Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 1 Jul 2024 21:48:34 +0200 Subject: [PATCH 3/5] fix a staticmethod warning --- bitrix24/bitrix24.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bitrix24/bitrix24.py b/bitrix24/bitrix24.py index 7096eb3..31d4435 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: From c1e1b319082b66bd63cd4847ac376d1109e2a4fd Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 1 Jul 2024 21:49:43 +0200 Subject: [PATCH 4/5] use None instead of {} as the default value for optional dict arguments --- bitrix24/bitrix24.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bitrix24/bitrix24.py b/bitrix24/bitrix24.py index 31d4435..b82a42b 100644 --- a/bitrix24/bitrix24.py +++ b/bitrix24/bitrix24.py @@ -115,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. @@ -125,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) @@ -139,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 @@ -151,6 +153,8 @@ 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 or len(method.split(".")) < 2: raise BitrixError("Wrong method name", 400) From fce3364db428c526ab35363bf0c2403266f3147c Mon Sep 17 00:00:00 2001 From: Igor Date: Mon, 1 Jul 2024 21:51:02 +0200 Subject: [PATCH 5/5] fix memory leak, if the method threw an exception, the loop was not closed --- bitrix24/bitrix24.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/bitrix24/bitrix24.py b/bitrix24/bitrix24.py index b82a42b..9ba94d0 100644 --- a/bitrix24/bitrix24.py +++ b/bitrix24/bitrix24.py @@ -169,8 +169,10 @@ def callMethod(self, method: str, params: Dict[str, Any] = None, **kwargs) -> Di ) 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