where proxy_command contains a string with a command line that will be launched as subprocess.

This mimick the ProxyCommand option of OpenSSH and offer a lot of flexibility, but this may not be interesting if you want your code to run reliably across different OSes and configurations. Actually, the OpenSSH ProxyCommand option is often configured to launch another ssh instance and daisy-chain connections, which is probably something that we can't or don't want to do.

The sock argument of the connect method support a socket-like object and so will happily use a real socket if you take care to create one. So let's use it to connect to our proxy, which is quite easy thanks to the httplib and urlparse modules: