ducky.streams module¶
Streams represent basic IO objects, used by devices for reading or writing (streams) of data.
Stream object encapsulates an actual IO object - file-like stream,
raw file descriptor, or even something completely different. Stream classes
then provide basic IO methods for moving data to and from stream, shielding
user from implementation details, like Python2/Python3 differencies.
-
class
ducky.streams.FDInputStream(machine, fd, **kwargs)[source]¶ Bases:
ducky.streams.InputStream
-
class
ducky.streams.FDOutputStream(machine, fd, **kwargs)[source]¶ Bases:
ducky.streams.OutputStream
-
class
ducky.streams.FileInputStream(machine, f, **kwargs)[source]¶ Bases:
ducky.streams.InputStream
-
class
ducky.streams.FileOutputStream(machine, f, **kwargs)[source]¶ Bases:
ducky.streams.OutputStream
-
class
ducky.streams.InputStream(machine, desc, stream=None, fd=None, close=True, allow_close=True)[source]¶ Bases:
ducky.streams.Stream
-
class
ducky.streams.MethodInputStream(machine, desc, **kwargs)[source]¶ Bases:
ducky.streams.InputStream
-
class
ducky.streams.MethodOutputStream(machine, desc, **kwargs)[source]¶ Bases:
ducky.streams.OutputStream
-
class
ducky.streams.OutputStream(machine, desc, stream=None, fd=None, close=True, allow_close=True)[source]¶ Bases:
ducky.streams.Stream
-
class
ducky.streams.StderrStream(machine)[source]¶ Bases:
ducky.streams.OutputStream
-
class
ducky.streams.StdinStream(machine, **kwargs)[source]¶ Bases:
ducky.streams.InputStream
-
class
ducky.streams.StdoutStream(machine)[source]¶ Bases:
ducky.streams.OutputStream
-
class
ducky.streams.Stream(machine, desc, stream=None, fd=None, close=True, allow_close=True)[source]¶ Bases:
objectAbstract base class of all streams.
Parameters: - machine – parent :py:class`ducky.machine.Machine` object.
- desc – description of stream. This is a short, string representation of the stream.
- stream –
file-like stream that provides IO method (read()orwrite). If it is set, it is preferred IO object. - fd (int) – raw file descriptor.
streamtakes precedence, otherwise this file descriptor is used. - close (bool) – if
True, and ifstreamhas aclose()method, stream will provideclose()method that will close the underlayingfile-like object.Trueby default. - allow_close (bool) – if not
True, stream’sclose()method will not close underlying IO resource.Trueby default.
-
close()[source]¶ This method will close the stream. If
allow_closeflag is not set toTrue, nothing will happen. If the stream wasn’t created withcloseset toTrue, nothing will happen. If the wrapped IO resource does not haveclose()method, nothing will happen.
-
has_fd()[source]¶ Check if stream has raw file descriptor. File descriptors can be checked for IO availability by reactor’s polling task.
Return type: bool Returns: Truewhen stream has file descriptor.
-
read(size=None)[source]¶ Read data from stream.
Parameters: size (int) – if set, read at maximum sizebytes.Return type: bytearray(Python2),bytes(Python3)Returns: read data, of maximum lenght of size,Nonewhen there are no available data, or empty string in case of EOF.
-
register_with_reactor(reactor, **kwargs)[source]¶ Called by owner to register the stream with reactor’s polling service.
See
ducky.reactor.Reactor.add_fd()for keyword arguments.Parameters: reactor (ducky.reactor.Reactor) – reactor instance to register with.
-
unregister_with_reactor(reactor)[source]¶ Called by owner to unregister the stream with reactor’s polling service, e.g. when stream is about to be closed.
Parameters: reactor (ducky.reactor.Reactor) – reactor instance to unregister from.