omlish 0.0.0.dev148__py3-none-any.whl → 0.0.0.dev150__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,5 @@
1
1
  # ruff: noqa: UP006 UP007
2
+ # @omlish-lite
2
3
  # PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
3
4
  # --------------------------------------------
4
5
  #
@@ -62,11 +63,9 @@ import textwrap
62
63
  import time
63
64
  import typing as ta
64
65
 
65
- from ..check import check_isinstance
66
- from ..check import check_none
67
- from ..check import check_not_none
68
- from ..socket import SocketAddress
69
- from ..socket import SocketHandler
66
+ from ..lite.check import check
67
+ from ..lite.socket import SocketAddress
68
+ from ..lite.socket import SocketHandler
70
69
  from .handlers import HttpHandler
71
70
  from .handlers import HttpHandlerRequest
72
71
  from .handlers import UnsupportedMethodHttpHandlerError
@@ -406,13 +405,13 @@ class CoroHttpServer:
406
405
  yield o
407
406
 
408
407
  elif isinstance(o, self.AnyReadIo):
409
- i = check_isinstance((yield o), bytes)
408
+ i = check.isinstance((yield o), bytes)
410
409
 
411
410
  elif isinstance(o, self._Response):
412
411
  i = None
413
412
  r = self._preprocess_response(o)
414
413
  b = self._build_response_bytes(r)
415
- check_none((yield self.WriteIo(b)))
414
+ check.none((yield self.WriteIo(b)))
416
415
 
417
416
  else:
418
417
  raise TypeError(o)
@@ -435,7 +434,7 @@ class CoroHttpServer:
435
434
  sz = next(gen)
436
435
  while True:
437
436
  try:
438
- line = check_isinstance((yield self.ReadLineIo(sz)), bytes)
437
+ line = check.isinstance((yield self.ReadLineIo(sz)), bytes)
439
438
  sz = gen.send(line)
440
439
  except StopIteration as e:
441
440
  parsed = e.value
@@ -454,11 +453,11 @@ class CoroHttpServer:
454
453
  yield self._build_error_response(err)
455
454
  return
456
455
 
457
- parsed = check_isinstance(parsed, ParsedHttpRequest)
456
+ parsed = check.isinstance(parsed, ParsedHttpRequest)
458
457
 
459
458
  # Log
460
459
 
461
- check_none((yield self.ParsedRequestLogIo(parsed)))
460
+ check.none((yield self.ParsedRequestLogIo(parsed)))
462
461
 
463
462
  # Handle CONTINUE
464
463
 
@@ -474,7 +473,7 @@ class CoroHttpServer:
474
473
 
475
474
  request_data: ta.Optional[bytes]
476
475
  if (cl := parsed.headers.get('Content-Length')) is not None:
477
- request_data = check_isinstance((yield self.ReadIo(int(cl))), bytes)
476
+ request_data = check.isinstance((yield self.ReadIo(int(cl))), bytes)
478
477
  else:
479
478
  request_data = None
480
479
 
@@ -482,7 +481,7 @@ class CoroHttpServer:
482
481
 
483
482
  handler_request = HttpHandlerRequest(
484
483
  client_address=self._client_address,
485
- method=check_not_none(parsed.method),
484
+ method=check.not_none(parsed.method),
486
485
  path=parsed.path,
487
486
  headers=parsed.headers,
488
487
  data=request_data,
@@ -1,9 +1,10 @@
1
1
  # ruff: noqa: UP006 UP007
2
+ # @omlish-lite
2
3
  import dataclasses as dc
3
4
  import http.server
4
5
  import typing as ta
5
6
 
6
- from ..socket import SocketAddress
7
+ from ..lite.socket import SocketAddress
7
8
  from .parsing import HttpHeaders
8
9
 
9
10
 
@@ -1,4 +1,5 @@
1
1
  # ruff: noqa: UP006 UP007
2
+ # @omlish-lite
2
3
  # PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
3
4
  # --------------------------------------------
4
5
  #
@@ -1,4 +1,5 @@
1
1
  # ruff: noqa: UP006 UP007
2
+ # @omlish-lite
2
3
  import typing as ta
3
4
 
4
5
 
omlish/io/__init__.py CHANGED
@@ -1,3 +0,0 @@
1
- from ..lite.io import ( # noqa
2
- DelimitingBuffer,
3
- )
@@ -1,11 +1,10 @@
1
1
  # ruff: noqa: UP007
2
+ # @omlish-lite
2
3
  import io
3
4
  import typing as ta
4
5
 
5
- from .check import check_isinstance
6
- from .check import check_non_empty
7
- from .check import check_not_none
8
- from .strings import attr_repr
6
+ from ..lite.check import check
7
+ from ..lite.strings import attr_repr
9
8
 
10
9
 
11
10
  class DelimitingBuffer:
@@ -39,7 +38,7 @@ class DelimitingBuffer:
39
38
  ) -> None:
