librus-python-api 1.10.2__py3-none-any.whl → 1.10.3__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.
@@ -1,7 +1,7 @@
1
1
  """Independent bounded async client. General live compatibility is unqualified."""
2
2
 
3
3
  # Before the imports: config reads it for the User-Agent.
4
- __version__ = "1.10.2"
4
+ __version__ = "1.10.3"
5
5
 
6
6
  from librus_python_api.attachments import AttachmentStream, ModernAttachmentStream
7
7
  from librus_python_api.budget import RequestBudget
@@ -1069,6 +1069,13 @@ PAGE_NOTICES = MappingProxyType(
1069
1069
  ErrorKind.VIEW_DISABLED
1070
1070
  ),
1071
1071
  "Wybrano nieprawidłowy zakres daty.": ErrorKind.INVALID_INPUT,
1072
+ # Observed on the school-year archive (2026-11-20) while Synergia fills
1073
+ # it with the previous year; the page has no archive tables until then.
1074
+ (
1075
+ "Opcja chwilowo niedostępna. Aktualnie trwa proces zasilania archiwum "
1076
+ "danymi z poprzedniego roku szkolnego. Po zakończeniu procesu "
1077
+ "zasilania opcja zostanie ponownie udostępniona."
1078
+ ): ErrorKind.MAINTENANCE,
1072
1079
  }
1073
1080
  )
1074
1081
  MODULE_UNAVAILABLE_PATH = "/modul_niedostepny"
@@ -356,8 +356,10 @@ def _detail_grades(cell: html.HtmlElement) -> dict[int, _Grades]:
356
356
 
357
357
  The cell holds one table: `DESCRIPTIVE_DETAIL_COLUMNS` as its header, then
358
358
  per period a heading row and either grade rows or one empty-marker row,
