| | |
| | | |
| | | from pyramid.path import caller_package |
| | | |
| | | from pyramid.response import Response, _get_response_factory |
| | | from pyramid.response import _get_response_factory |
| | | from pyramid.threadlocal import get_current_registry |
| | | |
| | | # API |
| | |
| | | ``self.param_name`` is present in request.GET; otherwise returns |
| | | plain-JSON encoded string with content-type ``application/json``""" |
| | | def _render(value, system): |
| | | request = system['request'] |
| | | request = system.get('request') |
| | | default = self._make_default(request) |
| | | val = self.serializer(value, default=default, **self.kw) |
| | | callback = request.GET.get(self.param_name) |
| | | if callback is None: |
| | | ct = 'application/json' |
| | | body = val |
| | | else: |
| | | ct = 'application/javascript' |
| | | body = '%s(%s);' % (callback, val) |
| | | response = request.response |
| | | if response.content_type == response.default_content_type: |
| | | response.content_type = ct |
| | | ct = 'application/json' |
| | | body = val |
| | | if request is not None: |
| | | callback = request.GET.get(self.param_name) |
| | | if callback is not None: |
| | | ct = 'application/javascript' |
| | | body = '%s(%s);' % (callback, val) |
| | | response = request.response |
| | | if response.content_type == response.default_content_type: |
| | | response.content_type = ct |
| | | return body |
| | | return _render |
| | | |