Make a standard "success" response,
        which contains some ancilliary data.

        Also, detect if this node is too far behind the Bitcoin blockchain,
        and if so, convert this into an error message.
508387
def success_response(self, method_resp, **kw):
        
        resp = {
            'status': True,
            'indexing': config.is_indexing(self.working_dir),
            'lastblock': virtualchain_hooks.get_last_block(self.working_dir),
        }

        resp.update(kw)
        resp.update(method_resp)
        
        if self.is_stale():
            # our state is stale
            resp['stale'] = True
            resp['warning'] = 'Daemon has not reindexed since {}'.format(self.last_indexing_time)

        return resp
608825
def decrypt_result(self, *args, **kwargs):
        
        if self.response is None:
            raise ValueError('Empty response')
        if self.response.response is None \
                or 'result' not in self.response.response \
                or self.response.response['result'] is None:
            raise ValueError('No result data')

        res_hex = self.response.response['result']

        # Strip out the plaintext part
        plain_length = bytes_to_long(from_hex(res_hex[0:4]))
        if plain_length > 0:
            res_hex = res_hex[4 + plain_length:]
        else:
            res_hex = res_hex[4:]

        # Optionally strip trailing _... string
        idx_trail = res_hex.find('_')
        if idx_trail != -1:
            res_hex = res_hex[0:idx_trail]

        # Decode hex coding
        res_bytes = from_hex(res_hex)

        # Crypto stuff - check the length & padding
        if len(res_bytes) < 16:
            raise InvalidResponse('Result too short')

        mac_given = res_bytes[-16:]
        res_bytes = res_bytes[:-16]

        # Check the MAC
        mac_computed = cbc_mac(self.uo.mac_key, res_bytes)
        if not str_equals(mac_given, mac_computed):
            raise CryptoError('MAC invalid')

        # Decrypt
        decrypted = aes_dec(self.uo.enc_key, res_bytes)
        if len(decrypted) < 1 + 4 + 8 or decrypted[0:1] != bchr(0xf1):
            raise InvalidResponse('Invalid format')

        self.resp_object_id = bytes_to_long(decrypted[1:5])
        self.resp_nonce = EBUtils.demangle_nonce(decrypted[5:5 + EBConsts.FRESHNESS_NONCE_LEN])
        self.decrypted = decrypted[5 + EBConsts.FRESHNESS_NONCE_LEN:]
        self.decrypted = PKCS7.unpad(self.decrypted)
        return self.response
1028612
@Override
    protected void haveResponse ( byte[] buffer, int start, int len ) throws SMBProtocolDecodingException {
        if ( isRetainPayload() ) {
            byte[] payload = new byte[len];
            System.arraycopy(buffer, start, payload, 0, len);
            setRawPayload(payload);
        }

        if ( !verifySignature(buffer, start, len) ) {
            throw new SMBProtocolDecodingException("Signature verification failed for " + getClass().getName());
        }

        setAsyncHandled(false);
        received();
    }
1020605
def _response_good(self, respond):
        
        if respond.status_code != requests.codes.ok:
            log.warning('Got a {} code response to {}: {}'.format(
                respond.status_code,
                respond.url,
                respond.text))
            if respond.status_code in self.errorsNotRetry:
              raise ApiError(usr_msg='Got a {} code response to {}: {}'.format(
                respond.status_code,
                respond.url,
                respond.text))
            else:
              return self._parse_response(respond)
        try:
            if (str(respond.headers['content-type']).startswith("text/html;")):
                self.result = respond.text
                return True
            else:
                self.result = respond.json()
        except (json.JSONDecodeError, ValueError):
            usr_msg = 'device server returned unexpected http response'
            dev_msg = usr_msg + ': ' + respond.text
            raise ApiError(usr_msg=usr_msg, dev_msg=dev_msg)
        if not isinstance(self.result, (list, dict)):
            msg = ('JSON not a list or dict: url: {0},'
                   'status: {1}, reason: {2}, text: {3}')
            raise ApiError(
                usr_msg=msg.format(respond.url,
                                   respond.status_code,
                                   respond.reason, respond.text))
        if ('error' not in self.result or
                ('status' not in self.result['error'] or
                 self.result['error']['status'] != 400)):
            return True
        else:
            log.warning("Got a 400 code JSON response to %s", respond.url)
            return False
244005
function () {
    const oThis = this
    ;

    const web3Object = new Web3();
    var newAddress = web3Object.eth.accounts.create(web3Object.utils.randomHex(32));

    return responseHelper.successWithData({address: newAddress.address, privateKey: newAddress.privateKey});
  }
