omlish 0.0.0.dev85__py3-none-any.whl → 0.0.0.dev86__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.dev85'
2
- __revision__ = '24c65e4f91478fb31341b3508843574da87b8786-untracked'
1
+ __version__ = '0.0.0.dev86'
2
+ __revision__ = '39be25efaa0206ceb3478be1878e14671f5940f1'
3
3
 
4
4
 
5
5
  #
@@ -52,14 +52,18 @@ SCALAR_VALUE_TYPES: tuple[type, ...] = tuple(
52
52
  ##
53
53
 
54
54
 
55
+ class Position(ta.NamedTuple):
56
+ ofs: int
57
+ line: int
58
+ col: int
59
+
60
+
55
61
  class Token(ta.NamedTuple):
56
62
  kind: TokenKind
57
63
  value: ScalarValue
58
64
  raw: str | None
59
65
 
60
- ofs: int
61
- line: int
62
- col: int
66
+ pos: Position
63
67
 
64
68
  def __iter__(self):
65
69
  raise TypeError
@@ -94,9 +98,7 @@ CONST_TOKENS: ta.Mapping[str, tuple[TokenKind, str | float | None]] = {
94
98
  class JsonLexError(Exception):
95
99
  message: str
96
100
 
97
- ofs: int
98
- line: int
99
- col: int
101
+ pos: Position
100
102
 
101
103
 
102
104
  class JsonStreamLexer(GenMachine[str, Token]):
@@ -108,13 +110,21 @@ class JsonStreamLexer(GenMachine[str, Token]):
108
110
  self._include_raw = include_raw
109
111
 
110
112
  self._ofs = 0
111
- self._line = 0
113
+ self._line = 1
112
114
  self._col = 0
113
115
 
114
116
  self._buf = io.StringIO()
115
117
 
116
118
  super().__init__(self._do_main())
117
119
 
120
+ @property
121
+ def pos(self) -> Position:
122
+ return Position(
123
+ self._ofs,
124
+ self._line,
125
+ self._col,
126
+ )
127
+
118
128
  def _char_in(self, c: str) -> str:
119
129
  if c and len(c) != 1:
120
130
  raise ValueError(c)
@@ -134,14 +144,13 @@ class JsonStreamLexer(GenMachine[str, Token]):
134
144
  kind: TokenKind,
135
145
  value: ScalarValue,
136
146
  raw: str,
147
+ pos: Position,
137
148
  ) -> ta.Sequence[Token]:
138
149
  tok = Token(
139
150
  kind,
140
151
  value,
141
152
  raw if self._include_raw else None,
142
- self._ofs,
143
- self._line,
144
- self._col,
153
+ pos,
145
154
  )
146
155
  return (tok,)
147
156
 
@@ -152,7 +161,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
152
161
  return raw
153
162
 
154
163
  def _raise(self, msg: str) -> ta.NoReturn:
155
- raise JsonLexError(msg, self._ofs, self._line, self._col)
164
+ raise JsonLexError(msg, self.pos)
156
165
 
157
166
  def _do_main(self):
158
167
  while True:
@@ -165,7 +174,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
165
174
  continue
166
175
 
167
176
  if c in CONTROL_TOKENS:
168
- yield self._make_tok(CONTROL_TOKENS[c], c, c)
177
+ yield self._make_tok(CONTROL_TOKENS[c], c, c, self.pos)
169
178
  continue
170
179
 
171
180
  if c == '"':
@@ -180,8 +189,11 @@ class JsonStreamLexer(GenMachine[str, Token]):
180
189
  self._raise(f'Unexpected character: {c}')
181
190
 
182
191
  def _do_string(self):
192
+ check.state(self._buf.tell() == 0)
183
193
  self._buf.write('"')
184
194
 
195
+ pos = self.pos
196
+
185
197
  last = None
186
198
  while True:
187
199
  try:
@@ -199,13 +211,16 @@ class JsonStreamLexer(GenMachine[str, Token]):
199
211
 
200
212
  raw = self._flip_buf()
201
213
  sv = json.loads(raw)
202
- yield self._make_tok('STRING', sv, raw)
214
+ yield self._make_tok('STRING', sv, raw, pos)
203
215
 
204
216
  return self._do_main()
205
217
 
206
218
  def _do_number(self, c: str):
219
+ check.state(self._buf.tell() == 0)
207
220
  self._buf.write(c)
208
221
 
222
+ pos = self.pos
223
+
209
224
  while True:
210
225
  try:
211
226
  c = self._char_in((yield None)) # noqa
@@ -240,7 +255,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
240
255
  self._raise(f'Invalid number format: {raw}')
241
256
 
242
257
  tk, tv = CONST_TOKENS[raw]
243
- yield self._make_tok(tk, tv, raw)
258
+ yield self._make_tok(tk, tv, raw, pos)
244
259
 
245
260
  return self._do_main()
246
261
 
@@ -250,7 +265,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
250
265
  nv = float(raw)
251
266
  else:
252
267
  nv = int(raw)
253
- yield self._make_tok('NUMBER', nv, raw)
268
+ yield self._make_tok('NUMBER', nv, raw, pos)
254
269
 
255
270
  #
256
271
 
@@ -258,7 +273,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
258
273
  return None
259
274
 
260
275
  if c in CONTROL_TOKENS:
261
- yield self._make_tok(CONTROL_TOKENS[c], c, c)
276
+ yield self._make_tok(CONTROL_TOKENS[c], c, c, pos)
262
277
 
263
278
  elif not c.isspace():
264
279
  self._raise(f'Unexpected character after number: {c}')
@@ -266,6 +281,7 @@ class JsonStreamLexer(GenMachine[str, Token]):
266
281
  return self._do_main()
267
282
 
268
283
  def _do_const(self, c: str):
284
+ pos = self.pos
269
285
  raw = c
270
286
  while True:
271
287
  try:
@@ -280,6 +296,6 @@ class JsonStreamLexer(GenMachine[str, Token]):
280
296
  self._raise(f'Invalid literal: {raw}')
281
297
 
282
298
  tk, tv = CONST_TOKENS[raw]
283
- yield self._make_tok(tk, tv, raw)
299
+ yield self._make_tok(tk, tv, raw, pos)
284
300
 
285
301
  return self._do_main()
omlish/http/sse.py CHANGED
@@ -1,6 +1,9 @@
1
1
  """
2
2
  TODO:
3
3
  - end-of-line = ( cr lf / cr / lf )
4
+
5
+ See:
6
+ - https://github.com/florimondmanca/httpx-sse/blob/master/src/httpx_sse/_decoders.py
4
7
  """
5
8
  import string
6
9
  import typing as ta
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: omlish
3
- Version: 0.0.0.dev85
3
+ Version: 0.0.0.dev86
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=k58Z80qSth9c-pBdbNtNHrjB2AYw-SW6T3eOVAZW-eU,3355
2
+ omlish/__about__.py,sha256=bmf1Xnu5T4--9ykGD63NIvhEZE9Fhk9w3IlmwLH40vU,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
@@ -201,7 +201,7 @@ omlish/formats/json/cli/cli.py,sha256=GkdNokklRuDWiXAIai1wijSBFVJlpdlNLTQ3Lyucos
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=hMnsZld72XE7GCWdjbUANRxrruuBSSQeCm8wypMiMv0,6172
204
+ omlish/formats/json/stream/lex.py,sha256=01K_M9na7-3xv0h3VDBobLXuTS-w4YesNJ6GhOaDtYA,6494
205
205
  omlish/formats/json/stream/parse.py,sha256=WkbW7tvcdrTSluKhw70nPvjsq943eryVcjx8FSz78tM,5198
206
206
  omlish/formats/json/stream/render.py,sha256=B9ZNuBiDJOT25prhIsZu1ICKjxk4eMPwpgQF37NPufs,3212
207
207
  omlish/graphs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -224,7 +224,7 @@ omlish/http/headers.py,sha256=ZMmjrEiYjzo0YTGyK0YsvjdwUazktGqzVVYorY4fd44,5081
224
224
  omlish/http/json.py,sha256=9XwAsl4966Mxrv-1ytyCqhcE6lbBJw-0_tFZzGszgHE,7440
225
225
  omlish/http/multipart.py,sha256=R9ycpHsXRcmh0uoc43aYb7BdWL-8kSQHe7J-M81aQZM,2240
226
226
  omlish/http/sessions.py,sha256=VZ_WS5uiQG5y7i3u8oKuQMqf8dPKUOjFm_qk_0OvI8c,4793
227
- omlish/http/sse.py,sha256=T2_EXTcDfEhCF4E9B68YtEYLFb803MPnh8eCNjdPlRo,2223
227
+ omlish/http/sse.py,sha256=MDs9RvxQXoQliImcc6qK1ERajEYM7Q1l8xmr-9ceNBc,2315
228
228
  omlish/http/wsgi.py,sha256=czZsVUX-l2YTlMrUjKN49wRoP4rVpS0qpeBn4O5BoMY,948
229
229
  omlish/inject/__init__.py,sha256=JQ7x8l9MjU-kJ5ap7cPVq7SY7zbbCIrjyJAF0UeE5-s,1886
230
230
  omlish/inject/binder.py,sha256=H8AQ4ecmBOtDL8fMgrU1yUJl1gBADLNcdysRbvO8Wso,4167
@@ -454,9 +454,9 @@ omlish/text/delimit.py,sha256=ubPXcXQmtbOVrUsNh5gH1mDq5H-n1y2R4cPL5_DQf68,4928
454
454
  omlish/text/glyphsplit.py,sha256=Ug-dPRO7x-OrNNr8g1y6DotSZ2KH0S-VcOmUobwa4B0,3296
455
455
  omlish/text/indent.py,sha256=6Jj6TFY9unaPa4xPzrnZemJ-fHsV53IamP93XGjSUHs,1274
456
456
  omlish/text/parts.py,sha256=7vPF1aTZdvLVYJ4EwBZVzRSy8XB3YqPd7JwEnNGGAOo,6495
457
- omlish-0.0.0.dev85.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
458
- omlish-0.0.0.dev85.dist-info/METADATA,sha256=qZazqEAxsweclSEJaWK9VAPkIIz48Xl30VrfFamUMi0,3987
459
- omlish-0.0.0.dev85.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
460
- omlish-0.0.0.dev85.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
461
- omlish-0.0.0.dev85.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
462
- omlish-0.0.0.dev85.dist-info/RECORD,,
457
+ omlish-0.0.0.dev86.dist-info/LICENSE,sha256=B_hVtavaA8zCYDW99DYdcpDLKz1n3BBRjZrcbv8uG8c,1451
458
+ omlish-0.0.0.dev86.dist-info/METADATA,sha256=w6dXN4XU0iMfkJxV1fEHQ96o_V5idhf7cy3GApDwdAc,3987
459
+ omlish-0.0.0.dev86.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
460
+ omlish-0.0.0.dev86.dist-info/entry_points.txt,sha256=Lt84WvRZJskWCAS7xnQGZIeVWksprtUHj0llrvVmod8,35
461
+ omlish-0.0.0.dev86.dist-info/top_level.txt,sha256=pePsKdLu7DvtUiecdYXJ78iO80uDNmBlqe-8hOzOmfs,7
462
+ omlish-0.0.0.dev86.dist-info/RECORD,,