pyjelly 0.7.1__cp311-cp311-macosx_11_0_x86_64.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.
Files changed (41) hide show
  1. cb523b6bada1c6eba8b4__mypyc.cpython-311-darwin.so +0 -0
  2. pyjelly/__init__.py +0 -0
  3. pyjelly/_proto/grpc.proto +33 -0
  4. pyjelly/_proto/patch.proto +165 -0
  5. pyjelly/_proto/rdf.proto +384 -0
  6. pyjelly/errors.py +10 -0
  7. pyjelly/integrations/__init__.py +0 -0
  8. pyjelly/integrations/generic/__init__.py +0 -0
  9. pyjelly/integrations/generic/generic_sink.py +202 -0
  10. pyjelly/integrations/generic/parse.py +412 -0
  11. pyjelly/integrations/generic/serialize.cpython-311-darwin.so +0 -0
  12. pyjelly/integrations/generic/serialize.py +402 -0
  13. pyjelly/integrations/rdflib/__init__.py +24 -0
  14. pyjelly/integrations/rdflib/parse.py +560 -0
  15. pyjelly/integrations/rdflib/serialize.py +408 -0
  16. pyjelly/jelly/__init__.py +5 -0
  17. pyjelly/jelly/rdf_pb2.py +70 -0
  18. pyjelly/jelly/rdf_pb2.pyi +231 -0
  19. pyjelly/options.py +141 -0
  20. pyjelly/parse/__init__.py +0 -0
  21. pyjelly/parse/decode.cpython-311-darwin.so +0 -0
  22. pyjelly/parse/decode.py +447 -0
  23. pyjelly/parse/ioutils.cpython-311-darwin.so +0 -0
  24. pyjelly/parse/ioutils.py +115 -0
  25. pyjelly/parse/lookup.cpython-311-darwin.so +0 -0
  26. pyjelly/parse/lookup.py +70 -0
  27. pyjelly/serialize/__init__.py +0 -0
  28. pyjelly/serialize/encode.cpython-311-darwin.so +0 -0
  29. pyjelly/serialize/encode.py +397 -0
  30. pyjelly/serialize/flows.py +196 -0
  31. pyjelly/serialize/ioutils.cpython-311-darwin.so +0 -0
  32. pyjelly/serialize/ioutils.py +13 -0
  33. pyjelly/serialize/lookup.cpython-311-darwin.so +0 -0
  34. pyjelly/serialize/lookup.py +137 -0
  35. pyjelly/serialize/streams.cpython-311-darwin.so +0 -0
  36. pyjelly/serialize/streams.py +281 -0
  37. pyjelly-0.7.1.dist-info/METADATA +114 -0
  38. pyjelly-0.7.1.dist-info/RECORD +41 -0
  39. pyjelly-0.7.1.dist-info/WHEEL +6 -0
  40. pyjelly-0.7.1.dist-info/entry_points.txt +7 -0
  41. pyjelly-0.7.1.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,231 @@
1
+ from google.protobuf.internal import containers as _containers
2
+ from google.protobuf.internal import enum_type_wrapper as _enum_type_wrapper
3
+ from google.protobuf import descriptor as _descriptor
4
+ from google.protobuf import message as _message
5
+ from collections.abc import Iterable as _Iterable, Mapping as _Mapping
6
+ from typing import ClassVar as _ClassVar, Optional as _Optional, Union as _Union
7
+
8
+ DESCRIPTOR: _descriptor.FileDescriptor
9
+
10
+ class PhysicalStreamType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
11
+ __slots__ = ()
12
+ PHYSICAL_STREAM_TYPE_UNSPECIFIED: _ClassVar[PhysicalStreamType]
13
+ PHYSICAL_STREAM_TYPE_TRIPLES: _ClassVar[PhysicalStreamType]
14
+ PHYSICAL_STREAM_TYPE_QUADS: _ClassVar[PhysicalStreamType]
15
+ PHYSICAL_STREAM_TYPE_GRAPHS: _ClassVar[PhysicalStreamType]
16
+
17
+ class LogicalStreamType(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
18
+ __slots__ = ()
19
+ LOGICAL_STREAM_TYPE_UNSPECIFIED: _ClassVar[LogicalStreamType]
20
+ LOGICAL_STREAM_TYPE_FLAT_TRIPLES: _ClassVar[LogicalStreamType]
21
+ LOGICAL_STREAM_TYPE_FLAT_QUADS: _ClassVar[LogicalStreamType]
22
+ LOGICAL_STREAM_TYPE_GRAPHS: _ClassVar[LogicalStreamType]
23
+ LOGICAL_STREAM_TYPE_DATASETS: _ClassVar[LogicalStreamType]
24
+ LOGICAL_STREAM_TYPE_SUBJECT_GRAPHS: _ClassVar[LogicalStreamType]
25
+ LOGICAL_STREAM_TYPE_NAMED_GRAPHS: _ClassVar[LogicalStreamType]
26
+ LOGICAL_STREAM_TYPE_TIMESTAMPED_NAMED_GRAPHS: _ClassVar[LogicalStreamType]
27
+ PHYSICAL_STREAM_TYPE_UNSPECIFIED: PhysicalStreamType
28
+ PHYSICAL_STREAM_TYPE_TRIPLES: PhysicalStreamType
29
+ PHYSICAL_STREAM_TYPE_QUADS: PhysicalStreamType
30
+ PHYSICAL_STREAM_TYPE_GRAPHS: PhysicalStreamType
31
+ LOGICAL_STREAM_TYPE_UNSPECIFIED: LogicalStreamType
32
+ LOGICAL_STREAM_TYPE_FLAT_TRIPLES: LogicalStreamType
33
+ LOGICAL_STREAM_TYPE_FLAT_QUADS: LogicalStreamType
34
+ LOGICAL_STREAM_TYPE_GRAPHS: LogicalStreamType
35
+ LOGICAL_STREAM_TYPE_DATASETS: LogicalStreamType
36
+ LOGICAL_STREAM_TYPE_SUBJECT_GRAPHS: LogicalStreamType
37
+ LOGICAL_STREAM_TYPE_NAMED_GRAPHS: LogicalStreamType
38
+ LOGICAL_STREAM_TYPE_TIMESTAMPED_NAMED_GRAPHS: LogicalStreamType
39
+
40
+ class RdfIri(_message.Message):
41
+ __slots__ = ("prefix_id", "name_id")
42
+ PREFIX_ID_FIELD_NUMBER: _ClassVar[int]
43
+ NAME_ID_FIELD_NUMBER: _ClassVar[int]
44
+ prefix_id: int
45
+ name_id: int
46
+ def __init__(self, prefix_id: _Optional[int] = ..., name_id: _Optional[int] = ...) -> None: ...
47
+
48
+ class RdfLiteral(_message.Message):
49
+ __slots__ = ("lex", "langtag", "datatype")
50
+ LEX_FIELD_NUMBER: _ClassVar[int]
51
+ LANGTAG_FIELD_NUMBER: _ClassVar[int]
52
+ DATATYPE_FIELD_NUMBER: _ClassVar[int]
53
+ lex: str
54
+ langtag: str
55
+ datatype: int
56
+ def __init__(self, lex: _Optional[str] = ..., langtag: _Optional[str] = ..., datatype: _Optional[int] = ...) -> None: ...
57
+
58
+ class RdfDefaultGraph(_message.Message):
59
+ __slots__ = ()
60
+ def __init__(self) -> None: ...
61
+
62
+ class RdfTriple(_message.Message):
63
+ __slots__ = ("s_iri", "s_bnode", "s_literal", "s_triple_term", "p_iri", "p_bnode", "p_literal", "p_triple_term", "o_iri", "o_bnode", "o_literal", "o_triple_term")
64
+ S_IRI_FIELD_NUMBER: _ClassVar[int]
65
+ S_BNODE_FIELD_NUMBER: _ClassVar[int]
66
+ S_LITERAL_FIELD_NUMBER: _ClassVar[int]
67
+ S_TRIPLE_TERM_FIELD_NUMBER: _ClassVar[int]
68
+ P_IRI_FIELD_NUMBER: _ClassVar[int]
69
+ P_BNODE_FIELD_NUMBER: _ClassVar[int]
70
+ P_LITERAL_FIELD_NUMBER: _ClassVar[int]
71
+ P_TRIPLE_TERM_FIELD_NUMBER: _ClassVar[int]
72
+ O_IRI_FIELD_NUMBER: _ClassVar[int]
73
+ O_BNODE_FIELD_NUMBER: _ClassVar[int]
74
+ O_LITERAL_FIELD_NUMBER: _ClassVar[int]
75
+ O_TRIPLE_TERM_FIELD_NUMBER: _ClassVar[int]
76
+ s_iri: RdfIri
77
+ s_bnode: str
78
+ s_literal: RdfLiteral
79
+ s_triple_term: RdfTriple
80
+ p_iri: RdfIri
81
+ p_bnode: str
82
+ p_literal: RdfLiteral
83
+ p_triple_term: RdfTriple
84
+ o_iri: RdfIri
85
+ o_bnode: str
86
+ o_literal: RdfLiteral
87
+ o_triple_term: RdfTriple
88
+ def __init__(self, s_iri: _Optional[_Union[RdfIri, _Mapping]] = ..., s_bnode: _Optional[str] = ..., s_literal: _Optional[_Union[RdfLiteral, _Mapping]] = ..., s_triple_term: _Optional[_Union[RdfTriple, _Mapping]] = ..., p_iri: _Optional[_Union[RdfIri, _Mapping]] = ..., p_bnode: _Optional[str] = ..., p_literal: _Optional[_Union[RdfLiteral, _Mapping]] = ..., p_triple_term: _Optional[_Union[RdfTriple, _Mapping]] = ..., o_iri: _Optional[_Union[RdfIri, _Mapping]] = ..., o_bnode: _Optional[str] = ..., o_literal: _Optional[_Union[RdfLiteral, _Mapping]] = ..., o_triple_term: _Optional[_Union[RdfTriple, _Mapping]] = ...) -> None: ...
89
+
90
+ class RdfQuad(_message.Message):
91
+ __slots__ = ("s_iri", "s_bnode", "s_literal", "s_triple_term", "p_iri", "p_bnode", "p_literal", "p_triple_term", "o_iri", "o_bnode", "o_literal", "o_triple_term", "g_iri", "g_bnode", "g_default_graph", "g_literal")
92
+ S_IRI_FIELD_NUMBER: _ClassVar[int]
93
+ S_BNODE_FIELD_NUMBER: _ClassVar[int]
94
+ S_LITERAL_FIELD_NUMBER: _ClassVar[int]
95
+ S_TRIPLE_TERM_FIELD_NUMBER: _ClassVar[int]
96
+ P_IRI_FIELD_NUMBER: _ClassVar[int]
97
+ P_BNODE_FIELD_NUMBER: _ClassVar[int]
98
+ P_LITERAL_FIELD_NUMBER: _ClassVar[int]
99
+ P_TRIPLE_TERM_FIELD_NUMBER: _ClassVar[int]
100
+ O_IRI_FIELD_NUMBER: _ClassVar[int]
101
+ O_BNODE_FIELD_NUMBER: _ClassVar[int]
102
+ O_LITERAL_FIELD_NUMBER: _ClassVar[int]
103
+ O_TRIPLE_TERM_FIELD_NUMBER: _ClassVar[int]
104
+ G_IRI_FIELD_NUMBER: _ClassVar[int]
105
+ G_BNODE_FIELD_NUMBER: _ClassVar[int]
106
+ G_DEFAULT_GRAPH_FIELD_NUMBER: _ClassVar[int]
107
+ G_LITERAL_FIELD_NUMBER: _ClassVar[int]
108
+ s_iri: RdfIri
109
+ s_bnode: str
110
+ s_literal: RdfLiteral
111
+ s_triple_term: RdfTriple
112
+ p_iri: RdfIri
113
+ p_bnode: str
114
+ p_literal: RdfLiteral
115
+ p_triple_term: RdfTriple
116
+ o_iri: RdfIri
117
+ o_bnode: str
118
+ o_literal: RdfLiteral
119
+ o_triple_term: RdfTriple
120
+ g_iri: RdfIri
121
+ g_bnode: str
122
+ g_default_graph: RdfDefaultGraph
123
+ g_literal: RdfLiteral
124
+ def __init__(self, s_iri: _Optional[_Union[RdfIri, _Mapping]] = ..., s_bnode: _Optional[str] = ..., s_literal: _Optional[_Union[RdfLiteral, _Mapping]] = ..., s_triple_term: _Optional[_Union[RdfTriple, _Mapping]] = ..., p_iri: _Optional[_Union[RdfIri, _Mapping]] = ..., p_bnode: _Optional[str] = ..., p_literal: _Optional[_Union[RdfLiteral, _Mapping]] = ..., p_triple_term: _Optional[_Union[RdfTriple, _Mapping]] = ..., o_iri: _Optional[_Union[RdfIri, _Mapping]] = ..., o_bnode: _Optional[str] = ..., o_literal: _Optional[_Union[RdfLiteral, _Mapping]] = ..., o_triple_term: _Optional[_Union[RdfTriple, _Mapping]] = ..., g_iri: _Optional[_Union[RdfIri, _Mapping]] = ..., g_bnode: _Optional[str] = ..., g_default_graph: _Optional[_Union[RdfDefaultGraph, _Mapping]] = ..., g_literal: _Optional[_Union[RdfLiteral, _Mapping]] = ...) -> None: ...
125
+
126
+ class RdfGraphStart(_message.Message):
127
+ __slots__ = ("g_iri", "g_bnode", "g_default_graph", "g_literal")
128
+ G_IRI_FIELD_NUMBER: _ClassVar[int]
129
+ G_BNODE_FIELD_NUMBER: _ClassVar[int]
130
+ G_DEFAULT_GRAPH_FIELD_NUMBER: _ClassVar[int]
131
+ G_LITERAL_FIELD_NUMBER: _ClassVar[int]
132
+ g_iri: RdfIri
133
+ g_bnode: str
134
+ g_default_graph: RdfDefaultGraph
135
+ g_literal: RdfLiteral
136
+ def __init__(self, g_iri: _Optional[_Union[RdfIri, _Mapping]] = ..., g_bnode: _Optional[str] = ..., g_default_graph: _Optional[_Union[RdfDefaultGraph, _Mapping]] = ..., g_literal: _Optional[_Union[RdfLiteral, _Mapping]] = ...) -> None: ...
137
+
138
+ class RdfGraphEnd(_message.Message):
139
+ __slots__ = ()
140
+ def __init__(self) -> None: ...
141
+
142
+ class RdfNamespaceDeclaration(_message.Message):
143
+ __slots__ = ("name", "value")
144
+ NAME_FIELD_NUMBER: _ClassVar[int]
145
+ VALUE_FIELD_NUMBER: _ClassVar[int]
146
+ name: str
147
+ value: RdfIri
148
+ def __init__(self, name: _Optional[str] = ..., value: _Optional[_Union[RdfIri, _Mapping]] = ...) -> None: ...
149
+
150
+ class RdfNameEntry(_message.Message):
151
+ __slots__ = ("id", "value")
152
+ ID_FIELD_NUMBER: _ClassVar[int]
153
+ VALUE_FIELD_NUMBER: _ClassVar[int]
154
+ id: int
155
+ value: str
156
+ def __init__(self, id: _Optional[int] = ..., value: _Optional[str] = ...) -> None: ...
157
+
158
+ class RdfPrefixEntry(_message.Message):
159
+ __slots__ = ("id", "value")
160
+ ID_FIELD_NUMBER: _ClassVar[int]
161
+ VALUE_FIELD_NUMBER: _ClassVar[int]
162
+ id: int
163
+ value: str
164
+ def __init__(self, id: _Optional[int] = ..., value: _Optional[str] = ...) -> None: ...
165
+
166
+ class RdfDatatypeEntry(_message.Message):
167
+ __slots__ = ("id", "value")
168
+ ID_FIELD_NUMBER: _ClassVar[int]
169
+ VALUE_FIELD_NUMBER: _ClassVar[int]
170
+ id: int
171
+ value: str
172
+ def __init__(self, id: _Optional[int] = ..., value: _Optional[str] = ...) -> None: ...
173
+
174
+ class RdfStreamOptions(_message.Message):
175
+ __slots__ = ("stream_name", "physical_type", "generalized_statements", "rdf_star", "max_name_table_size", "max_prefix_table_size", "max_datatype_table_size", "logical_type", "version")
176
+ STREAM_NAME_FIELD_NUMBER: _ClassVar[int]
177
+ PHYSICAL_TYPE_FIELD_NUMBER: _ClassVar[int]
178
+ GENERALIZED_STATEMENTS_FIELD_NUMBER: _ClassVar[int]
179
+ RDF_STAR_FIELD_NUMBER: _ClassVar[int]
180
+ MAX_NAME_TABLE_SIZE_FIELD_NUMBER: _ClassVar[int]
181
+ MAX_PREFIX_TABLE_SIZE_FIELD_NUMBER: _ClassVar[int]
182
+ MAX_DATATYPE_TABLE_SIZE_FIELD_NUMBER: _ClassVar[int]
183
+ LOGICAL_TYPE_FIELD_NUMBER: _ClassVar[int]
184
+ VERSION_FIELD_NUMBER: _ClassVar[int]
185
+ stream_name: str
186
+ physical_type: PhysicalStreamType
187
+ generalized_statements: bool
188
+ rdf_star: bool
189
+ max_name_table_size: int
190
+ max_prefix_table_size: int
191
+ max_datatype_table_size: int
192
+ logical_type: LogicalStreamType
193
+ version: int
194
+ def __init__(self, stream_name: _Optional[str] = ..., physical_type: _Optional[_Union[PhysicalStreamType, str]] = ..., generalized_statements: bool = ..., rdf_star: bool = ..., max_name_table_size: _Optional[int] = ..., max_prefix_table_size: _Optional[int] = ..., max_datatype_table_size: _Optional[int] = ..., logical_type: _Optional[_Union[LogicalStreamType, str]] = ..., version: _Optional[int] = ...) -> None: ...
195
+
196
+ class RdfStreamRow(_message.Message):
197
+ __slots__ = ("options", "triple", "quad", "graph_start", "graph_end", "namespace", "name", "prefix", "datatype")
198
+ OPTIONS_FIELD_NUMBER: _ClassVar[int]
199
+ TRIPLE_FIELD_NUMBER: _ClassVar[int]
200
+ QUAD_FIELD_NUMBER: _ClassVar[int]
201
+ GRAPH_START_FIELD_NUMBER: _ClassVar[int]
202
+ GRAPH_END_FIELD_NUMBER: _ClassVar[int]
203
+ NAMESPACE_FIELD_NUMBER: _ClassVar[int]
204
+ NAME_FIELD_NUMBER: _ClassVar[int]
205
+ PREFIX_FIELD_NUMBER: _ClassVar[int]
206
+ DATATYPE_FIELD_NUMBER: _ClassVar[int]
207
+ options: RdfStreamOptions
208
+ triple: RdfTriple
209
+ quad: RdfQuad
210
+ graph_start: RdfGraphStart
211
+ graph_end: RdfGraphEnd
212
+ namespace: RdfNamespaceDeclaration
213
+ name: RdfNameEntry
214
+ prefix: RdfPrefixEntry
215
+ datatype: RdfDatatypeEntry
216
+ def __init__(self, options: _Optional[_Union[RdfStreamOptions, _Mapping]] = ..., triple: _Optional[_Union[RdfTriple, _Mapping]] = ..., quad: _Optional[_Union[RdfQuad, _Mapping]] = ..., graph_start: _Optional[_Union[RdfGraphStart, _Mapping]] = ..., graph_end: _Optional[_Union[RdfGraphEnd, _Mapping]] = ..., namespace: _Optional[_Union[RdfNamespaceDeclaration, _Mapping]] = ..., name: _Optional[_Union[RdfNameEntry, _Mapping]] = ..., prefix: _Optional[_Union[RdfPrefixEntry, _Mapping]] = ..., datatype: _Optional[_Union[RdfDatatypeEntry, _Mapping]] = ...) -> None: ...
217
+
218
+ class RdfStreamFrame(_message.Message):
219
+ __slots__ = ("rows", "metadata")
220
+ class MetadataEntry(_message.Message):
221
+ __slots__ = ("key", "value")
222
+ KEY_FIELD_NUMBER: _ClassVar[int]
223
+ VALUE_FIELD_NUMBER: _ClassVar[int]
224
+ key: str
225
+ value: bytes
226
+ def __init__(self, key: _Optional[str] = ..., value: _Optional[bytes] = ...) -> None: ...
227
+ ROWS_FIELD_NUMBER: _ClassVar[int]
228
+ METADATA_FIELD_NUMBER: _ClassVar[int]
229
+ rows: _containers.RepeatedCompositeFieldContainer[RdfStreamRow]
230
+ metadata: _containers.ScalarMap[str, bytes]
231
+ def __init__(self, rows: _Optional[_Iterable[_Union[RdfStreamRow, _Mapping]]] = ..., metadata: _Optional[_Mapping[str, bytes]] = ...) -> None: ...
pyjelly/options.py ADDED
@@ -0,0 +1,141 @@
1
+ from __future__ import annotations
2
+
3
+ import mimetypes
4
+ from contextlib import suppress
5
+ from dataclasses import dataclass
6
+ from typing import Final
7
+ from typing_extensions import Self
8
+
9
+ from mypy_extensions import mypyc_attr
10
+
11
+ from pyjelly import jelly
12
+ from pyjelly.errors import (
13
+ JellyAssertionError,
14
+ JellyConformanceError,
15
+ )
16
+
17
+ MIN_NAME_LOOKUP_SIZE: Final[int] = 8
18
+
19
+ MAX_LOOKUP_SIZE: Final[int] = 4096
20
+ MIN_VERSION: Final[int] = 1
21
+ MAX_VERSION: Final[int] = 2
22
+
23
+ DEFAULT_NAME_LOOKUP_SIZE: Final[int] = 4000
24
+ DEFAULT_PREFIX_LOOKUP_SIZE: Final[int] = 150
25
+ DEFAULT_DATATYPE_LOOKUP_SIZE: Final[int] = 32
26
+
27
+ STRING_DATATYPE_IRI = "http://www.w3.org/2001/XMLSchema#string"
28
+
29
+ INTEGRATION_SIDE_EFFECTS: bool = True
30
+ """
31
+ Whether to allow integration module imports to trigger side effects.
32
+
33
+ These side effects are cheap and may include populating some registries
34
+ for guessing the defaults for external integrations that work with Jelly.
35
+ """
36
+
37
+ MIMETYPES = ("application/x-jelly-rdf",)
38
+
39
+
40
+ def register_mimetypes(extension: str = ".jelly") -> None:
41
+ """
42
+ Associate files that have Jelly extension with Jelly MIME types.
43
+
44
+ >>> register_mimetypes()
45
+ >>> mimetypes.guess_type("out.jelly")
46
+ ('application/x-jelly-rdf', None)
47
+ """
48
+ for mimetype in MIMETYPES:
49
+ mimetypes.add_type(mimetype, extension)
50
+
51
+
52
+ @mypyc_attr(allow_interpreted_subclasses=True)
53
+ @dataclass(frozen=True)
54
+ class LookupPreset:
55
+ max_names: int = DEFAULT_NAME_LOOKUP_SIZE
56
+ max_prefixes: int = DEFAULT_PREFIX_LOOKUP_SIZE
57
+ max_datatypes: int = DEFAULT_DATATYPE_LOOKUP_SIZE
58
+
59
+ def __post_init__(self) -> None:
60
+ if self.max_names < MIN_NAME_LOOKUP_SIZE:
61
+ msg = "name lookup size must be at least 8"
62
+ raise JellyConformanceError(msg)
63
+
64
+ @classmethod
65
+ def small(cls) -> Self:
66
+ return cls(max_names=128, max_prefixes=32, max_datatypes=32)
67
+
68
+
69
+ @dataclass(frozen=True)
70
+ class StreamTypes:
71
+ physical_type: jelly.PhysicalStreamType = jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED
72
+ logical_type: jelly.LogicalStreamType = jelly.LOGICAL_STREAM_TYPE_UNSPECIFIED
73
+
74
+ @property
75
+ def flat(self) -> bool:
76
+ return self.logical_type in (
77
+ jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES,
78
+ jelly.LOGICAL_STREAM_TYPE_FLAT_QUADS,
79
+ )
80
+
81
+ def __repr__(self) -> str:
82
+ """
83
+ Return the representation of StreamTypes.
84
+
85
+ >>> repr(StreamTypes(9999, 8888))
86
+ 'StreamTypes(9999, 8888)'
87
+ """
88
+ with suppress(ValueError):
89
+ physical_type_name = jelly.PhysicalStreamType.Name(self.physical_type)
90
+ logical_type_name = jelly.LogicalStreamType.Name(self.logical_type)
91
+ return f"StreamTypes({physical_type_name}, {logical_type_name})"
92
+ return f"StreamTypes({self.physical_type}, {self.logical_type})"
93
+
94
+ def __post_init__(self) -> None:
95
+ validate_type_compatibility(
96
+ physical_type=self.physical_type,
97
+ logical_type=self.logical_type,
98
+ )
99
+
100
+
101
+ @dataclass(frozen=True)
102
+ class StreamParameters:
103
+ generalized_statements: bool = False
104
+ rdf_star: bool = False
105
+ version: int = MAX_VERSION
106
+ delimited: bool = True
107
+ namespace_declarations: bool = False
108
+ stream_name: str = ""
109
+
110
+ def __post_init__(self) -> None:
111
+ selected = MAX_VERSION if self.namespace_declarations else MIN_VERSION
112
+ if not (MIN_VERSION <= selected <= MAX_VERSION):
113
+ msg = f"""Error occured while settin up the Stream options.
114
+ Version must be between {MIN_VERSION} and {MAX_VERSION}."""
115
+ raise JellyConformanceError(msg)
116
+ object.__setattr__(self, "version", selected)
117
+
118
+
119
+ TRIPLES_ONLY_LOGICAL_TYPES = {
120
+ jelly.LOGICAL_STREAM_TYPE_GRAPHS,
121
+ jelly.LOGICAL_STREAM_TYPE_SUBJECT_GRAPHS,
122
+ jelly.LOGICAL_STREAM_TYPE_FLAT_TRIPLES,
123
+ }
124
+
125
+
126
+ def validate_type_compatibility(
127
+ physical_type: jelly.PhysicalStreamType,
128
+ logical_type: jelly.LogicalStreamType,
129
+ ) -> None:
130
+ if (
131
+ physical_type == jelly.PHYSICAL_STREAM_TYPE_UNSPECIFIED
132
+ or logical_type == jelly.LOGICAL_STREAM_TYPE_UNSPECIFIED
133
+ ):
134
+ return
135
+ triples_physical_type = physical_type == jelly.PHYSICAL_STREAM_TYPE_TRIPLES
136
+ triples_logical_type = logical_type in TRIPLES_ONLY_LOGICAL_TYPES
137
+ if triples_physical_type != triples_logical_type:
138
+ physical_type_name = jelly.PhysicalStreamType.Name(physical_type)
139
+ logical_type_name = jelly.LogicalStreamType.Name(logical_type)
140
+ msg = f"{physical_type_name} is not compatible with {logical_type_name}"
141
+ raise JellyAssertionError(msg)
File without changes