282369
def build_api_error(response, blob=None):
    
    try:
        blob = blob or response.json()
    except json.JSONDecodeError:
        blob = {}
    error_list = blob.get('errors', None)
    error = (error_list[0] if error_list else {})
    if error:
        error_id = error.get('id', '')
        error_message = error.get('message', '')
    else:
        # In the case of an OAuth-specific error, the response data is the error
        # blob, and the keys are slightly different. See
        # https://developers.coinbase.com/api/v2#error-response
        error_id = blob.get('error')
        error_message = blob.get('error_description')
    error_class = (
        _error_id_to_class.get(error_id, None) or
        _status_code_to_class.get(response.status_code, APIError))
    return error_class(response, error_id, error_message, error_list)
980876
def make_response(status, headers, payload, environ):
    
    headers_dict = {}
    content_type = None
    for h in headers:
        if h[0].lower() == 'content-type':
            content_type = h[1]
        else:
            headers_dict[h[0]] = h[1]
    return HTTPResponse(body_bytes=payload, content_type=content_type,
                        status=int(status.split()[0]), headers=headers_dict)
1271959
def _handle_produce_response(self, node_id, send_time, batches, response):
        """"""
        # if we have a response, parse it
        log.debug('Parsing produce response: %r', response)
        if response:
            batches_by_partition = dict([(batch.topic_partition, batch)
                                         for batch in batches])

            for topic, partitions in response.topics:
                for partition_info in partitions:
                    if response.API_VERSION < 2:
                        partition, error_code, offset = partition_info
                        ts = None
                    else:
                        partition, error_code, offset, ts = partition_info
                    tp = TopicPartition(topic, partition)
                    error = Errors.for_code(error_code)
                    batch = batches_by_partition[tp]
                    self._complete_batch(batch, error, offset, ts)

            if response.API_VERSION > 0:
                self._sensors.record_throttle_time(response.throttle_time_ms, node=node_id)

        else:
            # this is the acks = 0 case, just complete all requests
            for batch in batches:
                self._complete_batch(batch, None, -1, None)
390073
def success(self, **kwargs):
        """"""
        response = {'success': True}
        # check dates can be manipulated
        response.update(kwargs)
        response.update(self.kwargs)
        response['test_argument3'] = datetime.timedelta(days=1) + response['test_argument3']
        return response
1257744
def _request_process_octet(response):
        
        status = 'Failure'
        # Handle document download
        data = response.content
        if data:
            status = 'Success'

        return data, 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,
        )
507991
def from_post_response(post_response, content):
        '''
        
        '''
        response = OutcomeResponse()
        response.post_response = post_response
        response.response_code = post_response.status
        response.process_xml(content)
        return response
1033390
def json_success_response(data, response):
    
    response.body = json.dumps(data)
    response.status_code = 200

    response.add_header("Content-Type", "application/json")
    response.add_header("Cache-Control", "no-store")
    response.add_header("Pragma", "no-cache")
444429
def make_response(message, status_code, details=None):
    """"""
    response_body = dict(message=message)
    if details:
        response_body['details'] = details
    response = jsonify(response_body)
    response.status_code = status_code
    return response
553977
def success(headers = None, data = ''):
    
    passed_headers = {} if headers is None else headers
    if isinstance(data, dict): data = json.dumps(data)
    ret_headers = {'status' : 'ok'}
    ret_headers.update(passed_headers)
    return server_responce(ret_headers, data)
290628
def post(self, title, body, permlink, tags):
        ''' 
        '''
        for num_of_retries in range(default.max_retry):
            try:
                self.msg.message("Attempting to post " + permlink)
                self.steem_instance().post(title, 
                                            body, 
                                            self.mainaccount, 
                                            permlink, 
                                            None, None, None, None, 
                                            tags, None, False)   
            except Exception as e:
                self.util.retry("COULD NOT POST '" + title + "'", 
                    e, num_of_retries, 10)
                self.s = None
            else:
                self.msg.message("Post seems successful. Wating 60 seconds before verifying...")
                self.s = None
                time.sleep(60)
                checkident = self.recent_post()
                ident = self.util.identifier(self.mainaccount, permlink)
                if checkident == ident:
                    return True
                else:
                    self.util.retry('A POST JUST CREATED WAS NOT FOUND IN THE '
                                    + 'BLOCKCHAIN {}'''.format(title), 
                                    "Identifiers do not match", 
                                    num_of_retries, default.wait_time)
                    self.s = None
1317018
def check_answer(self, hash_answer):
        
        for challenge in self.challenges:
            if challenge.response == hash_answer:
                # If we don't discard a used challenge then a node
                # could fake having the file because it already
                # knows the proper response
                self.delete_challenge(hash_answer)
                return True
        return False