librus-python-api 1.11.1__tar.gz → 1.11.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.11.1 → librus_python_api-1.11.3}/API.md +13 -2
  2. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/CHANGELOG.md +31 -0
  3. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/PKG-INFO +6 -4
  4. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/README.md +5 -3
  5. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/__init__.py +1 -1
  6. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/config.py +3 -0
  7. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/diagnostics.py +97 -39
  8. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/grade_parsers.py +52 -18
  9. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/grade_records.py +2 -2
  10. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/.gitignore +0 -0
  11. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/LICENSE +0 -0
  12. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/SECURITY.md +0 -0
  13. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/pyproject.toml +0 -0
  14. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/_notification_bootstrap.py +0 -0
  15. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/_notification_codec.py +0 -0
  16. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/_storage.py +0 -0
  17. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/_windows_filesystem.py +0 -0
  18. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/announcements.py +0 -0
  19. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/attachment_routes.py +0 -0
  20. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/attachments.py +0 -0
  21. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/attendance.py +0 -0
  22. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/attendance_frequency.py +0 -0
  23. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/budget.py +0 -0
  24. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/checkpoint.py +0 -0
  25. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/class_free_days.py +0 -0
  26. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/completed_lessons.py +0 -0
  27. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/detail_fields.py +0 -0
  28. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/exceptions.py +0 -0
  29. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/files.py +0 -0
  30. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/formative_grades.py +0 -0
  31. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/gateway_grades.py +0 -0
  32. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/homework_range.py +0 -0
  33. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/inspect_page.py +0 -0
  34. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/justifications.py +0 -0
  35. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/lifecycle.py +0 -0
  36. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/markup.py +0 -0
  37. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/message_content.py +0 -0
  38. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/messages.py +0 -0
  39. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/models.py +0 -0
  40. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/modern_body.py +0 -0
  41. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/modern_mailbox.py +0 -0
  42. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/modern_messages.py +0 -0
  43. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/notification_models.py +0 -0
  44. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/notification_persistence.py +0 -0
  45. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/notification_workflow.py +0 -0
  46. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/notifications.py +0 -0
  47. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/parsers.py +0 -0
  48. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/parsing.py +0 -0
  49. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/persistence.py +0 -0
  50. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/py.typed +0 -0
  51. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/recipients.py +0 -0
  52. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/scheduler.py +0 -0
  53. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/school_reads.py +0 -0
  54. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/school_year_archive.py +0 -0
  55. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/sending.py +0 -0
  56. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/service.py +0 -0
  57. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/timetable.py +0 -0
  58. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/src/librus_python_api/transport.py +0 -0
  59. {librus_python_api-1.11.1 → librus_python_api-1.11.3}/uv.lock +0 -0
@@ -183,7 +183,14 @@ from the exception's own traceback. Neither raises.
183
183
  present, title, headings, notices, forms and input types, then the first
184
184
  tables row by row, with known profile labels and notices by name. Output is
185
185
  bounded. It is meant for a human to review before sharing, not for
186
- automatic upload.
186
+ automatic upload. The layout sizes the failing code compared (`width`,
187
+ `span`, `position`) follow the elements (1.11.2).
188
+ - `diagnostics.failure_locator(error)` (1.11.2) returns one line, or None: the
189
+ masked path of the element nearest the failure, then those element counts
190
+ and sizes, for example `table.stretch.decorated[1] > tbody[1] >
191
+ tr.bolded.line0[2] > td.center[7]; cells 7, columns 11, width 10, span 1`.
192
+ It holds structure and counts only, at most 512 characters, so an
193
+ application can return it with the error, as `librus-mcp` does in `at`.
187
194
  - `python -m librus_python_api.inspect_page {grades,final-grades,profile} FILE`
188
195
  parses a saved page offline (a whole page or a copied table) and prints
189
196
  counts, or the failure kind, frames and structure. `profile` (1.8.1) reads the
