omlish 0.0.0.dev87__py3-none-any.whl → 0.0.0.dev88__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.dev87'
2
- __revision__ = '116137c4ae1e4aaf7ffb66a2847d4a38d6cce73e'
1
+ __version__ = '0.0.0.dev88'
2
+ __revision__ = 'ccf0f3b0ac6cc9e9ca522c8c4a9c8e6a4151bd7b'
3
3
 
4
4
 
5
5
  #
@@ -168,10 +168,9 @@ def _main() -> None:
168
168
  else:
169
169
  renderer = StreamJsonRenderer(
170
170
  out,
171
- StreamJsonRenderer.Options(
172
- **kw,
173
- style=term_color if args.color else None,
174
- ),
171
+ style=term_color if args.color else None,
172
+ delimiter='\n',
173
+ **kw,
175
174
  )
176
175
  build = None
177
176
 
@@ -198,7 +197,8 @@ def _main() -> None:
198
197
  if not buf:
199
198
  break
200
199
 
201
- out.write('\n')
200
+ if renderer is not None:
201
+ out.write('\n')
202
202
 
203
203
  else:
204
204
  with io.TextIOWrapper(in_file) as tw:
@@ -1,5 +1,4 @@
1
1
  import abc
2
- import dataclasses as dc
3
2
  import enum
4
3
  import io
5
4
  import json
@@ -20,35 +19,32 @@ class AbstractJsonRenderer(lang.Abstract, ta.Generic[I]):
20
19
  VALUE = enum.auto()
21
20
  KEY = enum.auto()
22
21
 
23
- @dc.dataclass(frozen=True, kw_only=True)
24
- class Options:
25
- indent: int | str | None = None
26
- separators: tuple[str, str] | None = None
27
- sort_keys: bool = False
28
- style: ta.Callable[[ta.Any, 'AbstractJsonRenderer.State'], tuple[str, str]] | None = None
29
-
30
22
  def __init__(
31
23
  self,
32
24
  out: JsonRendererOut,
33
- opts: Options = Options(),
25
+ *,
26
+ indent: int | str | None = None,
27
+ separators: tuple[str, str] | None = None,
28
+ sort_keys: bool = False,
29
+ style: ta.Callable[[ta.Any, State], tuple[str, str]] | None = None,
34
30
  ) -> None:
35
31
  super().__init__()
36
32
 
37
33
  self._out = out
38
- self._opts = opts
34
+ self._sort_keys = sort_keys
35
+ self._style = style
39
36
 
40
- separators = opts.separators
41
- if isinstance(opts.indent, (str, int)):
42
- self._indent = (' ' * opts.indent) if isinstance(opts.indent, int) else opts.indent
37
+ if isinstance(indent, (str, int)):
38
+ self._indent = (' ' * indent) if isinstance(indent, int) else indent
43
39
  self._endl = '\n'
44
40
  if separators is None:
45
41
  separators = (',', ': ')
46
- elif opts.indent is None:
42
+ elif indent is None:
47
43
  self._indent = self._endl = ''
48
44
  if separators is None:
49
45
  separators = (', ', ': ')
50
46
  else:
51
- raise TypeError(opts.indent)
47
+ raise TypeError(indent)
52
48
  self._comma, self._colon = separators
53
49
 
54
50
  self._level = 0
@@ -76,7 +72,7 @@ class AbstractJsonRenderer(lang.Abstract, ta.Generic[I]):
76
72
  @classmethod
77
73
  def render_str(cls, i: I, **kwargs: ta.Any) -> str:
78
74
  out = io.StringIO()
79
- cls(out, cls.Options(**kwargs)).render(i)
75
+ cls(out, **kwargs).render(i)
80
76
  return out.getvalue()
81
77
 
82
78
 
@@ -86,8 +82,8 @@ class JsonRenderer(AbstractJsonRenderer[ta.Any]):
86
82
  o: ta.Any,
87
83
  state: AbstractJsonRenderer.State = AbstractJsonRenderer.State.VALUE,
88
84
  ) -> None:
89
- if self._opts.style is not None:
90
- pre, post = self._opts.style(o, state)
85
+ if self._style is not None:
86
+ pre, post = self._style(o, state)
91
87
  self._write(pre)
92
88
  else:
93
89
  post = None
