Skip to content

Commit fd2e3a0

Browse files
committed
ENH: 'open' and 'close' functions for threaded and async classes
1 parent 6e59521 commit fd2e3a0

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
import httpx
2+
13
from ._api_base import _SaveRestoreAPI_Base
24

35

4-
class _SaveRestoreAPI_Async(_SaveRestoreAPI_Base): ...
6+
class _SaveRestoreAPI_Async(_SaveRestoreAPI_Base):
7+
def open(self):
8+
self._client = httpx.AsyncClient(base_url=self._base_url, timeout=self._timeout)
9+
10+
async def close(self):
11+
await self._client.aclose()
12+
self._client = None

src/save_and_restore_api/_api_base.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,9 @@ def gen_auth(username, password):
5959
def set_auth(self, *, username, password):
6060
self._auth = self.gen_auth(username=username, password=password)
6161

62-
def open(self):
63-
self._client = httpx.Client(base_url=self._base_url, timeout=self._timeout)
62+
def open(self): ...
6463

65-
def close(self):
66-
self._client.close()
67-
self._client = None
64+
def close(self): ...
6865

6966
def set_username_password(self, username=None, password=None):
7067
if not isinstance(username, str):
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1+
import httpx
2+
13
from ._api_base import _SaveRestoreAPI_Base
24

35

4-
class _SaveRestoreAPI_Threads(_SaveRestoreAPI_Base): ...
6+
class _SaveRestoreAPI_Threads(_SaveRestoreAPI_Base):
7+
def open(self):
8+
self._client = httpx.Client(base_url=self._base_url, timeout=self._timeout)
9+
10+
def close(self):
11+
self._client.close()
12+
self._client = None

0 commit comments

Comments
 (0)