From 1cc225917e4b2b731312c92143cb32e113f9df7a Mon Sep 17 00:00:00 2001 From: IluaAir Date: Thu, 26 Mar 2026 19:51:51 +0300 Subject: [PATCH] Add OxiApi create_session method for better view --- oxi/core.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/oxi/core.py b/oxi/core.py index 0563c84..dc23219 100644 --- a/oxi/core.py +++ b/oxi/core.py @@ -14,15 +14,24 @@ class OxiAPI: verify: bool = True, ): self.base_url = url.rstrip("/") - self._session = Session() - self._adapter = OxiAdapter(timeout=10, max_retries=3) - self._session.mount("https://", self._adapter) - self._session.mount("http://", self._adapter) - self._session.verify = verify - if username and password: - self._session.auth = (username, password) + self._session = self.__create_session(username, password, verify) self.node = Node(self._session, self.base_url) + def __create_session( + self, + username: Optional[str] = None, + password: Optional[str] = None, + verify: bool = True, + ) -> Session: + session = Session() + adapter = OxiAdapter(timeout=10, max_retries=3) + session.mount("https://", adapter) + session.mount("http://", adapter) + session.verify = verify + if username and password: + session.auth = (username, password) + return session + def __enter__(self): return self