librus-python-api 1.10.0__tar.gz → 1.10.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.
Files changed (59) hide show
  1. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/API.md +13 -4
  2. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/CHANGELOG.md +41 -0
  3. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/PKG-INFO +7 -4
  4. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/README.md +6 -3
  5. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/pyproject.toml +4 -0
  6. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/__init__.py +1 -1
  7. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/completed_lessons.py +4 -1
  8. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/config.py +27 -4
  9. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/gateway_grades.py +172 -33
  10. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/markup.py +6 -4
  11. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/service.py +14 -9
  12. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/uv.lock +115 -109
  13. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/.gitignore +0 -0
  14. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/LICENSE +0 -0
  15. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/SECURITY.md +0 -0
  16. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/_notification_bootstrap.py +0 -0
  17. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/_notification_codec.py +0 -0
  18. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/_storage.py +0 -0
  19. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/_windows_filesystem.py +0 -0
  20. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/announcements.py +0 -0
  21. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/attachment_routes.py +0 -0
  22. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/attachments.py +0 -0
  23. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/attendance.py +0 -0
  24. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/attendance_frequency.py +0 -0
  25. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/budget.py +0 -0
  26. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/checkpoint.py +0 -0
  27. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/class_free_days.py +0 -0
  28. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/detail_fields.py +0 -0
  29. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/diagnostics.py +0 -0
  30. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/exceptions.py +0 -0
  31. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/files.py +0 -0
  32. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/formative_grades.py +0 -0
  33. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/grade_parsers.py +0 -0
  34. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/grade_records.py +0 -0
  35. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/homework_range.py +0 -0
  36. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/inspect_page.py +0 -0
  37. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/justifications.py +0 -0
  38. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/lifecycle.py +0 -0
  39. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/message_content.py +0 -0
  40. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/messages.py +0 -0
  41. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/models.py +0 -0
  42. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/modern_body.py +0 -0
  43. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/modern_mailbox.py +0 -0
  44. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/modern_messages.py +0 -0
  45. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/notification_models.py +0 -0
  46. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/notification_persistence.py +0 -0
  47. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/notification_workflow.py +0 -0
  48. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/notifications.py +0 -0
  49. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/parsers.py +0 -0
  50. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/parsing.py +0 -0
  51. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/persistence.py +0 -0
  52. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/py.typed +0 -0
  53. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/recipients.py +0 -0
  54. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/scheduler.py +0 -0
  55. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/school_reads.py +0 -0
  56. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/school_year_archive.py +0 -0
  57. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/sending.py +0 -0
  58. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/timetable.py +0 -0
  59. {librus_python_api-1.10.0 → librus_python_api-1.10.2}/src/librus_python_api/transport.py +0 -0
@@ -102,7 +102,9 @@ one summary across four logins. Requests are counted at dispatch and never
102
102
  refunded. Exhaustion raises `LimitError`; deadlines raise `OperationTimeoutError`.
103
103
 
104
104
  - Fresh reads are the default. `max_age_seconds > 0` allows reuse from a
105
- 64-entry per-account result cache. A new login clears it.
105
+ 64-entry per-account result cache. Every read from Librus refreshes its
106
+ entry, and a full cache drops the entry refreshed longest ago. A new login
107
+ clears it.
106
108
  - Identical in-flight reads on one account share one request. Calls with
107
109
  explicit budgets share only when they pass the same budget object. Cancelling
108
110
  one waiter leaves others running; cancelling the last waiter cancels and joins
@@ -368,7 +370,7 @@ line (such as `wzorowe`), `day` is `Data wystawienia`, `teacher` stays `None`
368
370
  and `Dodał` is kept only in `metadata`. See [grades](contracts/grades.md).
369
371
 
370
372
  Schools on the new descriptive grading schema show a subject table
371
- (`newSchemaGradesByStudentTable`) in one of two layouts. Every view checks it
373
+ (`newSchemaGradesByStudentTable`) in one of three layouts. Every view checks it
372
374
  the same way (from 1.8.4; before, only the `ALL` view did):
373
375
 
374
376
  - Empty semester cells (`gradesCell` hooks) that the page script fills from
