@@ -67,9 +67,11 @@ def EncodeDecimal(o):
67
67
class AuthServiceProxy (object ):
68
68
__id_count = 0
69
69
70
- def __init__ (self , service_url , service_name = None , timeout = HTTP_TIMEOUT , connection = None ):
70
+ # ensure_ascii: escape unicode as \uXXXX, passed to json.dumps
71
+ def __init__ (self , service_url , service_name = None , timeout = HTTP_TIMEOUT , connection = None , ensure_ascii = True ):
71
72
self .__service_url = service_url
72
73
self ._service_name = service_name
74
+ self .ensure_ascii = ensure_ascii # can be toggled on the fly by tests
73
75
self .__url = urlparse .urlparse (service_url )
74
76
if self .__url .port is None :
75
77
port = 80
@@ -134,12 +136,12 @@ def __call__(self, *args):
134
136
AuthServiceProxy .__id_count += 1
135
137
136
138
log .debug ("-%s-> %s %s" % (AuthServiceProxy .__id_count , self ._service_name ,
137
- json .dumps (args , default = EncodeDecimal )))
139
+ json .dumps (args , default = EncodeDecimal , ensure_ascii = self . ensure_ascii )))
138
140
postdata = json .dumps ({'version' : '1.1' ,
139
141
'method' : self ._service_name ,
140
142
'params' : args ,
141
- 'id' : AuthServiceProxy .__id_count }, default = EncodeDecimal )
142
- response = self ._request ('POST' , self .__url .path , postdata )
143
+ 'id' : AuthServiceProxy .__id_count }, default = EncodeDecimal , ensure_ascii = self . ensure_ascii )
144
+ response = self ._request ('POST' , self .__url .path , postdata . encode ( 'utf-8' ) )
143
145
if response ['error' ] is not None :
144
146
raise JSONRPCException (response ['error' ])
145
147
elif 'result' not in response :
@@ -149,9 +151,9 @@ def __call__(self, *args):
149
151
return response ['result' ]
150
152
151
153
def _batch (self , rpc_call_list ):
152
- postdata = json .dumps (list (rpc_call_list ), default = EncodeDecimal )
154
+ postdata = json .dumps (list (rpc_call_list ), default = EncodeDecimal , ensure_ascii = self . ensure_ascii )
153
155
log .debug ("--> " + postdata )
154
- return self ._request ('POST' , self .__url .path , postdata )
156
+ return self ._request ('POST' , self .__url .path , postdata . encode ( 'utf-8' ) )
155
157
156
158
def _get_response (self ):
157
159
http_response = self .__conn .getresponse ()
@@ -167,7 +169,7 @@ def _get_response(self):
167
169
responsedata = http_response .read ().decode ('utf8' )
168
170
response = json .loads (responsedata , parse_float = decimal .Decimal )
169
171
if "error" in response and response ["error" ] is None :
170
- log .debug ("<-%s- %s" % (response ["id" ], json .dumps (response ["result" ], default = EncodeDecimal )))
172
+ log .debug ("<-%s- %s" % (response ["id" ], json .dumps (response ["result" ], default = EncodeDecimal , ensure_ascii = self . ensure_ascii )))
171
173
else :
172
174
log .debug ("<-- " + responsedata )
173
175
return response
0 commit comments