def json_responsed(*args, **kwargs): req = args[0] retval = func(*args, **kwargs) if not isinstance(retval, HttpResponse): charset = req.META.get('HTTP_ACCEPT_CHARSET', 'utf-8') try: #ignore request charset since it might request *, which is not valid #charsets = parse_charsets(charset) charsets = [] content = simplejson.dumps(retval, ensure_ascii=False, default=unicode) content, charset = try_encode(content, charsets, 'utf-8') response = HttpResponse( content, content_type='application/json; charset=%s' % charset) except ValueError, err: _LOGGER.error(err) return internal_server_error(req, err, exc_info=sys.exc_info()) except Exception, err: _LOGGER.error('failed to convert encoding: %s' % err, exc_info=1) return internal_server_error(req, 'Unexpected error happened.', exc_info=sys.exc_info())
def _obscure_json_response(*args, **kwargs): req = args[0] https_req, error = get_optional_parameter(req, 'https', default=0, formatter=int) if error: https_req = 1 retval = func(*args, **kwargs) if not isinstance(retval, HttpResponse): charset = req.META.get('HTTP_ACCEPT_CHARSET', 'utf-8') try: charsets = parse_charsets(charset) content = simplejson.dumps(retval, ensure_ascii=False) content, charset = try_encode(content, charsets, 'utf-8') if https_req < 1: #only obscure response for request without https content = obscure(content) response = HttpResponse( content, content_type='application/json; charset=%s' % charset) except ValueError, err: _LOGGER.error(err) return internal_server_error(req, err, exc_info=sys.exc_info()) except Exception, err: _LOGGER.error('failed to convert encoding: %s' % err, exc_info=1) return internal_server_error(req, 'Unexpected error happened.', exc_info=sys.exc_info())
def json_responsed(*args, **kwargs): req = args[0] retval = func(*args, **kwargs) if not isinstance(retval, HttpResponse): charset = req.META.get('HTTP_ACCEPT_CHARSET', 'utf-8') try: #ignore request charset since it might request *, which is not valid #charsets = parse_charsets(charset) charsets = [] content = simplejson.dumps(retval, ensure_ascii=False, default=unicode) content, charset = try_encode(content, charsets, 'utf-8') response = HttpResponse(content, content_type='application/json; charset=%s' % charset) except ValueError, err: _LOGGER.error(err) return internal_server_error(req, err, exc_info=sys.exc_info()) except Exception, err: _LOGGER.error('failed to convert encoding: %s' % err, exc_info=1) return internal_server_error(req, 'Unexpected error happened.', exc_info=sys.exc_info())
def _obscure_json_response(*args, **kwargs): req = args[0] https_req, error = get_optional_parameter(req, 'https', default=0, formatter=int) if error: https_req = 1 retval = func(*args, **kwargs) if not isinstance(retval, HttpResponse): charset = req.META.get('HTTP_ACCEPT_CHARSET', 'utf-8') try: charsets = parse_charsets(charset) content = simplejson.dumps(retval, ensure_ascii=False) content, charset = try_encode(content, charsets, 'utf-8') if https_req < 1: #only obscure response for request without https content = obscure(content) response = HttpResponse(content, content_type='application/json; charset=%s' % charset) except ValueError, err: _LOGGER.error(err) return internal_server_error(req, err, exc_info=sys.exc_info()) except Exception, err: _LOGGER.error('failed to convert encoding: %s' % err, exc_info=1) return internal_server_error(req, 'Unexpected error happened.', exc_info=sys.exc_info())