[Python-3000] suggestion for a new socket io stack

Blake Winton bwinton at latte.ca
Sat Apr 29 01:29:59 CEST 2006


tomer filiba wrote:
> Each protocol would subclass {Stream/Dgram/Raw}Socket
> and add its protocol-specific options.
> 
> here's an example for a hierarchy:
> Socket
>     RawSocket
>     DgramSocket
>         UDPSocket
>     StreamSocket
>         TCPSocket
>             SSLSocket

My one small complaint with that is that SSLSocket should really be an 
SSL wrapper around a TCPSocket, because I wouldn't want to have two 
classes for HTTP/HTTPS, or FTP/FTPS/SFTP.  Java does something 
reasonable in this regard, I think, where you can have subclasses of 
Filter(Input,Output)Stream which can build on one-another, so I can have 
a base-64 encoded, TEA-encrypted, SSL, TCP socket by writing a line 
similar to:
sock = TcpSocket( "129.97.134.11", 8080 )
myIn = Base64Stream( TeaStream( SslStream( sock.getInputStream() ) ) )
myOut = Base64Stream( TeaStream( SslStream( sock.getOutputStream() ) ) )

The real beauty of that is that I can hook up my Base64Stream to a 
StringIO-like object to base64-encode stuff in memory, for testing, or 
for actual use.  Or I could Tea-encrypt a file while writing it to disk.

On the downside, it's a larger change than the one you're proposing.  On 
the upside, it unifies stream sockets, strings, files, and any other 
source of stream data you can come up with (random generators?  keyboards?).

Further reading of your examples suggests to me that what I would really 
like is a stream-view of the Socket class, and let SSL (, etc...) be a 
wrapper around the Socket's input/output streams.

Other than that small suggestion, I quite like your proposal.

Later,
Blake.


More information about the Python-3000 mailing list