|
16 | 16 |
|
17 | 17 | __all__ = ('Channel', 'SerialChannel', 'Writer', 'ChannelWriter', 'CallbackChannelWriter',
|
18 | 18 | 'Reader', 'ChannelReader', 'CallbackChannelReader', 'mkchannel', 'ReadOnly',
|
19 |
| - 'IteratorReader') |
| 19 | + 'IteratorReader', 'CallbackReaderMixin', 'CallbackWriterMixin') |
20 | 20 |
|
21 | 21 | #{ Classes
|
22 | 22 | class Channel(object):
|
@@ -114,10 +114,12 @@ def __init__(self, *args):
|
114 | 114 | self._pre_cb = None
|
115 | 115 |
|
116 | 116 | def set_pre_cb(self, fun = lambda item: item):
|
117 |
| - """Install a callback to be called before the given item is written. |
| 117 | + """ |
| 118 | + Install a callback to be called before the given item is written. |
118 | 119 | It returns a possibly altered item which will be written to the channel
|
119 | 120 | instead, making it useful for pre-write item conversions.
|
120 | 121 | Providing None uninstalls the current method.
|
| 122 | + |
121 | 123 | :return: the previously installed function or None
|
122 | 124 | :note: Must be thread-safe if the channel is used in multiple threads"""
|
123 | 125 | prev = self._pre_cb
|
@@ -161,9 +163,11 @@ def next(self):
|
161 | 163 | #{ Interface
|
162 | 164 |
|
163 | 165 | def read(self, count=0, block=True, timeout=None):
|
164 |
| - """read a list of items read from the device. The list, as a sequence |
| 166 | + """ |
| 167 | + read a list of items read from the device. The list, as a sequence |
165 | 168 | of items, is similar to the string of characters returned when reading from
|
166 | 169 | file like objects.
|
| 170 | + |
167 | 171 | :param count: given amount of items to read. If < 1, all items will be read
|
168 | 172 | :param block: if True, the call will block until an item is available
|
169 | 173 | :param timeout: if positive and block is True, it will block only for the
|
@@ -275,21 +279,24 @@ def __init__(self, *args):
|
275 | 279 | self._post_cb = None
|
276 | 280 |
|
277 | 281 | def set_pre_cb(self, fun = lambda count: None):
|
278 |
| - """Install a callback to call with the item count to be read before any |
| 282 | + """ |
| 283 | + Install a callback to call with the item count to be read before any |
279 | 284 | item is actually read from the channel.
|
280 | 285 | Exceptions will be propagated.
|
281 | 286 | If a function is not provided, the call is effectively uninstalled.
|
| 287 | + |
282 | 288 | :return: the previously installed callback or None
|
283 | 289 | :note: The callback must be threadsafe if the channel is used by multiple threads."""
|
284 | 290 | prev = self._pre_cb
|
285 | 291 | self._pre_cb = fun
|
286 | 292 | return prev
|
287 | 293 |
|
288 | 294 | def set_post_cb(self, fun = lambda items: items):
|
289 |
| - """Install a callback to call after items have been read, but before |
290 |
| - they are returned to the caller. The callback may adjust the items and/or |
291 |
| - the list |
| 295 | + """ |
| 296 | + Install a callback to call after items have been read, but before |
| 297 | + they are returned to the caller. The callback may adjust the items and/or the list. |
292 | 298 | If no function is provided, the callback is uninstalled
|
| 299 | + |
293 | 300 | :return: the previously installed function"""
|
294 | 301 | prev = self._post_cb
|
295 | 302 | self._post_cb = fun
|
@@ -361,7 +368,8 @@ def read(self, count=0, block=True, timeout=None):
|
361 | 368 |
|
362 | 369 | #{ Constructors
|
363 | 370 | def mkchannel(ctype = Channel, wtype = ChannelWriter, rtype = ChannelReader):
|
364 |
| - """Create a channel, with a reader and a writer |
| 371 | + """ |
| 372 | + Create a channel, with a reader and a writer |
365 | 373 | :return: tuple(reader, writer)
|
366 | 374 | :param ctype: Channel to instantiate
|
367 | 375 | :param wctype: The type of the write channel to instantiate
|
|
0 commit comments