Last active
December 31, 2015 18:59
-
-
Save mattieb/8030339 to your computer and use it in GitHub Desktop.
Python xmlrpclib client over Unix sockets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# | |
# Works for Python 2.4. Newer versions of Python changed xmlrpclib, a lot... | |
# | |
import httplib | |
import socket | |
import xmlrpclib | |
class UnixStreamHTTPConnection(httplib.HTTPConnection): | |
def connect(self): | |
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
self.sock.connect(self.socketpath) | |
class UnixStreamHTTP(httplib.HTTP): | |
_connection_class = UnixStreamHTTPConnection | |
def __init__(self, socketpath): | |
self.socketpath = socketpath | |
httplib.HTTP.__init__(self) | |
def _setup(self, conn): | |
httplib.HTTP._setup(self, conn) | |
self._conn.socketpath = self.socketpath | |
class UnixStreamTransport(xmlrpclib.Transport): | |
def __init__(self, socketpath): | |
self.socketpath = socketpath | |
def make_connection(self, host): | |
return UnixStreamHTTP(self.socketpath) | |
proxy = xmlrpclib.ServerProxy( | |
'http://', # just enough to keep ServerProxy happy | |
transport=UnixStreamTransport('/tmp/server.sock') | |
) | |
print proxy.echo('echo') | |
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment