Don't serialize stings

This commit is contained in:
Honza Kral
2013-06-20 14:07:09 +02:00
parent 2c43cd0bd2
commit ba98e13da7
4 changed files with 9 additions and 2 deletions
+4
View File
@@ -16,6 +16,10 @@ class JSONSerializer(object):
raise SerializationError(e)
def dumps(self, data):
# don't serialize strings
if isinstance(data, (type(''), type(u''))):
return data
try:
return json.dumps(data, default=self.default)
except (ValueError, TypeError) as e:
+1 -1
View File
@@ -207,7 +207,7 @@ class Transport(object):
:arg body: body of the request, will be serializes using serializer and
passed to the connection
"""
if body:
if body is not None:
body = self.serializer.dumps(body)
for attempt in range(self.max_retries + 1):
+3
View File
@@ -15,3 +15,6 @@ class TestJSONSerializer(TestCase):
self.assertRaises(SerializationError, JSONSerializer().loads, object())
self.assertRaises(SerializationError, JSONSerializer().loads, '')
self.assertRaises(SerializationError, JSONSerializer().loads, '{{')
def test_strings_are_left_untouched(self):
self.assertEquals('Hello World!', JSONSerializer().dumps('Hello World!'))
+1 -1
View File
@@ -3,7 +3,7 @@ from unittest import TestCase
from elasticsearch.transport import Transport
from elasticsearch.connection import Connection
from elasticsearch.exceptions import TransportError, ConnectionError
from elasticsearch.exceptions import ConnectionError
class DummyConnection(Connection):
def __init__(self, **kwargs):