ecoledirecte 0.2.0__tar.gz → 0.2.2__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ecoledirecte
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Async Python client to interact with Ecole Directe API.
5
5
  License: LGPL-3.0-or-later
6
6
  License-File: LICENSE
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "ecoledirecte"
3
- version = "0.2.0"
3
+ version = "0.2.2"
4
4
  description = "Async Python client to interact with Ecole Directe API."
5
5
  license = { text = "LGPL-3.0-or-later" }
6
6
  readme = "README.rst"
@@ -42,7 +42,7 @@ pylint = "^4.0.3"
42
42
  isort = ">=5.13.2,<8.0.0"
43
43
  mypy = "^1.18.1"
44
44
  flake8 = "^7.3.0"
45
- pyupgrade = "^3.21.1"
45
+ pyupgrade = "^3.21.2"
46
46
  pytest-asyncio = ">=0.23.8,<1.4.0"
47
47
  typing-extensions=">=4.13.2"
48
48
 
@@ -1,4 +1,4 @@
1
1
  """Top-level package for Ecole Directe API."""
2
2
 
3
3
  __author__ = """Giga77"""
4
- __version__ = "0.2.0"
4
+ __version__ = "0.2.2"
@@ -58,6 +58,7 @@ class EDConnectionState:
58
58
  self.cn = None
59
59
  self.cv = None
60
60
  self.cookie_jar = None
61
+ LOGGER.debug("EDConnectionState reset done.")
61
62
 
62
63
 
63
64
  class EDClient:
@@ -95,6 +96,7 @@ class EDClient:
95
96
  self.server_endpoint = server_endpoint
96
97
  self.api_version = api_version
97
98
  self._session: ClientSession = None
99
+ LOGGER.debug("EDClient initialized.")
98
100
 
99
101
  async def __aenter__(self) -> EDClient:
100
102
  return self
@@ -112,6 +114,7 @@ class EDClient:
112
114
  if self._session is not None:
113
115
  await self._session.close()
114
116
  self._session = None
117
+ LOGGER.debug("_session closed (or none).")
115
118
 
116
119
  def __get_new_client__(self) -> None:
117
120
  """Create a new aiohttp client session."""
@@ -149,6 +152,7 @@ class EDClient:
149
152
 
150
153
  async def __get_gtk__(self) -> None:
151
154
  """Get the gtk value from the server."""
155
+ LOGGER.debug("getting gtk for cookies...")
152
156
  # first call to get a cookie
153
157
  if "x-gtk" in self._session.headers:
154
158
  self._session.headers.pop("x-gtk")
@@ -166,7 +170,7 @@ class EDClient:
166
170
  async def __get_token__(self, payload: str) -> Any:
167
171
  """Get the token value from the server."""
168
172
  LOGGER.debug(
169
- f"headers request: [{self._session.headers}] - payload: [{payload}]"
173
+ f"get_token headers request: [{self._session.headers}] - payload: [{payload}]"
170
174
  )
171
175
  response = await self._session.post(
172
176
  f"{self.server_endpoint}/login.awp",
@@ -181,8 +185,8 @@ class EDClient:
181
185
  bypassMFA=True,
182
186
  )
183
187
  json = await response.json(content_type=None)
184
- LOGGER.debug(f"headers response: {response.headers}")
185
- LOGGER.debug(f"json response: {json}")
188
+ LOGGER.debug(f"get_token headers response: {response.headers}")
189
+ LOGGER.debug(f"get_token json response: {json}")
186
190
 
187
191
  self.conn_state.token = response.headers["x-token"]
188
192
  self._session.headers.update({"x-token": self.conn_state.token})
@@ -220,6 +224,7 @@ class EDClient:
220
224
 
221
225
  async def __post_qcm_connexion__(self, proposition: str) -> dict:
222
226
  """Renvoyer la réponse du QCM donné."""
227
+ LOGGER.debug(f"__post_qcm_connexion__ proposition=[{proposition}]")
223
228
  response = await self._session.post(
224
229
  url=f"{self.server_endpoint}/connexion/doubleauth.awp",
225
230
  params={"verbe": "post", "v": self.api_version},
@@ -251,14 +256,18 @@ class EDClient:
251
256
  self,
252
257
  ) -> Any:
253
258
  """Authenticate and create an API session allowing access to the other operations."""
259
+ LOGGER.debug("Enter login...")
260
+
254
261
  if self._session is not None:
255
262
  await self._session.close()
256
263
  if self.conn_state.cn is None or self.conn_state.cv is None:
257
264
  self.conn_state.reset()
258
265
 
266
+ LOGGER.debug("getting new client...")
259
267
  self.__get_new_client__()
260
268
 
261
269
  if self.conn_state.cookie_jar is None:
270
+ LOGGER.debug("cookie_jar is None, get gtk...")
262
271
  await self.__get_gtk__()
263
272
  payload = (
264
273
  'data={"identifiant":"'
@@ -269,8 +278,13 @@ class EDClient:
269
278
  )
270
279
  first_token = await self.__get_token__(payload)
271
280
 
281
+ if first_token["code"] == ED_OK:
282
+ LOGGER.debug("first_token[code] == ED_OK !!!!!!!!")
283
+ return first_token
284
+
272
285
  # Si connexion initiale
273
286
  if first_token["code"] == ED_MFA_REQUIRED:
287
+ LOGGER.debug("first_token[code] == ED_MFA_REQUIRED, Trying MFA...")
274
288
  try_login = 2
275
289
 
276
290
  while try_login > 0:
@@ -331,6 +345,7 @@ class EDClient:
331
345
  + '"}]}'
332
346
  )
333
347
  return await self.__get_token__(payload)
348
+ LOGGER.debug("Login failed...")
334
349
 
335
350
  async def __get(self, path: str) -> Any:
336
351
  """Make a GET request to the Ecole Directe API"""
@@ -5,4 +5,4 @@ ED_MFA_REQUIRED = 250
5
5
  ED_OK = 200
6
6
  ED_NODATA = 210
7
7
  APIURL = "https://api.ecoledirecte.com/v3"
8
- APIVERSION = "4.89.1" # Version of the EcoleDirecte app
8
+ APIVERSION = "4.90.0"
File without changes
File without changes