@@ -214,7 +221,11 @@ source)` with an aware UTC timestamp.
214
221
  - `final_grades()` returns `FinalGrades` with one `SubjectGradeSummary` per
215
222
  subject: `midterm`, `predicted_annual` and `annual`, each a
216
223
  `GradeSummaryValue(availability, raw)`. Raw school text is kept as is.
217
- `UNAVAILABLE` means the column is absent.
224
+ `UNAVAILABLE` means the column is absent. In the `Zachowanie` row a value
225
+ may share a merged cell with the columns beside it, but never with a
226
+ current-grade (`Oceny bieżące`) column, where that row holds behaviour
227
+ points: such a row raises `ParseError` instead of returning the points as a
228
+ grade. `grades()` reads no summary value from that row and is unaffected.
218
229
  - `grades(view=GradeView.ALL)` returns `Grades(identity, records, observation,
219
230
  view)`. Selecting a view (`ALL`, `WEEK`, `LAST_LOGIN`) is one POST that changes
220
231
  the filter shown in that login's session; it is never replayed
@@ -1,5 +1,36 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.11.3 (2026-11-22) - Behaviour points never read as a final grade
4
+
5
+ - Grades: `final_grades()` no longer reads a summary value from a merged
6
+ `Zachowanie` cell that also covers a current-grade (`Oceny bieżące`)
7
+ column (#192). That cell holds the behaviour points, so a different span
8
+ order could return the points tally as the predicted grade or the midterm.
9
+ Such a row now raises `ParseError`, and so does a merged summary value in a
10
+ table whose header does not name both periods' current-grade columns, where
11
+ the rule cannot be checked. Values merged with other
12
+ columns, as in the point table and the #189 row, read as before.
13
+ `grades()` and `grades_window()` read only the subject from that row and
14
+ are unchanged. No layout seen live is affected.
15
+
16
+ ## 1.11.2 (2026-11-21) - A behaviour row wider than the grade table
17
+
18
+ - Grades: at one school the `Zachowanie` row ends with a cell that spans one
19
+ column past the grade table's header (#189). `grades()`, `grades_window()`
20
+ and `final_grades()` failed with `ParseError` for every such account. For
21
+ exactly that layout (cell spans 1, 1, 2, 1, 2, 1, 3), the extra column is
22
+ dropped: the annual grade keeps its value, and the annual average it merges
23
+ with is unavailable, as for any merged cell. Any other row wider than the
24
+ header still fails, since a different span order could put a value in the
25
+ wrong field.
26
+ - New `diagnostics.failure_locator(error)`: one line saying where in the page a
27
+ failure happened, such as `table.stretch.decorated[1] > tbody[1] >
28
+ tr.bolded.line0[2] > td.center[7]; cells 7, columns 11, width 10, span 1`.
29
+ It uses the masked path from `describe_failure` plus the sizes the parser
30
+ compared, and no page text or values, so an application can put it in an
31
+ error result. `describe_failure` and `inspect_page` now also show those sizes
32
+ (`width: 10`).
33
+
3
34
  ## 1.11.1 (2026-11-21) - Windows stores shared by several processes
4
35
 
5
36
  - Windows: a durable store shared by several processes could report
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: librus-python-api
3
- Version: 1.11.1
3
+ Version: 1.11.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,7 +42,9 @@ 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.11.1` fixes a Windows store shared by several processes
45
+ **Status:** `1.11.3` never returns behaviour points as a final grade when the
46
+ behaviour row's cells are merged differently. `1.11.2` reads a behaviour row whose last cell spans past the
47
+ grade table and names the failing cell in diagnostics. `1.11.1` fixes a Windows store shared by several processes
46
48
  reporting `StorageError`, also after a dispatched send. `1.11.0` raises `TemporarilyUnavailableError` for the archive's
47
49
  loading notice, a view that is unavailable for now while the rest of Synergia
48
50
  works. `1.10.3` reads pages with the libxml2 that lxml's Windows wheels
