Return a dict of data to log for a given request and response.

        Override this method if you need to log a different set of values.
331486
def get_log(self, request, response):
        
        return {
            'method': request.method,
            'path': request.get_full_path(),
            'code': response.status_code,
            'time': time.time(),
        }
1223115
def request(method, url, **kwargs):
    """"""
    _set_content_type(kwargs)
    if _content_type_is_json(kwargs) and kwargs.get('data') is not None:
        kwargs['data'] = dumps(kwargs['data'])
    _log_request(method, url, kwargs)
    response = requests.request(method, url, **kwargs)
    _log_response(response)
    return response
1364987
def parse_info(response):
    ''''''
    info = {}
    response = response.decode('utf-8')

    def get_value(value):
        if ',' and '=' not in value:
            return value
        sub_dict = {}
        for item in value.split(','):
            k, v = item.split('=')
            try:
                sub_dict[k] = int(v)
            except ValueError:
                sub_dict[k] = v
        return sub_dict
    data = info
    for line in response.splitlines():
        keyvalue = line.split(':')
        if len(keyvalue) == 2:
            key, value = keyvalue
            try:
                data[key] = int(value)
            except ValueError:
                data[key] = get_value(value)
        else:
            data = {}
            info[line[2:]] = data
    return info
727031
def __respond_with_dict(self, data):
        
        response = {}
        if isinstance(data, list):
            temp_data, data = data, {}
            for key, value in enumerate(temp_data):
                data[key] = value

        data.pop('seq', None)
        for index, item in data.items():
            values = item
            if isinstance(item, list) or isinstance(item, dict):
                values = self.__respond_with_dict(item)

            if isinstance(values, dict) and len(values) == 1:
                (key, values), = values.items()
            response[index] = values

        return response
538073
def metadata(self):
        
        resp = self.r_session.get(self.server_url)
        resp.raise_for_status()
        return response_to_json_dict(resp)
1015309
def _get_response(**kwargs):
    
    if 'code' not in kwargs:
        kwargs['code'] = 200
    if 'headers' not in kwargs:
        kwargs['headers'] = dict()
    if 'version' not in kwargs:
        kwargs['version'] = 'HTTP/1.1'

    return dict(**kwargs)
372698
def to_requests(self, method='get'):
        
        out = {}
        data_key = 'params' if method.lower() == 'get' else 'data'
        out[data_key] = self.data
        out.update(self.options)
        return dict([
            (key, list(value.items(multi=True)))
            for key, value in iteritems(out)
        ])
540260
def calc_log(request, calc_id, start, stop):
    
    start = start or 0
    stop = stop or 0
    try:
        response_data = logs.dbcmd('get_log_slice', calc_id, start, stop)
    except dbapi.NotFound:
        return HttpResponseNotFound()
    return HttpResponse(content=json.dumps(response_data), content_type=JSON)
477963
def logs(self):
        """"""
        url = self._url + "/logs"
        return _log(url=url,
                    securityHandler=self._securityHandler,
                    proxy_url=self._proxy_url,
                    proxy_port=self._proxy_port)
993357
def fetch_post_data(self):
        '''
        
        '''
        post_data = {}
        ext_dic = {}
        for key in self.request.arguments:
            if key.startswith('def_'):
                ext_dic[key] = self.get_argument(key)
            else:
                post_data[key] = self.get_arguments(key)[0]

        post_data['user_name'] = self.userinfo.user_name

        ext_dic = dict(ext_dic, **self.ext_post_data(postdata=post_data))

        return (post_data, ext_dic)
506908
def _process_response(self):
        
        response = self.conn.getresponse()
        if response.status == 200 or response.status == 201:
            data = response.read()
        else:
            data = {
                "error":  {
                    "code": response.status,
                    "reason": response.reason,
                    "data": response.read()
                }
            }

        return data
1014695
def _request_process_json_standard(self, response_data):
        
        data = response_data.get('data', {}).get(self.request_entity, [])
        status = response_data.get('status', 'Failure')
        return data, status
677952
def log(request):
    
    if request.method == "POST":
        log_dict = json_body(request.body.decode("utf-8"))
        if 'message' not in log_dict:
            return HttpResponseBadRequest('There is no message to log!')
        levels = {
            'debug': JAVASCRIPT_LOGGER.debug,
            'info': JAVASCRIPT_LOGGER.info,
            'warn': JAVASCRIPT_LOGGER.warn,
            'error': JAVASCRIPT_LOGGER.error,
        }
        log_fun = JAVASCRIPT_LOGGER.info
        if 'level' in log_dict:
            log_fun = levels[log_dict['level']]
        log_fun(log_dict['message'], extra={
            'request': request,
            'user': request.user.id if request.user.is_authenticated() else None,
            'client_data': json_lib.dumps(log_dict.get('data', {})),
        })
        return HttpResponse('ok', status=201)
    else:
        return render_json(request, {}, template='common_log_service.html', help_text=log.__doc__)
144662
def log_request(self, handler):
        
        packet = {'method': handler.request.method,
                  'uri': handler.request.uri,
                  'remote_ip': handler.request.remote_ip,
                  'status': handler.get_status(),
                  'request_time_ms': handler.request.request_time() * 1000.0,
                  'service_id': self.service_id,
                  'request_id': handler.request.headers.get(REQUEST_ID_HEADER,
                                                            'undefined')
                  }

        # handler can optionally define additional data to log
        if hasattr(handler, 'logvalues'):
            for key, value in handler.logvalues.iteritems():
                packet[key] = value

        servicelog.log(packet)

        metric = "requests." + str(handler.get_status())
        metrics.timing(metric, handler.request.request_time() * 1000.0)

        super(LoggingApplication, self).log_request(handler)
153388
def _get_responses(cls, requests, dispatcher):
        
        for request in requests:
            def response(**kwargs):
                return cls.RESPONSE_CLASS_MAP[request.JSONRPC_VERSION](
                    _id=request._id, **kwargs)

            try:
                method = dispatcher[request.method]
            except KeyError:
                output = response(error=JSONRPCMethodNotFound()._data)
            else:
                try:
                    result = method(*request.args, **request.kwargs)
                except JSONRPCDispatchException as e:
                    output = response(error=e.error._data)
                except Exception as e:
                    data = {
                        "type": e.__class__.__name__,
                        "args": e.args,
                        "message": str(e),
                    }
                    if isinstance(e, TypeError) and is_invalid_params(
                            method, *request.args, **request.kwargs):
                        output = response(
                            error=JSONRPCInvalidParams(data=data)._data)
                    else:
                        # logger.exception("API Exception: {0}".format(data))
                        print("API Exception: {0}".format(data))
                        output = response(
                            error=JSONRPCServerError(data=data)._data)
                else:
                    output = response(result=result)
            finally:
                if not request.is_notification:
                    yield output
823291
def get_paginated_response(self, data):
        
        metadata = {
            'next': self.get_next_link(),
            'previous': self.get_previous_link(),
            'count': self.get_result_count(),
            'num_pages': self.get_num_pages(),
        }
        if isinstance(data, dict):
            if 'results' not in data:
                raise TypeError(u'Malformed result dict')
            data['pagination'] = metadata
        else:
            data = {
                'results': data,
                'pagination': metadata,
            }
        return Response(data)
1220670
def route(self, data):
        
        if isinstance(data, (dict, list)):
            requests = data
        else:
            requests = json.loads(data)
        if not isinstance(requests, list):
            requests = [requests]
        responses = []
        for request in requests:
            responses.append(self.call(request))
        if len(responses) == 1:
            return json.dumps(responses[0])
        return json.dumps(responses)