359
- and an empty footer. A grade row with `Treść oceny` text fails: the grade
360
- boxes carry no such field, so the text would be lost.
359
+ and an empty footer. A subject without grades in either period may
360
+ instead have one empty-marker row and no period headings (#184). A grade
361
+ row with `Treść oceny` text fails: the grade boxes carry no such field, so
362
+ the text would be lost.
361
363
  """
362
364
  unsupported = LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
363
365
  tables = [node for node in cell if isinstance(node.tag, str)]
@@ -371,6 +373,7 @@ def _detail_grades(cell: html.HtmlElement) -> dict[int, _Grades]:
371
373
  result: dict[int, _Grades] = {}
372
374
  empty: set[int] = set()
373
375
  header = False
376
+ unscoped = False
374
377
  period: int | None = None
375
378
  for row in markup.rows(tables[0]):
376
379
  cells = markup.cells(row)
@@ -382,12 +385,23 @@ def _detail_grades(cell: html.HtmlElement) -> dict[int, _Grades]:
382
385
  elif next(row.iterancestors("tfoot"), None) is not None:
383
386
  if any(texts) or any(len(item) for item in cells):
384
387
  raise unsupported
388
+ elif unscoped:
389
+ # Nothing may follow the marker that stands for both periods.
390
+ raise unsupported
385
391
  elif len(cells) == 1 and texts[0] in DESCRIPTIVE_PERIOD_LABELS:
386
392
  period = DESCRIPTIVE_PERIOD_LABELS[texts[0]]
387
393
  if period in result or len(cells[0]):
388
394
  raise unsupported
389
395
  result[period] = []
390
- elif period is None or period in empty:
396
+ elif period is None:
397
+ if (
398
+ len(cells) != 1
399
+ or texts[0] not in GRADE_EMPTY_MARKERS - {""}
400
+ or len(cells[0])
401
+ ):
402
+ raise unsupported
403
+ unscoped = True
404
+ elif period in empty:
391
405
  raise unsupported
392
406
  elif len(cells) == 1:
393
407
  if result[period] or texts[0] not in GRADE_EMPTY_MARKERS - {""}:
@@ -405,7 +419,11 @@ def _detail_grades(cell: html.HtmlElement) -> dict[int, _Grades]:
405
419
  result[period].append((texts[0], markup.civil_date(day)))
406
420
  else:
407
421
  raise unsupported
408
- if not header or sorted(result) != [1, 2]:
422
+ if not header:
423
+ raise unsupported
424
+ if unscoped:
425
+ return {1: [], 2: []}
426
+ if sorted(result) != [1, 2]:
409
427
  raise unsupported
410
428
  if any(not result[key] and key not in empty for key in result):
411
429
  raise unsupported
@@ -3,6 +3,8 @@
3
3
  import json
4
4
  import math
5
5
  import re
6
+ from html import unescape
7
+ from html.entities import html5
6
8
  from typing import Any
7
9
 
8
10
  from lxml import etree, html
@@ -131,6 +133,67 @@ def parse_login(body: bytes) -> str:
131
133
  return location
132
134
 
133
135
 
136
+ # Browser HTML commonly contains stray closing tags; every libxml2 reports them.
137
+ HTML_RECOVERIES = frozenset({"ERR_TAG_NAME_MISMATCH"})
138
+ # libxml2 2.14 parses HTML as HTML5 does and reports none of these; the 2.11.9
139
+ # that lxml's Windows wheels bundle (#121) reports each one where a browser
140
+ # repairs the markup. Accepted only below 2.14, so newer libxml2 is unchanged.
141
+ # Seen on live pages: the first four. In the suite's fixtures and message
142
+ # bodies under 2.11: the rest. A misplaced html, head or body tag, which 2.14
143
+ # rejects too, is accepted only there.
144
+ HTML_RECOVERIES_BEFORE_2_14 = HTML_RECOVERIES | frozenset(
145
+ {
146
+ "ERR_ATTRIBUTE_REDEFINED", # a repeated attribute; the first one is kept
147
+ "ERR_NAME_REQUIRED", # a stray character where a name belongs
148
+ "ERR_ENTITYREF_SEMICOL_MISSING", # "&nbsp" without its ";"
149
+ "HTML_UNKNOWN_TAG", # an element HTML 4 does not list, such as nobr
150
+ "ERR_INVALID_CHAR", # a control character, dropped; 2.14 keeps it
151
+ "ERR_SPACE_REQUIRED", # "<?" without an XML processing instruction
152
+ "ERR_GT_REQUIRED", # a start tag the document ends inside
153
+ "ERR_COMMENT_ABRUPTLY_ENDED", # "<!-->"
154
+ "HTML_INCORRECTLY_OPENED_COMMENT", # "<!" that starts no comment
155
+ "HTML_STRUCURE_ERROR", # a misplaced DOCTYPE, html, head or body tag
156
+ }
157
+ )
158
+ _LEGACY_REFERENCES = frozenset(name for name in html5 if not name.endswith(";"))
159
+ # A named reference without its ";", which libxml2 2.11 keeps as text.
160
+ _BARE_REFERENCE = re.compile(r"&[A-Za-z][A-Za-z0-9]*+(?!;)")
161
+ # An escaped "&" before a name; parsed, it looks like a bare reference.
162
+ _ESCAPED_REFERENCE = re.compile(
163
+ r"&(?:amp;|#0*38;|#[xX]0*26;)([A-Za-z][A-Za-z0-9]*+)(?!;)"
164
+ )
165
+ _RAW_TEXT_ELEMENTS = frozenset({"script", "style"})
166
+
167
+
168
+ def _legacy(name: str) -> bool:
169
+ """Whether HTML5 decodes "&" + name without ";": a legacy name prefixes it."""
170
+ return any(name[:end] in _LEGACY_REFERENCES for end in range(len(name), 1, -1))
171
+
172
+
173
+ def _decode_bare_references(source: str, document: html.HtmlElement) -> None:
174
+ """Decode text the way libxml2 2.14 and browsers do, where 2.11 did not.
175
+
176
+ Synergia templates write "&nbsp" without ";" (#121: every timetable entry).
177
+ HTML5 decodes such a reference in text when a legacy name starts it, as
178
+ `html.unescape` does; libxml2 2.11 leaves it as text. Once parsed, an
179
+ escaped "&amp;para" looks the same as a bare "&para", so a document with
180
+ both fails instead of guessing; no live Synergia page had one. Only text
181
+ and tails change: the observed attribute values parse alike.
182
+ """
183
+ if any(_legacy(match.group(1)) for match in _ESCAPED_REFERENCE.finditer(source)):
184
+ raise LibrusError(ErrorKind.PARSE)
185
+
186
+ def decode(value: str | None) -> str | None:
187
+ if not value or "&" not in value:
188
+ return value
189
+ return _BARE_REFERENCE.sub(lambda match: unescape(match.group()), value)
190
+
191
+ for node in document.iter():
192
+ if isinstance(node.tag, str) and node.tag not in _RAW_TEXT_ELEMENTS:
193
+ node.text = decode(node.text)
194
+ node.tail = decode(node.tail)
195
+
196
+
134
197
  def parse_html_document(
135
198
  body: bytes, *, repeatable_id: str | None = None
136
199
  ) -> html.HtmlElement:
@@ -145,11 +208,16 @@ def parse_html_document(
145
208
  )
146
209
  except (UnicodeError, etree.LxmlError, ValueError):
147
210
  failed = True
148
- # Browser HTML commonly contains stray closing tags. Accept only this
149
- # observed repair category; semantic tables, spans, IDs, and bounds still
150
- # validate independently. Do not blanket-ignore arbitrary parser errors.
211
+ # Accept only the repairs a browser makes too; semantic tables, spans, IDs
212
+ # and bounds still validate independently. Do not blanket-ignore arbitrary
213
+ # parser errors, such as an exhausted allocation.
214
+ recoveries = (
215
+ HTML_RECOVERIES
216
+ if etree.LIBXML_VERSION >= (2, 14)
217
+ else HTML_RECOVERIES_BEFORE_2_14
218
+ )
151
219
  if failed or any(
152
- error.type_name != "ERR_TAG_NAME_MISMATCH"
220
+ error.type_name not in recoveries
153
221
  and not (
154
222
  repeatable_id is not None
155
223
  and error.type_name == "DTD_ID_REDEFINED"
@@ -159,6 +227,10 @@ def parse_html_document(
159
227
  ):
160
228
  raise LibrusError(ErrorKind.PARSE)
161
229
  assert document is not None
230
+ if etree.LIBXML_VERSION < (2, 14) and any(
231
+ error.type_name == "ERR_ENTITYREF_SEMICOL_MISSING" for error in parser.error_log
232
+ ):
233
+ _decode_bare_references(text, document)
162
234
  count = 0
163
235
  pending = [(document, 0)]
164
236
  while pending:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: librus-python-api
3
- Version: 1.10.2
3
+ Version: 1.10.3
4
4
  Summary: Independent bounded async Librus Synergia client
5
5
  Project-URL: Repository, https://github.com/krzysztofbury/librus-python-api
6
6
  Project-URL: Issues, https://github.com/krzysztofbury/librus-python-api/issues
@@ -42,9 +42,11 @@ private ACLs. Windows installations include `pywin32` and `tzdata` automatically
42
42
  Network paths, reparse-point paths and unsafe storage permissions fail closed.
43
43
  See [platform requirements](contracts/persistence.md#windows-disk-boundary-25).
44
44
 
45
- **Status:** `1.10.2` rejects a date whose weekday label names another
46
- day and a completed-lesson cell with more than one comma, and fixes two cache
47
- bugs. `1.10.1` reads descriptive grades that the new-schema table
45
+ **Status:** `1.10.3` reads pages with the libxml2 that lxml's Windows wheels
46
+ bundle, reads a grade detail table without period headings and types the
47
+ archive's loading notice as maintenance. `1.10.2` rejects a date whose weekday
48
+ label names another day and a completed-lesson cell with more than one comma,
49
+ and fixes two cache bugs. `1.10.1` reads descriptive grades that the new-schema table
48
50
  shows as grade boxes. `1.10.0` returns behaviour points as a typed value
49
51
  (`GradeRecords.behaviour_points`), reads the e-Justifications list on parent
50
52
  logins (`AccountClient.justifications()`) and checks the gateway grade
@@ -79,7 +81,7 @@ See [limitations](#supported-features-and-limitations) below.
79
81
  Install the exact release from PyPI after its gated publication completes:
80
82
 
81
83
  ```sh
82
- python -m pip install librus-python-api==1.10.2
84
+ python -m pip install librus-python-api==1.10.3
83
85
  ```
84
86
 
85
87
  Pin the exact version qualified by your application. Before publication, use a
@@ -95,7 +97,7 @@ python -m pip install .
95
97
  To install a locally built wheel instead:
96
98
 
97
99
  ```sh
98
- python -m pip install ./dist/librus_python_api-1.10.2-py3-none-any.whl
100
+ python -m pip install ./dist/librus_python_api-1.10.3-py3-none-any.whl
99
101
  ```
100
102
 
101
103
  No console script or background process is installed: import the library in your
@@ -1,4 +1,4 @@
1
- librus_python_api/__init__.py,sha256=mpHAI6zJzjN8ZTsBcSTN_Uk3E-IxoFDAsJ_FQ4TUR-8,6846
1
+ librus_python_api/__init__.py,sha256=iXDruSlF_gFI5JciNgDHEKHBxYTKPd9mRaIUOOFZyHU,6846
2
2
  librus_python_api/_notification_bootstrap.py,sha256=18nzH0doXBNaZXCz-_ckIvRrlHTWV5Mm1t5m2-5eYGI,4669
3
3
  librus_python_api/_notification_codec.py,sha256=hU6G3zGJ5fR8wfPC6fV2OqBKs-7XpT9eRnKO3FGsTzY,13451
4
4
  librus_python_api/_storage.py,sha256=M_6ZAzN4zs7laOdKJBRH1I2rvy3pgqYgC_MZtsd2xtM,15893
@@ -12,13 +12,13 @@ librus_python_api/budget.py,sha256=8fvqT7eIxyVX2P2OBG27XsYHk_HbtSS4lzuecYpHtgs,2
12
12
  librus_python_api/checkpoint.py,sha256=QBmG9GtpyaGRaFq-FXuGA3yR1BjuMFN9V3RTvvi_FNQ,1930
13
13
  librus_python_api/class_free_days.py,sha256=IwoCgr-9ZgEYYQ6717s4cDpyFzbosHMzESMabXJLGqA,2422
14
14
  librus_python_api/completed_lessons.py,sha256=X3NygnzEVaNM53mIf8wiIWF8GHvGCI4bmI0YROdXXLs,10875
15
- librus_python_api/config.py,sha256=Ft-pQL1pZqUAM_m3zRCfsWCmYr4eZruL7kAe0gSKJ0w,66148
15
+ librus_python_api/config.py,sha256=UOQHrhu5VFY4wkSsvCnzgy3esXuxznDtycARZBidr90,66577
16
16
  librus_python_api/detail_fields.py,sha256=vDDi5sV-e30-42SF0hwAUoldiZ5wvYtb1UlLt03lBHw,1708
17
17
  librus_python_api/diagnostics.py,sha256=SFQ3Wq6JEFOEHjRKe0-8zcCeJ8c8Eq8lIkVk2_a8IKU,19126
18
18
  librus_python_api/exceptions.py,sha256=x8_z5UTNmuRINTK4buLYiKdYcFA2w6GZP9ZXOL-OnRU,5531
19
19
  librus_python_api/files.py,sha256=pQBsIJyfTOZDz83ZB-5fcd-nPMcxR1HJ155h4zTHmsA,9223
20
20
  librus_python_api/formative_grades.py,sha256=VykwtGvViZVOJMwPH3Re1RTDCHMr1_m9_xHjZyaXDIQ,6452
21
- librus_python_api/gateway_grades.py,sha256=gAAqh2GmMklmYFQAhNlzD6xsDCdExP5pAbmfipyNeZs,22344
21
+ librus_python_api/gateway_grades.py,sha256=ILqWkkaRq120wG--h7GfFy4qFAQcuaa6LpzJOcCA2FU,22921
22
22
  librus_python_api/grade_parsers.py,sha256=ROfffkCP8yj5Q708TZdpp0PDTyVmoh6X7m0y2fyJcwg,11202
23
23
  librus_python_api/grade_records.py,sha256=Kt9zwqZNQMsIovNj2Qu9Y6oRGEqRXw-1T1X2PpkNbeY,31650
24
24
  librus_python_api/homework_range.py,sha256=erYfvS6PhHU5XhnR6LkiLNy677hGVflY3UAuHOs-YUw,1663
@@ -36,7 +36,7 @@ librus_python_api/notification_models.py,sha256=4eLTAE9JzHhveoaWtZQwGBolmb87QUP5
36
36
  librus_python_api/notification_persistence.py,sha256=8GYPbCVD0AecrC4IUXFkHkhNS-uGXkXzsuKxreTIk9I,49454
37
37
  librus_python_api/notification_workflow.py,sha256=XpWNGWbRsqtpTJinPsw65bjnnEnNpm-qzn0QPxz43Xg,13009
38
38
  librus_python_api/notifications.py,sha256=VbA8pqNG_19yYo9y7IqpGRmfEb4qDcvA5gBb1syGJKs,7806
39
- librus_python_api/parsers.py,sha256=FxRZvGHjCgz_2z5B9_uCCO4WCK54c0fYk5UqgJ4r0sc,9442
39
+ librus_python_api/parsers.py,sha256=XVimInaxMhYy2OR-d53PF5kJjBlLFziN6DGCuPPtxSY,12920
40
40
  librus_python_api/parsing.py,sha256=H71srw5yx-RFrAKZFgj-QFX-DIXZmhnGrDTmJhazCB8,1838
41
41
  librus_python_api/persistence.py,sha256=F35yBRu6D8aYgdwKTpzVdqVTyiUaLQludUmyyskb3Vo,15529
42
42
  librus_python_api/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -48,7 +48,7 @@ librus_python_api/sending.py,sha256=Nvvk2r-6D6Us53a2fH5GW9PcA6bWEfuOvy6c3M5QVcE,
48
48
  librus_python_api/service.py,sha256=0RQZW_jPwh8VJNphJ0NUcdeYR2VpZ30MQKns_12BsxU,105678
49
49
  librus_python_api/timetable.py,sha256=tX1QK9fQABxzfLaHHqTe8e6rAgdOkCoTOfAHdPwNmLE,9836
50
50
  librus_python_api/transport.py,sha256=yF-DnFy4xGYS_RWQ9161b9WJXOlYF8cFRgdjXmVVUIk,34988
51
- librus_python_api-1.10.2.dist-info/METADATA,sha256=ZYvel3prhVpM6ltwnf3cI2tjGkhbCGDPHE0IezmX2zM,15286
52
- librus_python_api-1.10.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
53
- librus_python_api-1.10.2.dist-info/licenses/LICENSE,sha256=IuerLb3cnZCsaB23znydjjvKqP-LmSJd3syKa9NGUts,1071
54
- librus_python_api-1.10.2.dist-info/RECORD,,
51
+ librus_python_api-1.10.3.dist-info/METADATA,sha256=1DR8M7cJOwLNQIFIg8TQcDAyUoFa-KjHWtCR5y_d8sQ,15465
52
+ librus_python_api-1.10.3.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
53
+ librus_python_api-1.10.3.dist-info/licenses/LICENSE,sha256=IuerLb3cnZCsaB23znydjjvKqP-LmSJd3syKa9NGUts,1071
54
+ librus_python_api-1.10.3.dist-info/RECORD,,