HedgeTech 0.2.0b1__py3-none-any.whl → 0.2.2b0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
  # Imports #
3
3
  # ========================================|======================================== #
4
4
 
5
+ from .__utils import RetriableAsyncClient
5
6
  from httpx import (
6
7
  AsyncClient ,
7
8
  Timeout ,
@@ -126,20 +127,23 @@ class AuthAsyncClient:
126
127
  headers = {'origin' : 'https://core.hedgetech.ir'}
127
128
  headers.update(token)
128
129
 
129
- httpx_Client = AsyncClient(
130
- verify=True ,
131
- http1=False ,
132
- http2=True ,
133
- headers=headers,
134
- cookies=httpx_Client.cookies,
135
- timeout=Timeout(
136
- connect=.5,
137
- read=1,
138
- write=1,
139
- pool=.5,
130
+ httpx_Client = RetriableAsyncClient(
131
+ client = AsyncClient(
132
+ verify=True ,
133
+ http1=False ,
134
+ http2=True ,
135
+ headers=headers,
136
+ cookies=httpx_Client.cookies,
137
+ timeout=Timeout(
138
+ connect=.250,
139
+ read=1.5,
140
+ write=1.5,
141
+ pool=.250,
142
+ ),
140
143
  ),
144
+ retries= 10
141
145
  )
142
-
146
+
143
147
  return cls(
144
148
  httpx_Client = httpx_Client,
145
149
  token = token
@@ -2,6 +2,7 @@
2
2
  # Imports #
3
3
  # ========================================|======================================== #
4
4
 
5
+ from .__utils import RetriableSyncClient
5
6
  from httpx import (
6
7
  Client ,
7
8
  Timeout ,
@@ -128,24 +129,27 @@ class AuthSyncClient:
128
129
  token = login_res.json()
129
130
  headers = {'origin' : 'https://core.hedgetech.ir'}
130
131
  headers.update(token)
131
-
132
- httpx_Client = Client(
133
- verify=True ,
134
- http1=False ,
135
- http2=True ,
136
- headers=headers,
137
- cookies=httpx_Client.cookies,
138
- timeout=Timeout(
139
- connect=.5,
140
- read=1,
141
- write=1,
142
- pool=.5,
132
+
133
+ httpx_Client = RetriableSyncClient(
134
+ client = Client(
135
+ verify=True ,
136
+ http1=False ,
137
+ http2=True ,
138
+ headers=headers,
139
+ cookies=httpx_Client.cookies,
140
+ timeout=Timeout(
141
+ connect=.250,
142
+ read=1.5,
143
+ write=1.5,
144
+ pool=.250,
145
+ ),
143
146
  ),
147
+ retries= 10
144
148
  )
145
-
149
+
146
150
  return cls(
147
151
  httpx_Client = httpx_Client,
148
- token = login_res.json()
152
+ token = token
149
153
  )
150
154
 
151
155
  else :
@@ -0,0 +1,63 @@
1
+ # ========================================|======================================== #
2
+ # Exports #
3
+ # ========================================|======================================== #
4
+
5
+ __all__ = [
6
+ 'RetriableAsyncClient'
7
+ ]
8
+
9
+ # ========================================|======================================== #
10
+ # Imports #
11
+ # ========================================|======================================== #
12
+
13
+ from httpx import (
14
+ AsyncClient,
15
+
16
+ ConnectTimeout,
17
+ PoolTimeout,
18
+ ReadTimeout,
19
+ WriteTimeout,
20
+ )
21
+
22
+ # ========================================|======================================== #
23
+ # Class Definitions #
24
+ # ========================================|======================================== #
25
+
26
+
27
+ class RetriableAsyncClient:
28
+
29
+ def __init__(
30
+ self,
31
+ client: AsyncClient,
32
+ retries: int = 10,
33
+ )-> AsyncClient:
34
+
35
+ self._client = client
36
+ self._retries = retries
37
+
38
+ async def _request(self, method: str, **kwargs):
39
+ attempt = self._retries
40
+
41
+ while True:
42
+ try:
43
+ return await getattr(self._client, method)(**kwargs)
44
+
45
+ except (
46
+ ConnectTimeout,
47
+ PoolTimeout,
48
+ ReadTimeout,
49
+ WriteTimeout,
50
+ ):
51
+ if attempt <= 0:
52
+ raise
53
+ attempt -= 1
54
+
55
+ def __getattr__(self, name: str):
56
+ attr = getattr(self._client, name)
57
+
58
+ if name in {"get", "post", "put", "delete", "patch", "options", "head"}:
59
+ async def wrapper(**kwargs):
60
+ return await self._request(name, **kwargs)
61
+ return wrapper
62
+
63
+ return attr
@@ -0,0 +1,65 @@
1
+ # ========================================|======================================== #
2
+ # Exports #
3
+ # ========================================|======================================== #
4
+
5
+ __all__ = [
6
+ 'RetriableSyncClient'
7
+ ]
8
+
9
+ # ========================================|======================================== #
10
+ # Imports #
11
+ # ========================================|======================================== #
12
+
13
+ from httpx import (
14
+ Client,
15
+
16
+ ConnectTimeout,
17
+ PoolTimeout,
18
+ ReadTimeout,
19
+ WriteTimeout,
20
+ )
21
+
22
+ # ========================================|======================================== #
23
+ # Class Definitions #
24
+ # ========================================|======================================== #
25
+
26
+
27
+ class RetriableSyncClient:
28
+
29
+ def __init__(
30
+ self,
31
+ client: Client,
32
+ retries: int = 10,
33
+ )-> Client:
34
+
35
+ self._client = client
36
+ self._retries = retries
37
+
38
+ def _request(self, method: str, **kwargs):
39
+ attempt = self._retries
40
+
41
+ while True:
42
+ try:
43
+ return getattr(self._client, method)(**kwargs)
44
+
45
+ except (
46
+ ConnectTimeout,
47
+ PoolTimeout,
48
+ ReadTimeout,
49
+ WriteTimeout,
50
+ ):
51
+ if attempt <= 0:
52
+ raise
53
+ attempt -= 1
54
+
55
+ def __getattr__(self, name: str):
56
+
57
+ attr = getattr(self._client, name)
58
+
59
+ if name in {"get", "post", "put", "delete", "patch", "options", "head"}:
60
+
61
+ def wrapper(**kwargs):
62
+ return self._request(name, **kwargs)
63
+ return wrapper
64
+
65
+ return attr
@@ -0,0 +1,2 @@
1
+ from .__RetriableAsyncClient import *
2
+ from .__RetriableSyncClient import *
@@ -1,4 +1,4 @@
1
1
  from .__tse_ifb import (
2
2
  EmsEngine_TseIfb_SyncClient,
3
- EmsEngine_TseIfb_ASyncClient
3
+ EmsEngine_TseIfb_AsyncClient
4
4
  )