-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
__init__.pyi
808 lines (740 loc) · 26.8 KB
/
__init__.pyi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
from abc import ABCMeta
from typing import (
Any,
AnyStr,
AsyncContextManager,
AsyncIterator,
Awaitable,
Callable,
ContextManager,
FrozenSet,
Generic,
Iterator,
Mapping,
NoReturn,
Optional,
Union,
Sequence,
TypeVar,
Tuple,
List,
Iterable,
TextIO,
BinaryIO,
IO,
overload,
)
from _typeshed import StrOrBytesPath
from _typeshed import OpenBinaryMode, OpenTextMode, ReadableBuffer, WriteableBuffer
from trio_typing import TaskStatus, takes_callable_and_args
from typing_extensions import Protocol, Literal
from mypy_extensions import NamedArg, VarArg
import signal
import io
import os
import pathlib
import subprocess
import ssl
import sys
import trio
from . import lowlevel as lowlevel, socket as socket, abc as abc
from . import to_thread as to_thread, from_thread as from_thread
T = TypeVar("T")
T_co = TypeVar("T_co", covariant=True)
T_contra = TypeVar("T_contra", contravariant=True)
class _Statistics:
def __getattr__(self, name: str) -> Any: ...
# Inheriting from this (even outside of stubs) produces a class that
# mypy thinks is abstract, but the interpreter thinks is concrete.
class _NotConstructible(Protocol):
_objects_of_this_type_are_not_directly_constructible: None
# _core._exceptions
class TrioInternalError(Exception):
pass
class RunFinishedError(Exception):
pass
class WouldBlock(Exception):
pass
class BusyResourceError(Exception):
pass
class ClosedResourceError(Exception):
pass
class BrokenResourceError(Exception):
pass
class EndOfChannel(Exception):
pass
class NoHandshakeError(Exception):
pass
class Cancelled(BaseException, _NotConstructible, metaclass=ABCMeta):
pass
# _core._multierror
class MultiError(BaseException):
exceptions: List[BaseException]
def __init__(self, exceptions: Sequence[BaseException]): ...
@classmethod
def filter(
cls,
handler: Callable[[BaseException], Optional[BaseException]],
root_exc: BaseException,
) -> BaseException: ...
@classmethod
def catch(
cls, handler: Callable[[BaseException], Optional[BaseException]]
) -> ContextManager[None]: ...
# _core._run
TASK_STATUS_IGNORED: TaskStatus[Any]
class CancelScope:
deadline: float
shield: bool
cancel_called: bool
cancelled_caught: bool
def __init__(self, *, deadline: float = ..., shield: bool = ...): ...
def __enter__(self) -> CancelScope: ...
def __exit__(self, *exc: object) -> bool: ...
def cancel(self) -> None: ...
class Nursery(_NotConstructible, metaclass=ABCMeta):
cancel_scope: CancelScope
@property
def child_tasks(self) -> FrozenSet[trio.lowlevel.Task]: ...
@property
def parent_task(self) -> trio.lowlevel.Task: ...
@takes_callable_and_args
def start_soon(
self,
async_fn: Union[
# List these explicitly instead of Callable[..., Awaitable[Any]]
# so that even without the plugin we catch cases of passing a
# function with keyword-only arguments to start_soon().
Callable[[], Awaitable[Any]],
Callable[[Any], Awaitable[Any]],
Callable[[Any, Any], Awaitable[Any]],
Callable[[Any, Any, Any], Awaitable[Any]],
Callable[[Any, Any, Any, Any], Awaitable[Any]],
Callable[[VarArg()], Awaitable[Any]],
],
*args: Any,
name: object = None,
) -> None: ...
@takes_callable_and_args
async def start(
self,
async_fn: Union[
# List these explicitly instead of Callable[..., Awaitable[Any]]
# so that even without the plugin we can infer the return type
# of start(), and fail when a function is passed that doesn't
# accept task_status.
Callable[[NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]],
Callable[[Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]],
Callable[
[Any, Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]
],
Callable[
[Any, Any, Any, NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]
],
Callable[
[Any, Any, Any, Any, NamedArg(TaskStatus[T], "task_status")],
Awaitable[Any],
],
Callable[
[VarArg(), NamedArg(TaskStatus[T], "task_status")], Awaitable[Any]
],
],
*args: Any,
name: object = None,
) -> T: ...
def open_nursery() -> AsyncContextManager[Nursery]: ...
def current_effective_deadline() -> float: ...
def current_time() -> float: ...
@takes_callable_and_args
def run(
afn: Union[Callable[..., Awaitable[T]], Callable[[VarArg()], Awaitable[T]]],
*args: Any,
clock: Optional[trio.abc.Clock] = ...,
instruments: Sequence[trio.abc.Instrument] = ...,
restrict_keyboard_interrupt_to_checkpoints: bool = ...,
) -> T: ...
# _timeouts
def move_on_at(deadline: float) -> CancelScope: ...
def move_on_after(seconds: float) -> CancelScope: ...
async def sleep_forever() -> NoReturn: ...
async def sleep_until(deadline: float) -> None: ...
async def sleep(seconds: float) -> None: ...
def fail_at(deadline: float) -> ContextManager[CancelScope]: ...
def fail_after(seconds: float) -> ContextManager[CancelScope]: ...
class TooSlowError(Exception):
pass
# _sync
class Event:
def is_set(self) -> bool: ...
def set(self) -> None: ...
async def wait(self) -> None: ...
def statistics(self) -> _Statistics: ...
class CapacityLimiter:
# float here really means Union[int, math.inf] but mypy doesn't
# understand that
total_tokens: float
borrowed_tokens: int
available_tokens: float
def __init__(self, total_tokens: float): ...
def acquire_nowait(self) -> None: ...
def acquire_on_behalf_of_nowait(self, borrower: object) -> None: ...
async def acquire(self) -> None: ...
async def acquire_on_behalf_of(self, borrower: object) -> None: ...
def release(self) -> None: ...
def release_on_behalf_of(self, borrower: object) -> None: ...
def statistics(self) -> _Statistics: ...
async def __aenter__(self) -> None: ...
async def __aexit__(self, *exc: object) -> None: ...
class Semaphore:
value: int
max_value: Optional[int]
def __init__(self, initial_value: int, *, max_value: Optional[int] = None): ...
def acquire_nowait(self) -> None: ...
async def acquire(self) -> None: ...
def release(self) -> None: ...
def statistics(self) -> _Statistics: ...
async def __aenter__(self) -> None: ...
async def __aexit__(self, *exc: object) -> None: ...
class Lock:
def locked(self) -> bool: ...
def acquire_nowait(self) -> None: ...
async def acquire(self) -> None: ...
def release(self) -> None: ...
def statistics(self) -> _Statistics: ...
async def __aenter__(self) -> None: ...
async def __aexit__(self, *exc: object) -> None: ...
class StrictFIFOLock(Lock):
pass
class Condition:
def __init__(self, lock: Optional[Lock] = None) -> None: ...
def locked(self) -> bool: ...
def acquire_nowait(self) -> None: ...
async def acquire(self) -> None: ...
def release(self) -> None: ...
async def wait(self) -> None: ...
def notify(self, n: int = 1) -> None: ...
def notify_all(self) -> None: ...
def statistics(self) -> _Statistics: ...
async def __aenter__(self) -> None: ...
async def __aexit__(self, *exc: object) -> None: ...
# _highlevel_generic
async def aclose_forcefully(resource: trio.abc.AsyncResource) -> None: ...
class StapledStream(trio.abc.HalfCloseableStream):
send_stream: trio.abc.SendStream
receive_stream: trio.abc.ReceiveStream
def __init__(
self, send_stream: trio.abc.SendStream, receive_stream: trio.abc.ReceiveStream
) -> None: ...
async def aclose(self) -> None: ...
async def send_all(self, data: Union[bytes, memoryview]) -> None: ...
async def wait_send_all_might_not_block(self) -> None: ...
async def receive_some(self, max_bytes: Optional[int] = ...) -> bytes: ...
async def send_eof(self) -> None: ...
# _channel
class MemorySendChannel(trio.abc.SendChannel[T_contra]):
def send_nowait(self, value: T_contra) -> None: ...
async def send(self, value: T_contra) -> None: ...
def clone(self: T) -> T: ...
async def aclose(self) -> None: ...
def statistics(self) -> _Statistics: ...
def close(self) -> None: ...
def __enter__(self) -> MemorySendChannel[T_contra]: ...
def __exit__(self, *exc: object) -> None: ...
class MemoryReceiveChannel(trio.abc.ReceiveChannel[T_co]):
def receive_nowait(self) -> T_co: ...
async def receive(self) -> T_co: ...
def clone(self: T) -> T: ...
async def aclose(self) -> None: ...
def statistics(self) -> _Statistics: ...
def close(self) -> None: ...
def __enter__(self) -> MemoryReceiveChannel[T_co]: ...
def __exit__(self, *exc: object) -> None: ...
# written as a class so you can say open_memory_channel[int](5)
class open_memory_channel(Tuple[MemorySendChannel[T], MemoryReceiveChannel[T]]):
def __new__( # type: ignore[misc] # "must return a subtype"
cls, max_buffer_size: float
) -> Tuple[MemorySendChannel[T], MemoryReceiveChannel[T]]: ...
def __init__(self, max_buffer_size: float): ...
# _signals
def open_signal_receiver(
*signals: signal.Signals,
) -> ContextManager[AsyncIterator[int]]: ...
# _highlevel_socket
class SocketStream(trio.abc.HalfCloseableStream):
socket: trio.socket.SocketType
def __init__(self, socket: trio.socket.SocketType) -> None: ...
def setsockopt(self, level: int, option: int, value: Union[int, bytes]) -> None: ...
@overload
def getsockopt(self, level: int, optname: int) -> int: ...
@overload
def getsockopt(self, level: int, optname: int, buflen: int) -> bytes: ...
async def aclose(self) -> None: ...
async def send_all(self, data: Union[bytes, memoryview]) -> None: ...
async def wait_send_all_might_not_block(self) -> None: ...
async def receive_some(self, max_bytes: Optional[int] = ...) -> bytes: ...
async def send_eof(self) -> None: ...
class SocketListener(trio.abc.Listener[SocketStream]):
socket: trio.socket.SocketType
def __init__(self, socket: trio.socket.SocketType) -> None: ...
async def accept(self) -> SocketStream: ...
async def aclose(self) -> None: ...
# _file_io
# The actual Trio I/O classes use metaprogramming to forward their methods
# to a regular non-async underlying I/O object. We represent this by replicating
# the I/O type hierarchy (ABCs from typing.pyi and implementations from io.pyi)
# with additional 'async' on the necessary methods.
# ABCs: (from typing.pyi, with more async)
class AsyncIO(AsyncIterator[AnyStr], Generic[AnyStr], trio.abc.AsyncResource):
mode: str
name: Union[str, int] # whatever was passed to open()
closed: bool
async def aclose(self) -> None: ...
def fileno(self) -> int: ...
async def flush(self) -> None: ...
def isatty(self) -> bool: ...
async def read(self, n: int = ...) -> AnyStr: ...
def readable(self) -> bool: ...
async def readline(self, limit: int = ...) -> AnyStr: ...
async def readlines(self, hint: int = ...) -> list[AnyStr]: ...
async def seek(self, offset: int, whence: int = ...) -> int: ...
def seekable(self) -> bool: ...
async def tell(self) -> int: ...
async def truncate(self, size: Optional[int] = ...) -> int: ...
def writable(self) -> bool: ...
async def write(self, s: AnyStr) -> int: ...
async def writelines(self, lines: Iterable[AnyStr]) -> None: ...
async def __anext__(self) -> AnyStr: ...
def __aiter__(self) -> AsyncIterator[AnyStr]: ...
async def __aenter__(self: T) -> T: ...
async def __aexit__(self, *exc: object) -> None: ...
class AsyncBinaryIO(AsyncIO[bytes]):
pass
class AsyncTextIO(AsyncIO[str]):
encoding: str
errors: Optional[str]
newlines: Union[str, Tuple[str, ...], None]
# Implementations: (from io.pyi, but simplified by removing the "Base" classes)
class AsyncFileIO(AsyncBinaryIO):
async def readall(self) -> bytes: ...
async def readinto(self, __buffer: WriteableBuffer) -> int: ...
async def write(self, __b: ReadableBuffer) -> int: ...
async def read(self, __size: int = ...) -> bytes: ...
class AsyncBufferedFileIO(AsyncFileIO):
async def detach(self) -> AsyncBinaryIO: ...
async def readinto1(self, __buffer: WriteableBuffer) -> int: ...
async def read(self, __size: Optional[int] = ...) -> bytes: ...
async def read1(self, __size: int = ...) -> bytes: ...
def peek(self, __size: int = ...) -> bytes: ...
class AsyncTextFileIO(AsyncTextIO):
async def detach(self) -> AsyncBinaryIO: ...
async def read(self, __size: Optional[int] = ...) -> str: ...
# Backward compatibility aliases
_AsyncIOBase = AsyncIO[AnyStr]
_AsyncRawIOBase = AsyncFileIO
_AsyncBufferedIOBase = AsyncBufferedFileIO
_AsyncTextIOBase = AsyncTextFileIO
# open_file() overloads cribbed from typeshed builtins.open, with
# some simplifications:
_OpenFile = Union[StrOrBytesPath, int]
_Opener = Callable[[str, int], int]
# Text mode
@overload
async def open_file(
file: _OpenFile,
mode: OpenTextMode = ...,
buffering: int = ...,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
newline: Optional[str] = ...,
closefd: bool = ...,
opener: Optional[_Opener] = ...,
) -> AsyncTextFileIO: ...
# Unbuffered binary mode
@overload
async def open_file(
file: _OpenFile,
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = ...,
errors: None = ...,
newline: None = ...,
closefd: bool = ...,
opener: Optional[_Opener] = ...,
) -> AsyncFileIO: ...
# Buffered binary mode
@overload
async def open_file(
file: _OpenFile,
mode: OpenBinaryMode,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
errors: None = ...,
newline: None = ...,
closefd: bool = ...,
opener: Optional[_Opener] = ...,
) -> AsyncBufferedFileIO: ...
# Buffering cannot be determined
@overload
async def open_file(
file: _OpenFile,
mode: OpenBinaryMode,
buffering: int,
encoding: None = ...,
errors: None = ...,
newline: None = ...,
closefd: bool = ...,
opener: Optional[_Opener] = ...,
) -> AsyncFileIO: ...
# Fallback if mode is not specified
@overload
async def open_file(
file: _OpenFile,
mode: str,
buffering: int = ...,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
newline: Optional[str] = ...,
closefd: bool = ...,
opener: Optional[_Opener] = ...,
) -> AsyncIO[Any]: ...
@overload
def wrap_file(obj: Union[TextIO, io.TextIOBase]) -> AsyncTextIO: ...
@overload
def wrap_file(obj: Union[BinaryIO, io.BufferedIOBase]) -> AsyncBinaryIO: ...
@overload
def wrap_file(obj: io.RawIOBase) -> AsyncBinaryIO: ...
@overload
def wrap_file(obj: Union[IO[Any], io.IOBase]) -> AsyncIO[Any]: ...
# _path
class Path(pathlib.PurePath):
@classmethod
async def cwd(cls) -> Path: ...
@classmethod
async def home(cls) -> Path: ...
async def stat(self) -> os.stat_result: ...
async def chmod(self, mode: int) -> None: ...
async def exists(self) -> bool: ...
async def glob(self, pattern: str) -> Iterator[Path]: ...
async def group(self) -> str: ...
async def is_dir(self) -> bool: ...
async def is_file(self) -> bool: ...
async def is_symlink(self) -> bool: ...
async def is_socket(self) -> bool: ...
async def is_fifo(self) -> bool: ...
async def is_block_device(self) -> bool: ...
async def is_char_device(self) -> bool: ...
async def iterdir(self) -> Iterator[Path]: ...
async def lchmod(self, mode: int) -> None: ...
async def lstat(self) -> os.stat_result: ...
async def mkdir(
self, mode: int = ..., parents: bool = ..., exist_ok: bool = ...
) -> None: ...
@overload
async def open(
self,
mode: OpenTextMode = ...,
buffering: int = ...,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
newline: Optional[str] = ...,
) -> AsyncTextFileIO: ...
@overload
async def open(
self,
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = ...,
errors: None = ...,
newline: None = ...,
) -> AsyncFileIO: ...
@overload
async def open(
self,
mode: OpenBinaryMode,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
errors: None = ...,
newline: None = ...,
) -> AsyncBufferedFileIO: ...
@overload
async def open(
self,
mode: OpenBinaryMode,
buffering: int,
encoding: None = ...,
errors: None = ...,
newline: None = ...,
) -> AsyncFileIO: ...
@overload
async def open(
self,
mode: str,
buffering: int = ...,
encoding: Optional[str] = ...,
errors: Optional[str] = ...,
newline: Optional[str] = ...,
) -> AsyncIO[Any]: ...
async def owner(self) -> str: ...
async def rename(self, target: Union[str, pathlib.PurePath]) -> None: ...
async def replace(self, target: Union[str, pathlib.PurePath]) -> None: ...
if sys.version_info < (3, 6):
async def resolve(self) -> Path: ...
else:
async def resolve(self, strict: bool = ...) -> Path: ...
async def rglob(self, pattern: str) -> Iterator[Path]: ...
async def rmdir(self) -> None: ...
async def symlink_to(
self, target: Union[str, pathlib.PurePath], target_is_directory: bool = ...
) -> None: ...
async def touch(self, mode: int = ..., exist_ok: bool = ...) -> None: ...
async def unlink(self) -> None: ...
# added in 3.5:
async def absolute(self) -> Path: ...
async def expanduser(self) -> Path: ...
async def read_bytes(self) -> bytes: ...
async def read_text(
self, encoding: Optional[str] = ..., errors: Optional[str] = ...
) -> str: ...
async def samefile(self, other_path: Union[str, bytes, int, Path]) -> bool: ...
async def write_bytes(self, data: bytes) -> int: ...
async def write_text(
self, data: str, encoding: Optional[str] = ..., errors: Optional[str] = ...
) -> int: ...
# _highlevel_serve_listeners
T_resource = TypeVar("T_resource", bound=trio.abc.AsyncResource)
async def serve_listeners(
handler: Callable[[T_resource], Awaitable[Any]],
listeners: Sequence[trio.abc.Listener[T_resource]],
*,
handler_nursery: Optional[Nursery] = None,
task_status: TaskStatus[Sequence[trio.abc.Listener[T_resource]]] = ...,
) -> NoReturn: ...
# _highlevel_open_tcp_stream
async def open_tcp_stream(
host: Union[str, bytes],
port: int,
*,
happy_eyeballs_delay: float = ...,
local_address: Union[str, bytes, None] = ...,
) -> SocketStream: ...
# _highlevel_open_tcp_listeners
async def open_tcp_listeners(
port: int, *, host: Optional[AnyStr] = None, backlog: Optional[int] = None
) -> Sequence[SocketListener]: ...
async def serve_tcp(
handler: Callable[[SocketStream], Awaitable[Any]],
port: int,
*,
host: Optional[AnyStr] = None,
backlog: Optional[int] = None,
handler_nursery: Optional[Nursery] = None,
task_status: TaskStatus[Sequence[SocketListener]] = ...,
) -> NoReturn: ...
# _highlevel_open_unix_stream
async def open_unix_socket(filename: AnyStr) -> SocketStream: ...
# _highlevel_ssl_helpers
async def open_ssl_over_tcp_stream(
host: AnyStr,
port: int,
*,
https_compatible: bool = False,
ssl_context: Optional[ssl.SSLContext] = None,
happy_eyeballs_delay: float = ...,
) -> trio.SSLStream: ...
async def open_ssl_over_tcp_listeners(
port: int,
ssl_context: ssl.SSLContext,
*,
host: Optional[AnyStr] = None,
https_compatible: bool = False,
backlog: Optional[int] = None,
) -> Sequence[trio.SSLListener]: ...
async def serve_ssl_over_tcp(
handler: Callable[[trio.SSLStream], Awaitable[Any]],
port: int,
ssl_context: ssl.SSLContext,
*,
host: Optional[AnyStr] = None,
https_compatible: bool = False,
backlog: Optional[int] = None,
handler_nursery: Optional[Nursery] = None,
task_status: TaskStatus[Sequence[trio.SSLListener]] = ...,
) -> NoReturn: ...
# _ssl
class SSLStream(trio.abc.Stream):
transport_stream: trio.abc.Stream
context: ssl.SSLContext
server_side: bool
server_hostname: Optional[str]
if sys.version_info >= (3, 6):
@property
def session(self) -> Optional[ssl.SSLSession]: ...
@property
def session_reused(self) -> bool: ...
def __init__(
self,
transport_stream: trio.abc.Stream,
ssl_context: ssl.SSLContext,
*,
server_hostname: Optional[str] = None,
server_side: bool = False,
https_compatible: bool = False,
) -> None: ...
def getpeercert(self, binary_form: bool = ...) -> ssl._PeerCertRetType: ...
def selected_npn_protocol(self) -> Optional[str]: ...
def selected_alpn_protocol(self) -> Optional[str]: ...
def cipher(self) -> Tuple[str, int, int]: ...
def shared_ciphers(self) -> Optional[List[Tuple[str, int, int]]]: ...
def compression(self) -> Optional[str]: ...
def pending(self) -> int: ...
def get_channel_binding(self, cb_type: str = ...) -> Optional[bytes]: ...
async def do_handshake(self) -> None: ...
async def unwrap(self) -> Tuple[trio.abc.Stream, bytes]: ...
async def aclose(self) -> None: ...
async def send_all(self, data: Union[bytes, memoryview]) -> None: ...
async def wait_send_all_might_not_block(self) -> None: ...
async def receive_some(self, max_bytes: Optional[int] = ...) -> bytes: ...
class SSLListener(trio.abc.Listener[SSLStream]):
transport_listener: trio.abc.Listener[trio.abc.Stream]
def __init__(
self,
transport_listener: trio.abc.Listener[trio.abc.Stream],
ssl_context: ssl.SSLContext,
*,
https_compatible: bool = False,
) -> None: ...
async def accept(self) -> SSLStream: ...
async def aclose(self) -> None: ...
# _subprocess
class _HasFileno(Protocol):
def fileno(self) -> int: ...
_Redirect = Union[int, _HasFileno, None]
class Process(trio.abc.AsyncResource, _NotConstructible, metaclass=ABCMeta):
stdin: Optional[trio.abc.SendStream]
stdout: Optional[trio.abc.ReceiveStream]
stderr: Optional[trio.abc.ReceiveStream]
stdio: Optional[StapledStream]
args: Union[str, Sequence[str]]
pid: int
@property
def returncode(self) -> Optional[int]: ...
async def aclose(self) -> None: ...
async def wait(self) -> int: ...
def poll(self) -> Optional[int]: ...
def send_signal(self, sig: signal.Signals) -> None: ...
def terminate(self) -> None: ...
def kill(self) -> None: ...
# There's a lot of duplication here because mypy doesn't
# have a good way to represent overloads that differ only
# slightly. A cheat sheet:
# - on Windows, command is Union[str, Sequence[str]];
# on Unix, command is str if shell=True and Sequence[str] otherwise
# - on Windows, there are startupinfo and creationflags options;
# on Unix, there are preexec_fn, restore_signals, start_new_session, and pass_fds
# - run_process() has the signature of open_process() plus arguments
# capture_stdout, capture_stderr, check, deliver_cancel, and the ability to pass
# bytes as stdin
if sys.platform == "win32":
async def open_process(
command: Union[StrOrBytesPath, Sequence[StrOrBytesPath]],
*,
stdin: _Redirect = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
startupinfo: subprocess.STARTUPINFO = ...,
creationflags: int = ...,
) -> Process: ...
async def run_process(
command: Union[StrOrBytesPath, Sequence[StrOrBytesPath]],
*,
stdin: Union[bytes, _Redirect] = ...,
capture_stdout: bool = ...,
capture_stderr: bool = ...,
check: bool = ...,
deliver_cancel: Optional[Callable[[Process], Awaitable[None]]] = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
startupinfo: subprocess.STARTUPINFO = ...,
creationflags: int = ...,
) -> subprocess.CompletedProcess[bytes]: ...
else:
@overload
async def open_process(
command: StrOrBytesPath,
*,
stdin: _Redirect = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: Literal[True],
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Sequence[int] = ...,
) -> Process: ...
@overload
async def open_process(
command: Sequence[StrOrBytesPath],
*,
stdin: _Redirect = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Sequence[int] = ...,
) -> Process: ...
@overload
async def run_process(
command: StrOrBytesPath,
*,
stdin: Union[bytes, _Redirect] = ...,
capture_stdout: bool = ...,
capture_stderr: bool = ...,
check: bool = ...,
deliver_cancel: Optional[Callable[[Process], Awaitable[None]]] = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: Literal[True],
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Sequence[int] = ...,
) -> subprocess.CompletedProcess[bytes]: ...
@overload
async def run_process(
command: Sequence[StrOrBytesPath],
*,
stdin: Union[bytes, _Redirect] = ...,
capture_stdout: bool = ...,
capture_stderr: bool = ...,
check: bool = ...,
deliver_cancel: Optional[Callable[[Process], Awaitable[None]]] = ...,
stdout: _Redirect = ...,
stderr: _Redirect = ...,
close_fds: bool = ...,
shell: bool = ...,
cwd: Optional[StrOrBytesPath] = ...,
env: Optional[Mapping[str, str]] = ...,
preexec_fn: Optional[Callable[[], Any]] = ...,
restore_signals: bool = ...,
start_new_session: bool = ...,
pass_fds: Sequence[int] = ...,
) -> subprocess.CompletedProcess[bytes]: ...