rashid 0.1.0__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.
- rashid/__init__.py +32 -0
- rashid/_multihash.py +58 -0
- rashid/_spdx.py +740 -0
- rashid/catalog.py +202 -0
- rashid/cli.py +90 -0
- rashid/config.py +35 -0
- rashid/data/__init__.py +191 -0
- rashid/data/checks.py +1267 -0
- rashid/data/reader.py +170 -0
- rashid/live.py +399 -0
- rashid/model.py +100 -0
- rashid/rule.py +56 -0
- rashid/rules/__init__.py +114 -0
- rashid/rules/_common.py +42 -0
- rashid/rules/assets.py +183 -0
- rashid/rules/bbox.py +112 -0
- rashid/rules/collections.py +268 -0
- rashid/rules/conformance.py +141 -0
- rashid/rules/files.py +215 -0
- rashid/rules/item_mirror.py +143 -0
- rashid/rules/license.py +82 -0
- rashid/rules/links.py +198 -0
- rashid/rules/partitions.py +93 -0
- rashid/rules/provenance.py +172 -0
- rashid/rules/providers.py +102 -0
- rashid/rules/temporal.py +72 -0
- rashid/rules/titles.py +91 -0
- rashid/rules/viz.py +254 -0
- rashid/runner.py +256 -0
- rashid/schema.py +217 -0
- rashid/structural.py +135 -0
- rashid-0.1.0.dist-info/METADATA +115 -0
- rashid-0.1.0.dist-info/RECORD +36 -0
- rashid-0.1.0.dist-info/WHEEL +4 -0
- rashid-0.1.0.dist-info/entry_points.txt +2 -0
- rashid-0.1.0.dist-info/licenses/LICENSE +201 -0
rashid/__init__.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"""rashid — validator and linter for Portolan catalogs.
|
|
2
|
+
|
|
3
|
+
Usage:
|
|
4
|
+
|
|
5
|
+
from rashid import validate
|
|
6
|
+
report = validate("path/to/catalog")
|
|
7
|
+
if not report.passed:
|
|
8
|
+
for finding in report.errors:
|
|
9
|
+
print(finding.message)
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from rashid.config import RulesConfig
|
|
15
|
+
from rashid.data import validate_data
|
|
16
|
+
from rashid.live import validate_live
|
|
17
|
+
from rashid.model import Finding, Report, Severity
|
|
18
|
+
from rashid.runner import validate
|
|
19
|
+
from rashid.schema import validate_schema
|
|
20
|
+
from rashid.structural import validate_structural
|
|
21
|
+
|
|
22
|
+
__all__ = [
|
|
23
|
+
"Finding",
|
|
24
|
+
"Report",
|
|
25
|
+
"RulesConfig",
|
|
26
|
+
"Severity",
|
|
27
|
+
"validate",
|
|
28
|
+
"validate_data",
|
|
29
|
+
"validate_live",
|
|
30
|
+
"validate_schema",
|
|
31
|
+
"validate_structural",
|
|
32
|
+
]
|
rashid/_multihash.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Multihash well-formedness checking.
|
|
2
|
+
|
|
3
|
+
A multihash is ``varint(code) + varint(digest length) + digest``, hex-encoded
|
|
4
|
+
(https://github.com/multiformats/multihash). This module only checks that a
|
|
5
|
+
string decodes as one; verifying the digest against file bytes is a data-pass
|
|
6
|
+
job, so no hashing happens here and no dependency is needed.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _read_varint(data: bytes, offset: int) -> tuple[int, int] | None:
|
|
13
|
+
"""Decode an unsigned varint at ``offset``; return (value, next_offset)."""
|
|
14
|
+
value = 0
|
|
15
|
+
shift = 0
|
|
16
|
+
while offset < len(data):
|
|
17
|
+
byte = data[offset]
|
|
18
|
+
value |= (byte & 0x7F) << shift
|
|
19
|
+
offset += 1
|
|
20
|
+
if not byte & 0x80:
|
|
21
|
+
return value, offset
|
|
22
|
+
shift += 7
|
|
23
|
+
if shift > 63: # implausibly large varint; corrupt input
|
|
24
|
+
return None
|
|
25
|
+
return None # ran out of bytes mid-varint
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def decode_multihash(value: object) -> tuple[int, bytes] | None:
|
|
29
|
+
"""Decode a hex multihash into ``(hash-function code, digest bytes)``.
|
|
30
|
+
|
|
31
|
+
Returns None when ``value`` is not a hex string that decodes as a complete
|
|
32
|
+
multihash. The code names the hash function (e.g. ``0x12`` = sha2-256); the
|
|
33
|
+
data pass maps it to a hashlib algorithm to verify the digest against the
|
|
34
|
+
asset's bytes.
|
|
35
|
+
"""
|
|
36
|
+
if not isinstance(value, str) or not value:
|
|
37
|
+
return None
|
|
38
|
+
try:
|
|
39
|
+
raw = bytes.fromhex(value)
|
|
40
|
+
except ValueError:
|
|
41
|
+
return None
|
|
42
|
+
decoded = _read_varint(raw, 0)
|
|
43
|
+
if decoded is None:
|
|
44
|
+
return None
|
|
45
|
+
code, offset = decoded
|
|
46
|
+
decoded = _read_varint(raw, offset)
|
|
47
|
+
if decoded is None:
|
|
48
|
+
return None
|
|
49
|
+
length, offset = decoded
|
|
50
|
+
digest = raw[offset:]
|
|
51
|
+
if length <= 0 or len(digest) != length:
|
|
52
|
+
return None
|
|
53
|
+
return code, digest
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def is_well_formed_multihash(value: object) -> bool:
|
|
57
|
+
"""True when ``value`` is a hex string decoding as a complete multihash."""
|
|
58
|
+
return decode_multihash(value) is not None
|