40
39
  super().__init__()
41
40
 
42
- self._delimiters = frozenset(check_isinstance(d, int) for d in delimiters)
41
+ self._delimiters = frozenset(check.isinstance(d, int) for d in delimiters)
43
42
  self._keep_ends = keep_ends
44
43
  self._max_size = max_size
45
44
 
@@ -70,7 +69,7 @@ class DelimitingBuffer:
70
69
  return r
71
70
 
72
71
  def _append_and_reset(self, chunk: bytes) -> bytes:
73
- buf = check_not_none(self._buf)
72
+ buf = check.not_none(self._buf)
74
73
  if not buf.tell():
75
74
  return chunk
76
75
 
@@ -192,7 +191,7 @@ class IncrementalWriteBuffer:
192
191
  ) -> None:
193
192
  super().__init__()
194
193
 
195
- check_non_empty(data)
194
+ check.not_empty(data)
196
195
  self._len = len(data)
197
196
  self._write_size = write_size
198
197
 
@@ -207,11 +206,11 @@ class IncrementalWriteBuffer:
207
206
  return self._len - self._pos
208
207
 
209
208
  def write(self, fn: ta.Callable[[bytes], int]) -> int:
210
- lst = check_non_empty(self._lst)
209
+ lst = check.not_empty(self._lst)
211
210
 
212
211
  t = 0
213
212
  for i, d in enumerate(lst): # noqa
214
- n = fn(check_non_empty(d))
213
+ n = fn(check.not_empty(d))
215
214
  if not n:
216
215
  break
217
216
  t += n
@@ -2,15 +2,12 @@
2
2
  import socket
3
3
  import typing as ta
4
4
 
5
- from ..check import check_isinstance
6
- from ..check import check_none
7
- from ..check import check_not_none
8
- from ..check import check_state
9
- from ..http.coroserver import CoroHttpServer
10
- from ..http.handlers import HttpHandler
11
- from ..io import IncrementalWriteBuffer
12
- from ..io import ReadableListBuffer
13
- from ..socket import SocketAddress
5
+ from ...http.coroserver import CoroHttpServer
6
+ from ...http.handlers import HttpHandler
7
+ from ...lite.check import check
8
+ from ...lite.socket import SocketAddress
9
+ from ..buffers import IncrementalWriteBuffer
10
+ from ..buffers import ReadableListBuffer
14
11
  from .handlers import SocketFdioHandler
15
12
 
16
13
 
@@ -25,7 +22,7 @@ class CoroHttpServerConnectionFdioHandler(SocketFdioHandler):
25
22
  write_size: int = 0x10000,
26
23
  log_handler: ta.Optional[ta.Callable[[CoroHttpServer, CoroHttpServer.AnyLogIo], None]] = None,
27
24
  ) -> None:
28
- check_state(not sock.getblocking())
25
+ check.state(not sock.getblocking())
29
26
 
30
27
  super().__init__(addr, sock)
31
28
 
@@ -49,7 +46,7 @@ class CoroHttpServerConnectionFdioHandler(SocketFdioHandler):
49
46
  #
50
47
 
51
48
  def _next_io(self) -> None: # noqa
52
- coro = check_not_none(self._srv_coro)
49
+ coro = check.not_none(self._srv_coro)
53
50
 
54
51
  d: bytes | None = None
55
52
  o = self._cur_io
@@ -82,7 +79,7 @@ class CoroHttpServerConnectionFdioHandler(SocketFdioHandler):
82
79
  o = None
83
80
 
84
81
  elif isinstance(o, CoroHttpServer.WriteIo):
85
- check_none(self._write_buf)
82
+ check.none(self._write_buf)
86
83
  self._write_buf = IncrementalWriteBuffer(o.data, write_size=self._write_size)
87
84
  break
88
85
 
@@ -103,7 +100,7 @@ class CoroHttpServerConnectionFdioHandler(SocketFdioHandler):
103
100
 
104
101
  def on_readable(self) -> None:
105
102
  try:
106
- buf = check_not_none(self._sock).recv(self._read_size)
103
+ buf = check.not_none(self._sock).recv(self._read_size)
107
104
  except BlockingIOError:
108
105
  return
109
106
  except ConnectionResetError:
