librus-python-api 1.10.2__tar.gz → 1.10.3__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.
Files changed (59) hide show
  1. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/API.md +5 -3
  2. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/CHANGELOG.md +31 -0
  3. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/PKG-INFO +8 -6
  4. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/README.md +7 -5
  5. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/__init__.py +1 -1
  6. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/config.py +7 -0
  7. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/gateway_grades.py +22 -4
  8. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/parsers.py +76 -4
  9. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/.gitignore +0 -0
  10. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/LICENSE +0 -0
  11. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/SECURITY.md +0 -0
  12. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/pyproject.toml +0 -0
  13. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/_notification_bootstrap.py +0 -0
  14. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/_notification_codec.py +0 -0
  15. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/_storage.py +0 -0
  16. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/_windows_filesystem.py +0 -0
  17. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/announcements.py +0 -0
  18. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/attachment_routes.py +0 -0
  19. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/attachments.py +0 -0
  20. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/attendance.py +0 -0
  21. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/attendance_frequency.py +0 -0
  22. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/budget.py +0 -0
  23. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/checkpoint.py +0 -0
  24. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/class_free_days.py +0 -0
  25. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/completed_lessons.py +0 -0
  26. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/detail_fields.py +0 -0
  27. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/diagnostics.py +0 -0
  28. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/exceptions.py +0 -0
  29. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/files.py +0 -0
  30. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/formative_grades.py +0 -0
  31. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/grade_parsers.py +0 -0
  32. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/grade_records.py +0 -0
  33. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/homework_range.py +0 -0
  34. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/inspect_page.py +0 -0
  35. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/justifications.py +0 -0
  36. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/lifecycle.py +0 -0
  37. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/markup.py +0 -0
  38. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/message_content.py +0 -0
  39. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/messages.py +0 -0
  40. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/models.py +0 -0
  41. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/modern_body.py +0 -0
  42. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/modern_mailbox.py +0 -0
  43. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/modern_messages.py +0 -0
  44. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/notification_models.py +0 -0
  45. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/notification_persistence.py +0 -0
  46. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/notification_workflow.py +0 -0
  47. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/notifications.py +0 -0
  48. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/parsing.py +0 -0
  49. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/persistence.py +0 -0
  50. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/py.typed +0 -0
  51. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/recipients.py +0 -0
  52. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/scheduler.py +0 -0
  53. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/school_reads.py +0 -0
  54. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/school_year_archive.py +0 -0
  55. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/sending.py +0 -0
  56. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/service.py +0 -0
  57. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/timetable.py +0 -0
  58. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/src/librus_python_api/transport.py +0 -0
  59. {librus_python_api-1.10.2 → librus_python_api-1.10.3}/uv.lock +0 -0
@@ -334,7 +334,8 @@ rows, 256 achievements, 1024 characters per short field, 65536 per long text
334
334
  cell and 262144 total rendered characters, plus the shared transport/tree bounds.
335
335
 
336
336
  The observed `Brak danych` information notice returns empty `years` and
337
- `achievements`. Missing tables without that explicit marker still raise `PARSE`;
337
+ `achievements`. The notice that the archive is temporarily unavailable while
338
+ Synergia fills it with the previous school year raises `MaintenanceError` (1.10.3). Missing tables without that explicit marker still raise `PARSE`;
338
339
  an empty notice combined with data tables is rejected. Repeated school years
339
340
  (including a class-change layout) are ambiguous and raise `PARSE`. Unknown
340
341
  geometry/markup raises `UNSUPPORTED_CAPABILITY`; bounds raise `LIMIT`, never
@@ -385,7 +386,8 @@ the same way (from 1.8.4; before, only the `ALL` view did):
385
386
  `Umiejętność` and the other tooltip lines in `metadata`, and no view makes a
386
387
  gateway request. The detail rows must list the same grades, value and date,
387
388
  in the same order; otherwise, or when a detail grade has `Treść oceny` text,
388
- the read raises `UnsupportedCapabilityError`.
389
+ the read raises `UnsupportedCapabilityError`. A detail table with one
390
+ `Brak ocen` row and no period headings is a subject without grades (1.10.3).
389
391
  - Anything else fails the read: blank cells without hooks, a cell with an
390
392
  attribute or markup, mixed layouts in one table, a bare-text table that still
391
393
  has empty `studentGradesDetailsRow` rows (`UnsupportedCapabilityError`), or rows
@@ -1293,7 +1295,7 @@ text. `error_for(kind)` builds one.
1293
1295
  | `UnsupportedCapabilityError` | A recognized but unsupported layout or content |
1294
1296
  | `ParseError` | The page or JSON does not match the expected structure |
1295
1297
  | `StaleCursorError` | A previously valid continuation no longer matches the current sequence; restart explicitly |
