0001from simplejson import load, dump, loads, dumps
0002from httpencode.format import Format
0003
0004def dump_json_iter(data, content_type):
0005    return [dumps(data)]
0006
0007def load_json(fp, content_type):
0008    data = fp.read()
0009    # @@: For some reason simplejson is not liking \', even though
0010    # that seems entirely reasonable to me.  So we'll fix
0011    # it up:
0012    data = data.replace("\\'", "'")
0013    return loads(data)
0014
0015json = Format(
0016    'json', ['application/json', 'text/x-json'],
0017    type='python',
0018    dump_iter=dump_json_iter,
0019    load=load_json,
0020    secure=True,
0021    )