@@ -119,12 +116,12 @@ class CoroHttpServerConnectionFdioHandler(SocketFdioHandler):
119
116
  self._next_io()
120
117
 
121
118
  def on_writable(self) -> None:
122
- check_isinstance(self._cur_io, CoroHttpServer.WriteIo)
123
- wb = check_not_none(self._write_buf)
119
+ check.isinstance(self._cur_io, CoroHttpServer.WriteIo)
120
+ wb = check.not_none(self._write_buf)
124
121
  while wb.rem > 0:
125
122
  def send(d: bytes) -> int:
126
123
  try:
127
- return check_not_none(self._sock).send(d)
124
+ return check.not_none(self._sock).send(d)
128
125
  except ConnectionResetError:
129
126
  self.close()
130
127
  return 0
@@ -3,8 +3,8 @@ import abc
3
3
  import socket
4
4
  import typing as ta
5
5
 
6
- from ..check import check_not_none
7
- from ..socket import SocketAddress
6
+ from ...lite.check import check
7
+ from ...lite.socket import SocketAddress
8
8
 
9
9
 
10
10
  class FdioHandler(abc.ABC):
@@ -55,7 +55,7 @@ class SocketFdioHandler(FdioHandler, abc.ABC):
55
55
  self._sock: ta.Optional[socket.socket] = sock
56
56
 
57
57
  def fd(self) -> int:
58
- return check_not_none(self._sock).fileno()
58
+ return check.not_none(self._sock).fileno()
59
59
 
60
60
  @property
61
61
  def closed(self) -> bool:
@@ -8,10 +8,7 @@ import subprocess
8
8
  import sys
9
9
  import typing as ta
10
10
 
11
- from ..check import check_equal
12
- from ..check import check_isinstance
13
- from ..check import check_not_none
14
- from ..check import check_single
11
+ from ..check import check
15
12
  from ..logs import log
16
13
  from ..subprocesses import DEFAULT_SUBPROCESS_TRY_EXCEPTIONS
17
14
  from ..subprocesses import prepare_subprocess_invocation
@@ -36,7 +33,7 @@ async def asyncio_subprocess_popen(
36
33
  if shell:
37
34
  fac = functools.partial(
38
35
  asyncio.create_subprocess_shell,
39
- check_single(cmd),
36
+ check.single(cmd),
40
37
  )
41
38
  else:
42
39
  fac = functools.partial(
@@ -76,7 +73,7 @@ class AsyncioProcessCommunicator:
76
73
  self._proc = proc
77
74
  self._loop = loop
78
75
 
79
- self._transport: asyncio.base_subprocess.BaseSubprocessTransport = check_isinstance(
76
+ self._transport: asyncio.base_subprocess.BaseSubprocessTransport = check.isinstance(
80
77
  proc._transport, # type: ignore # noqa
81
78
  asyncio.base_subprocess.BaseSubprocessTransport,
82
79
  )
@@ -86,7 +83,7 @@ class AsyncioProcessCommunicator:
86
83
  return self._loop.get_debug()
87
84
 
88
85
  async def _feed_stdin(self, input: bytes) -> None: # noqa
89
- stdin = check_not_none(self._proc.stdin)
86
+ stdin = check.not_none(self._proc.stdin)
90
87
  try:
91
88
  if input is not None:
92
89
  stdin.write(input)
@@ -110,13 +107,13 @@ class AsyncioProcessCommunicator:
110
107
  return None
111
108
 
112
109
  async def _read_stream(self, fd: int) -> bytes:
113
- transport: ta.Any = check_not_none(self._transport.get_pipe_transport(fd))
110
+ transport: ta.Any = check.not_none(self._transport.get_pipe_transport(fd))
114
111
 
115
112
  if fd == 2:
116
- stream = check_not_none(self._proc.stderr)
113
+ stream = check.not_none(self._proc.stderr)
117
114
  else:
118
- check_equal(fd, 1)
119
- stream = check_not_none(self._proc.stdout)
115
+ check.equal(fd, 1)
116
+ stream = check.not_none(self._proc.stdout)
120
117
 
121
118
  if self._debug:
122
119
  name = 'stdout' if fd == 1 else 'stderr'
@@ -236,7 +233,7 @@ async def asyncio_subprocess_check_output(
236
233
  **kwargs,
237
234
  )
238
235
 
239
- return check_not_none(stdout)
236
+ return check.not_none(stdout)
240
237
 
241
238
 
242
239
  async def asyncio_subprocess_check_output_str(*args: str, **kwargs: ta.Any) -> str: