equal
deleted
inserted
replaced
62 if 'callback' in self._cw.form: # jsonp |
62 if 'callback' in self._cw.form: # jsonp |
63 json_padding = self._cw.form['callback'].encode('ascii') |
63 json_padding = self._cw.form['callback'].encode('ascii') |
64 # use ``application/javascript`` if ``callback`` parameter is |
64 # use ``application/javascript`` if ``callback`` parameter is |
65 # provided, keep ``application/json`` otherwise |
65 # provided, keep ``application/json`` otherwise |
66 self._cw.set_content_type('application/javascript') |
66 self._cw.set_content_type('application/javascript') |
67 json_data = b'%s(%s)' % (json_padding, json_data) |
67 json_data = json_padding + b'(' + json_data + b')' |
68 return json_data |
68 return json_data |
69 |
69 |
70 |
70 |
71 class JsonMixIn(object): |
71 class JsonMixIn(object): |
72 """mixin class for json views |
72 """mixin class for json views |
83 def wdata(self, data): |
83 def wdata(self, data): |
84 if '_indent' in self._cw.form: |
84 if '_indent' in self._cw.form: |
85 indent = int(self._cw.form['_indent']) |
85 indent = int(self._cw.form['_indent']) |
86 else: |
86 else: |
87 indent = None |
87 indent = None |
88 self.w(json_dumps(data, indent=indent)) |
88 # python's json.dumps escapes non-ascii characters |
|
89 self.w(json_dumps(data, indent=indent).encode('ascii')) |
89 |
90 |
90 |
91 |
91 class JsonRsetView(JsonMixIn, AnyRsetView): |
92 class JsonRsetView(JsonMixIn, AnyRsetView): |
92 """dumps raw result set in JSON format""" |
93 """dumps raw result set in JSON format""" |
93 __regid__ = 'jsonexport' |
94 __regid__ = 'jsonexport' |