Low-level socket abstraction layer¶
Different types of stream-like classes (sockets, files, pipes, …) have very different interfaces and behaviors under exceptional conditions. The goal of this “simple socket” module is to provide a unified interface for a variety of stream types. The Netcat class then uses this interface to provide all the convenient functionality you love.
All Netcat methods should automatically wrap any stream objects you provide with the appropriate wrapper.
- class nclib.simplesock.Simple[source]¶
The base class for implementing a simple, unified interface for socket-like objects. Instances of this type should act like a simple unbuffered blocking socket.
- Variables:
can_send – Whether this stream supports send operations
can_recv – Whether this stream supports recv operations
- property closed¶
Whether the stream has been closed.
- fileno()[source]¶
The file descriptor associated with the stream. Should raise NetcatError if there is not a single file descriptor to return.
- nclib.simplesock.wrap(sock)[source]¶
A helper function to automatically pick the correct wrapper class for a sock-like object.
- class nclib.simplesock.SimpleSocket(sock)[source]¶
A wrapper for sockets.
- Parameters:
sock – A python
socket.socket
object.
- class nclib.simplesock.SimpleFile(fp)[source]¶
A wrapper for files from the python
io
module, includingsys.stdin
, subprocess pipes, etc. If the file has an encoding, it will be discarded.- Parameters:
fp – An
io.IOBase
object
- class nclib.simplesock.SimpleDuplex(child_recv=None, child_send=None)[source]¶
A wrapper which splits recv and send operations across two different streams.
- Parameters:
If either of these parameters are None, that operation will be disabled and generate exceptions.
- class nclib.simplesock.SimpleMerge(children)[source]¶
A stream that merges the output of many readable streams into one.
- Parameters:
children (list of Simple) – A list of streams from which to read
- class nclib.simplesock.SimpleNetcat(nc)[source]¶
A wrapper for a Netcat object! Why? Just in case you want to do Netcat-level instrumentation [logging] at a finer granularity than the top-level.
- Parameters:
sock – A Netcat object.
- class nclib.simplesock.SimpleLogger(logger='nclib.logs', level='INFO', encoding=None)[source]¶
A socket-like interface for dumping data to a python logging endpoint.
- Parameters:
logger – The dotted name for the endpoint for the logs to go to
level – The string or numeric severity level for the logging messages
encoding – simplesock objects are fed bytestrings. Loggers consume unicode strings. How should we translate?