@@ -83,7 +85,7 @@ See [limitations](#supported-features-and-limitations) below.
83
85
  Install the exact release from PyPI after its gated publication completes:
84
86
 
85
87
  ```sh
86
- python -m pip install librus-python-api==1.11.1
88
+ python -m pip install librus-python-api==1.11.3
87
89
  ```
88
90
 
89
91
  Pin the exact version qualified by your application. Before publication, use a
@@ -99,7 +101,7 @@ python -m pip install .
99
101
  To install a locally built wheel instead:
100
102
 
101
103
  ```sh
102
- python -m pip install ./dist/librus_python_api-1.11.1-py3-none-any.whl
104
+ python -m pip install ./dist/librus_python_api-1.11.3-py3-none-any.whl
103
105
  ```
104
106
 
105
107
  No console script or background process is installed: import the library in your
@@ -16,7 +16,9 @@ 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.11.1` fixes a Windows store shared by several processes
19
+ **Status:** `1.11.3` never returns behaviour points as a final grade when the
20
+ behaviour row's cells are merged differently. `1.11.2` reads a behaviour row whose last cell spans past the
21
+ grade table and names the failing cell in diagnostics. `1.11.1` fixes a Windows store shared by several processes
20
22
  reporting `StorageError`, also after a dispatched send. `1.11.0` raises `TemporarilyUnavailableError` for the archive's
21
23
  loading notice, a view that is unavailable for now while the rest of Synergia
22
24
  works. `1.10.3` reads pages with the libxml2 that lxml's Windows wheels
@@ -57,7 +59,7 @@ See [limitations](#supported-features-and-limitations) below.
57
59
  Install the exact release from PyPI after its gated publication completes:
58
60
 
59
61
  ```sh
60
- python -m pip install librus-python-api==1.11.1
62
+ python -m pip install librus-python-api==1.11.3
61
63
  ```
62
64
 
63
65
  Pin the exact version qualified by your application. Before publication, use a
@@ -73,7 +75,7 @@ python -m pip install .
73
75
  To install a locally built wheel instead:
74
76
 
75
77
  ```sh
76
- python -m pip install ./dist/librus_python_api-1.11.1-py3-none-any.whl
78
+ python -m pip install ./dist/librus_python_api-1.11.3-py3-none-any.whl
77
79
  ```
78
80
 
79
81
  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.11.1"
4
+ __version__ = "1.11.3"
5
5
 
6
6
  from librus_python_api.attachments import AttachmentStream, ModernAttachmentStream
7
7
  from librus_python_api.budget import RequestBudget
@@ -730,6 +730,9 @@ GRADE_MAX_COLUMNS = 64
730
730
  GRADE_MAX_SUBJECTS = 128
731
731
  GRADE_MAX_VALUE_LENGTH = 1024
732
732
  GRADE_MERGED_SUBJECTS = frozenset({"Zachowanie"})
733
+ # Cell spans of the behaviour row reported in #189 (2026-11-21): the last cell
734
+ # covers the annual average, the annual grade and one column the header lacks.
735
+ GRADE_BEHAVIOUR_OVERFLOW_SPANS = (1, 1, 2, 1, 2, 1, 3)
733
736
  GRADE_INLINE_DETAIL_LABEL = "Ocena"
734
737
  # Tooltip fields whose free text may continue on unlabelled lines. A teacher's
735
738
  # multi-line grade comment was observed on 2026-10-27. A formative mirror's
@@ -41,6 +41,10 @@ _INPUT_TYPES = frozenset(
41
41
  # Element IDs whose presence tells a Synergia page from a login or error page.
42
42
  _PAGE_MARKERS = ("graphic-menu", "user-section")
43
43
  _REPORT_BYTES = 32 * 1024
44
+ _LOCATOR_BYTES = 512
45
+ # Integer locals that hold a table's layout, never a value read from the page:
46
+ # a row's expected width, a cell's span, a column position.
47
+ _SHAPE_COUNTS = frozenset({"width", "span", "position"})
44
48
  # Markup observed on Synergia pages. Other class tokens, tags and attribute
45
49
  # names are shown only as lengths, since they could carry data.
46
50
  _CLASSES = frozenset(
@@ -494,55 +498,109 @@ def _is_page(element: html.HtmlElement) -> bool:
494
498
  return element.getparent() is None and element.tag == "html"
495
499
 
496
500
 
501
+ _Elements = list[tuple[str, html.HtmlElement]]
502
+ _Sequences = list[tuple[str, list[html.HtmlElement] | tuple[html.HtmlElement, ...]]]
503
+
504
+
505
+ def _failure_site(
506
+ error: BaseException,
507
+ ) -> tuple[FrameType, int, _Elements, _Sequences, list[tuple[str, int]]] | None:
508
+ """The innermost library frame holding HTML elements, with those elements,
509
+ element sequences and the layout counts named in `_SHAPE_COUNTS`."""
510
+ for frame, line in reversed(_frames(error, (_PACKAGE,))):
511
+ local_items = list(frame.f_locals.items())
512
+ elements = [
513
+ (name, value)
514
+ for name, value in local_items
515
+ if isinstance(value, html.HtmlElement)
516
+ ][:_ELEMENT_LOCALS]
517
+ sequences = [
518
+ (name, value)
519
+ for name, value in local_items
520
+ if isinstance(value, (list, tuple))
521
+ and value
522
+ and all(isinstance(item, html.HtmlElement) for item in value)
523
+ ][:_ELEMENT_LOCALS]
524
+ if not elements and not sequences:
525
+ continue
526
+ counts = [
527
+ (name, value)
528
+ for name, value in local_items
529
+ if name in _SHAPE_COUNTS and type(value) is int
530
+ ]
531
+ return frame, line, elements, sequences, counts
532
+ return None
533
+
534
+
497
535
  def describe_failure(error: BaseException) -> str | None:
498
536
  """The page structure around a failure, for a bug report.
499
537
 
500
538
  Shows the HTML elements held by the innermost library frame that holds
501
539
  any: tags, safe class tokens, known tooltip labels, known link families
502
- and lengths. A whole page is summarized last (see _page_summary). Text
503
- and attribute values are masked unless they equal a parser constant.
540
+ and lengths, then the layout counts it compared (such as `width`). A
541
+ whole page is summarized last (see _page_summary). Text and attribute
542
+ values are masked unless they equal a parser constant.
504
543
  Returns None when there is nothing to show; never raises.
505
544
  """
506
545
  try:
546
+ site = _failure_site(error)
547
+ if site is None:
548
+ return None
549
+ frame, line, elements, sequences, counts = site
507
550
  redactor = _Redactor()
508
- for frame, line in reversed(_frames(error, (_PACKAGE,))):
509
- local_items = list(frame.f_locals.items())
510
- elements = [
511
- (name, value)
512
- for name, value in local_items
513
- if isinstance(value, html.HtmlElement)
514
- ][:_ELEMENT_LOCALS]
515
- sequences = [
516
- (name, value)
517
- for name, value in local_items
518
- if isinstance(value, (list, tuple))
519
- and value
520
- and all(isinstance(item, html.HtmlElement) for item in value)
521
- ][:_ELEMENT_LOCALS]
522
- if not elements and not sequences:
551
+ lines = [f"at {_site(frame, line)}"]
552
+ # The elements nearest the failure first; a page summary last.
553
+ for name, value in sorted(elements, key=lambda item: _is_page(item[1])):
554
+ redactor.nodes = 0
555
+ if _is_page(value):
556
+ summary = "\n".join(_page_summary(value, redactor))
557
+ if len(summary) > _ELEMENT_BYTES:
558
+ summary = summary[:_ELEMENT_BYTES] + "...(truncated)"
559
+ lines += [f"{name}: page", summary]
523
560
  continue
524
- lines = [f"at {_site(frame, line)}"]
525
- # The elements nearest the failure first; a page summary last.
526
- for name, value in sorted(elements, key=lambda item: _is_page(item[1])):
527
- redactor.nodes = 0
528
- if _is_page(value):
529
- summary = "\n".join(_page_summary(value, redactor))
530
- if len(summary) > _ELEMENT_BYTES:
531
- summary = summary[:_ELEMENT_BYTES] + "...(truncated)"
532
- lines += [f"{name}: page", summary]
533
- continue
534
- lines.append(f"{name}: {_path(value, redactor)}")
535
- rendered = redactor.element(value)
536
- if len(rendered) > _ELEMENT_BYTES:
537
- rendered = rendered[:_ELEMENT_BYTES] + "...(truncated)"
538
- lines.append(" " + rendered)
539
- for name, items in sequences:
540
- tags = ",".join(str(item.tag) for item in items[:20])
541
- lines.append(f"{name}: {len(items)} elements: {tags}")
542
- report = "\n".join(lines)
543
- if len(report) > _REPORT_BYTES:
544
- report = report[:_REPORT_BYTES] + "...(truncated)"
545
- return report
561
+ lines.append(f"{name}: {_path(value, redactor)}")
562
+ rendered = redactor.element(value)
563
+ if len(rendered) > _ELEMENT_BYTES:
564
+ rendered = rendered[:_ELEMENT_BYTES] + "...(truncated)"
565
+ lines.append(" " + rendered)
566
+ for name, items in sequences:
567
+ tags = ",".join(str(item.tag) for item in items[:20])
568
+ lines.append(f"{name}: {len(items)} elements: {tags}")
569
+ for name, count in counts:
570
+ lines.append(f"{name}: {count}")
571
+ report = "\n".join(lines)
572
+ if len(report) > _REPORT_BYTES:
573
+ report = report[:_REPORT_BYTES] + "...(truncated)"
574
+ return report
575
+ except Exception:
546
576
  return None
577
+
578
+
579
+ def failure_locator(error: BaseException) -> str | None:
580
+ """One line saying where in the page a failure happened, for an error result.
581
+
582
+ The masked path of the element nearest the failure (as in
583
+ `describe_failure`), then the sizes it was checked against, for example
584
+ `table.stretch.decorated[1] > tbody[1] > tr.bolded.line0[2] > td.center[7];
585
+ cells 7, columns 11, width 10`. Structure and counts only, never page text
586
+ or values. Returns None when no page element is involved; never raises.
587
+ """
588
+ try:
589
+ site = _failure_site(error)
590
+ if site is None:
591
+ return None
592
+ _, _, elements, sequences, counts = site
593
+ redactor = _Redactor()
594
+ parts = [
595
+ _path(value, redactor) for _, value in elements if not _is_page(value)
596
+ ][:1]
597
+ sizes = [f"{name} {len(items)}" for name, items in sequences]
598
+ sizes += [f"{name} {value}" for name, value in counts]
599
+ if sizes:
600
+ parts.append(", ".join(sizes))
601
+ if not parts:
602
+ return None
603
+ locator = "; ".join(parts)
604
+ return locator[:_LOCATOR_BYTES]
547
605
  except Exception:
548
606
  return None
@@ -7,6 +7,7 @@ from lxml import html
7
7
 
8
8
  from librus_python_api import markup
9
9
  from librus_python_api.config import (
10
+ GRADE_BEHAVIOUR_OVERFLOW_SPANS,
10
11
  GRADE_BODY_PREFIX_COLUMNS,
11
12
  GRADE_CURRENT_HEADER,
12
13
  GRADE_EMPTY_MARKERS,
@@ -47,20 +48,24 @@ def _summary_field(cell: html.HtmlElement, *, points: bool = False) -> str | Non
47
48
 
48
49
  def _header(
49
50
  row: html.HtmlElement, *, points: bool = False
50
- ) -> tuple[dict[str, int], int]:
51
+ ) -> tuple[dict[str, int], int, frozenset[int]]:
52
+ """Summary field columns, the width, and the current-grade columns."""
51
53
  fields: dict[str, int] = {}
54
+ current: set[int] = set()
52
55
  position = GRADE_BODY_PREFIX_COLUMNS
53
56
  for cell in markup.cells(row):
54
57
  span = markup.colspan(cell)
55
58
  if position + span > GRADE_MAX_COLUMNS:
56
59
  raise LibrusError(ErrorKind.LIMIT)
60
+ if markup.text(cell) == GRADE_CURRENT_HEADER:
61
+ current.update(range(position, position + span))
57
62
  field = _summary_field(cell, points=points)
58
63
  if field is not None:
59
64
  if field in fields:
60
65
  raise LibrusError(ErrorKind.PARSE)
61
66
  fields[field] = position
62
67
  position += span
63
- return fields, position
68
+ return fields, position, frozenset(current)
64
69
 
65
70
 
66
71
  def is_point_table(table: html.HtmlElement) -> bool:
@@ -84,8 +89,11 @@ def _current_header(table: html.HtmlElement) -> bool:
84
89
  )
85
90
 
86
91
 
87
- def point_layout(table: html.HtmlElement) -> tuple[dict[str, int], int]:
88
- """Summary fields and width from the point table's current-grade header row.
92
+ def point_layout(
93
+ table: html.HtmlElement,
94
+ ) -> tuple[dict[str, int], int, frozenset[int]]:
95
+ """Summary fields, width and current-grade columns from the point table's
96
+ current-grade header row.
89
97
 
90
98
  Point tables are not required to have an annual column, so the row with
91
99
  the two current-grade headers defines the body alignment instead.
@@ -101,10 +109,11 @@ def point_layout(table: html.HtmlElement) -> tuple[dict[str, int], int]:
101
109
  return _header(headers[0], points=True)
102
110
 
103
111
 
104
- def _candidates(
105
- document: html.HtmlElement,
106
- ) -> list[tuple[html.HtmlElement, dict[str, int], int]]:
107
- candidates: list[tuple[html.HtmlElement, dict[str, int], int]] = []
112
+ _Layout = tuple[html.HtmlElement, dict[str, int], int, frozenset[int]]
113
+
114
+
115
+ def _candidates(document: html.HtmlElement) -> list[_Layout]:
116
+ candidates: list[_Layout] = []
108
117
  for table in document.iter("table"):
109
118
  if not {"decorated", "stretch"} <= set(table.get("class", "").split()):
110
119
  continue
@@ -117,14 +126,12 @@ def _candidates(
117
126
  # an annual summary title defines the body alignment contract.
118
127
  if not any(_summary_field(cell) == "annual" for cell in markup.cells(row)):
119
128
  continue
120
- fields, width = _header(row)
121
- candidates.append((table, fields, width))
129
+ fields, width, current = _header(row)
130
+ candidates.append((table, fields, width, current))
122
131
  return candidates
123
132
 
124
133
 
125
- def _locate(
126
- document: html.HtmlElement,
127
- ) -> tuple[html.HtmlElement, dict[str, int], int]:
134
+ def _locate(document: html.HtmlElement) -> _Layout:
128
135
  candidates = _candidates(document)
129
136
  if len(candidates) != 1:
130
137
  raise LibrusError(ErrorKind.PARSE)
@@ -163,6 +170,16 @@ def _subject_columns(
163
170
  if len(columns) + span > GRADE_MAX_COLUMNS:
164
171
  raise LibrusError(ErrorKind.LIMIT)
165
172
  columns.extend([cell] * span)
173
+ # One school's behaviour row ends with a cell spanning one column past the
174
+ # header (2026-11-21, #189). Only that exact layout drops the extra column;
175
+ # any other span order could shift summary values into the wrong fields.
176
+ if (
177
+ subject in GRADE_MERGED_SUBJECTS
178
+ and tuple(markup.colspan(cell) for cell in cells)
179
+ == GRADE_BEHAVIOUR_OVERFLOW_SPANS
180
+ and len(columns) == width + 1
181
+ ):
182
+ del columns[width:]
166
183
  if len(columns) != width:
167
184
  raise LibrusError(ErrorKind.PARSE)
168
185
  return subject, columns
@@ -172,12 +189,29 @@ def _summary(
172
189
  cells: list[html.HtmlElement],
173
190
  fields: dict[str, int],
174
191
  width: int,
192
+ current: frozenset[int] | None = None,
175
193
  ) -> SubjectGradeSummary:
194
+ """One subject's summary values.
195
+
196
+ `current` holds the header's current-grade columns. Pass it whenever the
197
+ values are returned; `grades()` reads only the subject and passes none.
198
+ """
176
199
  subject, columns = _subject_columns(cells, width)
177
200
  selected = [columns[index] for index in fields.values()]
178
201
  if len({id(cell) for cell in selected}) != len(selected):
179
202
  # A single merged value cannot mean two different summary fields.
180
203
  raise LibrusError(ErrorKind.PARSE)
204
+ # A merged cell over a current-grade column holds the behaviour points,
205
+ # not a summary value (#192). Unless the header names both periods'
206
+ # current-grade columns, as every grade table does, a merged value cannot
207
+ # be checked at all.
208
+ for cell in selected:
209
+ if (
210
+ current is not None
211
+ and markup.colspan(cell) > 1
212
+ and (len(current) != 2 or any(columns[index] is cell for index in current))
213
+ ):
214
+ raise LibrusError(ErrorKind.PARSE)
181
215
  values = {
182
216
  name: GradeSummaryValue(Availability.AVAILABLE, markup.text(columns[index]))
183
217
  for name, index in fields.items()
@@ -259,21 +293,21 @@ def parse_final_grades(body: bytes) -> tuple[SubjectGradeSummary, ...]:
259
293
  if len(sources) > 1 or not (sources or point_tables):
260
294
  raise LibrusError(ErrorKind.PARSE)
261
295
  if point_tables:
262
- located = {id(table) for table, _, _ in sources}
296
+ located = {id(table) for table, _, _, _ in sources}
263
297
  if any(
264
298
  _current_header(table) and id(table) not in located
265
299
  for table in document.iter("table")
266
300
  if table not in point_tables
267
301
  ):
268
302
  raise LibrusError(ErrorKind.PARSE)
269
- fields, width = point_layout(point_tables[0])
303
+ fields, width, current = point_layout(point_tables[0])
270
304
  if fields:
271
- sources.append((point_tables[0], fields, width))
305
+ sources.append((point_tables[0], fields, width, current))
272
306
  items: dict[str, SubjectGradeSummary] = {}
273
- for table, fields, width in sources:
307
+ for table, fields, width, current in sources:
274
308
  family_subjects: set[str] = set()
275
309
  for cells in _subject_rows(table, width, points=table in point_tables):
276
- item = _summary(cells, fields, width)
310
+ item = _summary(cells, fields, width, current)
277
311
  if item.subject in family_subjects:
278
312
  raise LibrusError(ErrorKind.PARSE)
279
313
  family_subjects.add(item.subject)
@@ -587,9 +587,9 @@ def _read_numeric_table(
587
587
  # Preserve the established full-row and summary alignment validation. A
588
588
  # point table aligns on its current-grade header row and may lack summaries.
589
589
  if points:
590
- fields, width = point_layout(table)
590
+ fields, width, _ = point_layout(table)
591
591
  else:
592
- _, fields, width = _locate(table)
592
+ _, fields, width, _ = _locate(table)
593
593
  current, means = _layout(table, points=points)
594
594
  periods = _period_columns(table, points=points)
595
595
  averages = collection.point_results if points else collection.averages