1296
- | `ThrottledError`, `MaintenanceError` | HTTP 429 or 503; the shared scheduler pauses |
1298
+ | `ThrottledError`, `MaintenanceError` | HTTP 429 or 503; the shared scheduler pauses. Since 1.10.3 `MaintenanceError` is also the archive's notice that it is being filled, with no pause |
1297
1299
  | `ConnectionError`, `OperationTimeoutError` | Transport failure or budget deadline |
1298
1300
  | `LimitError` | A request, byte, item or queue bound was reached |
1299
1301
  | `ClosedError` | The service is closed |
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.10.3 (2026-11-20) - Pages read on Windows; grade details without periods
4
+
5
+ Thank you, @mpietson, for krzysztofbury/librus-mcp#121, with the libxml2 error
6
+ counts that located the failure, and @wiktorw, for #184 and its offline
7
+ reproduction.
8
+
9
+ - Windows: every page read failed with `PARSE`. lxml's Windows wheels bundle
10
+ libxml2 2.11.9, which reports repairs that libxml2 2.14 (in the Linux and
11
+ macOS wheels) makes silently, such as a repeated attribute, a stray quote in
12
+ a start tag, an unknown tag such as `nobr` or `&nbsp` without its `;`. They
13
+ are now accepted, and a text reference without its `;` is decoded as 2.14
14
+ decodes it, so timetable teacher and room text no longer keeps a literal
15
+ `&nbsp`. On four live logins, every `librus-mcp check-tools` result was the
16
+ same with both libxml2 versions. Only libxml2 older than 2.14 accepts these
17
+ repairs, so Linux and macOS behave as before. With 2.11, a duplicate ID, a
18
+ failed allocation, a message body that ends inside a start tag (`... <x`)
19
+ and a text with both a bare reference and an escaped one such as
20
+ `&amp;para` still fail as `PARSE` (krzysztofbury/librus-mcp#121).
21
+ - Grades: a filled detail row whose table holds one `Brak ocen` row and no
22
+ period headings failed the whole read with `UnsupportedCapabilityError`. It
23
+ is now a subject with no grades in either period, when its semester cells
24
+ show no grades either; anything after that row still fails (#184).
25
+ - School-year archive: the notice that the archive is temporarily unavailable
26
+ while Synergia fills it with the previous school year's data (observed
27
+ 2026-11-20 on every login) now raises `MaintenanceError` instead of
28
+ `ParseError`. Nothing pauses the shared scheduler.
29
+ - CI and release qualification run the full suite on Windows x64 and ARM64,
30
+ not only the disk tests. The loopback test servers also listen on ::1, which
31
+ Windows tries first for `localhost`. The maintainer capture scripts refuse
32
+ Windows, where their owner-only file modes protect nothing.
33
+
3
34
  ## 1.10.2 (2026-11-17) - Stricter dates and lesson cells; cache fixes
4
35
 
5
36
  - Dates followed by a weekday label, such as `2026-11-15 (ndz.)` in grade and
@@ -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
@@ -16,9 +16,11 @@ private ACLs. Windows installations include `pywin32` and `tzdata` automatically
16
16
  Network paths, reparse-point paths and unsafe storage permissions fail closed.
17
17
  See [platform requirements](contracts/persistence.md#windows-disk-boundary-25).
18
18
 
19
- **Status:** `1.10.2` rejects a date whose weekday label names another
20
- day and a completed-lesson cell with more than one comma, and fixes two cache
21
- bugs. `1.10.1` reads descriptive grades that the new-schema table
19
+ **Status:** `1.10.3` reads pages with the libxml2 that lxml's Windows wheels
20
+ bundle, reads a grade detail table without period headings and types the
21
+ archive's loading notice as maintenance. `1.10.2` rejects a date whose weekday
22
+ label names another day and a completed-lesson cell with more than one comma,
23
+ and fixes two cache bugs. `1.10.1` reads descriptive grades that the new-schema table
22
24
  shows as grade boxes. `1.10.0` returns behaviour points as a typed value
23
25
  (`GradeRecords.behaviour_points`), reads the e-Justifications list on parent
24
26
  logins (`AccountClient.justifications()`) and checks the gateway grade
@@ -53,7 +55,7 @@ See [limitations](#supported-features-and-limitations) below.
53
55
  Install the exact release from PyPI after its gated publication completes:
54
56
 
55
57
  ```sh
56
- python -m pip install librus-python-api==1.10.2
58
+ python -m pip install librus-python-api==1.10.3
57
59
  ```
58
60
 
59
61
  Pin the exact version qualified by your application. Before publication, use a
@@ -69,7 +71,7 @@ python -m pip install .
69
71
  To install a locally built wheel instead:
70
72
 
71
73
  ```sh
72
- python -m pip install ./dist/librus_python_api-1.10.2-py3-none-any.whl
74
+ python -m pip install ./dist/librus_python_api-1.10.3-py3-none-any.whl
73
75
  ```
74
76
 
75
77
  No console script or background process is installed: import the library in your
@@ -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: