Skip to content

Commit e321f64

Browse files
committed
Support unix:/foo/bar URLs for the client
1 parent 58b2e39 commit e321f64

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

jsonrpclib/jsonrpc.py

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,23 @@ class Transport(TransportMixIn, XMLTransport):
144144

145145
class SafeTransport(TransportMixIn, XMLSafeTransport):
146146
pass
147+
148+
from httplib import HTTP, HTTPConnection
149+
from socket import socket, AF_UNIX, SOCK_STREAM
150+
class UnixHTTPConnection(HTTPConnection):
151+
def connect(self):
152+
self.sock = socket(AF_UNIX, SOCK_STREAM)
153+
self.sock.connect(self.host)
154+
155+
class UnixHTTP(HTTP):
156+
_connection_class = UnixHTTPConnection
157+
158+
class UnixTransport(TransportMixIn, XMLTransport):
159+
def make_connection(self, host):
160+
import httplib
161+
host, extra_headers, x509 = self.get_host_info(host)
162+
return UnixHTTP(host)
163+
147164

148165
class ServerProxy(XMLServerProxy):
149166
"""
@@ -158,15 +175,21 @@ def __init__(self, uri, transport=None, encoding=None,
158175
version = config.version
159176
self.__version = version
160177
schema, uri = urllib.splittype(uri)
161-
if schema not in ('http', 'https'):
178+
if schema not in ('http', 'https', 'unix'):
162179
raise IOError('Unsupported JSON-RPC protocol.')
163-
self.__host, self.__handler = urllib.splithost(uri)
164-
if not self.__handler:
165-
# Not sure if this is in the JSON spec?
166-
#self.__handler = '/'
167-
self.__handler == '/'
180+
if schema == 'unix':
181+
self.__host = uri
182+
self.__handler = '/'
183+
else:
184+
self.__host, self.__handler = urllib.splithost(uri)
185+
if not self.__handler:
186+
# Not sure if this is in the JSON spec?
187+
#self.__handler = '/'
188+
self.__handler == '/'
168189
if transport is None:
169-
if schema == 'https':
190+
if schema == 'unix':
191+
transport = UnixTransport()
192+
elif schema == 'https':
170193
transport = SafeTransport()
171194
else:
172195
transport = Transport()

0 commit comments

Comments
 (0)