omlish 0.0.0.dev83__py3-none-any.whl → 0.0.0.dev84__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
omlish/__about__.py CHANGED
@@ -1,5 +1,5 @@
1
- __version__ = '0.0.0.dev83'
2
- __revision__ = '25a87321f2e19f536595fa049cd2f53fb5497448'
1
+ __version__ = '0.0.0.dev84'
2
+ __revision__ = 'b3347da7d48862b90c274893e4f9bfa477fecc70'
3
3
 
4
4
 
5
5
  #
@@ -101,7 +101,7 @@ class Project(ProjectBase):
101
101
 
102
102
  'apsw ~= 3.46',
103
103
 
104
- 'sqlean.py ~= 3.45; python_version < "3.13"',
104
+ 'sqlean.py ~= 3.45',
105
105
 
106
106
  'duckdb ~= 1.1',
107
107
  ],
@@ -35,7 +35,7 @@ def raise_field_validation_error(
35
35
  field: str,
36
36
  fn: ta.Callable,
37
37
  value: ta.Any,
38
- ):
38
+ ) -> ta.NoReturn:
39
39
  raise FieldValidationError(
40
40
  obj,
41
41
  field,
@@ -23,6 +23,19 @@ from .utils import set_new_attribute
23
23
  MISSING = dc.MISSING
24
24
 
25
25
 
26
+ ##
27
+
28
+
29
+ def raise_validation_error(
30
+ obj: ta.Any,
31
+ fn: ta.Callable,
32
+ ) -> ta.NoReturn:
33
+ raise ValidationError(obj, fn)
34
+
35
+
36
+ ##
37
+
38
+
26
39
  class InitFields(ta.NamedTuple):
27
40
  all: ta.Sequence[dc.Field]
28
41
  ordered: ta.Sequence[dc.Field]
@@ -57,6 +70,9 @@ def init_param(f: dc.Field) -> str:
57
70
  return f'{f.name}: __dataclass_type_{f.name}__{default}' # noqa
58
71
 
59
72
 
73
+ ##
74
+
75
+
60
76
  class InitBuilder:
61
77
 
62
78
  def __init__(
@@ -100,7 +116,7 @@ class InitBuilder:
100
116
  '__dataclass_builtins_object__': object,
101
117
  '__dataclass_builtins_isinstance__': isinstance,
102
118
  '__dataclass_builtins_TypeError__': TypeError,
103
- '__dataclass_ValidationError__': ValidationError,
119
+ '__dataclass_raise_validation_error__': raise_validation_error,
104
120
  '__dataclass_raise_field_validation_error__': raise_field_validation_error,
105
121
  })
106
122
 
@@ -128,7 +144,7 @@ class InitBuilder:
128
144
  locals[cn] = fn
129
145
  csig = inspect.signature(fn)
130
146
  cas = ', '.join(p.name for p in csig.parameters.values())
131
- body_lines.append(f'if not {cn}({cas}): raise __dataclass_ValidationError__')
147
+ body_lines.append(f'if not {cn}({cas}): __dataclass_raise_validation_error__({self._self_name}, {cn})')
132
148
 
133
149
  inits = self._info.merged_metadata.get(Init, [])
134
150
  mro_dct = lang.build_mro_dict(self._info.cls)
@@ -1,6 +1,5 @@
1
1
  import typing as ta
2
2
 
3
- from ....genmachine import GenMachine
4
3
  from .lex import SCALAR_VALUE_TYPES
5
4
  from .parse import BeginArray
6
5
  from .parse import BeginObject
@@ -14,7 +13,7 @@ from .parse import Key
14
13
  ##
15
14
 
16
15
 
17
- class JsonObjectBuilder(GenMachine[JsonStreamParserEvent, ta.Any]):
16
+ class JsonObjectBuilder:
18
17
  def __init__(
19
18
  self,
20
19
  *,
@@ -23,91 +22,88 @@ class JsonObjectBuilder(GenMachine[JsonStreamParserEvent, ta.Any]):
23
22
  self._stack: list[JsonStreamObject | list | Key] = []
24
23
  self._yield_object_lists = yield_object_lists
25
24
 
26
- super().__init__(self._do())
25
+ class StateError(Exception):
26
+ pass
27
27
 
28
- def _do(self):
29
- stk = self._stack
30
-
31
- def emit_value(v):
32
- if not stk:
33
- return (v,)
28
+ def __enter__(self) -> ta.Self:
29
+ return self
34
30
 
35
- tv = stk[-1]
36
- if isinstance(tv, Key):
37
- stk.pop()
38
- if not stk:
39
- raise self.StateError
31
+ def __exit__(self, exc_type, exc_val, exc_tb):
32
+ if exc_type is None:
33
+ self.close()
40
34
 
41
- tv2 = stk[-1]
42
- if not isinstance(tv2, JsonStreamObject):
43
- raise self.StateError
35
+ def close(self) -> None:
36
+ if self._stack:
37
+ raise self.StateError
44
38
 
45
- tv2.append((tv.key, v))
46
- return ()
39
+ def _emit_value(self, v):
40
+ if not (stk := self._stack):
41
+ return (v,)
47
42
 
48
- elif isinstance(tv, list):
49
- tv.append(v)
50
- return ()
43
+ tv = stk[-1]
44
+ if isinstance(tv, Key):
45
+ stk.pop()
46
+ if not stk:
47
+ raise self.StateError
51
48
 
52
- else:
49
+ tv2 = stk[-1]
50
+ if not isinstance(tv2, JsonStreamObject):
53
51
  raise self.StateError
54
52
 
55
- while True:
56
- try:
57
- e = yield None
58
- except GeneratorExit:
59
- if stk:
60
- raise self.StateError from None
61
- else:
62
- raise
53
+ tv2.append((tv.key, v))
54
+ return ()
55
+
56
+ elif isinstance(tv, list):
57
+ tv.append(v)
58
+ return ()
63
59
 
64
- #
60
+ else:
61
+ raise self.StateError
65
62
 
66
- if isinstance(e, SCALAR_VALUE_TYPES):
67
- if t := emit_value(e):
68
- yield t
69
- continue
63
+ def __call__(self, e: JsonStreamParserEvent) -> ta.Any:
64
+ stk = self._stack
65
+
66
+ #
67
+
68
+ if isinstance(e, SCALAR_VALUE_TYPES):
69
+ return self._emit_value(e)
70
70
 
71
- #
71
+ #
72
72
 
73
- elif e is BeginObject:
74
- stk.append(JsonStreamObject())
75
- continue
73
+ elif e is BeginObject:
74
+ stk.append(JsonStreamObject())
75
+ return ()
76
76
 
77
- elif isinstance(e, Key):
78
- if not stk or not isinstance(stk[-1], JsonStreamObject):
79
- raise self.StateError
77
+ elif isinstance(e, Key):
78
+ if not stk or not isinstance(stk[-1], JsonStreamObject):
79
+ raise self.StateError
80
80
 
81
- stk.append(e)
82
- continue
81
+ stk.append(e)
82
+ return ()
83
83
 
84
- elif e is EndObject:
85
- tv: ta.Any
86
- if not stk or not isinstance(tv := stk.pop(), JsonStreamObject):
87
- raise self.StateError
84
+ elif e is EndObject:
85
+ tv: ta.Any
86
+ if not stk or not isinstance(tv := stk.pop(), JsonStreamObject):
87
+ raise self.StateError
88
88
 
89
- if not self._yield_object_lists:
90
- tv = dict(tv)
89
+ if not self._yield_object_lists:
90
+ tv = dict(tv)
91
91
 
92
- if t := emit_value(tv):
93
- yield t
94
- continue
92
+ return self._emit_value(tv)
95
93
 
96
- #
94
+ #
97
95
 
98
- elif e is BeginArray:
99
- stk.append([])
100
- continue
96
+ elif e is BeginArray:
97
+ stk.append([])
98
+ return ()
101
99
 
102
- elif e is EndArray:
103
- if not stk or not isinstance(tv := stk.pop(), list):
104
- raise self.StateError
100
+ elif e is EndArray:
101
+ if not stk or not isinstance(tv := stk.pop(), list):
102
+ raise self.StateError
105
103
 
106
- if t := emit_value(tv):
107
- yield t
108
- continue
104
+ return self._emit_value(tv)
109
105
 
110
- #
106
+ #
111
107
 
112
- else:
113
- raise TypeError(e)
108
+ else:
109
+ raise TypeError(e)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omlish
3
- Version: 0.0.0.dev83
3
+ Version: 0.0.0.dev84
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -40,9 +40,9 @@ Requires-Dist: aiomysql ~=0.2 ; extra == 'all'
40
40
  Requires-Dist: aiosqlite ~=0.20 ; extra == 'all'
41
41
  Requires-Dist: asyncpg ~=0.30 ; extra == 'all'
42
42
  Requires-Dist: apsw ~=3.46 ; extra == 'all'
43
+ Requires-Dist: sqlean.py ~=3.45 ; extra == 'all'
43
44
  Requires-Dist: duckdb ~=1.1 ; extra == 'all'
44
45
  Requires-Dist: pytest ~=8.0 ; extra == 'all'
45
- Requires-Dist: sqlean.py ~=3.45 ; (python_version < "3.13") and extra == 'all'
46
46
  Provides-Extra: async
47
47
  Requires-Dist: anyio ~=4.6 ; extra == 'async'
48
48
  Requires-Dist: sniffio ~=1.3 ; extra == 'async'
@@ -87,8 +87,8 @@ Requires-Dist: aiomysql ~=0.2 ; extra == 'sqldrivers'
87
87
  Requires-Dist: aiosqlite ~=0.20 ; extra == 'sqldrivers'
88
88
  Requires-Dist: asyncpg ~=0.30 ; extra == 'sqldrivers'
89
89
  Requires-Dist: apsw ~=3.46 ; extra == 'sqldrivers'
90
+ Requires-Dist: sqlean.py ~=3.45 ; extra == 'sqldrivers'
90
91
  Requires-Dist: duckdb ~=1.1 ; extra == 'sqldrivers'
91
- Requires-Dist: sqlean.py ~=3.45 ; (python_version < "3.13") and extra == 'sqldrivers'
92
92
  Provides-Extra: testing
93
93
  Requires-Dist: pytest ~=8.0 ; extra == 'testing'
94
94
 
@@ -1,5 +1,5 @@
1
1
  omlish/.manifests.json,sha256=hTFp9tvE72BxKloIq1s1SS0LRQlIsvMtO69Sbc47rKg,1704
2
- omlish/__about__.py,sha256=ekzbyJ-nihCL3SJ4lJ_uq-a-V1a5SLP_kMNo0ugzCOw,3370
2
+ omlish/__about__.py,sha256=oOKwJVkrCVI_eRBapOS36eRWek5mbyQvP62epTd67RE,3345
3
3
  omlish/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  omlish/argparse.py,sha256=Dc73G8lyoQBLvXhMYUbzQUh4SJu_OTvKUXjSUxq_ang,7499
5
5
  omlish/c3.py,sha256=4vogWgwPb8TbNS2KkZxpoWbwjj7MuHG2lQG-hdtkvjI,8062
@@ -132,10 +132,10 @@ omlish/dataclasses/impl/as_.py,sha256=CD-t7hkC1EP2F_jvZKIA_cVoDuwZ-Ln_xC4fJumPYX
132
132
  omlish/dataclasses/impl/copy.py,sha256=Tn8_n6Vohs-w4otbGdubBEvhd3TsSTaM3EfNGdS2LYo,591
133
133
  omlish/dataclasses/impl/descriptors.py,sha256=rEYE1Len99agTQCC25hSPMnM19BgPr0ZChABGi58Fdk,2476
134
134
  omlish/dataclasses/impl/exceptions.py,sha256=-vqxZmfXVflymVuiM553XTlJProse5HEMktTpfdPCIY,1275
135
- omlish/dataclasses/impl/fields.py,sha256=DbdTUnwFNL7KxNZBmEAGg4muMyFWbiMR8BUtUAOLrrc,6863
135
+ omlish/dataclasses/impl/fields.py,sha256=4_5qMz9LlOS6U67cDKQ-oorTtSGGxR77I4hw88soM44,6878
136
136
  omlish/dataclasses/impl/frozen.py,sha256=x87DSM8FIMZ3c_BIUE8NooCkExFjPsabeqIueEP5qKs,2988
137
137
  omlish/dataclasses/impl/hashing.py,sha256=FKnHuXCg9ylrzK2TLGqO5yfRN4HX3F415CSLlVYXtYE,3190
138
- omlish/dataclasses/impl/init.py,sha256=t8wFWS5jw1XaY8KwL5iLSoeON0iILA2sqa-lDair0Ck,6181
138
+ omlish/dataclasses/impl/init.py,sha256=5kYcMDlI6EVeLQ6RCTk1bvYjb-cwg0AYfVE9FPZJlYI,6365
139
139
  omlish/dataclasses/impl/internals.py,sha256=UvZYjrLT1S8ntyxJ_vRPIkPOF00K8HatGAygErgoXTU,2990
140
140
  omlish/dataclasses/impl/main.py,sha256=Ti0PKbFKraKvfmoPuR-G7nLVNzRC8mvEuXhCuC-M2kc,2574
141
141
  omlish/dataclasses/impl/metaclass.py,sha256=Fb0ExFiyYdOpvck4ayXMr_vEVDvHLhe28Ns3F4aduM8,3222
@@ -200,7 +200,7 @@ omlish/formats/json/cli/__main__.py,sha256=1wxxKZVkj_u7HCcewwMIbGuZj_Wph95yrUbm4
200
200
  omlish/formats/json/cli/cli.py,sha256=GkdNokklRuDWiXAIai1wijSBFVJlpdlNLTQ3Lyucos0,5493
201
201
  omlish/formats/json/cli/formats.py,sha256=tqEZKby4HeafGcaUs-m8B-2ZV12dRo40rzL-V99cp00,1714
202
202
  omlish/formats/json/stream/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
203
- omlish/formats/json/stream/build.py,sha256=2Bikvvcaqad85J3kvmD6I5Dqp8NstyP6Gb2COeN-lxs,2780
203
+ omlish/formats/json/stream/build.py,sha256=6deXBxTx1toFAPShz2Jo5OiXxH5Y4ppG8gDPRFoUgjA,2461
204
204
  omlish/formats/json/stream/lex.py,sha256=hMnsZld72XE7GCWdjbUANRxrruuBSSQeCm8wypMiMv0,6172
205
205
  omlish/formats/json/stream/parse.py,sha256=WkbW7tvcdrTSluKhw70nPvjsq943eryVcjx8FSz78tM,5198
206
206
  omlish/formats/json/stream/render.py,sha256=B9ZNuBiDJOT25prhIsZu1ICKjxk4eMPwpgQF37NPufs,3212
@@ -453,9 +453,9 @@ omlish/text/delimit.py,sha256=ubPXcXQmtbOVrUsNh5gH1mDq5H-n1y2R4cPL5_DQf68,4928
453
453
  omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,3296
454
454
  omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
455
455
  omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
456
- omlish-0.0.0.dev83.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
457
- omlish-0.0.0.dev83.dist-info/METADATA,sha256=3V-8-n6HgqRRGC2ot30034BVPmmVkrX9-QfCfx7sLSQ,4047
458
- omlish-0.0.0.dev83.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
459
- omlish-0.0.0.dev83.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
460
- omlish-0.0.0.dev83.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
461
- omlish-0.0.0.dev83.dist-info/RECORD,,
456
+ omlish-0.0.0.dev84.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
457
+ omlish-0.0.0.dev84.dist-info/METADATA,sha256=Ui6NExa9RJ31Hhf-FtoRkeGzkSw-2RiAy2bI-1Octl8,3987
458
+ omlish-0.0.0.dev84.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
459
+ omlish-0.0.0.dev84.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
460
+ omlish-0.0.0.dev84.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
461
+ omlish-0.0.0.dev84.dist-info/RECORD,,