@@ -102,7 +98,7 @@ class JsonRenderer(AbstractJsonRenderer[ta.Any]):
102
98
  self._write('{')
103
99
  self._level += 1
104
100
  items = list(o.items())
105
- if self._opts.sort_keys:
101
+ if self._sort_keys:
106
102
  items.sort(key=lambda t: t[0])
107
103
  for i, (k, v) in enumerate(items):
108
104
  if i:
@@ -94,7 +94,7 @@ CONST_TOKENS: ta.Mapping[str, tuple[TokenKind, str | float | None]] = {
94
94
  ##
95
95
 
96
96
 
97
- @dc.dataclass(frozen=True)
97
+ @dc.dataclass()
98
98
  class JsonLexError(Exception):
99
99
  message: str
100
100
 
@@ -3,7 +3,6 @@ import typing as ta
3
3
 
4
4
  from ..render import AbstractJsonRenderer
5
5
  from ..render import JsonRendererOut
6
- from .build import JsonObjectBuilder
7
6
  from .parse import BeginArray
8
7
  from .parse import BeginObject
9
8
  from .parse import EndArray
@@ -19,23 +18,28 @@ class StreamJsonRenderer(AbstractJsonRenderer[ta.Iterable[JsonStreamParserEvent]
19
18
  def __init__(
20
19
  self,
21
20
  out: JsonRendererOut,
22
- opts: AbstractJsonRenderer.Options = AbstractJsonRenderer.Options(),
21
+ *,
22
+ delimiter: str = '',
23
+ sort_keys: bool = False,
24
+ **kwargs: ta.Any,
23
25
  ) -> None:
24
- if opts.sort_keys:
26
+ if sort_keys:
25
27
  raise TypeError('Not yet implemented')
26
28
 
27
- super().__init__(out, opts)
29
+ self._delimiter = delimiter
30
+
31
+ super().__init__(out, **kwargs)
28
32
 
29
33
  self._stack: list[tuple[ta.Literal['OBJECT', 'ARRAY'], int]] = []
30
- self._builder: JsonObjectBuilder | None = None
34
+ self._need_delimit = False
31
35
 
32
36
  def _render_value(
33
37
  self,
34
38
  o: ta.Any,
35
39
  state: AbstractJsonRenderer.State = AbstractJsonRenderer.State.VALUE,
36
40
  ) -> None:
37
- if self._opts.style is not None:
38
- pre, post = self._opts.style(o, state)
41
+ if self._style is not None:
42
+ pre, post = self._style(o, state)
39
43
  self._write(pre)
40
44
  else:
41
45
  post = None
@@ -53,6 +57,10 @@ class StreamJsonRenderer(AbstractJsonRenderer[ta.Iterable[JsonStreamParserEvent]
53
57
  self._write(post)
54
58
 
55
59
  def _render(self, e: JsonStreamParserEvent) -> None:
60
+ if self._need_delimit:
61
+ self._write(self._delimiter)
62
+ self._need_delimit = False
63
+
56
64
  if e != EndArray and self._stack and (tt := self._stack[-1])[0] == 'ARRAY':
57
65
  if tt[1]:
58
66
  self._write(self._comma)
@@ -64,6 +72,8 @@ class StreamJsonRenderer(AbstractJsonRenderer[ta.Iterable[JsonStreamParserEvent]
64
72
 
65
73
  if e is None or isinstance(e, (str, int, float, bool)):
66
74
  self._render_value(e)
75
+ if not self._stack:
76
+ self._need_delimit = True
67
77
 
68
78
  #
69
79
 
@@ -92,6 +102,8 @@ class StreamJsonRenderer(AbstractJsonRenderer[ta.Iterable[JsonStreamParserEvent]
92
102
  if tt[1]:
93
103
  self._write_indent()
94
104
  self._write('}')
105
+ if not self._stack:
106
+ self._need_delimit = True
95
107
 
96
108
  #
97
109
 
@@ -108,6 +120,8 @@ class StreamJsonRenderer(AbstractJsonRenderer[ta.Iterable[JsonStreamParserEvent]
108
120
  if tt[1]:
109
121
  self._write_indent()
110
122
  self._write(']')
123
+ if not self._stack:
124
+ self._need_delimit = True
111
125
 
112
126
  #
113
127
 
omlish/sql/dbapi.py CHANGED
@@ -69,6 +69,10 @@ class DbapiDriver:
69
69
 
70
70
 
71
71
  class DbapiDrivers(lang.Namespace):
72
+
73
+ ##
74
+ # sqlite
75
+
72
76
  SQLITE3 = DbapiDriver(
73
77
  name='sqlite3',
74
78
  dialect=DbapiDialect.SQLITE,
@@ -88,7 +92,8 @@ class DbapiDrivers(lang.Namespace):
88
92
  param_style=ParamStyle.QMARK,
89
93
  )
90
94
 
91
- #
95
+ ##
96
+ # mysql
92
97
 
93
98
  PYMYSQL = DbapiDriver(
94
99
  name='pymysql',
@@ -112,7 +117,8 @@ class DbapiDrivers(lang.Namespace):
112
117
  module_name='MySQLdb',
113
118
  )
114
119
 
115
- #
120
+ ##
121
+ # postgres
116
122
 
117
123
  PG8000 = DbapiDriver(
118
124
  name='pg8000',
@@ -132,7 +138,8 @@ class DbapiDrivers(lang.Namespace):
132
138
  param_style=ParamStyle.PYFORMAT,
133
139
  )
134
140
 
135
- #
141
+ ##
142
+ # snowflake
136
143
 
137
144
  SNOWFLAKE = DbapiDriver(
138
145
  name='snowflake',
@@ -18,11 +18,11 @@ from .stmts import Stmt
18
18
 
19
19
 
20
20
  class Values(dc.Frozen, lang.Final):
21
- vs: ta.Sequence[Expr]
21
+ vs: ta.Sequence[Expr] = dc.xfield(coerce=tuple)
22
22
 
23
23
 
24
24
  class Insert(Stmt, lang.Final):
25
- columns: ta.Sequence[Ident]
25
+ columns: ta.Sequence[Ident] = dc.xfield(coerce=tuple)
26
26
  into: Relation
27
27
  data: Values | Select
28
28
 
@@ -44,7 +44,7 @@ class SelectBuilder(ExprBuilder, RelationBuilder):
44
44
  where: CanExpr | None = None,
45
45
  ) -> Select:
46
46
  return Select(
47
- [self.select_item(i) for i in items],
47
+ tuple(self.select_item(i) for i in items),
48
48
  from_=self.relation(from_) if from_ is not None else None,
49
49
  where=self.expr(where) if where is not None else None,
50
50
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omlish
3
- Version: 0.0.0.dev87
3
+ Version: 0.0.0.dev88
4
4
  Summary: omlish
5
5
  Author: wrmsr
6
6
  License: BSD-3-Clause
@@ -1,5 +1,5 @@
1
1
  omlish/.manifests.json,sha256=hTFp9tvE72BxKloIq1s1SS0LRQlIsvMtO69Sbc47rKg,1704
2
- omlish/__about__.py,sha256=Q99g7Qxo_-Dt6G8U5KsZ2FKuyTgYrxju6TU7S9xtiok,3345
2
+ omlish/__about__.py,sha256=_pr15t5ifEAY1adRq4S8Fp21jhhRHPNo6mJlHz7_xBo,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
@@ -187,7 +187,7 @@ omlish/formats/json/__init__.py,sha256=xqW2APLGvCTO9dVTOlroR_AdrA5bCkdmUnbTkYHhJ
187
187
  omlish/formats/json/consts.py,sha256=u-x-qXqZvK0tWk3l3TrCTjk4mSjKmZ_ATdmd1hwHNAY,263
188
188
  omlish/formats/json/encoding.py,sha256=O4iIWle7W_-RwpOvJNlqOfkbnDyiQHexV5Za4hlrFzw,497
189
189
  omlish/formats/json/json.py,sha256=Mdqv2vdMi7gp96eV0BIYH5UdWpjWfsh-tSMZeywG-08,331
190
- omlish/formats/json/render.py,sha256=H6q1R3gL6ULAnfEhQRKDOzDJjWizdsRDYxIerBSEbq8,3797
190
+ omlish/formats/json/render.py,sha256=CRAh-DhfOcyjqM1DVBvZ22xl_h3jPPd_Hn0WqDYT3bo,3623
191
191
  omlish/formats/json/backends/__init__.py,sha256=gnaNDCxy_KmmPUPDnjxO5_WjuWxLGbI9FYWx8ZJuQUU,97
192
192
  omlish/formats/json/backends/base.py,sha256=WqtyoM82pyM0NyqpPwndrebr1bUVU1QlpmVQNrcAO8c,1114
193
193
  omlish/formats/json/backends/default.py,sha256=a-eM-Y1IHdpYvZFjazwq_orRncjtYR7BKxP_2kpEXog,322
@@ -197,13 +197,13 @@ omlish/formats/json/backends/std.py,sha256=PM00Kh9ZR2XzollHMEvdo35Eml1N-zFfRW-LO
197
197
  omlish/formats/json/backends/ujson.py,sha256=BNJCU4kluGHdqTUKLJEuHhE2m2TmqR7HEN289S0Eokg,2278
198
198
  omlish/formats/json/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
199
199
  omlish/formats/json/cli/__main__.py,sha256=1wxxKZVkj_u7HCcewwMIbGuZj_Wph95yrUbm474Op9M,188
200
- omlish/formats/json/cli/cli.py,sha256=GkdNokklRuDWiXAIai1wijSBFVJlpdlNLTQ3Lyucos0,5493
200
+ omlish/formats/json/cli/cli.py,sha256=a_Ak3x8U1ulK2EkG4DQ4XbfsV_4gz5YAigv43Ah_XlY,5491
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
203
  omlish/formats/json/stream/build.py,sha256=6deXBxTx1toFAPShz2Jo5OiXxH5Y4ppG8gDPRFoUgjA,2461
204
- omlish/formats/json/stream/lex.py,sha256=01K_M9na7-3xv0h3VDBobLXuTS-w4YesNJ6GhOaDtYA,6494
204
+ omlish/formats/json/stream/lex.py,sha256=_JYoWFRpo3_dQmT7xXCWGFNoBT4M8m97G9oGzwPZeo4,6483
205
205
  omlish/formats/json/stream/parse.py,sha256=WkbW7tvcdrTSluKhw70nPvjsq943eryVcjx8FSz78tM,5198
206
- omlish/formats/json/stream/render.py,sha256=B9ZNuBiDJOT25prhIsZu1ICKjxk4eMPwpgQF37NPufs,3212
206
+ omlish/formats/json/stream/render.py,sha256=EKQ9tstWgnVdSlzJWNpX3diaSZWzVGLgIzRaSZMVqKM,3549
207
207
  omlish/graphs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
208
208
  omlish/graphs/dags.py,sha256=zp55lYgUdRCxmADwiGDHeehMJczZFA_tzdWqy77icOk,3047
209
209
  omlish/graphs/domination.py,sha256=oCGoWzWTxLwow0LDyGjjEf2AjFiOiDz4WaBtczwSbsQ,7576
@@ -397,7 +397,7 @@ omlish/specs/openapi/marshal.py,sha256=ob_qUbT9-de86KhPjFccl_NP0liQcXK7Ao-b5Hn0V
397
397
  omlish/specs/openapi/openapi.py,sha256=y4h04jeB7ORJSVrcy7apaBdpwLjIyscv1Ub5SderH2c,12682
398
398
  omlish/sql/__init__.py,sha256=TpZLsEJKJzvJ0eMzuV8hwOJJbkxBCV1RZPUMLAVB6io,173
399
399
  omlish/sql/_abc.py,sha256=kiOitW_ZhTXrJanJ582wD7o9K69v6HXqDPkxuHEAxrc,1606
400
- omlish/sql/dbapi.py,sha256=j7iTExICb5as82j3OaxQ4ZBqmz0mrpaPCYot2k9JxCc,3127
400
+ omlish/sql/dbapi.py,sha256=5ghJH-HexsmDlYdWlhf00nCGQX2IC98_gxIxMkucOas,3195
401
401
  omlish/sql/dbs.py,sha256=lpdFmm2vTwLoBiVYGj9yPsVcTEYYNCxlYZZpjfChzkY,1870
402
402
  omlish/sql/params.py,sha256=Z4VPet6GhNqD1T_MXSWSHkdy3cpUEhST-OplC4B_fYI,4433
403
403
  omlish/sql/qualifiedname.py,sha256=rlW3gVmyucJbqwcxj_7BfK4X2HoXrMroZT2H45zPgJQ,2264
@@ -413,14 +413,14 @@ omlish/sql/queries/binary.py,sha256=dcEzeEn104AMPuQ7QrJU2O-YCN3SUdxB5S4jaWKOUqY,
413
413
  omlish/sql/queries/building.py,sha256=dIQyEqNef2egKAf5qO_aZvXxlAEfxIGWS23qvJ-ozqQ,591
414
414
  omlish/sql/queries/exprs.py,sha256=kAI5PmvfJ-TqEzzc9H4_womFShT1eA0jWSZH2j2Wg-c,1802
415
415
  omlish/sql/queries/idents.py,sha256=erW6fE9UapuvW1ZeLfGFz7yuW6zzktWIWmOuAHeF8_g,496
416
- omlish/sql/queries/inserts.py,sha256=PS3oqGjDgnjUd4sxHVpfKDQnsjG4_6KTseRzWyiJQl0,1229
416
+ omlish/sql/queries/inserts.py,sha256=Uo0ewnLPEt43dnX5AJWOC9ioViou7xYes7sGT9lD_0k,1281
417
417
  omlish/sql/queries/marshal.py,sha256=uLN_gOqiYHBQioZEvg7OREycY0bzKwzBw5mnbg_0cio,2938
418
418
  omlish/sql/queries/multi.py,sha256=7x6x-4jnPzxA6ZasBjnjFuhHFpWt5rGCua3UvuTMIJ0,837
419
419
  omlish/sql/queries/names.py,sha256=YiIyS6ehYMYrdLlUxMawV_Xf2zdi7RwVO9Qsxr_W4_4,772
420
420
  omlish/sql/queries/ops.py,sha256=B7IDfjr2DW5LJhWoNaY1WW90BJhe5ZtmxIELhWXbW-0,129
421
421
  omlish/sql/queries/relations.py,sha256=-d3n-dN17c3TPMZmzSplhWawllUzdq12XPDAuzoeMEQ,838
422
422
  omlish/sql/queries/rendering.py,sha256=QegTkbSGlGKen4U4XB2lqjpkt1WGaZUmXmVR2gm8UiU,5944
423
- omlish/sql/queries/selects.py,sha256=EcHlyKl5kGSY1d3GVxnImhGCTB6WvwQnlSA9eZanBqU,1364
423
+ omlish/sql/queries/selects.py,sha256=8dqm4KyrJvOsW3KHSO7qLEfPlZa7sJDp8puuGxrfvoA,1369
424
424
  omlish/sql/queries/stmts.py,sha256=pBqwD7dRlqMu6uh6vR3xaWOEgbZCcFWbOQ9ryYd17T4,441
425
425
  omlish/sql/queries/unary.py,sha256=MEYBDZn_H0bexmUrJeONOv5-gIpYowUaXOsEHeQM4ks,1144
426
426
  omlish/sql/tabledefs/__init__.py,sha256=TvtQsp-jJu6_ZahyCOFAaElSSBcRftNyJpdiDPGYCDk,190
@@ -456,9 +456,9 @@ omlish/text/delimit.py,sha256=ubPXcXQmtbOVrUsNh5gH1mDq5H-n1y2R4cPL5_DQf68,4928
456
456
  omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,3296
457
457
  omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
458
458
  omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
459
- omlish-0.0.0.dev87.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
460
- omlish-0.0.0.dev87.dist-info/METADATA,sha256=qGRlUmzNWBRYtFD05J2YIWoeH_zcIAR6kKj3hBa6x9s,3987
461
- omlish-0.0.0.dev87.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
462
- omlish-0.0.0.dev87.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
463
- omlish-0.0.0.dev87.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
464
- omlish-0.0.0.dev87.dist-info/RECORD,,
459
+ omlish-0.0.0.dev88.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
460
+ omlish-0.0.0.dev88.dist-info/METADATA,sha256=_sR0eXqLj64VXjpIND0FJ_jFD56oVh9f7QXetS_XP0g,3987
461
+ omlish-0.0.0.dev88.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
462
+ omlish-0.0.0.dev88.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
463
+ omlish-0.0.0.dev88.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
464
+ omlish-0.0.0.dev88.dist-info/RECORD,,