Skip to content

Commit 526b862

Browse files
committed
BaseProxy: allow to specify custom connection
This allows to handle disconnects and reconnections outside the library, by supplying your own connection object instead of httplib.HTTPConnection
1 parent 05cbb3c commit 526b862

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

bitcoin/rpc.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ def __init__(self,
123123
service_url=None,
124124
service_port=None,
125125
btc_conf_file=None,
126-
timeout=DEFAULT_HTTP_TIMEOUT):
126+
timeout=DEFAULT_HTTP_TIMEOUT,
127+
connection=None):
127128

128129
# Create a dummy connection early on so if __init__() fails prior to
129130
# __conn being created __del__() can detect the condition and handle it
@@ -204,8 +205,11 @@ def __init__(self,
204205
authpair = authpair.encode('utf8')
205206
self.__auth_header = b"Basic " + base64.b64encode(authpair)
206207

207-
self.__conn = httplib.HTTPConnection(self.__url.hostname, port=port,
208-
timeout=timeout)
208+
if connection:
209+
self.__conn = connection
210+
else:
211+
self.__conn = httplib.HTTPConnection(self.__url.hostname, port=port,
212+
timeout=timeout)
209213

210214
def _call(self, service_name, *args):
211215
self.__id_count += 1

0 commit comments

Comments
 (0)