libvirtpy 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- libvirtpy/__init__.py +5 -0
- libvirtpy/client/__init__.py +54 -0
- libvirtpy/client/_bases.py +326 -0
- libvirtpy/client/_runner.py +57 -0
- libvirtpy/client/aio.py +5922 -0
- libvirtpy/client/client.py +5695 -0
- libvirtpy/client/operations/__init__.py +631 -0
- libvirtpy/client/operations/_common.py +495 -0
- libvirtpy/client/operations/checkpoint.py +196 -0
- libvirtpy/client/operations/connection.py +93 -0
- libvirtpy/client/operations/connection_extra.py +256 -0
- libvirtpy/client/operations/domain.py +306 -0
- libvirtpy/client/operations/domain_agent.py +115 -0
- libvirtpy/client/operations/domain_block.py +368 -0
- libvirtpy/client/operations/domain_info.py +400 -0
- libvirtpy/client/operations/domain_lifecycle.py +338 -0
- libvirtpy/client/operations/domain_migration.py +164 -0
- libvirtpy/client/operations/domain_network.py +113 -0
- libvirtpy/client/operations/domain_tuning.py +494 -0
- libvirtpy/client/operations/host.py +246 -0
- libvirtpy/client/operations/host_interface.py +100 -0
- libvirtpy/client/operations/interface_extra.py +45 -0
- libvirtpy/client/operations/network.py +135 -0
- libvirtpy/client/operations/network_info.py +155 -0
- libvirtpy/client/operations/network_port.py +142 -0
- libvirtpy/client/operations/node_device.py +76 -0
- libvirtpy/client/operations/node_device_info.py +189 -0
- libvirtpy/client/operations/nwfilter.py +67 -0
- libvirtpy/client/operations/nwfilter_binding.py +74 -0
- libvirtpy/client/operations/secret.py +93 -0
- libvirtpy/client/operations/secret_extra.py +24 -0
- libvirtpy/client/operations/snapshot.py +100 -0
- libvirtpy/client/operations/snapshot_tree.py +114 -0
- libvirtpy/client/operations/storage.py +267 -0
- libvirtpy/client/operations/storage_info.py +188 -0
- libvirtpy/client/operations/streams.py +201 -0
- libvirtpy/client/references.py +249 -0
- libvirtpy/client/subscribing.py +88 -0
- libvirtpy/client/testing/__init__.py +24 -0
- libvirtpy/client/testing/_common.py +167 -0
- libvirtpy/client/testing/_domains.py +294 -0
- libvirtpy/client/testing/_objects.py +205 -0
- libvirtpy/client/testing/_state.py +246 -0
- libvirtpy/client/testing/_storage.py +171 -0
- libvirtpy/client/testing/async_transport.py +30 -0
- libvirtpy/client/testing/fake.py +81 -0
- libvirtpy/client/transport.py +87 -0
- libvirtpy/client/types.py +59 -0
- libvirtpy/client/wire.py +436 -0
- libvirtpy/client/wire_aio.py +348 -0
- libvirtpy/errors.py +7 -0
- libvirtpy/py.typed +0 -0
- libvirtpy/rpc/__init__.py +1 -0
- libvirtpy/rpc/aio.py +387 -0
- libvirtpy/rpc/cpumap.py +48 -0
- libvirtpy/rpc/errors.py +186 -0
- libvirtpy/rpc/events.py +259 -0
- libvirtpy/rpc/options.py +66 -0
- libvirtpy/rpc/procedure.py +27 -0
- libvirtpy/rpc/protocol/__init__.py +0 -0
- libvirtpy/rpc/protocol/procedures.py +5163 -0
- libvirtpy/rpc/protocol/typed_hints.py +210 -0
- libvirtpy/rpc/protocol/types.py +9299 -0
- libvirtpy/rpc/remote.py +295 -0
- libvirtpy/rpc/remote_aio.py +106 -0
- libvirtpy/rpc/sasl.py +467 -0
- libvirtpy/rpc/session.py +424 -0
- libvirtpy/rpc/sockets.py +251 -0
- libvirtpy/rpc/stream.py +323 -0
- libvirtpy/rpc/subscription.py +451 -0
- libvirtpy/rpc/sync.py +460 -0
- libvirtpy/rpc/typed_params.py +97 -0
- libvirtpy/rpc/uri.py +85 -0
- libvirtpy/rpc/xdr.py +552 -0
- libvirtpy/xml/__init__.py +49 -0
- libvirtpy/xml/_base.py +145 -0
- libvirtpy/xml/_shared/__init__.py +1 -0
- libvirtpy/xml/_shared/metadata.py +67 -0
- libvirtpy/xml/_shared/network.py +108 -0
- libvirtpy/xml/_shared/storage.py +131 -0
- libvirtpy/xml/_shared/sysinfo.py +83 -0
- libvirtpy/xml/_types.py +197 -0
- libvirtpy/xml/_xml_element.py +134 -0
- libvirtpy/xml/backup/__init__.py +25 -0
- libvirtpy/xml/backup/backup.py +89 -0
- libvirtpy/xml/backup/checkpoint.py +48 -0
- libvirtpy/xml/capabilities/__init__.py +43 -0
- libvirtpy/xml/capabilities/domain.py +436 -0
- libvirtpy/xml/capabilities/host.py +413 -0
- libvirtpy/xml/capabilities/storagepool.py +59 -0
- libvirtpy/xml/domain/__init__.py +493 -0
- libvirtpy/xml/domain/blkiotune.py +81 -0
- libvirtpy/xml/domain/clock.py +79 -0
- libvirtpy/xml/domain/cpu.py +265 -0
- libvirtpy/xml/domain/devices/__init__.py +495 -0
- libvirtpy/xml/domain/devices/address.py +152 -0
- libvirtpy/xml/domain/devices/audio.py +204 -0
- libvirtpy/xml/domain/devices/chardev.py +197 -0
- libvirtpy/xml/domain/devices/common.py +75 -0
- libvirtpy/xml/domain/devices/controller.py +262 -0
- libvirtpy/xml/domain/devices/devices.py +79 -0
- libvirtpy/xml/domain/devices/disk.py +471 -0
- libvirtpy/xml/domain/devices/filesystem.py +206 -0
- libvirtpy/xml/domain/devices/graphics.py +245 -0
- libvirtpy/xml/domain/devices/hostdev.py +221 -0
- libvirtpy/xml/domain/devices/input.py +89 -0
- libvirtpy/xml/domain/devices/interface.py +459 -0
- libvirtpy/xml/domain/devices/iommu.py +54 -0
- libvirtpy/xml/domain/devices/memballoon.py +42 -0
- libvirtpy/xml/domain/devices/memory_device.py +101 -0
- libvirtpy/xml/domain/devices/misc.py +169 -0
- libvirtpy/xml/domain/devices/nvram.py +20 -0
- libvirtpy/xml/domain/devices/shmem.py +46 -0
- libvirtpy/xml/domain/devices/sound.py +42 -0
- libvirtpy/xml/domain/devices/tpm.py +103 -0
- libvirtpy/xml/domain/devices/usb.py +86 -0
- libvirtpy/xml/domain/devices/video.py +101 -0
- libvirtpy/xml/domain/domain.py +157 -0
- libvirtpy/xml/domain/features.py +312 -0
- libvirtpy/xml/domain/iothread.py +41 -0
- libvirtpy/xml/domain/launch_security.py +82 -0
- libvirtpy/xml/domain/memory.py +149 -0
- libvirtpy/xml/domain/misc.py +113 -0
- libvirtpy/xml/domain/namespaces.py +96 -0
- libvirtpy/xml/domain/numa.py +140 -0
- libvirtpy/xml/domain/os.py +267 -0
- libvirtpy/xml/domain/qemu.py +102 -0
- libvirtpy/xml/domain/seclabel.py +29 -0
- libvirtpy/xml/domain/storage_source.py +466 -0
- libvirtpy/xml/domain/sysinfo.py +34 -0
- libvirtpy/xml/interface/__init__.py +17 -0
- libvirtpy/xml/interface/interface.py +153 -0
- libvirtpy/xml/network/__init__.py +101 -0
- libvirtpy/xml/network/network.py +311 -0
- libvirtpy/xml/network/port.py +84 -0
- libvirtpy/xml/nodedev/__init__.py +13 -0
- libvirtpy/xml/nodedev/nodedev.py +490 -0
- libvirtpy/xml/nwfilter/__init__.py +81 -0
- libvirtpy/xml/nwfilter/binding.py +51 -0
- libvirtpy/xml/nwfilter/filter.py +92 -0
- libvirtpy/xml/nwfilter/rules.py +534 -0
- libvirtpy/xml/secret/__init__.py +11 -0
- libvirtpy/xml/secret/secret.py +36 -0
- libvirtpy/xml/snapshot/__init__.py +29 -0
- libvirtpy/xml/snapshot/snapshot.py +136 -0
- libvirtpy/xml/storage/__init__.py +75 -0
- libvirtpy/xml/storage/pool.py +219 -0
- libvirtpy/xml/storage/volume.py +102 -0
- libvirtpy/xml/sysinfo.py +40 -0
- libvirtpy-0.1.0.dist-info/METADATA +109 -0
- libvirtpy-0.1.0.dist-info/RECORD +154 -0
- libvirtpy-0.1.0.dist-info/WHEEL +4 -0
- libvirtpy-0.1.0.dist-info/licenses/LICENSE +501 -0
- libvirtpy-0.1.0.dist-info/licenses/NOTICE +23 -0
libvirtpy/rpc/stream.py
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
"""Data streams: console, screenshot and volume upload/download.
|
|
2
|
+
|
|
3
|
+
A stream is the open end of a data channel that a call set up. ``RemoteStream``
|
|
4
|
+
is a file-like object (``read``, ``write``, ``close``, ``with``); ``AsyncRemoteStream``
|
|
5
|
+
has the same methods as coroutines::
|
|
6
|
+
|
|
7
|
+
with client.open_domain_console("vm") as console:
|
|
8
|
+
console.write(b"\\n")
|
|
9
|
+
print(console.read(100))
|
|
10
|
+
|
|
11
|
+
with client.download_pool_volume("pool", "disk.img") as source:
|
|
12
|
+
data = source.read()
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import asyncio
|
|
16
|
+
import contextlib
|
|
17
|
+
import io
|
|
18
|
+
import queue
|
|
19
|
+
from types import TracebackType
|
|
20
|
+
from typing import Any, Literal, TypeVar
|
|
21
|
+
|
|
22
|
+
from libvirtpy.rpc.aio import AsyncRpc
|
|
23
|
+
from libvirtpy.rpc.session import StreamEvent
|
|
24
|
+
from libvirtpy.rpc.sync import SyncRpc
|
|
25
|
+
|
|
26
|
+
__all__ = ["AsyncRemoteStream", "Mode", "RemoteStream"]
|
|
27
|
+
|
|
28
|
+
Mode = Literal["read", "write", "both"]
|
|
29
|
+
CHUNK_SIZE = 65536
|
|
30
|
+
CLOSE_TIMEOUT_SECONDS = 10
|
|
31
|
+
AsyncSelf = TypeVar("AsyncSelf", bound="AsyncRemoteStream")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class RemoteStream(io.RawIOBase):
|
|
35
|
+
"""A blocking, file-like stream to or from a daemon."""
|
|
36
|
+
|
|
37
|
+
def __init__(self, rpc: SyncRpc, mode: Mode) -> None:
|
|
38
|
+
"""Create the stream; the connection sets ``serial`` when the call is sent.
|
|
39
|
+
|
|
40
|
+
:param rpc: the connection the stream is on.
|
|
41
|
+
:param mode: ``read`` (data comes from the daemon), ``write`` (data goes to
|
|
42
|
+
it) or ``both`` (a console).
|
|
43
|
+
"""
|
|
44
|
+
super().__init__()
|
|
45
|
+
self.mode = mode
|
|
46
|
+
self.serial = -1
|
|
47
|
+
self.reply: Any = None
|
|
48
|
+
"""What the call that opened the stream returned (for a screenshot: the
|
|
49
|
+
MIME type)."""
|
|
50
|
+
|
|
51
|
+
self._rpc = rpc
|
|
52
|
+
self._events: queue.Queue[StreamEvent] = queue.Queue()
|
|
53
|
+
self._pending = b""
|
|
54
|
+
self._eof = False
|
|
55
|
+
self._dead = False
|
|
56
|
+
|
|
57
|
+
def deliver(self, event: StreamEvent) -> None:
|
|
58
|
+
"""Receive what the connection read for this stream (reading thread).
|
|
59
|
+
|
|
60
|
+
:param event: the data, the end, or the error.
|
|
61
|
+
"""
|
|
62
|
+
self._events.put(event)
|
|
63
|
+
|
|
64
|
+
def readable(self) -> bool:
|
|
65
|
+
"""Tell whether data can be read from the stream.
|
|
66
|
+
|
|
67
|
+
:returns: ``True`` for a ``read`` or ``both`` stream.
|
|
68
|
+
"""
|
|
69
|
+
return self.mode in ("read", "both")
|
|
70
|
+
|
|
71
|
+
def writable(self) -> bool:
|
|
72
|
+
"""Tell whether data can be written to the stream.
|
|
73
|
+
|
|
74
|
+
:returns: ``True`` for a ``write`` or ``both`` stream.
|
|
75
|
+
"""
|
|
76
|
+
return self.mode in ("write", "both")
|
|
77
|
+
|
|
78
|
+
def readinto( # type: ignore[override] # narrower than RawIOBase's buffer type
|
|
79
|
+
self, buffer: bytearray | memoryview
|
|
80
|
+
) -> int:
|
|
81
|
+
"""Read bytes into a buffer, waiting for the daemon if there are none.
|
|
82
|
+
|
|
83
|
+
:param buffer: where to put the bytes.
|
|
84
|
+
:returns: how many bytes; 0 when the daemon has sent everything.
|
|
85
|
+
:raises LibvirtError: if the daemon reports a failure.
|
|
86
|
+
:raises UnsupportedOperation: if the stream is write-only.
|
|
87
|
+
"""
|
|
88
|
+
if not self.readable():
|
|
89
|
+
raise io.UnsupportedOperation("this stream is write-only")
|
|
90
|
+
|
|
91
|
+
while not self._pending and not self._eof:
|
|
92
|
+
self._take(self._events.get())
|
|
93
|
+
if not self._pending:
|
|
94
|
+
return 0
|
|
95
|
+
|
|
96
|
+
view = memoryview(buffer)
|
|
97
|
+
count = min(len(view), len(self._pending))
|
|
98
|
+
view[:count] = self._pending[:count]
|
|
99
|
+
self._pending = self._pending[count:]
|
|
100
|
+
return count
|
|
101
|
+
|
|
102
|
+
def write( # type: ignore[override] # narrower than RawIOBase's buffer type
|
|
103
|
+
self, data: bytes | bytearray | memoryview
|
|
104
|
+
) -> int:
|
|
105
|
+
"""Send bytes to the daemon.
|
|
106
|
+
|
|
107
|
+
:param data: the bytes.
|
|
108
|
+
:returns: how many bytes were sent: all of them.
|
|
109
|
+
:raises UnsupportedOperation: if the stream is read-only.
|
|
110
|
+
"""
|
|
111
|
+
if not self.writable():
|
|
112
|
+
raise io.UnsupportedOperation("this stream is read-only")
|
|
113
|
+
|
|
114
|
+
view = memoryview(data)
|
|
115
|
+
for start in range(0, len(view), CHUNK_SIZE):
|
|
116
|
+
self._rpc.send_stream_data(
|
|
117
|
+
self.serial, bytes(view[start : start + CHUNK_SIZE])
|
|
118
|
+
)
|
|
119
|
+
return len(view)
|
|
120
|
+
|
|
121
|
+
def close(self) -> None:
|
|
122
|
+
"""End the stream: finish what we send, or give up on what we read."""
|
|
123
|
+
if self.closed:
|
|
124
|
+
return
|
|
125
|
+
try:
|
|
126
|
+
self._finish()
|
|
127
|
+
finally:
|
|
128
|
+
super().close()
|
|
129
|
+
|
|
130
|
+
def _take(self, event: StreamEvent) -> None:
|
|
131
|
+
"""Handle one event while reading.
|
|
132
|
+
|
|
133
|
+
:param event: what the connection delivered.
|
|
134
|
+
:raises Exception: the error the daemon (or the connection) reported.
|
|
135
|
+
"""
|
|
136
|
+
if event.kind == "data":
|
|
137
|
+
self._pending += event.data
|
|
138
|
+
return
|
|
139
|
+
|
|
140
|
+
self._eof = True
|
|
141
|
+
if event.kind in ("closed", "error"):
|
|
142
|
+
self._dead = True
|
|
143
|
+
if event.error is not None:
|
|
144
|
+
raise event.error
|
|
145
|
+
|
|
146
|
+
def _finish(self) -> None:
|
|
147
|
+
"""Tell the daemon we are done, and wait for it to confirm.
|
|
148
|
+
|
|
149
|
+
A stream we were still reading is given up (aborted) instead.
|
|
150
|
+
"""
|
|
151
|
+
if self._dead:
|
|
152
|
+
return
|
|
153
|
+
self._dead = True
|
|
154
|
+
|
|
155
|
+
if self.mode == "read" and not self._eof:
|
|
156
|
+
self._rpc.abort_stream(self.serial)
|
|
157
|
+
return
|
|
158
|
+
|
|
159
|
+
self._rpc.finish_stream(self.serial)
|
|
160
|
+
with contextlib.suppress(queue.Empty, Exception):
|
|
161
|
+
while self._events.get(timeout=CLOSE_TIMEOUT_SECONDS).kind not in (
|
|
162
|
+
"closed",
|
|
163
|
+
"error",
|
|
164
|
+
):
|
|
165
|
+
pass
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
class AsyncRemoteStream:
|
|
169
|
+
"""A stream to or from a daemon, for ``async`` code."""
|
|
170
|
+
|
|
171
|
+
def __init__(self, rpc: AsyncRpc, mode: Mode) -> None:
|
|
172
|
+
"""Create the stream; the connection sets ``serial`` when the call is sent.
|
|
173
|
+
|
|
174
|
+
:param rpc: the connection the stream is on.
|
|
175
|
+
:param mode: ``read``, ``write`` or ``both`` (a console).
|
|
176
|
+
"""
|
|
177
|
+
self.mode = mode
|
|
178
|
+
self.serial = -1
|
|
179
|
+
self.reply: Any = None
|
|
180
|
+
"""What the call that opened the stream returned."""
|
|
181
|
+
|
|
182
|
+
self._rpc = rpc
|
|
183
|
+
self._events: asyncio.Queue[StreamEvent] = asyncio.Queue()
|
|
184
|
+
self._pending = b""
|
|
185
|
+
|
|
186
|
+
self._eof = False
|
|
187
|
+
self._dead = False
|
|
188
|
+
self._closed = False
|
|
189
|
+
|
|
190
|
+
def deliver(self, event: StreamEvent) -> None:
|
|
191
|
+
"""Receive what the connection read for this stream (in the event loop).
|
|
192
|
+
|
|
193
|
+
:param event: the data, the end, or the error.
|
|
194
|
+
"""
|
|
195
|
+
self._events.put_nowait(event)
|
|
196
|
+
|
|
197
|
+
async def read(self, size: int = -1) -> bytes:
|
|
198
|
+
"""Read bytes, waiting for the daemon if there are none.
|
|
199
|
+
|
|
200
|
+
:param size: the most bytes to return; -1 reads until the end.
|
|
201
|
+
:returns: the bytes; empty when the daemon has sent everything.
|
|
202
|
+
:raises LibvirtError: if the daemon reports a failure.
|
|
203
|
+
"""
|
|
204
|
+
self._check_readable()
|
|
205
|
+
while not self._eof and (size < 0 or len(self._pending) < size):
|
|
206
|
+
self._take(await self._events.get())
|
|
207
|
+
|
|
208
|
+
count = len(self._pending) if size < 0 else min(size, len(self._pending))
|
|
209
|
+
data, self._pending = self._pending[:count], self._pending[count:]
|
|
210
|
+
return data
|
|
211
|
+
|
|
212
|
+
async def read_chunk(self) -> bytes:
|
|
213
|
+
"""Read the next piece the daemon sent.
|
|
214
|
+
|
|
215
|
+
:returns: the bytes; empty when the daemon has sent everything.
|
|
216
|
+
:raises LibvirtError: if the daemon reports a failure.
|
|
217
|
+
"""
|
|
218
|
+
self._check_readable()
|
|
219
|
+
while not self._pending and not self._eof:
|
|
220
|
+
self._take(await self._events.get())
|
|
221
|
+
data, self._pending = self._pending, b""
|
|
222
|
+
return data
|
|
223
|
+
|
|
224
|
+
async def write(self, data: bytes) -> int:
|
|
225
|
+
"""Send bytes to the daemon.
|
|
226
|
+
|
|
227
|
+
:param data: the bytes.
|
|
228
|
+
:returns: how many bytes were sent: all of them.
|
|
229
|
+
:raises UnsupportedOperation: if the stream is read-only.
|
|
230
|
+
"""
|
|
231
|
+
if self.mode == "read":
|
|
232
|
+
raise io.UnsupportedOperation("this stream is read-only")
|
|
233
|
+
|
|
234
|
+
for start in range(0, len(data), CHUNK_SIZE):
|
|
235
|
+
await self._rpc.send_stream_data(
|
|
236
|
+
self.serial, data[start : start + CHUNK_SIZE]
|
|
237
|
+
)
|
|
238
|
+
return len(data)
|
|
239
|
+
|
|
240
|
+
async def close(self) -> None:
|
|
241
|
+
"""End the stream: finish what we send, or give up on what we read."""
|
|
242
|
+
if self._closed:
|
|
243
|
+
return
|
|
244
|
+
self._closed = True
|
|
245
|
+
if self._dead:
|
|
246
|
+
return
|
|
247
|
+
self._dead = True
|
|
248
|
+
|
|
249
|
+
if self.mode == "read" and not self._eof:
|
|
250
|
+
await self._rpc.abort_stream(self.serial)
|
|
251
|
+
return
|
|
252
|
+
|
|
253
|
+
await self._rpc.finish_stream(self.serial)
|
|
254
|
+
with contextlib.suppress(asyncio.TimeoutError, Exception):
|
|
255
|
+
while True:
|
|
256
|
+
event = await asyncio.wait_for(
|
|
257
|
+
self._events.get(), CLOSE_TIMEOUT_SECONDS
|
|
258
|
+
)
|
|
259
|
+
if event.kind in ("closed", "error"):
|
|
260
|
+
break
|
|
261
|
+
|
|
262
|
+
def __aiter__(self: AsyncSelf) -> AsyncSelf:
|
|
263
|
+
"""Iterate over the pieces the daemon sends.
|
|
264
|
+
|
|
265
|
+
:returns: the stream.
|
|
266
|
+
"""
|
|
267
|
+
return self
|
|
268
|
+
|
|
269
|
+
async def __anext__(self) -> bytes:
|
|
270
|
+
"""Read the next piece.
|
|
271
|
+
|
|
272
|
+
:returns: the bytes.
|
|
273
|
+
:raises StopAsyncIteration: when the daemon has sent everything.
|
|
274
|
+
"""
|
|
275
|
+
data = await self.read_chunk()
|
|
276
|
+
if not data:
|
|
277
|
+
raise StopAsyncIteration
|
|
278
|
+
return data
|
|
279
|
+
|
|
280
|
+
async def __aenter__(self: AsyncSelf) -> AsyncSelf:
|
|
281
|
+
"""Use the stream in an ``async with`` block.
|
|
282
|
+
|
|
283
|
+
:returns: the stream.
|
|
284
|
+
"""
|
|
285
|
+
return self
|
|
286
|
+
|
|
287
|
+
async def __aexit__(
|
|
288
|
+
self,
|
|
289
|
+
exception_type: type[BaseException] | None,
|
|
290
|
+
exception: BaseException | None,
|
|
291
|
+
traceback: TracebackType | None,
|
|
292
|
+
) -> None:
|
|
293
|
+
"""Close the stream when the block ends.
|
|
294
|
+
|
|
295
|
+
:param exception_type: the exception class, if the block raised.
|
|
296
|
+
:param exception: the exception, if the block raised.
|
|
297
|
+
:param traceback: its traceback, if the block raised.
|
|
298
|
+
"""
|
|
299
|
+
await self.close()
|
|
300
|
+
|
|
301
|
+
def _check_readable(self) -> None:
|
|
302
|
+
"""Refuse to read a write-only stream.
|
|
303
|
+
|
|
304
|
+
:raises UnsupportedOperation: if it is write-only.
|
|
305
|
+
"""
|
|
306
|
+
if self.mode == "write":
|
|
307
|
+
raise io.UnsupportedOperation("this stream is write-only")
|
|
308
|
+
|
|
309
|
+
def _take(self, event: StreamEvent) -> None:
|
|
310
|
+
"""Handle one event while reading.
|
|
311
|
+
|
|
312
|
+
:param event: what the connection delivered.
|
|
313
|
+
:raises Exception: the error the daemon (or the connection) reported.
|
|
314
|
+
"""
|
|
315
|
+
if event.kind == "data":
|
|
316
|
+
self._pending += event.data
|
|
317
|
+
return
|
|
318
|
+
|
|
319
|
+
self._eof = True
|
|
320
|
+
if event.kind in ("closed", "error"):
|
|
321
|
+
self._dead = True
|
|
322
|
+
if event.error is not None:
|
|
323
|
+
raise event.error
|