Fake a response which looks like we get from all the other
 paths. The default response is a single array.
166734
def response_shim(body, status)
      resp, err_msg = parsed_response(body)

      { response: resp,
        status:   { result:  status == 200 ? 'OK' : 'ERROR',
                    message: err_msg,
                    code:    status } }.to_json
    end
182058
function (context, name, actual, expectedArray) {
		'use strict';
		for (let i = 0; i < expectedArray.length; i++) {
			if (actual === expectedArray[i]) {
				return;
			}
		}
		context.assert(
			{
				message: "the response did not contain a valid speechOutput",
				expected: "one of [" + expectedArray.map(text => `"${text}"`).join(', ') + "]",
				actual: actual,
				operator: "==", showDiff: true
			});
	}
662078
def build(self, response):
        
        response_json = response.json()

        # Special case for ticket audits.
        if get_endpoint_path(self.api, response).startswith('/ticket_audits.json'):
            return TicketAuditGenerator(self, response_json)

        zenpy_objects = self.deserialize(response_json)

        # Collection of objects (eg, users/tickets)
        plural_object_type = as_plural(self.api.object_type)
        if plural_object_type in zenpy_objects:
            return ZendeskResultGenerator(self, response_json, response_objects=zenpy_objects[plural_object_type])

        # Here the response matches the API object_type, seems legit.
        if self.api.object_type in zenpy_objects:
            return zenpy_objects[self.api.object_type]

        # Could be anything, if we know of this object then return it.
        for zenpy_object_name in self.object_mapping.class_mapping:
            if zenpy_object_name in zenpy_objects:
                return zenpy_objects[zenpy_object_name]

        # Maybe a collection of known objects?
        for zenpy_object_name in self.object_mapping.class_mapping:
            plural_zenpy_object_name = as_plural(zenpy_object_name)
            if plural_zenpy_object_name in zenpy_objects:
                return ZendeskResultGenerator(self, response_json, object_type=plural_zenpy_object_name)

        # Bummer, bail out.
        raise ZenpyException("Unknown Response: " + str(response_json))
724545
def init_original_response(self):
        """"""
        if 'json' in self.request:
            self.request['data'] = json.dumps(self.request.pop('json')).encode(
                self.encoding)
        r1 = self.req.request(
            retry=self.retry, timeout=self.timeout, **self.request)
        resp = r1.x
        assert resp, ValueError(
            'original_response should not be failed. %s' % self.request)
        self.encoding = self.encoding or resp.encoding
        self.original_response = self.ensure_response(r1)
        return self.original_response
1331703
def index(path=None):
    """"""
    payload = {
        "username": "soandso",
        "message": "Hello bot",
        "vars": {
            "name": "Soandso",
        }
    }
    return Response(r"""Usage: curl -i \
    -H "Content-Type: application/json" \
    -X POST -d '{}' \
    http://localhost:5000/reply""".format(json.dumps(payload)),
    mimetype="text/plain")
10791
function createResponse(request, response, body){
  return {
    statusCode: response.statusCode,
    statusText: response.statusMessage,
    headers: response.headers,
    originalUrl: request.url,
    effectiveUrl: request.url,
    redirected: false,
    requestMethod: request.method,
    requestHeaders: request.headers,
    body: body,
    retries: 0,
    throttled: false
  };
}
238129
def init_original_response(self):
        """"""
        no_cookie_resp = None
        self.is_cookie_necessary = True
        if 'json' in self.request:
            self.request['data'] = json.dumps(self.request.pop('json')).encode(
                self.encoding)
        r1 = self.req.request(
            retry=self.retry, timeout=self.timeout, **self.request)
        if 'headers' in self.request:
            # test is_cookie_necessary
            cookie = self.request['headers'].get('Cookie', None)
            if cookie:
                new_request = deepcopy(self.request)
                new_request['headers']['Cookie'] = ''
                r2 = self.req.request(
                    retry=self.retry, timeout=self.timeout, **new_request)
                no_cookie_resp = self.ensure_response(r2)
        resp = r1.x
        assert resp, ValueError(
            'original_response should not be failed. %s' % self.request)
        self.original_response = self.ensure_response(r1)
        self.encoding = self.encoding or resp.encoding
        if no_cookie_resp == self.original_response:
            self.ignore['headers'].append('Cookie')
            self.is_cookie_necessary = False
        return self.original_response
632773
def ProcessEntry(self, responses):
    """"""
    if not responses.success:
      return

    # The Find client action does not return a StatEntry but a
    # FindSpec. Normalize to a StatEntry.
    stat_responses = [
        r.hit if isinstance(r, rdf_client_fs.FindSpec) else r for r in responses
    ]

    # If this was a pure path matching call without any regex / recursion, we
    # know exactly which node in the component tree we have to process next and
    # get it from the component_path. If this was a regex match though, we
    # sent the client a combined regex that matches all nodes in order to save
    # round trips and client processing time. In that case we only get the
    # base node and have to check for all subnodes if the response actually
    # matches that subnode before we continue processing.
    component_path = responses.request_data.get("component_path")
    if component_path is not None:

      for response in stat_responses:
        self._ProcessResponse(response, [component_path])

    else:
      # This is a combined match.
      base_path = responses.request_data["base_path"]
      base_node = self.FindNode(base_path)
      for response in stat_responses:
        matching_components = []
        for next_node in base_node:
          pathspec = rdf_paths.PathSpec.FromSerializedString(next_node)

          if self._MatchPath(pathspec, response):
            matching_path = base_path + [next_node]
            matching_components.append(matching_path)

        if matching_components:
          self._ProcessResponse(
              response, matching_components, base_wildcard=True)
