Returns a Flask response object for the specified data and HTTP status.
768188
def getFlaskResponse(responseString, httpStatus=200):
    
    return flask.Response(responseString, status=httpStatus, mimetype=MIMETYPE)
1236961
def json_response(self, status=200, data={}, headers={}):
        '''
          
        '''
        mimetype = 'application/json'

        header_dict = {}
        for k, v in headers.items():
            header_dict[k] = v

        return Response(
            json.dumps(data),
            status=status,
            mimetype=mimetype,
            headers=header_dict)
225443
def jsonp_response(data, callback="f", status=200, serializer=None):
    
    val = json.dumps(data, default=serializer)
    ret = "{callback}('{val}');".format(callback=callback, val=val)

    return HttpResponse(ret,
                        status=status,
                        content_type='application/x-javascript; charset=UTF-8')
483435
def _api_response(response):
    '''
    
    '''
    if response.status_code == 404:
        __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
        raise CommandExecutionError('Element doesn\'t exists')
    if response.status_code == 401:
        __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
        raise CommandExecutionError('Bad username or password')
    elif response.status_code == 200 or response.status_code == 500:
        try:
            data = salt.utils.json.loads(response.content)
            if data['exit_code'] != 'SUCCESS':
                __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
                raise CommandExecutionError(data['message'])
            return data
        except ValueError:
            __context__['retcode'] = salt.defaults.exitcodes.SALT_BUILD_FAIL
            raise CommandExecutionError('The server returned no data')
    else:
        response.raise_for_status()
503533
def create_response(
        self, data: dict = None, response: requests.Response = None, errors: list = None
    ) -> Response:
        
        status = FAILURE_STATUS if errors else SUCCESS_STATUS
        return Response(
            status=status,
            provider=self.name,
            data=data,
            response=response,
            errors=errors,
        )
60844
def build_response(
            self,
            status=NOT_SET,
            error="",
            data=None):
        

        res_node = {
            "status": status,
            "error": error,
            "data": data
        }
        return res_node
544475
def _get_response(self, endpoint, query, is_post=False):
        """"""
        timeout_secs = self._settings.get('timeout', 10)
        headers = self._settings.get('request_headers', {})
        try:
            if is_post:
                response = requests.post(
                    endpoint, data=query, headers=headers, timeout=timeout_secs)
            else:
                response = requests.get(
                    endpoint, params=query, headers=headers, timeout=timeout_secs)
        except requests.exceptions.Timeout as e:
            raise Exception(
                'API request timed out after %s seconds.' % timeout_secs)
        except Exception as e:
            raise e

        if response.status_code != 200:
            raise Exception('Received status code %s from %s. Content is:\n%s'
                            % (response.status_code,
                               self.get_service_name(),
                               response.text))
        return response
1246945
def response(cls, dic, status=200):
        
        response = JsonResponse(dic, status=status)
        response['Cache-Control'] = 'no-store'
        response['Pragma'] = 'no-cache'

        return response
470590
def parse_response(self, response):
        
        status = response.status_code
        if response.ok:
            data = response.json()
            return HttpResponse(ok=response.ok, status=status, errors=None, data=data)
        else:
            try:
                errors = response.json()
            except ValueError:
                errors = response.content
            return HttpResponse(ok=response.ok, status=status, errors=errors, data=None)
930103
def getresponse(self):
        
        resp = self.http.getresponse()
        self.log.info("resp is %s", str(resp))
        if resp.status < 400:
            return resp
        else:
            errtext = resp.read()
            content_type = resp.getheader('Content-Type', 'text/plain')
            raise HttpError(code=resp.status, content_type=content_type, content=errtext)
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)
766839
def _req(self, endpoint, get_data=dict(), post_data=dict()):

        

        if get_data:
            request_parameter = "{}?{}".format(endpoint, urlencode(get_data))
        else:
            request_parameter = endpoint

        try:
            encdata = urlencode(post_data, True).encode('utf-8')
            response = self.oauth.request(request_parameter, data=encdata)
            self._checkResponseForErrors(response)
        except HTTPError as e:
            raise DeviantartError(e)

        return response
978259
def post(self, url, data, params=None):
        
        r = self.session.post(url, data=data, params=params)
        return self._response_parser(r, expect_json=False)
183257
def _request(self, method, url, query_or_data=None, **kwargs):
        

        if query_or_data is None:
            query_or_data = {}

        request_method = getattr(self, '_http_{0}'.format(method))
        response = retry_request(self)(request_method)(url, query_or_data, **kwargs)

        if self.raw_mode:
            return response

        if response.status_code >= 300:
            error = get_error(response)
            if self.raise_errors:
                raise error
            return error

        # Return response object on NoContent
        if response.status_code == 204 or not response.text:
            return response

        return ResourceBuilder(
            self,
            self.default_locale,
            response.json()
        ).build()
295091
def handleResponse(self, data):
        """"""

        self.factory.response_xml = data

        if self.status == '200':
            self.factory.parseErrorAndResponse(data)

        self.factory.deferred = None
        self.transport.loseConnection()
161230
function(data) {
    var h, headerArray, headers, i, l, len, o;
    headers = {};
    headerArray = data.getAllResponseHeaders().split('\r');
    for (l = 0, len = headerArray.length; l < len; l++) {
      i = headerArray[l];
      h = i.match(/^([^:]*?):(.*)$/);
      if (!h) {
        h = [];
      }
      h.shift();
      if (h[0] !== void 0 && h[1] !== void 0) {
        headers[h[0].trim()] = h[1].trim();
      }
    }
    o = {};
    o.content = {};
    o.content.data = data.responseText;
    o.headers = headers;
    o.request = {};
    o.request.url = this.invocationUrl;
    o.status = data.status;
    return o;
  }
81620
def post(self, url, data, headers={}):
        
        response = self._run_method('POST', url, data=data, headers=headers)
        return self._handle_response(url, response)