librus-python-api 1.12.1__py3-none-any.whl → 1.13.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  """Independent bounded async client. General live compatibility is unqualified."""
2
2
 
3
3
  # Before the imports: config reads it for the User-Agent.
4
- __version__ = "1.12.1"
4
+ __version__ = "1.13.2"
5
5
 
6
6
  from librus_python_api.attachments import AttachmentStream, ModernAttachmentStream
7
7
  from librus_python_api.budget import RequestBudget
@@ -56,6 +56,7 @@ from librus_python_api.models import (
56
56
  GatewayAttendance,
57
57
  GatewayAttendanceRecord,
58
58
  GradeCorrection,
59
+ GradeDetail,
59
60
  GradeKind,
60
61
  GradeRecords,
61
62
  Grades,
@@ -267,6 +268,7 @@ __all__ = [
267
268
  "BehaviourPointEntry",
268
269
  "BehaviourPoints",
269
270
  "GradeCorrection",
271
+ "GradeDetail",
270
272
  "GradeKind",
271
273
  "GradeRecords",
272
274
  "Grades",
@@ -434,6 +434,14 @@ ENDPOINTS: Mapping[str, Endpoint] = MappingProxyType(
434
434
  False,
435
435
  Evidence.INDEPENDENTLY_OBSERVED,
436
436
  ),
437
+ Endpoint(
438
+ "grade_detail",
439
+ "GET",
440
+ "/przegladaj_oceny/szczegoly/{id}",
441
+ SideEffect.NONE,
442
+ True,
443
+ Evidence.INDEPENDENTLY_OBSERVED,
444
+ ),
437
445
  # Gateway reads behind the grades page's new-schema descriptive
438
446
  # table. Routes and field names come from public client code and the
439
447
  # official page script; one authorized read parsed four records.
@@ -934,10 +942,14 @@ BEHAVIOUR_POINT_LABELS = frozenset(
934
942
  )
935
943
  # Recognition only: point-grade detail links are classified, never requested.
936
944
  POINT_GRADE_DETAIL_PATH_PREFIX = "/przegladaj_oceny_punktowe/szczegoly/"
937
- # Recognition only: an ordinary grade's own detail link gives its stable grade
938
- # ID (librus-mcp#88); the page is never requested. Formative links share this
939
- # prefix but have no digits-only rest, so they never yield a grade ID.
945
+ # Why: a grade's stable ID (librus-mcp#88); formative links never yield one.
940
946
  GRADE_DETAIL_PATH_PREFIX = "/przegladaj_oceny/szczegoly/"
947
+ GRADE_DETAIL_TABLE_CLASSES = frozenset({"decorated", "medium", "center"})
948
+ GRADE_DETAIL_MAX_FIELDS = 32
949
+ # Why: a detail comment is the full text the tooltip cuts at ~100 characters.
950
+ GRADE_DETAIL_MAX_VALUE_LENGTH = 16384
951
+ GRADE_DETAIL_REQUIRED_LABEL = "Ocena"
952
+ GRADE_DETAIL_COMMENT_LABEL = "Komentarz"
941
953
  FORMATIVE_HEADERS = (
942
954
  "przedmiot",
943
955
  "ocena kształtująca",
@@ -0,0 +1,56 @@
1
+ """Bounded parser for one ordinary grade's own detail page (#225)."""
2
+
3
+ from librus_python_api import markup
4
+ from librus_python_api.config import (
5
+ GRADE_DETAIL_MAX_FIELDS,
6
+ GRADE_DETAIL_MAX_VALUE_LENGTH,
7
+ GRADE_DETAIL_REQUIRED_LABEL,
8
+ GRADE_DETAIL_TABLE_CLASSES,
9
+ )
10
+ from librus_python_api.exceptions import ErrorKind, LibrusError
11
+ from librus_python_api.parsers import parse_page
12
+
13
+
14
+ def parse_grade_detail(body: bytes) -> tuple[tuple[str, str], ...]:
15
+ """The grade's labelled fields in page order, values never shortened.
16
+
17
+ A value keeps its line breaks; an image-only value is empty. A label cell
18
+ is a TH, or a TD as in the correction row #40 recorded.
19
+ """
20
+ document = parse_page(body)
21
+ tables = [
22
+ table
23
+ for table in document.iter("table")
24
+ if GRADE_DETAIL_TABLE_CLASSES <= set(table.get("class", "").split())
25
+ ]
26
+ if len(tables) != 1:
27
+ raise LibrusError(ErrorKind.PARSE)
28
+ rows = [
29
+ row
30
+ for row in markup.rows(tables[0])
31
+ if not markup.in_header(row) and next(row.iterancestors("tfoot"), None) is None
32
+ ]
33
+ if len(rows) > GRADE_DETAIL_MAX_FIELDS:
34
+ raise LibrusError(ErrorKind.LIMIT)
35
+ fields: dict[str, str] = {}
36
+ for row in rows:
37
+ cells = markup.cells(row)
38
+ if (
39
+ len(cells) != 2
40
+ or cells[0].tag not in {"th", "td"}
41
+ or cells[1].tag != "td"
42
+ or any(
43
+ c.get("rowspan", "1") != "1" or c.get("colspan", "1") != "1"
44
+ for c in cells
45
+ )
46
+ ):
47
+ raise LibrusError(ErrorKind.PARSE)
48
+ label = markup.text(cells[0]).rstrip(":")
49
+ if not label or label in fields:
50
+ raise LibrusError(ErrorKind.PARSE)
51
+ fields[label] = markup.text(
52
+ cells[1], GRADE_DETAIL_MAX_VALUE_LENGTH, multiline=True
53
+ )
54
+ if GRADE_DETAIL_REQUIRED_LABEL not in fields:
55
+ raise LibrusError(ErrorKind.PARSE)
56
+ return tuple(fields.items())
@@ -29,6 +29,7 @@ _RANGE = re.compile(rf"od {_DAY} do {_DAY}")
29
29
  # "lekcja" (one lesson) and "lekcje" were observed; "lekcji" is Polish for
30
30
  # five or more and is accepted with them.
31
31
  _ONE_DAY = re.compile(rf"{_DAY}, lekcj[aei]: ([0-9]{{1,2}}(?:, [0-9]{{1,2}})*)")
32
+ _BARE_DAY = re.compile(_DAY)
32
33
  _SENT = re.compile(rf"{_DAY} ([0-9]{{2}}:[0-9]{{2}}:[0-9]{{2}})")
33
34
  _STATUS = re.compile(r"(\S+)(?: \((.+)\))?")
34
35
 
@@ -103,6 +104,9 @@ def _period(text: str) -> tuple[date, date, tuple[int, ...]]:
103
104
  if start > end:
104
105
  raise _fail()
105
106
  return start, end, ()
107
+ if _BARE_DAY.fullmatch(text):
108
+ day = _day(text)
109
+ return day, day, ()
106
110
  match = _ONE_DAY.fullmatch(text)
107
111
  if not match:
108
112
  raise _fail()
@@ -23,6 +23,7 @@ type OperationName = Literal[
23
23
  "grades",
24
24
  "attendance",
25
25
  "attendance_detail",
26
+ "grade_detail",
26
27
  "gateway_attendance",
27
28
  "subject_frequency",
28
29
  "timetable",
@@ -1064,6 +1065,10 @@ class FinalGrades:
1064
1065
  observation: Observation
1065
1066
 
1066
1067
 
1068
+ def _shortened(comment: str | None) -> bool:
1069
+ return comment is not None and comment.rstrip().endswith(("\u2026", "..."))
1070
+
1071
+
1067
1072
  @dataclass(frozen=True, slots=True)
1068
1073
  class NumericGrade:
1069
1074
  """A school grade symbol, not an invented numeric conversion.
@@ -1125,6 +1130,16 @@ class NumericGrade:
1125
1130
 
1126
1131
  return detail_id(self.href, GRADE_DETAIL_PATH_PREFIX)
1127
1132
 
1133
+ @property
1134
+ def comment_truncated(self) -> bool:
1135
+ """Whether `comment` is a shortened tooltip comment, ending in an ellipsis.
1136
+
1137
+ The list tooltip cuts long comments to about 100 characters;
1138
+ `grade_detail(grade_id)` gives the full text. Computed for the same
1139
+ identity reason as `formative_id`.
1140
+ """
1141
+ return _shortened(self.comment)
1142
+
1128
1143
 
1129
1144
  @dataclass(frozen=True, slots=True)
1130
1145
  class DescriptiveGrade:
@@ -1162,6 +1177,16 @@ class DescriptiveGrade:
1162
1177
 
1163
1178
  return detail_id(self.href, GRADE_DETAIL_PATH_PREFIX)
1164
1179
 
1180
+ @property
1181
+ def comment_truncated(self) -> bool:
1182
+ """Whether `comment` is a shortened tooltip comment, ending in an ellipsis.
1183
+
1184
+ The list tooltip cuts long comments to about 100 characters;
1185
+ `grade_detail(grade_id)` gives the full text. Computed for the same
1186
+ identity reason as `formative_id`.
1187
+ """
1188
+ return _shortened(self.comment)
1189
+
1165
1190
 
1166
1191
  @dataclass(frozen=True, slots=True)
1167
1192
  class SchoolAverage:
@@ -1287,6 +1312,26 @@ class GradeWindow:
1287
1312
  behaviour_points: tuple[BehaviourPoints, ...] = field(default=(), repr=False)
1288
1313
 
1289
1314
 
1315
+ @dataclass(frozen=True, slots=True)
1316
+ class GradeDetail:
1317
+ """One ordinary grade's own detail page: labelled fields in page order.
1318
+
1319
+ Read on demand only; `grades()` never requests it.
1320
+ """
1321
+
1322
+ identity: Identity
1323
+ grade_id: str = field(repr=False)
1324
+ fields: tuple[tuple[str, str], ...] = field(repr=False)
1325
+ observation: Observation
1326
+
1327
+ @property
1328
+ def comment(self) -> str | None:
1329
+ """The full `Komentarz` text with its line breaks; None when absent or empty."""
1330
+ from librus_python_api.config import GRADE_DETAIL_COMMENT_LABEL
1331
+
1332
+ return dict(self.fields).get(GRADE_DETAIL_COMMENT_LABEL) or None
1333
+
1334
+
1290
1335
  @dataclass(frozen=True, slots=True)
1291
1336
  class AttendanceRecord:
1292
1337
  symbol: str = field(repr=False)
@@ -91,6 +91,7 @@ from librus_python_api.gateway_grades import (
91
91
  parse_token_info,
92
92
  parse_user_info,
93
93
  )
94
+ from librus_python_api.grade_detail import parse_grade_detail
94
95
  from librus_python_api.grade_parsers import parse_final_grades
95
96
  from librus_python_api.homework_range import HomeworkAccumulator
96
97
  from librus_python_api.justifications import parse_justifications
@@ -116,6 +117,7 @@ from librus_python_api.models import (
116
117
  FinalGrades,
117
118
  GatewayAttendance,
118
119
  GatewayAttendanceRecord,
120
+ GradeDetail,
119
121
  GradeRecords,
120
122
  Grades,
121
123
  GradeView,
@@ -1433,6 +1435,37 @@ class AccountClient:
1433
1435
  ),
1434
1436
  )
1435
1437
 
1438
+ async def grade_detail(
1439
+ self,
1440
+ grade_id: str,
1441
+ *,
1442
+ budget: RequestBudget | None = None,
1443
+ max_age_seconds: float = 0.0,
1444
+ ) -> GradeDetail:
1445
+ """Read one ordinary grade's own detail page by its numeric `grade_id`.
1446
+
1447
+ Its `Komentarz` is the full comment that the grades list tooltip cuts
1448
+ to about 100 characters (`comment_truncated`). One GET per call; the
1449
+ grades read never requests it.
1450
+ """
1451
+ if type(grade_id) is not str or not NUMERIC_ID.fullmatch(grade_id):
1452
+ raise LibrusError(ErrorKind.INVALID_INPUT)
1453
+
1454
+ async def fetch(budget: RequestBudget, _: bool) -> GradeDetail:
1455
+ fields = await self._page(
1456
+ "grade_detail", budget, parse_grade_detail, reference=grade_id
1457
+ )
1458
+ return GradeDetail(
1459
+ self._session_identity(),
1460
+ grade_id,
1461
+ fields,
1462
+ self._observation("grade_detail"),
1463
+ )
1464
+
1465
+ return await self._read(
1466
+ ("grade_detail", grade_id), fetch, budget, max_age_seconds
1467
+ )
1468
+
1436
1469
  async def class_free_days(
1437
1470
  self,
1438
1471
  *,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: librus-python-api
3
- Version: 1.12.1
3
+ Version: 1.13.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
@@ -48,7 +48,9 @@ private ACLs. Windows installations include `pywin32` and `tzdata` automatically
48
48
  Network paths, reparse-point paths and unsafe storage permissions fail closed.
49
49
  See [platform requirements](contracts/persistence.md#windows-disk-boundary-25).
50
50
 
51
- **Status:** `1.12.1` reads school-year archive rows that hold marks for one
51
+ **Status:** `1.13.2` reads a grade's full comment from its detail page
52
+ (`grade_detail`), which the grades list shortens, and e-Justifications
53
+ entries listed by a bare date (1.13.0 and 1.13.1 were never published). `1.12.1` reads school-year archive rows that hold marks for one
52
54
  year and text for another. `1.12.0` resolves a school's own attendance types, counts
53
55
  attendance whose lesson or subject cannot be resolved apart instead of failing
54
56
  the subject frequency read, keeps grade comment lines that hold a colon as
@@ -100,7 +102,7 @@ See [limitations](#supported-features-and-limitations) below.
100
102
  Install the exact release from PyPI after its gated publication completes:
101
103
 
102
104
  ```sh
103
- python -m pip install librus-python-api==1.12.1
105
+ python -m pip install librus-python-api==1.13.2
104
106
  ```
105
107
 
106
108
  Pin the exact version qualified by your application. Before publication, use a
@@ -116,7 +118,7 @@ python -m pip install .
116
118
  To install a locally built wheel instead:
117
119
 
118
120
  ```sh
119
- python -m pip install ./dist/librus_python_api-1.12.1-py3-none-any.whl
121
+ python -m pip install ./dist/librus_python_api-1.13.2-py3-none-any.whl
120
122
  ```
121
123
 
122
124
  No console script or background process is installed: import the library in your
@@ -1,4 +1,4 @@
1
- librus_python_api/__init__.py,sha256=PPBgdYxnKbJhjOHquqyIpiOcEqZaVzX8v0h54LzliO4,6846
1
+ librus_python_api/__init__.py,sha256=RpIzudDD1U8xMA9VUpZ-PIlOG1CaHtlyGhok1rjDfHw,6882
2
2
  librus_python_api/_notification_bootstrap.py,sha256=18nzH0doXBNaZXCz-_ckIvRrlHTWV5Mm1t5m2-5eYGI,4669
3
3
  librus_python_api/_notification_codec.py,sha256=hU6G3zGJ5fR8wfPC6fV2OqBKs-7XpT9eRnKO3FGsTzY,13451
4
4
  librus_python_api/_storage.py,sha256=M_6ZAzN4zs7laOdKJBRH1I2rvy3pgqYgC_MZtsd2xtM,15893
@@ -12,23 +12,24 @@ librus_python_api/budget.py,sha256=8fvqT7eIxyVX2P2OBG27XsYHk_HbtSS4lzuecYpHtgs,2
12
12
  librus_python_api/checkpoint.py,sha256=QBmG9GtpyaGRaFq-FXuGA3yR1BjuMFN9V3RTvvi_FNQ,1930
13
13
  librus_python_api/class_free_days.py,sha256=IwoCgr-9ZgEYYQ6717s4cDpyFzbosHMzESMabXJLGqA,2422
14
14
  librus_python_api/completed_lessons.py,sha256=7TwLbUo67hbxO2Te6PzRfe7UzP94P1eRqfbttn9S3KA,11139
15
- librus_python_api/config.py,sha256=LtD9EoPPlL6oCcwyBIFGueFDtqUCXrhW9rygK_cP_cE,68091
15
+ librus_python_api/config.py,sha256=PPPA5YvbJ4rH7xTgvcNetOg7aHyDaGaQBDinMUjRILU,68486
16
16
  librus_python_api/detail_fields.py,sha256=vDDi5sV-e30-42SF0hwAUoldiZ5wvYtb1UlLt03lBHw,1708
17
17
  librus_python_api/diagnostics.py,sha256=kPo1Xgwnm2lxsxcl4XbhwQQGdBRYFDwpBbK-rf81RTQ,21918
18
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_detail.py,sha256=Gl_iSoh6AZeT24EJndlmPNt-ziYlcBEQ9PKJB8p7-Fg,1977
22
23
  librus_python_api/grade_parsers.py,sha256=P7s9yOzY6gYoWJUbo_ZKjE2xZlkHyDXakbQLJOQ5a9U,12759
23
24
  librus_python_api/grade_records.py,sha256=IzAw5V76vAaZzq65upDguZO9ClVZQKG8JeAoaaDh7v4,31664
24
25
  librus_python_api/homework_range.py,sha256=erYfvS6PhHU5XhnR6LkiLNy677hGVflY3UAuHOs-YUw,1663
25
26
  librus_python_api/inspect_page.py,sha256=uSFJRcEd5m36kqqP6kf2uowB4x2RGNqyfnmaakVzL94,5938
26
- librus_python_api/justifications.py,sha256=ZzfeZR5TvYyArQ5Oqi6VM5JmBKS2lZok4UR7hc3dI4o,7799
27
+ librus_python_api/justifications.py,sha256=4gFkcqsfS4LH5vwA6mf5yAi5SqHlzGZOccjBBPAgSGU,7915
27
28
  librus_python_api/lifecycle.py,sha256=XzA5CEdZFo7iL5IMUrawnRvf2m9BFe0OseP-fpQFaAE,856
28
29
  librus_python_api/markup.py,sha256=nCG6XQCAHL1tZbIJ7S_vXSgLbaKtaPYQ59YAkKb09ys,8699
29
30
  librus_python_api/message_content.py,sha256=v_qoEAoaYS0_9MQBaj57i5XnC7pzv_HHWefgTt4CNyM,9043
30
31
  librus_python_api/messages.py,sha256=K9F8XVs1SojfFpdxxLV8gx9E0g81YxEHjigDzLHmDCg,10230
31
- librus_python_api/models.py,sha256=v9J-5qDUPbpO_MJx-jAlq-p3OGs44mfqEhGAiv3EoSQ,47782
32
+ librus_python_api/models.py,sha256=sWerNNpp96ZjnDtJEodvL2t9uiX3uovfV4AwYg8Rn-8,49326
32
33
  librus_python_api/modern_body.py,sha256=SocXJTyGm1Q_2owzh1PE1zcCB2kqZTz1KPJ2R4yMyoc,3895
33
34
  librus_python_api/modern_mailbox.py,sha256=2jF9UnJZ5AF6dip-GrMcv_z2kSLpp87dIpVeXk9jMzA,20600
34
35
  librus_python_api/modern_messages.py,sha256=qt2CXtrxCZQ-jTt0aQCD6ZaPAJQZXf0BxmvacPo9B0w,10653
@@ -45,10 +46,10 @@ librus_python_api/scheduler.py,sha256=3JplYxqvQdFz3aKXcoQUJHE9s3FPw_xRhQ2CPNLuQm
45
46
  librus_python_api/school_reads.py,sha256=YHta7DmhjS5vSa4Djq8pzp01-2jhVfGOo1Mnc738rV4,15209
46
47
  librus_python_api/school_year_archive.py,sha256=TdcwtF8u3I9k6qmke2JdU3NkWIHpGieqrVcf15m6mxc,15899
47
48
  librus_python_api/sending.py,sha256=Nvvk2r-6D6Us53a2fH5GW9PcA6bWEfuOvy6c3M5QVcE,4549
48
- librus_python_api/service.py,sha256=LTXH1DvhN-SRqHfcgDAj4V3NNjAFCImr1U8upxJqT0E,110422
49
+ librus_python_api/service.py,sha256=QOtlksStPzF-VBaiEjTdBzm2CDRYhZMWqq_oFqvchnA,111610
49
50
  librus_python_api/timetable.py,sha256=tX1QK9fQABxzfLaHHqTe8e6rAgdOkCoTOfAHdPwNmLE,9836
50
51
  librus_python_api/transport.py,sha256=SAg-LovpilhgmBghjw0snm5DXYQPpgYazyOQzM2T1Aw,35571
51
- librus_python_api-1.12.1.dist-info/METADATA,sha256=sm9B4fx7kKIxalr77lo4ktQlBViLaAuh6uyOXmzJZug,17515
52
- librus_python_api-1.12.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
53
- librus_python_api-1.12.1.dist-info/licenses/LICENSE,sha256=IuerLb3cnZCsaB23znydjjvKqP-LmSJd3syKa9NGUts,1071
54
- librus_python_api-1.12.1.dist-info/RECORD,,
52
+ librus_python_api-1.13.2.dist-info/METADATA,sha256=6J4A5GqySJUf2e8lvuugGKf5NdrKY02SQQYiCy_uYNU,17717
53
+ librus_python_api-1.13.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
54
+ librus_python_api-1.13.2.dist-info/licenses/LICENSE,sha256=IuerLb3cnZCsaB23znydjjvKqP-LmSJd3syKa9NGUts,1071
55
+ librus_python_api-1.13.2.dist-info/RECORD,,