368807
def composite_response(responses)
      result = responses.all?(&:ok?) ? 'OK' : 'ERROR'
      summary = { sent: 0, rejected: 0, unsent: 0 }

      %i[sent rejected unsent].each do |k|
        summary[k] = responses.map { |r| r.response[k] }.inject(:+)
      end

      Wavefront::Response.new(
        { status:   { result: result, message: nil, code: nil },
          response: summary.to_h }.to_json, nil
      )
    end
608575
def stub_request(self, expected_url, filename, status=None, body=None):
        """"""
        self.fake_web = True
        self.faker = get_faker(expected_url, filename, status, body)
171629
function interceptIndex(request, response, next) {
	if (args.index === true && request.path === '/') {
		request.path = '/index.json';
	}
	return next();
}
930612
function mockResponseHeaders (req, res, next) {
  if (res.swagger) {
    util.debug("Setting %d response headers...", _.keys(res.swagger.headers).length);

    if (res.swagger.headers) {
      _.forEach(res.swagger.headers, (header, name) => {
        // Set all HTTP headers that are defined in the Swagger API.
        // If a default value is specified in the Swagger API, then use it; otherwise generate a value.
        if (res.get(name) !== undefined) {
          util.debug("    %s: %s (already set)", name, res.get(name));
        }
        else if (header.default !== undefined) {
          res.set(name, header.default);
          util.debug("    %s: %s (default)", name, header.default);
        }
        else {
          switch (name.toLowerCase()) {
            case "location":
              res.location(req.baseUrl + (res.swagger.location || req.path));
              break;
            case "last-modified":
              res.set(name, util.rfc1123(res.swagger.lastModified));
              break;
            case "content-disposition":
              res.set(name, 'attachment; filename="' + path.basename(res.swagger.location || req.path) + '"');
              break;
            case "set-cookie":
              // Generate a random "swagger" cookie, or re-use it if it already exists
              if (req.cookies.swagger === undefined) {
                res.cookie("swagger", _.uniqueId("random") + _.random(99999999999.9999));
              }
              else {
                res.cookie("swagger", req.cookies.swagger);
              }
              break;
            default:
              // Generate a sample value from the schema
              let sample = new JsonSchema(header).sample();
              if (_.isDate(sample)) {
                res.set(name, util.rfc1123(sample));
              }
              else {
                res.set(name, _(sample).toString());
              }
          }
          util.debug("    %s: %s", name, res.get(name));
        }
      });
    }
  }

  next();
}
327741
def response_as_single(self, copy=0):
        
        arr = []
        for sid, frame in self.response.iteritems():
            if copy:
                frame = frame.copy()
            'security' not in frame and frame.insert(0, 'security', sid)
            arr.append(frame.reset_index().set_index(['date', 'security']))
        return concat(arr).unstack()
1113819
def middleware(func):
    
    @wraps(func)
    def parse(*args, **kwargs):
        """ get middleware from route, execute middleware in order """
        middleware = copy.deepcopy(kwargs['middleware'])
        kwargs.pop('middleware')
        if request.method == "OPTIONS":
            # return 200 json response for CORS
            return JsonResponse(200)
        if middleware is None:
            return func(*args, **kwargs)
        for mware in middleware:
            ware = mware()
            if ware.status is False:
                return ware.response
            return func(*args, **kwargs)
    return parse
1112214
def handle_response(self, content, target=None, single_result=True, raw=False):
        
        response = content['response']

        self.check_errors(response)

        data = response.get('data')

        if is_empty(data):
            return data
        elif is_paginated(data):
            if 'count' in data and not data['count']:
                # Response is paginated, but is empty
                return data['data']
            data = data['data']

        if raw:
            return data
        return self.init_all_objects(data, target=target, single_result=single_result)
958783
def _unwrap_response_single(cls, obj, wrapper=None):
        

        if wrapper is not None:
            return obj[cls._FIELD_RESPONSE][cls._INDEX_FIRST][wrapper]

        return obj[cls._FIELD_RESPONSE][cls._INDEX_FIRST]
596090
function (methodName) {
            var response = this.getResponseSchema(methodName),
                payloadName = this.getResponsePayloadName(methodName),
                isList = false;

            if (response.type !== "null") {
                if ((payloadName && response.properties[payloadName] && response.properties[payloadName].type === "array") ||
                        (response.type && response.type === "array")) {
                    isList = true;
                }
            }

            return isList;
        }