60
60
# Standard library
61
61
import contextlib
62
62
import logging
63
+ import os
63
64
import socket
64
65
import sys
65
66
import uuid
@@ -497,9 +498,15 @@ class UnixTransport(TransportMixIn, XMLTransport):
497
498
"""
498
499
Mixed-in HTTP transport over a UNIX socket
499
500
"""
500
- def __init__ (self , config ):
501
+ def __init__ (self , config , path = None ):
502
+ """
503
+ :param config: The jsonrpclib configuration
504
+ :param path: Path to the Unix socket (overrides the host name later)
505
+ """
501
506
TransportMixIn .__init__ (self , config )
502
507
XMLTransport .__init__ (self )
508
+ # Keep track of the given path, if any
509
+ self .__unix_path = os .path .abspath (path ) if path else None
503
510
504
511
def make_connection (self , host ):
505
512
"""
@@ -510,11 +517,15 @@ def make_connection(self, host):
510
517
511
518
Code copied from xmlrpc.client (Python 3)
512
519
513
- :param host: Target host
520
+ :param host: Target host (ignored if a path was given)
514
521
:return A UnixHTTPConnection object
515
522
"""
523
+ if self .__unix_path :
524
+ host = self .__unix_path
525
+
516
526
if self ._connection and host == self ._connection [0 ]:
517
527
return self ._connection [1 ]
528
+
518
529
# create a HTTP connection object from a host descriptor
519
530
path , self ._extra_headers , _ = self .get_host_info (host )
520
531
self ._connection = host , UnixHTTPConnection (path )
@@ -560,14 +571,21 @@ def __init__(self, uri, transport=None, encoding=None,
560
571
raise IOError ('Unsupported JSON-RPC protocol.' )
561
572
562
573
self .__host , self .__handler = splithost (uri )
563
- if not self .__handler :
574
+ if use_unix :
575
+ unix_path = self .__handler
576
+ self .__handler = '/'
577
+ elif not self .__handler :
564
578
# Not sure if this is in the JSON spec?
565
579
self .__handler = '/'
566
580
567
581
if transport is None :
568
582
if use_unix :
569
583
if schema == "http" :
570
- transport = UnixTransport (config = config )
584
+ # In Unix mode, we use the path part of the URL (handler)
585
+ # as the path to the socket file
586
+ transport = UnixTransport (
587
+ config = config , path = unix_path
588
+ )
571
589
elif schema == 'https' :
572
590
transport = SafeTransport (config = config , context = context )
573
591
else :
0 commit comments