View | Details | Raw Unified | Return to bug 33520
Collapse All | Expand All

(-)message.py (-1 / +19 lines)
 Lines 116-122    Link Here 
116
		if _type == Message.REQUEST:
116
		if _type == Message.REQUEST:
117
			type = 'REQUEST'
117
			type = 'REQUEST'
118
		if mimetype == MIMETYPE_JSON:
118
		if mimetype == MIMETYPE_JSON:
119
			data = json.dumps( body )
119
			try:
120
				data = json.dumps( body )
121
			except UnicodeDecodeError:
122
				data = json.dumps(_fix_encoding(body))
120
		else:
123
		else:
121
			data = body
124
			data = body
122
		args = ''
125
		args = ''
 Lines 316-321    Link Here 
316
			del body['options']
319
			del body['options']
317
		return Message._formattedMessage(self._id, self._type, self.mimetype, self.command, body, self.arguments)
320
		return Message._formattedMessage(self._id, self._type, self.mimetype, self.command, body, self.arguments)
318
321
322
323
def _fix_encoding(data):
324
	if isinstance(data, bytestring):
325
		try:
326
			data.decode('utf-8')
327
		except UnicodeDecodeError:
328
			data = data.decode('iso8859-1').encode('utf-8')
329
	elif isinstance(data, (list, tuple)):
330
		data = data.__class__(_fix_encoding(d) for d in data)
331
	elif isinstance(data, dict):
332
		data = data.__class__((_fix_encoding(k), _fix_encoding(v)) for k, v in data.iteritems())
333
334
	return data
335
336
319
if __name__ == '__main__':
337
if __name__ == '__main__':
320
	# encode
338
	# encode
321
	auth = Request( 'AUTH' )
339
	auth = Request( 'AUTH' )

Return to bug 33520