| 1 |
"""Trio - A friendly Python library for async concurrency and I/O""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
from typing import TYPE_CHECKING |
| 6 |
|
| 7 |
# General layout: |
| 8 |
# |
| 9 |
# trio/_core/... is the self-contained core library. It does various |
| 10 |
# shenanigans to export a consistent "core API", but parts of the core API are |
| 11 |
# too low-level to be recommended for regular use. |
| 12 |
# |
| 13 |
# trio/*.py define a set of more usable tools on top of this. They import from |
| 14 |
# trio._core and from each other. |
| 15 |
# |
| 16 |
# This file pulls together the friendly public API, by re-exporting the more |
| 17 |
# innocuous bits of the _core API + the higher-level tools from trio/*.py. |
| 18 |
# |
| 19 |
# Uses `from x import y as y` for compatibility with `pyright --verifytypes` (#2625) |
| 20 |
# |
| 21 |
# must be imported early to avoid circular import |
| 22 |
from ._core import TASK_STATUS_IGNORED as TASK_STATUS_IGNORED # isort: split |
| 23 |
|
| 24 |
# Submodules imported by default |
| 25 |
from . import abc, from_thread, lowlevel, socket, to_thread |
| 26 |
from ._channel import ( |
| 27 |
MemoryChannelStatistics as MemoryChannelStatistics, |
| 28 |
MemoryReceiveChannel as MemoryReceiveChannel, |
| 29 |
MemorySendChannel as MemorySendChannel, |
| 30 |
as_safe_channel as as_safe_channel, |
| 31 |
open_memory_channel as open_memory_channel, |
| 32 |
) |
| 33 |
from ._core import ( |
| 34 |
BrokenResourceError as BrokenResourceError, |
| 35 |
BusyResourceError as BusyResourceError, |
| 36 |
Cancelled as Cancelled, |
| 37 |
CancelScope as CancelScope, |
| 38 |
ClosedResourceError as ClosedResourceError, |
| 39 |
EndOfChannel as EndOfChannel, |
| 40 |
Nursery as Nursery, |
| 41 |
RunFinishedError as RunFinishedError, |
| 42 |
TaskStatus as TaskStatus, |
| 43 |
TrioInternalError as TrioInternalError, |
| 44 |
WouldBlock as WouldBlock, |
| 45 |
current_effective_deadline as current_effective_deadline, |
| 46 |
current_time as current_time, |
| 47 |
open_nursery as open_nursery, |
| 48 |
run as run, |
| 49 |
) |
| 50 |
from ._deprecate import TrioDeprecationWarning as TrioDeprecationWarning |
| 51 |
from ._dtls import ( |
| 52 |
DTLSChannel as DTLSChannel, |
| 53 |
DTLSChannelStatistics as DTLSChannelStatistics, |
| 54 |
DTLSEndpoint as DTLSEndpoint, |
| 55 |
) |
| 56 |
from ._file_io import open_file as open_file, wrap_file as wrap_file |
| 57 |
from ._highlevel_generic import ( |
| 58 |
StapledStream as StapledStream, |
| 59 |
aclose_forcefully as aclose_forcefully, |
| 60 |
) |
| 61 |
from ._highlevel_open_tcp_listeners import ( |
| 62 |
open_tcp_listeners as open_tcp_listeners, |
| 63 |
serve_tcp as serve_tcp, |
| 64 |
) |
| 65 |
from ._highlevel_open_tcp_stream import open_tcp_stream as open_tcp_stream |
| 66 |
from ._highlevel_open_unix_stream import open_unix_socket as open_unix_socket |
| 67 |
from ._highlevel_serve_listeners import serve_listeners as serve_listeners |
| 68 |
from ._highlevel_socket import ( |
| 69 |
SocketListener as SocketListener, |
| 70 |
SocketStream as SocketStream, |
| 71 |
) |
| 72 |
from ._highlevel_ssl_helpers import ( |
| 73 |
open_ssl_over_tcp_listeners as open_ssl_over_tcp_listeners, |
| 74 |
open_ssl_over_tcp_stream as open_ssl_over_tcp_stream, |
| 75 |
serve_ssl_over_tcp as serve_ssl_over_tcp, |
| 76 |
) |
| 77 |
from ._path import Path as Path, PosixPath as PosixPath, WindowsPath as WindowsPath |
| 78 |
from ._signals import open_signal_receiver as open_signal_receiver |
| 79 |
from ._ssl import ( |
| 80 |
NeedHandshakeError as NeedHandshakeError, |
| 81 |
SSLListener as SSLListener, |
| 82 |
SSLStream as SSLStream, |
| 83 |
) |
| 84 |
from ._subprocess import Process as Process, run_process as run_process |
| 85 |
from ._sync import ( |
| 86 |
CapacityLimiter as CapacityLimiter, |
| 87 |
CapacityLimiterStatistics as CapacityLimiterStatistics, |
| 88 |
Condition as Condition, |
| 89 |
ConditionStatistics as ConditionStatistics, |
| 90 |
Event as Event, |
| 91 |
EventStatistics as EventStatistics, |
| 92 |
Lock as Lock, |
| 93 |
LockStatistics as LockStatistics, |
| 94 |
Semaphore as Semaphore, |
| 95 |
StrictFIFOLock as StrictFIFOLock, |
| 96 |
) |
| 97 |
from ._timeouts import ( |
| 98 |
TooSlowError as TooSlowError, |
| 99 |
fail_after as fail_after, |
| 100 |
fail_at as fail_at, |
| 101 |
move_on_after as move_on_after, |
| 102 |
move_on_at as move_on_at, |
| 103 |
sleep as sleep, |
| 104 |
sleep_forever as sleep_forever, |
| 105 |
sleep_until as sleep_until, |
| 106 |
) |
| 107 |
from ._version import __version__ as __version__ |
| 108 |
|
| 109 |
# Not imported by default, but mentioned here so static analysis tools like |
| 110 |
# pylint will know that it exists. |
| 111 |
if TYPE_CHECKING: |
| 112 |
from . import testing |
| 113 |
|
| 114 |
from . import _deprecate as _deprecate |
| 115 |
|
| 116 |
_deprecate.deprecate_attributes(__name__, {}) |
| 117 |
|
| 118 |
# Having the public path in .__module__ attributes is important for: |
| 119 |
# - exception names in printed tracebacks |
| 120 |
# - sphinx :show-inheritance: |
| 121 |
# - deprecation warnings |
| 122 |
# - pickle |
| 123 |
# - probably other stuff |
| 124 |
from ._util import fixup_module_metadata |
| 125 |
|
| 126 |
fixup_module_metadata(__name__, globals()) |
| 127 |
fixup_module_metadata(lowlevel.__name__, lowlevel.__dict__) |
| 128 |
fixup_module_metadata(socket.__name__, socket.__dict__) |
| 129 |
fixup_module_metadata(abc.__name__, abc.__dict__) |
| 130 |
fixup_module_metadata(from_thread.__name__, from_thread.__dict__) |
| 131 |
fixup_module_metadata(to_thread.__name__, to_thread.__dict__) |
| 132 |
del fixup_module_metadata |
| 133 |
del TYPE_CHECKING |