equal
deleted
inserted
replaced
325 self.body.getvalue()) |
325 self.body.getvalue()) |
326 |
326 |
327 |
327 |
328 try: |
328 try: |
329 # may not be there if cubicweb-web not installed |
329 # may not be there if cubicweb-web not installed |
330 if sys.version_info < (2,6): |
330 if sys.version_info < (2, 6): |
331 import simplejson as json |
331 import simplejson as json |
332 else: |
332 else: |
333 import json |
333 import json |
334 except ImportError: |
334 except ImportError: |
335 pass |
335 json_dumps = None |
|
336 |
336 else: |
337 else: |
337 |
338 |
338 class CubicWebJsonEncoder(json.JSONEncoder): |
339 class CubicWebJsonEncoder(json.JSONEncoder): |
339 """define a json encoder to be able to encode yams std types""" |
340 """define a json encoder to be able to encode yams std types""" |
340 |
341 |
358 except TypeError: |
359 except TypeError: |
359 # we never ever want to fail because of an unknown type, |
360 # we never ever want to fail because of an unknown type, |
360 # just return None in those cases. |
361 # just return None in those cases. |
361 return None |
362 return None |
362 |
363 |
|
364 def json_dumps(value): |
|
365 return json.dumps(value, cls=CubicWebJsonEncoder) |
|
366 |
363 |
367 |
364 @deprecated('[3.7] merge_dicts is deprecated') |
368 @deprecated('[3.7] merge_dicts is deprecated') |
365 def merge_dicts(dict1, dict2): |
369 def merge_dicts(dict1, dict2): |
366 """update a copy of `dict1` with `dict2`""" |
370 """update a copy of `dict1` with `dict2`""" |
367 dict1 = dict(dict1) |
371 dict1 = dict(dict1) |