42
42
import time
43
43
import urllib .parse
44
44
45
- USER_AGENT = "AuthServiceProxy/0.1"
46
-
47
45
HTTP_TIMEOUT = 30
46
+ USER_AGENT = "AuthServiceProxy/0.1"
48
47
49
48
log = logging .getLogger ("BitcoinRPC" )
50
49
@@ -70,7 +69,7 @@ class AuthServiceProxy(object):
70
69
def __init__ (self , service_url , service_name = None , timeout = HTTP_TIMEOUT , connection = None , ensure_ascii = True ):
71
70
self .__service_url = service_url
72
71
self ._service_name = service_name
73
- self .ensure_ascii = ensure_ascii # can be toggled on the fly by tests
72
+ self .ensure_ascii = ensure_ascii # can be toggled on the fly by tests
74
73
self .__url = urllib .parse .urlparse (service_url )
75
74
if self .__url .port is None :
76
75
port = 80
@@ -92,11 +91,9 @@ def __init__(self, service_url, service_name=None, timeout=HTTP_TIMEOUT, connect
92
91
# Callables re-use the connection of the original proxy
93
92
self .__conn = connection
94
93
elif self .__url .scheme == 'https' :
95
- self .__conn = http .client .HTTPSConnection (self .__url .hostname , port ,
96
- timeout = timeout )
94
+ self .__conn = http .client .HTTPSConnection (self .__url .hostname , port , timeout = timeout )
97
95
else :
98
- self .__conn = http .client .HTTPConnection (self .__url .hostname , port ,
99
- timeout = timeout )
96
+ self .__conn = http .client .HTTPConnection (self .__url .hostname , port , timeout = timeout )
100
97
101
98
def __getattr__ (self , name ):
102
99
if name .startswith ('__' ) and name .endswith ('__' ):
@@ -119,13 +116,13 @@ def _request(self, method, path, postdata):
119
116
self .__conn .request (method , path , postdata , headers )
120
117
return self ._get_response ()
121
118
except http .client .BadStatusLine as e :
122
- if e .line == "''" : # if connection was closed, try again
119
+ if e .line == "''" : # if connection was closed, try again
123
120
self .__conn .close ()
124
121
self .__conn .request (method , path , postdata , headers )
125
122
return self ._get_response ()
126
123
else :
127
124
raise
128
- except (BrokenPipeError ,ConnectionResetError ):
125
+ except (BrokenPipeError , ConnectionResetError ):
129
126
# Python 3.5+ raises BrokenPipeError instead of BadStatusLine when the connection was reset
130
127
# ConnectionResetError happens on FreeBSD with Python 3.4
131
128
self .__conn .close ()
@@ -135,8 +132,8 @@ def _request(self, method, path, postdata):
135
132
def get_request (self , * args , ** argsn ):
136
133
AuthServiceProxy .__id_count += 1
137
134
138
- log .debug ("-%s-> %s %s" % (AuthServiceProxy .__id_count , self ._service_name ,
139
- json .dumps (args , default = EncodeDecimal , ensure_ascii = self .ensure_ascii )))
135
+ log .debug ("-%s-> %s %s" % (AuthServiceProxy .__id_count , self ._service_name ,
136
+ json .dumps (args , default = EncodeDecimal , ensure_ascii = self .ensure_ascii )))
140
137
if args and argsn :
141
138
raise ValueError ('Cannot handle both named and positional arguments' )
142
139
return {'version' : '1.1' ,
@@ -157,7 +154,7 @@ def __call__(self, *args, **argsn):
157
154
158
155
def batch (self , rpc_call_list ):
159
156
postdata = json .dumps (list (rpc_call_list ), default = EncodeDecimal , ensure_ascii = self .ensure_ascii )
160
- log .debug ("--> " + postdata )
157
+ log .debug ("--> " + postdata )
161
158
return self ._request ('POST' , self .__url .path , postdata .encode ('utf-8' ))
162
159
163
160
def _get_response (self ):
@@ -184,9 +181,9 @@ def _get_response(self):
184
181
response = json .loads (responsedata , parse_float = decimal .Decimal )
185
182
elapsed = time .time () - req_start_time
186
183
if "error" in response and response ["error" ] is None :
187
- log .debug ("<-%s- [%.6f] %s" % (response ["id" ], elapsed , json .dumps (response ["result" ], default = EncodeDecimal , ensure_ascii = self .ensure_ascii )))
184
+ log .debug ("<-%s- [%.6f] %s" % (response ["id" ], elapsed , json .dumps (response ["result" ], default = EncodeDecimal , ensure_ascii = self .ensure_ascii )))
188
185
else :
189
- log .debug ("<-- [%.6f] %s" % (elapsed ,responsedata ))
186
+ log .debug ("<-- [%.6f] %s" % (elapsed , responsedata ))
190
187
return response
191
188
192
189
def __truediv__ (self , relative_uri ):
0 commit comments