Skip to content

Commit 145583d

Browse files
author
Sean Cribbs
committed
Merge pull request basho#205 from Atilla/proper_json
Switching JSON encoding to UTF-8.
2 parents f25f4a2 + a9fdf11 commit 145583d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

riak/client/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
from riak.util import lazy_property
3939

4040

41+
def default_encoder(obj):
42+
"""
43+
Default encoder for JSON datatypes, which returns UTF-8 encoded
44+
json instead of the default bloated \uXXXX escaped ASCII strings.
45+
"""
46+
return json.dumps(obj, ensure_ascii=False).encode("utf-8")
47+
48+
4149
@deprecateQuorumAccessors
4250
class RiakClient(RiakMapReduceChain, RiakClientOperations):
4351
"""
@@ -91,8 +99,8 @@ def __init__(self, protocol='http', transport_options={},
9199
self._http_pool = RiakHttpPool(self, **transport_options)
92100
self._pb_pool = RiakPbcPool(self, **transport_options)
93101

94-
self._encoders = {'application/json': json.dumps,
95-
'text/json': json.dumps}
102+
self._encoders = {'application/json': default_encoder,
103+
'text/json': default_encoder}
96104
self._decoders = {'application/json': json.loads,
97105
'text/json': json.loads}
98106
self._buckets = WeakValueDictionary()

0 commit comments

Comments
 (0)