@@ -377,9 +379,16 @@ the same way (from 1.8.4; before, only the `ALL` view did):
377
379
  - Semester cells holding bare text, such as `5` or `Brak ocen` (1.8.3). The
378
380
  text becomes undated `descriptive_summaries` (`Brak ocen` is empty) and no
379
381
  view makes a gateway request. Undated summaries are not notified.
382
+ - Semester cells holding grade boxes such as `O` or `C+`, with filled detail
383
+ rows (1.10.1, #173). The boxes become dated `DescriptiveGrade`s in
384
+ `descriptive` (kind `CURRENT`, no `href`), with `Obszar oceniania`,
385
+ `Umiejętność` and the other tooltip lines in `metadata`, and no view makes a
386
+ gateway request. The detail rows must list the same grades, value and date,
387
+ in the same order; otherwise, or when a detail grade has `Treść oceny` text,
388
+ the read raises `UnsupportedCapabilityError`.
380
389
  - Anything else fails the read: blank cells without hooks, a cell with an
381
- attribute or markup, both layouts in one table, a bare-text table that still
382
- has `studentGradesDetailsRow` rows (`UnsupportedCapabilityError`), or rows
390
+ attribute or markup, mixed layouts in one table, a bare-text table that still
391
+ has empty `studentGradesDetailsRow` rows (`UnsupportedCapabilityError`), or rows
383
392
  of more than one student (`ParseError`).
384
393
 
385
394
  Gateway descriptive grades (1.8.0): with the empty layout, the `ALL` view
@@ -1,5 +1,46 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.10.2 (2026-11-17) - Stricter dates and lesson cells; cache fixes
4
+
5
+ - Dates followed by a weekday label, such as `2026-11-15 (ndz.)` in grade and
6
+ point-grade tooltips, now fail as `PARSE` when the label names another day
7
+ of the week (`2026-11-15 (pon.)`), as homework dates already did. Both
8
+ Sunday labels, `ndz.` and `nd.`, are still accepted, and dates without a
9
+ label are unchanged (#178).
10
+ - Completed lessons: a subject/teacher cell with more than one comma (such as
11
+ `Biology, advanced, Teacher`) now fails the read as a parse error. It used to
12
+ keep the whole cell as the subject and drop the teacher (#177).
13
+ - Attendance frequency: a lesson or subject collection that fails to parse, is
14
+ denied or is too large is no longer cached as an empty map for an hour, which
15
+ made every later `subject_frequency` call look up each lesson on its own. The
16
+ next call reads the collection again; parsed collections keep their one-hour
17
+ lifetime (#176).
18
+ - The per-account result cache and the attendance metadata cache drop the
19
+ entry refreshed longest ago when full. They used to drop the entry stored
20
+ first, even if it had just been read again (#175).
21
+
22
+ ## 1.10.1 (2026-11-15) - Descriptive grades shown as grade boxes
23
+
24
+ Thank you, @sanyok-ua, for the sanitized pages on #76 that showed this layout (#173).
25
+
26
+ - Grades: a new-schema descriptive table whose semester cells hold grade boxes
27
+ (such as `O` or `C+`) and whose hidden detail rows the page already filled
28
+ made every grades read fail with `UnsupportedCapabilityError`. The boxes are
29
+ now `DescriptiveGrade`s in `descriptive` (kind `CURRENT`, no `href`), with
30
+ `Obszar oceniania`, `Umiejętność`, `Data`, `Nauczyciel`, `Dodał` and
31
+ `Komentarz` in `metadata`, and no view makes a gateway request for such a
32
+ table. The detail rows must list the same grades, value and date, in the
33
+ same order. A detail grade with `Treść oceny` text, which the boxes do not
34
+ carry, a missing, extra or empty detail row, other columns, a semester cell
35
+ with other content, or a table mixing layouts still fails closed. So does a
36
+ table with empty script hooks whose detail rows hold a table, which used to
37
+ go on to the gateway read and could have counted grades twice.
38
+ - `Obszar oceniania` and `Umiejętność` are known tooltip labels
39
+ (`config.TOOLTIP_LABELS`), so failure diagnostics show them by name.
40
+ - The layout follows two sanitized pages the reporter checked with
41
+ `inspect_page`, with original fixtures. None of the owner's four logins shows
42
+ it; their live grade reads gave the same counts with and without the change.
43
+
3
44
  ## 1.10.0 (2026-11-13) - Behaviour points and e-Justifications
4
45
 
5
46
  Thank you, @sanyok-ua, for reporting #76 and asking for behaviour points as a
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: librus-python-api
3
- Version: 1.10.0
3
+ Version: 1.10.2
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,10 @@ 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.0` returns behaviour points as a typed value
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
48
+ shows as grade boxes. `1.10.0` returns behaviour points as a typed value
46
49
  (`GradeRecords.behaviour_points`), reads the e-Justifications list on parent
47
50
  logins (`AccountClient.justifications()`) and checks the gateway grade
48
51
  pagination member recorded live.
@@ -76,7 +79,7 @@ See [limitations](#supported-features-and-limitations) below.
76
79
  Install the exact release from PyPI after its gated publication completes:
77
80
 
78
81
  ```sh
79
- python -m pip install librus-python-api==1.10.0
82
+ python -m pip install librus-python-api==1.10.2
80
83
  ```
81
84
 
82
85
  Pin the exact version qualified by your application. Before publication, use a
@@ -92,7 +95,7 @@ python -m pip install .
92
95
  To install a locally built wheel instead:
93
96
 
94
97
  ```sh
95
- python -m pip install ./dist/librus_python_api-1.10.0-py3-none-any.whl
98
+ python -m pip install ./dist/librus_python_api-1.10.2-py3-none-any.whl
96
99
  ```
97
100
 
98
101
  No console script or background process is installed: import the library in your
@@ -16,7 +16,10 @@ 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.0` returns behaviour points as a typed value
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
22
+ shows as grade boxes. `1.10.0` returns behaviour points as a typed value
20
23
  (`GradeRecords.behaviour_points`), reads the e-Justifications list on parent
21
24
  logins (`AccountClient.justifications()`) and checks the gateway grade
22
25
  pagination member recorded live.
@@ -50,7 +53,7 @@ See [limitations](#supported-features-and-limitations) below.
50
53
  Install the exact release from PyPI after its gated publication completes:
51
54
 
52
55
  ```sh
53
- python -m pip install librus-python-api==1.10.0
56
+ python -m pip install librus-python-api==1.10.2
54
57
  ```
55
58
 
56
59
  Pin the exact version qualified by your application. Before publication, use a
@@ -66,7 +69,7 @@ python -m pip install .
66
69
  To install a locally built wheel instead:
67
70
 
68
71
  ```sh
69
- python -m pip install ./dist/librus_python_api-1.10.0-py3-none-any.whl
72
+ python -m pip install ./dist/librus_python_api-1.10.2-py3-none-any.whl
70
73
  ```
71
74
 
72
75
  No console script or background process is installed: import the library in your
@@ -49,6 +49,10 @@ dev = [
49
49
  # so a freshly published (possibly compromised) release never reaches the lock.
50
50
  # The lock stores only the window, so it does not change from day to day.
51
51
  exclude-newer = "7 days"
52
+ # The project's own releases are exempt: the release workflow's `confirm` job
53
+ # installs the version uploaded seconds earlier from this checkout. Their
54
+ # dependencies stay inside the window.
55
+ exclude-newer-package = { librus-python-api = false }
52
56
 
53
57
  [tool.hatch.version]
54
58
  path = "src/librus_python_api/__init__.py"
@@ -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.0"
4
+ __version__ = "1.10.2"
5
5
 
6
6
  from librus_python_api.attachments import AttachmentStream, ModernAttachmentStream
7
7
  from librus_python_api.budget import RequestBudget
@@ -203,8 +203,11 @@ def _lesson(
203
203
  raw_number, combined, topic, z_value, symbol = values
204
204
  if raw_number not in {"", "-"} and re.fullmatch(r"[0-9]{1,2}", raw_number) is None:
205
205
  raise LibrusError(ErrorKind.PARSE)
206
- # Some schools render "<b>Subject</b>, <br>Teacher" or pad the comma.
206
+ # Some schools render "<b>Subject</b>, <br>Teacher" or pad the comma. More
207
+ # than one comma leaves the subject/teacher boundary ambiguous, so fail.
207
208
  names = [name.strip() for name in combined.split(",")]
209
+ if len(names) > 2:
210
+ raise LibrusError(ErrorKind.PARSE)
208
211
  subject, teacher = (names[0], names[1]) if len(names) == 2 else (combined, None)
209
212
  if not subject or teacher == "":
210
213
  raise LibrusError(ErrorKind.PARSE)
@@ -760,11 +760,13 @@ TOOLTIP_LABELS = frozenset(
760
760
  "Maksymalna ilość punktów",
761
761
  "Nauczyciel",
762
762
  "Obowiązek wyk. zadania",
763
+ "Obszar oceniania",
763
764
  "Ocena",
764
765
  "Poprawa oceny",
765
766
  "Rodzaj",
766
767
  "Suma punktów",
767
768
  "Temat zajęć",
769
+ "Umiejętność",
768
770
  "Waga",
769
771
  "Zakres do",
770
772
  "Zakres od",
@@ -807,12 +809,29 @@ GRADE_PERIOD_HEADERS = MappingProxyType(
807
809
  "Ocena roczna": 0,
808
810
  }
809
811
  )
810
- # New-schema descriptive grading: the page renders this table either with empty
812
+ # New-schema descriptive grading: the page renders this table with empty
811
813
  # `gradesCell` semester cells, which its script fills from the gateway routes
812
- # above, or with bare semester text, which needs no gateway read.
814
+ # above, with bare semester text, or with grade boxes and filled detail rows;
815
+ # the last two need no gateway read.
813
816
  DESCRIPTIVE_TABLE_CLASS = "newSchemaGradesByStudentTable"
814
817
  DESCRIPTIVE_ROW_CLASS = "studentRow"
815
818
  DESCRIPTIVE_DETAILS_ROW_CLASS = "studentGradesDetailsRow"
819
+ DESCRIPTIVE_DETAILS_CELL_CLASS = "studentGradesDetailsCell"
820
+ # A filled detail row's table (2026-11-15, reported page, #173): these column
821
+ # labels, then per period a heading row with one `DESCRIPTIVE_PERIOD_LABELS` cell and
822
+ # either `detail-grades` rows or one empty-marker row.
823
+ DESCRIPTIVE_DETAIL_COLUMNS = (
824
+ "Ocena",
825
+ "K",
826
+ "Obszar oceniania",
827
+ "Umiejętność",
828
+ "Data",
829
+ "Nauczyciel",
830
+ "Treść oceny",
831
+ "Dodał",
832
+ )
833
+ DESCRIPTIVE_DETAIL_GRADE_ROW_CLASS = "detail-grades"
834
+ DESCRIPTIVE_PERIOD_LABELS = MappingProxyType({"Okres 1": 1, "Okres 2": 2})
816
835
  # Gateway account and student identifiers are opaque strings, unlike every
817
836
  # other `{id}` route, which takes a numeric ID.
818
837
  DESCRIPTIVE_IDENTIFIER = re.compile(r"[A-Za-z0-9_-]{1,128}")
@@ -1033,8 +1052,12 @@ HOMEWORK_MARK_DONE_HANDLER = (
1033
1052
  r"\s*showConfirmQuestion\(\s*[0-9]{1,64}\s*,\s*[0-9]{1,64}\s*\);?\s*"
1034
1053
  )
1035
1054
  WEEKDAY_LABELS = ("pon.", "wt.", "śr.", "czw.", "pt.", "sob.", "ndz.")
1036
- # Grade tooltips also use the short Sunday display label.
1037
- CIVIL_DATE_WEEKDAY_LABELS = frozenset((*WEEKDAY_LABELS, "nd."))
1055
+ # Accepted labels per weekday (Monday first) after a civil date. Grade
1056
+ # tooltips also use the short Sunday display label.
1057
+ CIVIL_DATE_WEEKDAY_LABELS: tuple[tuple[str, ...], ...] = (
1058
+ *((label,) for label in WEEKDAY_LABELS[:-1]),
1059
+ (WEEKDAY_LABELS[-1], "nd."),
1060
+ )
1038
1061
  # Observed page-level notices shown instead of the requested content.
1039
1062
  PAGE_NOTICES = MappingProxyType(
1040
1063
  {
@@ -10,9 +10,10 @@ the pagination member, `{"limit", "page", "total"}` integers beside `data` or
10
10
  shape fails instead of producing a partial collection.
11
11
 
12
12
  Another school renders the same table with plain text in its semester cells and
13
- no script hooks (#115, from a reporter's synthetic example). The grade record
14
- parser reads those cells like any descriptive row, so that table needs no
15
- gateway read.
13
+ no script hooks (#115, from a reporter's synthetic example), and another with
14
+ grade boxes in them and filled detail rows that list the same grades (#173,
15
+ from a reporter's sanitized page). The grade record parser reads those cells
16
+ like any descriptive row, so neither table needs a gateway read.
16
17
  """
17
18
 
18
19
  import re
@@ -27,13 +28,18 @@ from pydantic import BaseModel, ConfigDict, Field, ValidationError, field_valida
27
28
 
28
29
  from librus_python_api import markup
29
30
  from librus_python_api.config import (
31
+ DESCRIPTIVE_DETAIL_COLUMNS,
32
+ DESCRIPTIVE_DETAIL_GRADE_ROW_CLASS,
33
+ DESCRIPTIVE_DETAILS_CELL_CLASS,
30
34
  DESCRIPTIVE_DETAILS_ROW_CLASS,
31
35
  DESCRIPTIVE_IDENTIFIER,
32
36
  DESCRIPTIVE_MAX_NAME_LENGTH,
33
37
  DESCRIPTIVE_MAX_SUBJECTS,
34
38
  DESCRIPTIVE_MAX_USERS,
39
+ DESCRIPTIVE_PERIOD_LABELS,
35
40
  DESCRIPTIVE_ROW_CLASS,
36
41
  DESCRIPTIVE_TABLE_CLASS,
42
+ GRADE_EMPTY_MARKERS,
37
43
  GRADE_MAX_METADATA_LENGTH,
38
44
  GRADE_MAX_RECORDS,
39
45
  GRADE_MAX_SUBJECTS,
@@ -309,14 +315,118 @@ def _classes(element: html.HtmlElement) -> set[str]:
309
315
  return set(element.get("class", "").split())
310
316
 
311
317
 
318
+ _Grades = list[tuple[str, date]]
319
+
320
+
321
+ def _box_grades(cell: html.HtmlElement) -> _Grades | None:
322
+ """Value and date of each grade box in a semester cell of the box layout.
323
+
324
+ The cell has no attributes and holds either only grade boxes, each one
325
+ link with no markup, or a bare empty marker (no grades). Anything else is
326
+ None. The record parser reads and validates the same boxes.
327
+ """
328
+ if cell.attrib:
329
+ return None
330
+ elements = [node for node in cell if isinstance(node.tag, str)]
331
+ if not elements:
332
+ value = markup.text(cell)
333
+ return [] if value and value in GRADE_EMPTY_MARKERS else None
334
+ if (cell.text or "").strip() or any((node.tail or "").strip() for node in cell):
335
+ return None
336
+ result: _Grades = []
337
+ for box in elements:
338
+ links = [node for node in box if isinstance(node.tag, str)]
339
+ if (
340
+ box.tag != "span"
341
+ or "grade-box" not in _classes(box)
342
+ or (box.text or "").strip()
343
+ or len(links) != 1
344
+ or links[0].tag != "a"
345
+ or len(links[0])
346
+ or (links[0].tail or "").strip()
347
+ ):
348
+ return None
349
+ fields = markup.tooltip_fields(links[0])
350
+ result.append((markup.text(links[0]), markup.civil_date(fields.get("Data"))))
351
+ return result
352
+
353
+
354
+ def _detail_grades(cell: html.HtmlElement) -> dict[int, _Grades]:
355
+ """Value and date of each grade in a filled detail row, by period.
356
+
357
+ The cell holds one table: `DESCRIPTIVE_DETAIL_COLUMNS` as its header, then
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.
361
+ """
362
+ unsupported = LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
363
+ tables = [node for node in cell if isinstance(node.tag, str)]
364
+ if (
365
+ len(tables) != 1
366
+ or tables[0].tag != "table"
367
+ or (cell.text or "").strip()
368
+ or (tables[0].tail or "").strip()
369
+ ):
370
+ raise unsupported
371
+ result: dict[int, _Grades] = {}
372
+ empty: set[int] = set()
373
+ header = False
374
+ period: int | None = None
375
+ for row in markup.rows(tables[0]):
376
+ cells = markup.cells(row)
377
+ texts = [markup.text(item) for item in cells]
378
+ if markup.in_header(row):
379
+ if header or texts != list(DESCRIPTIVE_DETAIL_COLUMNS):
380
+ raise unsupported
381
+ header = True
382
+ elif next(row.iterancestors("tfoot"), None) is not None:
383
+ if any(texts) or any(len(item) for item in cells):
384
+ raise unsupported
385
+ elif len(cells) == 1 and texts[0] in DESCRIPTIVE_PERIOD_LABELS:
386
+ period = DESCRIPTIVE_PERIOD_LABELS[texts[0]]
387
+ if period in result or len(cells[0]):
388
+ raise unsupported
389
+ result[period] = []
390
+ elif period is None or period in empty:
391
+ raise unsupported
392
+ elif len(cells) == 1:
393
+ if result[period] or texts[0] not in GRADE_EMPTY_MARKERS - {""}:
394
+ raise unsupported
395
+ if len(cells[0]):
396
+ raise unsupported
397
+ empty.add(period)
398
+ elif (
399
+ DESCRIPTIVE_DETAIL_GRADE_ROW_CLASS in _classes(row)
400
+ and len(cells) == len(DESCRIPTIVE_DETAIL_COLUMNS)
401
+ and texts[0]
402
+ and not texts[DESCRIPTIVE_DETAIL_COLUMNS.index("Treść oceny")]
403
+ ):
404
+ day = texts[DESCRIPTIVE_DETAIL_COLUMNS.index("Data")]
405
+ result[period].append((texts[0], markup.civil_date(day)))
406
+ else:
407
+ raise unsupported
408
+ if not header or sorted(result) != [1, 2]:
409
+ raise unsupported
410
+ if any(not result[key] and key not in empty for key in result):
411
+ raise unsupported
412
+ return result
413
+
414
+
312
415
  def read_descriptive_table(document: html.HtmlElement) -> DescriptiveTable | None:
313
416
  """The new-schema subject table, or None when the page has none.
314
417
 
315
- Its rows hold an expander, the subject and two semester cells. Either
316
- every row has empty `gradesCell` cells that the page script fills from
317
- the gateway, or every row has plain cells the page filled itself, which
318
- `read_grade_records` reads and validates. A script cell the page already
319
- filled would duplicate the gateway records, so it is unsupported.
418
+ Its rows hold an expander, the subject and two semester cells, in one of
419
+ three layouts that `read_grade_records` reads, with no gateway grades
420
+ except in the first:
421
+
422
+ - empty `gradesCell` cells that the page script fills from the gateway;
423
+ - bare text cells the page filled itself (#115), with no detail rows;
424
+ - grade boxes or a bare empty marker (2026-11-15, #173), with a filled
425
+ `studentGradesDetailsRow` for every subject row that lists the same
426
+ grades, value and date, in the same order.
427
+
428
+ A script cell the page already filled would duplicate the gateway records,
429
+ so it is unsupported, as is any other cell or a table mixing layouts.
320
430
  """
321
431
  tables = [
322
432
  table
@@ -338,6 +448,26 @@ def read_descriptive_table(document: html.HtmlElement) -> DescriptiveTable | Non
338
448
  if not populated:
339
449
  return None
340
450
  tables = populated
451
+ detail_rows = [
452
+ row
453
+ for row in markup.rows(tables[0])
454
+ if DESCRIPTIVE_DETAILS_ROW_CLASS in _classes(row)
455
+ ]
456
+ # Detail rows the page script fills from the gateway are empty; filled
457
+ # ones hold a table and belong to the box layout.
458
+ rendered = any(next(row.iter("table"), None) is not None for row in detail_rows)
459
+ details: dict[str, dict[int, _Grades]] = {}
460
+ if rendered:
461
+ for row in detail_rows:
462
+ cells = markup.cells(row)
463
+ if len(cells) != 1 or DESCRIPTIVE_DETAILS_CELL_CLASS not in _classes(
464
+ cells[0]
465
+ ):
466
+ raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
467
+ key = row.get("data-subject_id", "")
468
+ if key in details:
469
+ raise LibrusError(ErrorKind.PARSE)
470
+ details[key] = _detail_grades(cells[0])
341
471
  subjects: dict[int, str] = {}
342
472
  students: set[str | None] = set()
343
473
  layouts: set[bool] = set()
@@ -350,26 +480,36 @@ def read_descriptive_table(document: html.HtmlElement) -> DescriptiveTable | Non
350
480
  ):
351
481
  raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
352
482
  semesters = cells[2:]
353
- # A filled cell is bare text: no attributes and no markup, so a renamed
354
- # or moved script hook never passes as a filled table.
355
- filled = all(
356
- not cell.attrib
357
- and markup.text(cell)
358
- and not any(isinstance(node.tag, str) for node in cell)
359
- for cell in semesters
360
- )
361
- if not filled and (
362
- [cell.get("data-semester") for cell in semesters] != ["1", "2"]
363
- or not all("gradesCell" in _classes(cell) for cell in semesters)
364
- ):
365
- raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
366
- layouts.add(filled)
367
- if not filled and any(
368
- markup.text(cell) or any(isinstance(node.tag, str) for node in cell)
369
- for cell in semesters
370
- ):
371
- raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
372
483
  identifier = row.get("data-subject_id", "")
484
+ if rendered:
485
+ boxes = [_box_grades(cell) for cell in semesters]
486
+ if boxes[0] is None or boxes[1] is None:
487
+ raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
488
+ # The detail row must list exactly the grades the boxes show; any
489
+ # other grade there would be dropped.
490
+ if details.pop(identifier, None) != {1: boxes[0], 2: boxes[1]}:
491
+ raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
492
+ filled = True
493
+ else:
494
+ # A filled cell is bare text: no attributes and no markup, so a
495
+ # renamed or moved script hook never passes as a filled table.
496
+ filled = all(
497
+ not cell.attrib
498
+ and markup.text(cell)
499
+ and not any(isinstance(node.tag, str) for node in cell)
500
+ for cell in semesters
501
+ )
502
+ if not filled and (
503
+ [cell.get("data-semester") for cell in semesters] != ["1", "2"]
504
+ or not all("gradesCell" in _classes(cell) for cell in semesters)
505
+ ):
506
+ raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
507
+ if not filled and any(
508
+ markup.text(cell) or any(isinstance(node.tag, str) for node in cell)
509
+ for cell in semesters
510
+ ):
511
+ raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
512
+ layouts.add(filled)
373
513
  name = markup.text(cells[1])
374
514
  if not re.fullmatch(r"[0-9]{1,18}", identifier) or not name:
375
515
  raise LibrusError(ErrorKind.PARSE)
@@ -382,13 +522,12 @@ def read_descriptive_table(document: html.HtmlElement) -> DescriptiveTable | Non
382
522
  if len(students) > 1:
383
523
  # One page shows one student; rows of several students are unknown.
384
524
  raise LibrusError(ErrorKind.PARSE)
385
- if len(layouts) > 1:
525
+ if len(layouts) > 1 or details:
526
+ # Mixed layouts, or a filled detail row without its subject row.
386
527
  raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
387
- if layouts == {True} and any(
388
- DESCRIPTIVE_DETAILS_ROW_CLASS in _classes(row) for row in markup.rows(tables[0])
389
- ):
390
- # Detail rows are what the page script fills from the gateway; a filled
391
- # table that still has them may also have gateway grades.
528
+ if not rendered and layouts == {True} and detail_rows:
529
+ # Empty detail rows are what the page script fills from the gateway; a
530
+ # bare-text table that still has them may also have gateway grades.
392
531
  raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
393
532
  return DescriptiveTable(MappingProxyType(subjects), layouts == {True})
394
533
 
@@ -164,14 +164,16 @@ def tooltip_line(chunk: str) -> str:
164
164
  def civil_date(value: str | None) -> date:
165
165
  """An ISO date, optionally followed by its weekday label in parentheses."""
166
166
  match = re.fullmatch(r"([0-9]{4}-[0-9]{2}-[0-9]{2})(?: \(([^()]+)\))?", value or "")
167
- if match is None or (
168
- match[2] is not None and match[2] not in CIVIL_DATE_WEEKDAY_LABELS
169
- ):
167
+ if match is None:
170
168
  raise LibrusError(ErrorKind.PARSE)
171
169
  try:
172
- return date.fromisoformat(match[1])
170
+ day = date.fromisoformat(match[1])
173
171
  except ValueError:
174
172
  pass
173
+ else:
174
+ # A label must name the date's own weekday, as for homework dates.
175
+ if match[2] is None or match[2] in CIVIL_DATE_WEEKDAY_LABELS[day.weekday()]:
176
+ return day
175
177
  raise LibrusError(ErrorKind.PARSE)
176
178
 
177
179
 
@@ -1331,10 +1331,12 @@ class AccountClient:
1331
1331
  no POST. Missing inline weight/count data remains unknown.
1332
1332
 
1333
1333
  Every view checks a new-schema descriptive table the same way. Its
1334
- semester cells either are empty script hooks or hold bare text, which
1335
- becomes undated summaries with no extra request; any other layout
1336
- fails the read. Only the all view with empty hooks adds that table's
1337
- grades from the gateway: three more reads, five when there are grades.
1334
+ semester cells are empty script hooks, hold bare text, which becomes
1335
+ undated summaries, or hold grade boxes matched by filled detail rows,
1336
+ which become descriptive grades; any other layout fails the read. Only
1337
+ the all view with empty hooks adds that table's grades from the
1338
+ gateway: three more reads, five when there are grades. The other
1339
+ layouts need no extra request.
1338
1340
 
1339
1341
  `records.corrections` links a corrected grade to its corrections by
1340
1342
  `grade_id`, read from the page's correction brackets. Only the all view
@@ -2199,6 +2201,9 @@ class AccountClient:
2199
2201
  error.kind,
2200
2202
  )
2201
2203
  raise
2204
+ # Reinsert so iteration order follows refresh time: eviction then drops
2205
+ # the least recently refreshed entry, not the one just read again.
2206
+ self._cache.pop(key, None)
2202
2207
  self._cache[key] = (time.monotonic(), result)
2203
2208
  if len(self._cache) > ACCOUNT_RESULT_CACHE_SIZE:
2204
2209
  del self._cache[next(iter(self._cache))]
@@ -2587,6 +2592,7 @@ class AccountClient:
2587
2592
  reference=identifier,
2588
2593
  content_type=JSON,
2589
2594
  )
2595
+ self._metadata.pop(key, None) # refresh order, as in _cached
2590
2596
  self._metadata[key] = time.monotonic(), value
2591
2597
  if len(self._metadata) > ATTENDANCE_METADATA_CACHE_SIZE:
2592
2598
  del self._metadata[next(iter(self._metadata))]
@@ -2610,15 +2616,14 @@ class AccountClient:
2610
2616
  )
2611
2617
  except LibrusError as error:
2612
2618
  # An unavailable or unexpected collection degrades to the original
2613
- # per-reference lookups. Deadlines, budgets, cancellation and session
2614
- # failures still propagate. Only deterministic outcomes are cached.
2619
+ # per-reference lookups for this call only; the next call reads the
2620
+ # collection again. Deadlines, budgets, cancellation and session
2621
+ # failures still propagate. Only parsed maps are cached.
2615
2622
  if error.kind not in _METADATA_MAP_FALLBACK:
2616
2623
  raise
2617
2624
  if error.kind is ErrorKind.LIMIT:
2618
2625
  budget.check() # An exhausted caller budget is not a large collection.
2619
- if error.kind is ErrorKind.CONNECTION:
2620
- return MappingProxyType({})
2621
- value = MappingProxyType({})
2626
+ return MappingProxyType({})
2622
2627
  self._metadata_maps[endpoint] = time.monotonic(), value
2623
2628
  return value
2624
2629