librus-python-api 1.11.2__py3-none-any.whl → 1.11.4__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.
- librus_python_api/__init__.py +1 -1
- librus_python_api/attendance_frequency.py +8 -38
- librus_python_api/completed_lessons.py +4 -0
- librus_python_api/config.py +4 -1
- librus_python_api/diagnostics.py +18 -4
- librus_python_api/exceptions.py +3 -1
- librus_python_api/grade_parsers.py +41 -18
- librus_python_api/grade_records.py +2 -2
- librus_python_api/parsers.py +54 -2
- librus_python_api/service.py +62 -18
- librus_python_api/transport.py +9 -0
- {librus_python_api-1.11.2.dist-info → librus_python_api-1.11.4.dist-info}/METADATA +9 -4
- {librus_python_api-1.11.2.dist-info → librus_python_api-1.11.4.dist-info}/RECORD +15 -15
- {librus_python_api-1.11.2.dist-info → librus_python_api-1.11.4.dist-info}/WHEEL +0 -0
- {librus_python_api-1.11.2.dist-info → librus_python_api-1.11.4.dist-info}/licenses/LICENSE +0 -0
librus_python_api/__init__.py
CHANGED
|
@@ -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.
|
|
4
|
+
__version__ = "1.11.4"
|
|
5
5
|
|
|
6
6
|
from librus_python_api.attachments import AttachmentStream, ModernAttachmentStream
|
|
7
7
|
from librus_python_api.budget import RequestBudget
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Original validated gateway parsing and explicit attendance ratio policies."""
|
|
2
2
|
|
|
3
|
-
from pydantic import BaseModel
|
|
3
|
+
from pydantic import BaseModel
|
|
4
4
|
|
|
5
5
|
from librus_python_api import markup
|
|
6
6
|
from librus_python_api.config import (
|
|
@@ -20,7 +20,7 @@ from librus_python_api.models import (
|
|
|
20
20
|
_SubjectEnvelopeWire,
|
|
21
21
|
_SubjectsEnvelopeWire,
|
|
22
22
|
)
|
|
23
|
-
from librus_python_api.parsers import decode_json
|
|
23
|
+
from librus_python_api.parsers import decode_json, validate_wire
|
|
24
24
|
|
|
25
25
|
|
|
26
26
|
def parse_gateway_attendance(body: bytes) -> tuple[GatewayAttendanceRecord, ...]:
|
|
@@ -31,14 +31,7 @@ def parse_gateway_attendance(body: bytes) -> tuple[GatewayAttendanceRecord, ...]
|
|
|
31
31
|
and len(data["Attendances"]) > ATTENDANCE_MAX_RECORDS
|
|
32
32
|
):
|
|
33
33
|
raise LibrusError(ErrorKind.LIMIT)
|
|
34
|
-
|
|
35
|
-
envelope = None
|
|
36
|
-
try:
|
|
37
|
-
envelope = _AttendanceEnvelopeWire.model_validate(data)
|
|
38
|
-
except ValidationError:
|
|
39
|
-
failed = True
|
|
40
|
-
if failed or envelope is None:
|
|
41
|
-
raise LibrusError(ErrorKind.PARSE)
|
|
34
|
+
envelope = validate_wire(_AttendanceEnvelopeWire, data)
|
|
42
35
|
seen: set[str] = set()
|
|
43
36
|
records: list[GatewayAttendanceRecord] = []
|
|
44
37
|
for row in envelope.Attendances:
|
|
@@ -62,31 +55,16 @@ def parse_gateway_attendance(body: bytes) -> tuple[GatewayAttendanceRecord, ...]
|
|
|
62
55
|
|
|
63
56
|
def parse_lesson_subject(body: bytes, identifier: str) -> str:
|
|
64
57
|
data = decode_json(body)
|
|
65
|
-
|
|
66
|
-
lesson
|
|
67
|
-
try:
|
|
68
|
-
lesson = _LessonEnvelopeWire.model_validate(data).Lesson
|
|
69
|
-
except ValidationError:
|
|
70
|
-
failed = True
|
|
71
|
-
if failed or lesson is None or lesson.Id != identifier:
|
|
58
|
+
lesson = validate_wire(_LessonEnvelopeWire, data).Lesson
|
|
59
|
+
if lesson.Id != identifier:
|
|
72
60
|
raise LibrusError(ErrorKind.PARSE)
|
|
73
61
|
return lesson.Subject.Id
|
|
74
62
|
|
|
75
63
|
|
|
76
64
|
def parse_subject_name(body: bytes, identifier: str) -> str:
|
|
77
65
|
data = decode_json(body)
|
|
78
|
-
|
|
79
|
-
subject
|
|
80
|
-
try:
|
|
81
|
-
subject = _SubjectEnvelopeWire.model_validate(data).Subject
|
|
82
|
-
except ValidationError:
|
|
83
|
-
failed = True
|
|
84
|
-
if (
|
|
85
|
-
failed
|
|
86
|
-
or subject is None
|
|
87
|
-
or subject.Id != identifier
|
|
88
|
-
or not subject.Name.strip()
|
|
89
|
-
):
|
|
66
|
+
subject = validate_wire(_SubjectEnvelopeWire, data).Subject
|
|
67
|
+
if subject.Id != identifier or not subject.Name.strip():
|
|
90
68
|
raise LibrusError(ErrorKind.PARSE)
|
|
91
69
|
return subject.Name.strip()
|
|
92
70
|
|
|
@@ -98,15 +76,7 @@ def _collection[M: BaseModel](data: object, key: str, maximum: int, wire: type[M
|
|
|
98
76
|
and len(data[key]) > maximum
|
|
99
77
|
):
|
|
100
78
|
raise LibrusError(ErrorKind.LIMIT)
|
|
101
|
-
|
|
102
|
-
envelope = None
|
|
103
|
-
try:
|
|
104
|
-
envelope = wire.model_validate(data)
|
|
105
|
-
except ValidationError:
|
|
106
|
-
failed = True
|
|
107
|
-
if failed or envelope is None:
|
|
108
|
-
raise LibrusError(ErrorKind.PARSE)
|
|
109
|
-
return envelope
|
|
79
|
+
return validate_wire(wire, data)
|
|
110
80
|
|
|
111
81
|
|
|
112
82
|
def _unique(pairs: list[tuple[str, str]]) -> dict[str, str]:
|
|
@@ -103,6 +103,10 @@ def _pagination(document: html.HtmlElement, page: int) -> tuple[int, int | None]
|
|
|
103
103
|
first, last, total = int(match[3]), int(match[4]), int(match[5])
|
|
104
104
|
if not 1 <= first <= last <= total:
|
|
105
105
|
raise LibrusError(ErrorKind.PARSE)
|
|
106
|
+
# The range must agree with the page count (#196): the first page starts
|
|
107
|
+
# at the first item, only the last page ends at the total.
|
|
108
|
+
if (current == 1 and first != 1) or ((current == count) != (last == total)):
|
|
109
|
+
raise LibrusError(ErrorKind.PARSE)
|
|
106
110
|
return count, last - first + 1
|
|
107
111
|
|
|
108
112
|
|
librus_python_api/config.py
CHANGED
|
@@ -737,7 +737,10 @@ GRADE_INLINE_DETAIL_LABEL = "Ocena"
|
|
|
737
737
|
# Tooltip fields whose free text may continue on unlabelled lines. A teacher's
|
|
738
738
|
# multi-line grade comment was observed on 2026-10-27. A formative mirror's
|
|
739
739
|
# assessment text after `Ocena` also spans lines (2026-11-08, markup.py).
|
|
740
|
-
|
|
740
|
+
# In a descriptive grade the skill after `Umiejętność` wrapped onto a line of
|
|
741
|
+
# its own (librus-mcp#136); its sibling `Obszar oceniania` is the same kind of
|
|
742
|
+
# curriculum text and continues the same way.
|
|
743
|
+
TOOLTIP_MULTILINE_LABELS = frozenset({"Komentarz", "Obszar oceniania", "Umiejętność"})
|
|
741
744
|
# Labels a tooltip may repeat. In the week view a correction listed
|
|
742
745
|
# `Poprawa oceny` twice, both naming the same original grade, the first ending
|
|
743
746
|
# in a comma; the all view showed it once (2026-11-08). The tooltip is no
|
librus_python_api/diagnostics.py
CHANGED
|
@@ -15,6 +15,7 @@ from typing import Protocol
|
|
|
15
15
|
|
|
16
16
|
from lxml import html
|
|
17
17
|
|
|
18
|
+
from librus_python_api.exceptions import ParseError
|
|
18
19
|
from librus_python_api.models import DiagnosticEvent
|
|
19
20
|
|
|
20
21
|
_PACKAGE = "librus_python_api"
|
|
@@ -532,6 +533,14 @@ def _failure_site(
|
|
|
532
533
|
return None
|
|
533
534
|
|
|
534
535
|
|
|
536
|
+
def _wire_failure(error: BaseException) -> str | None:
|
|
537
|
+
"""Where a JSON envelope failed validation (`parsers.validate_wire`)."""
|
|
538
|
+
for failure in _chain(error):
|
|
539
|
+
if isinstance(failure, ParseError) and failure._wire_failure:
|
|
540
|
+
return f"wire {failure._wire_failure}"
|
|
541
|
+
return None
|
|
542
|
+
|
|
543
|
+
|
|
535
544
|
def describe_failure(error: BaseException) -> str | None:
|
|
536
545
|
"""The page structure around a failure, for a bug report.
|
|
537
546
|
|
|
@@ -539,13 +548,15 @@ def describe_failure(error: BaseException) -> str | None:
|
|
|
539
548
|
any: tags, safe class tokens, known tooltip labels, known link families
|
|
540
549
|
and lengths, then the layout counts it compared (such as `width`). A
|
|
541
550
|
whole page is summarized last (see _page_summary). Text and attribute
|
|
542
|
-
values are masked unless they equal a parser constant.
|
|
551
|
+
values are masked unless they equal a parser constant. A JSON envelope
|
|
552
|
+
that failed validation is named by field path and rule instead.
|
|
543
553
|
Returns None when there is nothing to show; never raises.
|
|
544
554
|
"""
|
|
545
555
|
try:
|
|
546
556
|
site = _failure_site(error)
|
|
547
557
|
if site is None:
|
|
548
|
-
|
|
558
|
+
wire = _wire_failure(error)
|
|
559
|
+
return None if wire is None else wire[:_REPORT_BYTES]
|
|
549
560
|
frame, line, elements, sequences, counts = site
|
|
550
561
|
redactor = _Redactor()
|
|
551
562
|
lines = [f"at {_site(frame, line)}"]
|
|
@@ -583,12 +594,15 @@ def failure_locator(error: BaseException) -> str | None:
|
|
|
583
594
|
`describe_failure`), then the sizes it was checked against, for example
|
|
584
595
|
`table.stretch.decorated[1] > tbody[1] > tr.bolded.line0[2] > td.center[7];
|
|
585
596
|
cells 7, columns 11, width 10`. Structure and counts only, never page text
|
|
586
|
-
or values.
|
|
597
|
+
or values. A JSON envelope that failed validation gives its field path and
|
|
598
|
+
rule, for example `wire Attendances[3].Lesson missing`. Returns None when
|
|
599
|
+
neither is involved; never raises.
|
|
587
600
|
"""
|
|
588
601
|
try:
|
|
589
602
|
site = _failure_site(error)
|
|
590
603
|
if site is None:
|
|
591
|
-
|
|
604
|
+
wire = _wire_failure(error)
|
|
605
|
+
return None if wire is None else wire[:_LOCATOR_BYTES]
|
|
592
606
|
_, _, elements, sequences, counts = site
|
|
593
607
|
redactor = _Redactor()
|
|
594
608
|
parts = [
|
librus_python_api/exceptions.py
CHANGED
|
@@ -151,7 +151,9 @@ class LimitError(LibrusError):
|
|
|
151
151
|
|
|
152
152
|
|
|
153
153
|
class ParseError(LibrusError):
|
|
154
|
-
|
|
154
|
+
# Library-private: where a JSON envelope failed validation, as wire field
|
|
155
|
+
# names, list indexes and pydantic error types only (`wire_failure`).
|
|
156
|
+
_wire_failure: str | None = None
|
|
155
157
|
|
|
156
158
|
|
|
157
159
|
class StaleCursorError(LibrusError):
|
|
@@ -48,20 +48,24 @@ def _summary_field(cell: html.HtmlElement, *, points: bool = False) -> str | Non
|
|
|
48
48
|
|
|
49
49
|
def _header(
|
|
50
50
|
row: html.HtmlElement, *, points: bool = False
|
|
51
|
-
) -> tuple[dict[str, int], int]:
|
|
51
|
+
) -> tuple[dict[str, int], int, frozenset[int]]:
|
|
52
|
+
"""Summary field columns, the width, and the current-grade columns."""
|
|
52
53
|
fields: dict[str, int] = {}
|
|
54
|
+
current: set[int] = set()
|
|
53
55
|
position = GRADE_BODY_PREFIX_COLUMNS
|
|
54
56
|
for cell in markup.cells(row):
|
|
55
57
|
span = markup.colspan(cell)
|
|
56
58
|
if position + span > GRADE_MAX_COLUMNS:
|
|
57
59
|
raise LibrusError(ErrorKind.LIMIT)
|
|
60
|
+
if markup.text(cell) == GRADE_CURRENT_HEADER:
|
|
61
|
+
current.update(range(position, position + span))
|
|
58
62
|
field = _summary_field(cell, points=points)
|
|
59
63
|
if field is not None:
|
|
60
64
|
if field in fields:
|
|
61
65
|
raise LibrusError(ErrorKind.PARSE)
|
|
62
66
|
fields[field] = position
|
|
63
67
|
position += span
|
|
64
|
-
return fields, position
|
|
68
|
+
return fields, position, frozenset(current)
|
|
65
69
|
|
|
66
70
|
|
|
67
71
|
def is_point_table(table: html.HtmlElement) -> bool:
|
|
@@ -85,8 +89,11 @@ def _current_header(table: html.HtmlElement) -> bool:
|
|
|
85
89
|
)
|
|
86
90
|
|
|
87
91
|
|
|
88
|
-
def point_layout(
|
|
89
|
-
|
|
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.
|
|
90
97
|
|
|
91
98
|
Point tables are not required to have an annual column, so the row with
|
|
92
99
|
the two current-grade headers defines the body alignment instead.
|
|
@@ -102,10 +109,11 @@ def point_layout(table: html.HtmlElement) -> tuple[dict[str, int], int]:
|
|
|
102
109
|
return _header(headers[0], points=True)
|
|
103
110
|
|
|
104
111
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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] = []
|
|
109
117
|
for table in document.iter("table"):
|
|
110
118
|
if not {"decorated", "stretch"} <= set(table.get("class", "").split()):
|
|
111
119
|
continue
|
|
@@ -118,14 +126,12 @@ def _candidates(
|
|
|
118
126
|
# an annual summary title defines the body alignment contract.
|
|
119
127
|
if not any(_summary_field(cell) == "annual" for cell in markup.cells(row)):
|
|
120
128
|
continue
|
|
121
|
-
fields, width = _header(row)
|
|
122
|
-
candidates.append((table, fields, width))
|
|
129
|
+
fields, width, current = _header(row)
|
|
130
|
+
candidates.append((table, fields, width, current))
|
|
123
131
|
return candidates
|
|
124
132
|
|
|
125
133
|
|
|
126
|
-
def _locate(
|
|
127
|
-
document: html.HtmlElement,
|
|
128
|
-
) -> tuple[html.HtmlElement, dict[str, int], int]:
|
|
134
|
+
def _locate(document: html.HtmlElement) -> _Layout:
|
|
129
135
|
candidates = _candidates(document)
|
|
130
136
|
if len(candidates) != 1:
|
|
131
137
|
raise LibrusError(ErrorKind.PARSE)
|
|
@@ -183,12 +189,29 @@ def _summary(
|
|
|
183
189
|
cells: list[html.HtmlElement],
|
|
184
190
|
fields: dict[str, int],
|
|
185
191
|
width: int,
|
|
192
|
+
current: frozenset[int] | None = None,
|
|
186
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
|
+
"""
|
|
187
199
|
subject, columns = _subject_columns(cells, width)
|
|
188
200
|
selected = [columns[index] for index in fields.values()]
|
|
189
201
|
if len({id(cell) for cell in selected}) != len(selected):
|
|
190
202
|
# A single merged value cannot mean two different summary fields.
|
|
191
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)
|
|
192
215
|
values = {
|
|
193
216
|
name: GradeSummaryValue(Availability.AVAILABLE, markup.text(columns[index]))
|
|
194
217
|
for name, index in fields.items()
|
|
@@ -270,21 +293,21 @@ def parse_final_grades(body: bytes) -> tuple[SubjectGradeSummary, ...]:
|
|
|
270
293
|
if len(sources) > 1 or not (sources or point_tables):
|
|
271
294
|
raise LibrusError(ErrorKind.PARSE)
|
|
272
295
|
if point_tables:
|
|
273
|
-
located = {id(table) for table, _, _ in sources}
|
|
296
|
+
located = {id(table) for table, _, _, _ in sources}
|
|
274
297
|
if any(
|
|
275
298
|
_current_header(table) and id(table) not in located
|
|
276
299
|
for table in document.iter("table")
|
|
277
300
|
if table not in point_tables
|
|
278
301
|
):
|
|
279
302
|
raise LibrusError(ErrorKind.PARSE)
|
|
280
|
-
fields, width = point_layout(point_tables[0])
|
|
303
|
+
fields, width, current = point_layout(point_tables[0])
|
|
281
304
|
if fields:
|
|
282
|
-
sources.append((point_tables[0], fields, width))
|
|
305
|
+
sources.append((point_tables[0], fields, width, current))
|
|
283
306
|
items: dict[str, SubjectGradeSummary] = {}
|
|
284
|
-
for table, fields, width in sources:
|
|
307
|
+
for table, fields, width, current in sources:
|
|
285
308
|
family_subjects: set[str] = set()
|
|
286
309
|
for cells in _subject_rows(table, width, points=table in point_tables):
|
|
287
|
-
item = _summary(cells, fields, width)
|
|
310
|
+
item = _summary(cells, fields, width, current)
|
|
288
311
|
if item.subject in family_subjects:
|
|
289
312
|
raise LibrusError(ErrorKind.PARSE)
|
|
290
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
|
librus_python_api/parsers.py
CHANGED
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
import json
|
|
4
4
|
import math
|
|
5
5
|
import re
|
|
6
|
+
import typing
|
|
6
7
|
from html import unescape
|
|
7
8
|
from html.entities import html5
|
|
8
9
|
from typing import Any
|
|
9
10
|
|
|
10
11
|
from lxml import etree, html
|
|
11
|
-
from pydantic import ValidationError
|
|
12
|
+
from pydantic import BaseModel, ValidationError
|
|
12
13
|
|
|
13
14
|
from librus_python_api.config import (
|
|
14
15
|
LOGGED_IN_PAGE_MARKER,
|
|
@@ -18,7 +19,7 @@ from librus_python_api.config import (
|
|
|
18
19
|
PROFILE_LUCKY_NUMBER_CLASS,
|
|
19
20
|
PROFILE_LUCKY_NUMBER_DISABLED,
|
|
20
21
|
)
|
|
21
|
-
from librus_python_api.exceptions import ErrorKind, LibrusError
|
|
22
|
+
from librus_python_api.exceptions import ErrorKind, LibrusError, ParseError
|
|
22
23
|
from librus_python_api.models import (
|
|
23
24
|
Availability,
|
|
24
25
|
LuckyNumber,
|
|
@@ -264,6 +265,57 @@ def parse_page(body: bytes, *, repeatable_id: str | None = None) -> html.HtmlEle
|
|
|
264
265
|
return document
|
|
265
266
|
|
|
266
267
|
|
|
268
|
+
def _wire_names(model: type[BaseModel], seen: set[type[BaseModel]]) -> set[str]:
|
|
269
|
+
"""Every field name of a wire model and the models nested in it."""
|
|
270
|
+
if model in seen:
|
|
271
|
+
return set()
|
|
272
|
+
seen.add(model)
|
|
273
|
+
names: set[str] = set()
|
|
274
|
+
for name, field in model.model_fields.items():
|
|
275
|
+
names.add(name)
|
|
276
|
+
if field.alias:
|
|
277
|
+
names.add(field.alias)
|
|
278
|
+
pending: list[object] = [field.annotation]
|
|
279
|
+
while pending:
|
|
280
|
+
kind = pending.pop()
|
|
281
|
+
if isinstance(kind, type) and issubclass(kind, BaseModel):
|
|
282
|
+
names |= _wire_names(kind, seen)
|
|
283
|
+
pending.extend(typing.get_args(kind))
|
|
284
|
+
return names
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def wire_failure(error: ValidationError, model: type[BaseModel]) -> str:
|
|
288
|
+
"""Where a wire model rejected a body: field path and rule, never a value.
|
|
289
|
+
|
|
290
|
+
A path part is shown only when it is a list index or a field name of
|
|
291
|
+
`model`; anything else (such as a dict key from the body) is `?`.
|
|
292
|
+
"""
|
|
293
|
+
names = _wire_names(model, set())
|
|
294
|
+
errors = error.errors(include_url=False, include_context=False, include_input=False)
|
|
295
|
+
shown: list[str] = []
|
|
296
|
+
for item in errors[:3]:
|
|
297
|
+
path = ""
|
|
298
|
+
for part in item["loc"]:
|
|
299
|
+
if type(part) is int:
|
|
300
|
+
path += f"[{part}]"
|
|
301
|
+
else:
|
|
302
|
+
path += ("." if path else "") + (part if part in names else "?")
|
|
303
|
+
shown.append(f"{path or '(body)'} {item['type']}")
|
|
304
|
+
more = f"; {len(errors)} errors" if len(errors) > 3 else ""
|
|
305
|
+
return "; ".join(shown) + more
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
def validate_wire[M: BaseModel](model: type[M], data: object) -> M:
|
|
309
|
+
"""`model` validated from decoded JSON; PARSE naming the failing field."""
|
|
310
|
+
try:
|
|
311
|
+
return model.model_validate(data)
|
|
312
|
+
except ValidationError as error:
|
|
313
|
+
failure = wire_failure(error, model)
|
|
314
|
+
parse = ParseError(ErrorKind.PARSE)
|
|
315
|
+
parse._wire_failure = failure
|
|
316
|
+
raise parse
|
|
317
|
+
|
|
318
|
+
|
|
267
319
|
def is_logged_out_page(body: bytes) -> bool:
|
|
268
320
|
"""Synergia's page for a session it no longer knows; never raises."""
|
|
269
321
|
if LOGGED_OUT_HEADING.encode() not in body:
|
librus_python_api/service.py
CHANGED
|
@@ -8,7 +8,7 @@ import json
|
|
|
8
8
|
import math
|
|
9
9
|
import re
|
|
10
10
|
import time
|
|
11
|
-
from collections.abc import Awaitable, Callable, Hashable, Mapping
|
|
11
|
+
from collections.abc import Awaitable, Callable, Hashable, Iterable, Mapping
|
|
12
12
|
from dataclasses import dataclass, replace
|
|
13
13
|
from datetime import UTC, date, datetime
|
|
14
14
|
from types import MappingProxyType, TracebackType
|
|
@@ -397,25 +397,34 @@ def _require_dates(*days: date | None, max_days: int | None = None) -> None:
|
|
|
397
397
|
|
|
398
398
|
|
|
399
399
|
def _check_record_count(records: GradeRecords, added: int) -> None:
|
|
400
|
+
# The same records `grade_records._Collection.check_size` counts (#195).
|
|
400
401
|
if (
|
|
401
402
|
len(records.numeric)
|
|
402
403
|
+ len(records.descriptive)
|
|
403
404
|
+ len(records.descriptive_summaries)
|
|
404
405
|
+ len(records.formative)
|
|
406
|
+
+ sum(len(item.entries) for item in records.behaviour_points)
|
|
405
407
|
+ added
|
|
406
408
|
> GRADE_MAX_RECORDS
|
|
407
409
|
):
|
|
408
410
|
raise LibrusError(ErrorKind.LIMIT)
|
|
409
411
|
|
|
410
412
|
|
|
413
|
+
def _check_lookups(budget: RequestBudget, lookups: int) -> None:
|
|
414
|
+
"""LIMIT now when `lookups` more requests would exceed the budget."""
|
|
415
|
+
if budget.requests_dispatched + lookups > budget._max_requests:
|
|
416
|
+
raise LibrusError(ErrorKind.LIMIT)
|
|
417
|
+
|
|
418
|
+
|
|
411
419
|
def _cooldown_due(error: LibrusError) -> bool:
|
|
412
420
|
"""A denial, an unrecovered expiry, or a logged-out page that a session
|
|
413
|
-
just signed in also got
|
|
421
|
+
just signed in also got (PARSE, or VIEW_DISABLED for a module that is
|
|
422
|
+
off): signing in again at once cannot help."""
|
|
414
423
|
if error.kind in (ErrorKind.ACCESS_DENIED, ErrorKind.SESSION_EXPIRED):
|
|
415
424
|
return True
|
|
416
425
|
cause = error.__cause__
|
|
417
426
|
return (
|
|
418
|
-
error.kind
|
|
427
|
+
error.kind in (ErrorKind.PARSE, ErrorKind.VIEW_DISABLED)
|
|
419
428
|
and isinstance(cause, SessionExpiredError)
|
|
420
429
|
and cause._logged_out_page
|
|
421
430
|
)
|
|
@@ -1001,7 +1010,13 @@ class AccountClient:
|
|
|
1001
1010
|
raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
|
|
1002
1011
|
# A bound cookie/account is not proof it is still valid. One fresh
|
|
1003
1012
|
# side-effect-free identity GET prevents avoidable UNKNOWN sends.
|
|
1004
|
-
|
|
1013
|
+
try:
|
|
1014
|
+
await self._modern_ready(budget, refresh=True)
|
|
1015
|
+
except SessionExpiredError as error:
|
|
1016
|
+
# A send never signs in again by itself, whatever ended the
|
|
1017
|
+
# session: the caller decides whether to send again.
|
|
1018
|
+
error._logged_out_page = False
|
|
1019
|
+
raise
|
|
1005
1020
|
|
|
1006
1021
|
def dispatched() -> None:
|
|
1007
1022
|
attempt._dispatch(
|
|
@@ -1434,15 +1449,26 @@ class AccountClient:
|
|
|
1434
1449
|
and are not returned. Only a login whose identity reports the parent
|
|
1435
1450
|
account group (`JUSTIFICATION_ACCOUNT_GROUP`) sends the request; any
|
|
1436
1451
|
other or missing group fails as UNSUPPORTED_CAPABILITY without it,
|
|
1437
|
-
because the page ends a student login's session.
|
|
1452
|
+
because the page ends a student login's session. A parent login that
|
|
1453
|
+
still gets the logged-out page right after signing in fails as
|
|
1454
|
+
VIEW_DISABLED, and its session is cleared.
|
|
1438
1455
|
"""
|
|
1439
1456
|
|
|
1440
|
-
async def fetch(budget: RequestBudget,
|
|
1457
|
+
async def fetch(budget: RequestBudget, fresh_login: bool) -> Justifications:
|
|
1441
1458
|
if self._account_group != JUSTIFICATION_ACCOUNT_GROUP:
|
|
1442
1459
|
raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1460
|
+
try:
|
|
1461
|
+
start, end, items = await self._page(
|
|
1462
|
+
"justifications", budget, parse_justifications
|
|
1463
|
+
)
|
|
1464
|
+
except SessionExpiredError as error:
|
|
1465
|
+
if not (fresh_login and error._logged_out_page):
|
|
1466
|
+
raise
|
|
1467
|
+
# A session just signed in still gets the logged-out page: the
|
|
1468
|
+
# module is off for this login, and the request ended the
|
|
1469
|
+
# session (librus-mcp#136), so the next read signs in again.
|
|
1470
|
+
self._invalidate()
|
|
1471
|
+
raise LibrusError(ErrorKind.VIEW_DISABLED) from error
|
|
1446
1472
|
return Justifications(
|
|
1447
1473
|
self._session_identity(),
|
|
1448
1474
|
start,
|
|
@@ -2573,13 +2599,29 @@ class AccountClient:
|
|
|
2573
2599
|
_check_record_count(records, len(added))
|
|
2574
2600
|
return replace(records, descriptive=records.descriptive + added)
|
|
2575
2601
|
|
|
2602
|
+
def _fresh_metadata(self, endpoint: str, identifier: str) -> str | None:
|
|
2603
|
+
cached = self._metadata.get((endpoint, identifier))
|
|
2604
|
+
if cached and time.monotonic() - cached[0] <= ATTENDANCE_METADATA_TTL_SECONDS:
|
|
2605
|
+
return cached[1]
|
|
2606
|
+
return None
|
|
2607
|
+
|
|
2608
|
+
def _lookups(
|
|
2609
|
+
self, endpoint: str, known: Mapping[str, str], identifiers: Iterable[str]
|
|
2610
|
+
) -> int:
|
|
2611
|
+
"""How many of `identifiers` would cost a per-reference request."""
|
|
2612
|
+
return sum(
|
|
2613
|
+
identifier not in known
|
|
2614
|
+
and self._fresh_metadata(endpoint, identifier) is None
|
|
2615
|
+
for identifier in identifiers
|
|
2616
|
+
)
|
|
2617
|
+
|
|
2576
2618
|
async def _metadata_value(
|
|
2577
2619
|
self, endpoint: str, identifier: str, budget: RequestBudget
|
|
2578
2620
|
) -> str:
|
|
2579
2621
|
key = endpoint, identifier
|
|
2580
|
-
cached = self.
|
|
2581
|
-
if cached
|
|
2582
|
-
return cached
|
|
2622
|
+
cached = self._fresh_metadata(endpoint, identifier)
|
|
2623
|
+
if cached is not None:
|
|
2624
|
+
return cached
|
|
2583
2625
|
parser = (
|
|
2584
2626
|
parse_lesson_subject
|
|
2585
2627
|
if endpoint == "attendance_lesson"
|
|
@@ -2640,14 +2682,15 @@ class AccountClient:
|
|
|
2640
2682
|
if (start is None or r.day >= start) and (end is None or r.day <= end)
|
|
2641
2683
|
)
|
|
2642
2684
|
lessons = dict.fromkeys(row.lesson_id for row in rows)
|
|
2643
|
-
if len(lessons) > ATTENDANCE_METADATA_CACHE_SIZE:
|
|
2644
|
-
raise LibrusError(ErrorKind.LIMIT)
|
|
2645
2685
|
# Two collection reads keep the request count independent of how many
|
|
2646
|
-
# lessons and subjects a student has
|
|
2647
|
-
# collection keep the strict
|
|
2686
|
+
# lessons and subjects a student has; the attendance row cap bounds
|
|
2687
|
+
# both (#199). References absent from a collection keep the strict
|
|
2688
|
+
# per-reference contract, one request each, so fail before spending the
|
|
2689
|
+
# budget on lookups it cannot finish.
|
|
2648
2690
|
lesson_map = (
|
|
2649
2691
|
await self._metadata_map("attendance_lessons", budget) if lessons else {}
|
|
2650
2692
|
)
|
|
2693
|
+
_check_lookups(budget, self._lookups("attendance_lesson", lesson_map, lessons))
|
|
2651
2694
|
lesson_subjects = {
|
|
2652
2695
|
lesson: lesson_map.get(lesson)
|
|
2653
2696
|
or await self._metadata_value("attendance_lesson", lesson, budget)
|
|
@@ -2656,11 +2699,12 @@ class AccountClient:
|
|
|
2656
2699
|
subjects: dict[str, list[GatewayAttendanceRecord]] = {}
|
|
2657
2700
|
for row in rows:
|
|
2658
2701
|
subjects.setdefault(lesson_subjects[row.lesson_id], []).append(row)
|
|
2659
|
-
if len(subjects) > ATTENDANCE_METADATA_CACHE_SIZE:
|
|
2660
|
-
raise LibrusError(ErrorKind.LIMIT)
|
|
2661
2702
|
subject_map = (
|
|
2662
2703
|
await self._metadata_map("attendance_subjects", budget) if subjects else {}
|
|
2663
2704
|
)
|
|
2705
|
+
_check_lookups(
|
|
2706
|
+
budget, self._lookups("attendance_subject", subject_map, subjects)
|
|
2707
|
+
)
|
|
2664
2708
|
items = [
|
|
2665
2709
|
SubjectFrequency(
|
|
2666
2710
|
subject,
|
librus_python_api/transport.py
CHANGED
|
@@ -67,6 +67,7 @@ from librus_python_api.models import (
|
|
|
67
67
|
SendSubmission,
|
|
68
68
|
TransportResponse,
|
|
69
69
|
)
|
|
70
|
+
from librus_python_api.parsers import is_logged_out_page
|
|
70
71
|
from librus_python_api.scheduler import RequestScheduler
|
|
71
72
|
|
|
72
73
|
NUMERIC_REFERENCE = re.compile(r"[0-9]{1,64}")
|
|
@@ -335,6 +336,14 @@ class AiohttpTransport:
|
|
|
335
336
|
budget,
|
|
336
337
|
None,
|
|
337
338
|
)
|
|
339
|
+
if response.status == 200 and is_logged_out_page(response.body):
|
|
340
|
+
# Synergia no longer knows the session, for example after a
|
|
341
|
+
# GET of /eusprawiedliwienia ended it (live 2026-11-23). The
|
|
342
|
+
# launch comes before the operation's own request, so nothing
|
|
343
|
+
# was applied and the read may sign in again once.
|
|
344
|
+
expired = SessionExpiredError(ErrorKind.SESSION_EXPIRED)
|
|
345
|
+
expired._logged_out_page = True
|
|
346
|
+
raise expired
|
|
338
347
|
if response.status != 302:
|
|
339
348
|
raise LibrusError(ErrorKind.UNSUPPORTED_CAPABILITY)
|
|
340
349
|
if self._native_login_redirect(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: librus-python-api
|
|
3
|
-
Version: 1.11.
|
|
3
|
+
Version: 1.11.4
|
|
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,12 @@ 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.
|
|
45
|
+
**Status:** `1.11.4` recovers the messages sign-in after a page that ended the
|
|
46
|
+
session, reports e-Justifications switched off for a parent login as
|
|
47
|
+
`ViewDisabledError`, reads descriptive grade skills that wrap onto a second
|
|
48
|
+
tooltip line and names the failing field of a gateway JSON envelope.
|
|
49
|
+
`1.11.3` never returns behaviour points as a final grade when the
|
|
50
|
+
behaviour row's cells are merged differently. `1.11.2` reads a behaviour row whose last cell spans past the
|
|
46
51
|
grade table and names the failing cell in diagnostics. `1.11.1` fixes a Windows store shared by several processes
|
|
47
52
|
reporting `StorageError`, also after a dispatched send. `1.11.0` raises `TemporarilyUnavailableError` for the archive's
|
|
48
53
|
loading notice, a view that is unavailable for now while the rest of Synergia
|
|
@@ -84,7 +89,7 @@ See [limitations](#supported-features-and-limitations) below.
|
|
|
84
89
|
Install the exact release from PyPI after its gated publication completes:
|
|
85
90
|
|
|
86
91
|
```sh
|
|
87
|
-
python -m pip install librus-python-api==1.11.
|
|
92
|
+
python -m pip install librus-python-api==1.11.4
|
|
88
93
|
```
|
|
89
94
|
|
|
90
95
|
Pin the exact version qualified by your application. Before publication, use a
|
|
@@ -100,7 +105,7 @@ python -m pip install .
|
|
|
100
105
|
To install a locally built wheel instead:
|
|
101
106
|
|
|
102
107
|
```sh
|
|
103
|
-
python -m pip install ./dist/librus_python_api-1.11.
|
|
108
|
+
python -m pip install ./dist/librus_python_api-1.11.4-py3-none-any.whl
|
|
104
109
|
```
|
|
105
110
|
|
|
106
111
|
No console script or background process is installed: import the library in your
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
librus_python_api/__init__.py,sha256=
|
|
1
|
+
librus_python_api/__init__.py,sha256=U3Zvb7FOlKfiyeaO5-b9vY92KJWXhxLXuZG_3AqGN88,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
|
|
@@ -7,20 +7,20 @@ librus_python_api/announcements.py,sha256=13FoOR1sq7tt9w6aLf0vclcFKDqLUiIYaO5iYD
|
|
|
7
7
|
librus_python_api/attachment_routes.py,sha256=uSg5wCQqHJiphF0KdI0GatQxZr5SLUx6xWQRsl_U4_U,4123
|
|
8
8
|
librus_python_api/attachments.py,sha256=Iq-ERZWc3gYXu6Lcv6womT2EXCc-c1Q7r_Q6VyaCm2E,10818
|
|
9
9
|
librus_python_api/attendance.py,sha256=Dq2IC8WERO-9x-LZIN5Nl0PTLYmL1Iq7BZtOz6nssOI,7428
|
|
10
|
-
librus_python_api/attendance_frequency.py,sha256=
|
|
10
|
+
librus_python_api/attendance_frequency.py,sha256=snIDyyyCJy71YefA-P3DsGHp21atTRg0unVlXflds_o,4625
|
|
11
11
|
librus_python_api/budget.py,sha256=8fvqT7eIxyVX2P2OBG27XsYHk_HbtSS4lzuecYpHtgs,2878
|
|
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
|
-
librus_python_api/completed_lessons.py,sha256=
|
|
15
|
-
librus_python_api/config.py,sha256=
|
|
14
|
+
librus_python_api/completed_lessons.py,sha256=7TwLbUo67hbxO2Te6PzRfe7UzP94P1eRqfbttn9S3KA,11139
|
|
15
|
+
librus_python_api/config.py,sha256=gzFI0gx3sIZU_NiI2JYKT3ernMPzhQ5fG_0WDoHVtFI,67046
|
|
16
16
|
librus_python_api/detail_fields.py,sha256=vDDi5sV-e30-42SF0hwAUoldiZ5wvYtb1UlLt03lBHw,1708
|
|
17
|
-
librus_python_api/diagnostics.py,sha256=
|
|
18
|
-
librus_python_api/exceptions.py,sha256=
|
|
17
|
+
librus_python_api/diagnostics.py,sha256=LxcN4BwX1Bn9lk70v0CxWd23-q2H_KlyJzKC6vm2SMQ,21989
|
|
18
|
+
librus_python_api/exceptions.py,sha256=lymPWTInw_ZBPXWftyHtolnKGfeY2Z4gB5WrqtAVYQ4,6087
|
|
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
21
|
librus_python_api/gateway_grades.py,sha256=ILqWkkaRq120wG--h7GfFy4qFAQcuaa6LpzJOcCA2FU,22921
|
|
22
|
-
librus_python_api/grade_parsers.py,sha256=
|
|
23
|
-
librus_python_api/grade_records.py,sha256=
|
|
22
|
+
librus_python_api/grade_parsers.py,sha256=P7s9yOzY6gYoWJUbo_ZKjE2xZlkHyDXakbQLJOQ5a9U,12759
|
|
23
|
+
librus_python_api/grade_records.py,sha256=vx56fzZF4aX6Fq8Bev6Ya_c9ZtXd55K0PBhUW2RM0mc,31656
|
|
24
24
|
librus_python_api/homework_range.py,sha256=erYfvS6PhHU5XhnR6LkiLNy677hGVflY3UAuHOs-YUw,1663
|
|
25
25
|
librus_python_api/inspect_page.py,sha256=uSFJRcEd5m36kqqP6kf2uowB4x2RGNqyfnmaakVzL94,5938
|
|
26
26
|
librus_python_api/justifications.py,sha256=ZzfeZR5TvYyArQ5Oqi6VM5JmBKS2lZok4UR7hc3dI4o,7799
|
|
@@ -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=
|
|
39
|
+
librus_python_api/parsers.py,sha256=2BAIe_ebcLkhFhmA6_lzO7NHoVkwg7MVQhUYQdZhlwE,14868
|
|
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
|
|
@@ -45,10 +45,10 @@ librus_python_api/scheduler.py,sha256=3JplYxqvQdFz3aKXcoQUJHE9s3FPw_xRhQ2CPNLuQm
|
|
|
45
45
|
librus_python_api/school_reads.py,sha256=YHta7DmhjS5vSa4Djq8pzp01-2jhVfGOo1Mnc738rV4,15209
|
|
46
46
|
librus_python_api/school_year_archive.py,sha256=D0A1ywMKgoYgvi-d70__SFreMGvMb_72870Akkbb_m8,15492
|
|
47
47
|
librus_python_api/sending.py,sha256=Nvvk2r-6D6Us53a2fH5GW9PcA6bWEfuOvy6c3M5QVcE,4549
|
|
48
|
-
librus_python_api/service.py,sha256=
|
|
48
|
+
librus_python_api/service.py,sha256=XbC2ZkYQnrTEScpOgK9T1mz2L0i_9GKHUdvtlZQzNCM,107844
|
|
49
49
|
librus_python_api/timetable.py,sha256=tX1QK9fQABxzfLaHHqTe8e6rAgdOkCoTOfAHdPwNmLE,9836
|
|
50
|
-
librus_python_api/transport.py,sha256=
|
|
51
|
-
librus_python_api-1.11.
|
|
52
|
-
librus_python_api-1.11.
|
|
53
|
-
librus_python_api-1.11.
|
|
54
|
-
librus_python_api-1.11.
|
|
50
|
+
librus_python_api/transport.py,sha256=SAg-LovpilhgmBghjw0snm5DXYQPpgYazyOQzM2T1Aw,35571
|
|
51
|
+
librus_python_api-1.11.4.dist-info/METADATA,sha256=TP_m8tG7Jt9khvfGJqno675mGb01xfqethAVbctWWKE,16188
|
|
52
|
+
librus_python_api-1.11.4.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
53
|
+
librus_python_api-1.11.4.dist-info/licenses/LICENSE,sha256=IuerLb3cnZCsaB23znydjjvKqP-LmSJd3syKa9NGUts,1071
|
|
54
|
+
librus_python_api-1.11.4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|